chore(Core/Shared): little cleanup (#18385)

This commit is contained in:
Winfidonarleyan
2024-02-25 22:07:08 +07:00
committed by GitHub
parent 27da4554cf
commit 2a2cc3c22f
10 changed files with 25 additions and 37 deletions
@@ -39,7 +39,7 @@ char* DBCDatabaseLoader::Load(uint32& records, char**& indexTable)
std::string query = Acore::StringFormat("SELECT * FROM `%s` ORDER BY `ID` DESC", _sqlTableName); std::string query = Acore::StringFormat("SELECT * FROM `%s` ORDER BY `ID` DESC", _sqlTableName);
// no error if empty set // no error if empty set
QueryResult result = WorldDatabase.Query(query.c_str()); QueryResult result = WorldDatabase.Query(query);
if (!result) if (!result)
return nullptr; return nullptr;
-8
View File
@@ -21,20 +21,12 @@
#include "Define.h" #include "Define.h"
#pragma pack(push, 1) #pragma pack(push, 1)
struct DBCPosition2D
{
float X;
float Y;
};
struct DBCPosition3D struct DBCPosition3D
{ {
float X; float X;
float Y; float Y;
float Z; float Z;
}; };
#pragma pack(pop) #pragma pack(pop)
// Client expected level limitation, like as used in DBC item max levels for "until max player level" // Client expected level limitation, like as used in DBC item max levels for "until max player level"
+4 -8
View File
@@ -27,11 +27,7 @@
using boost::asio::ip::tcp; using boost::asio::ip::tcp;
#if BOOST_VERSION >= 106600 constexpr auto ACORE_MAX_LISTEN_CONNECTIONS = boost::asio::socket_base::max_listen_connections;
#define ACORE_MAX_LISTEN_CONNECTIONS boost::asio::socket_base::max_listen_connections
#else
#define ACORE_MAX_LISTEN_CONNECTIONS boost::asio::socket_base::max_connections
#endif
class AsyncAcceptor class AsyncAcceptor
{ {
@@ -40,7 +36,7 @@ public:
AsyncAcceptor(Acore::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port) : AsyncAcceptor(Acore::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port) :
_acceptor(ioContext), _endpoint(Acore::Net::make_address(bindIp), port), _acceptor(ioContext), _endpoint(Acore::Net::make_address(bindIp), port),
_socket(ioContext), _closed(false), _socketFactory(std::bind(&AsyncAcceptor::DefeaultSocketFactory, this)) _socket(ioContext), _closed(false), _socketFactory([this](){ return DefaultSocketFactory(); })
{ {
} }
@@ -122,7 +118,7 @@ public:
void SetSocketFactory(std::function<std::pair<tcp::socket*, uint32>()> func) { _socketFactory = func; } void SetSocketFactory(std::function<std::pair<tcp::socket*, uint32>()> func) { _socketFactory = func; }
private: private:
std::pair<tcp::socket*, uint32> DefeaultSocketFactory() { return std::make_pair(&_socket, 0); } std::pair<tcp::socket*, uint32> DefaultSocketFactory() { return std::make_pair(&_socket, 0); }
tcp::acceptor _acceptor; tcp::acceptor _acceptor;
tcp::endpoint _endpoint; tcp::endpoint _endpoint;
@@ -155,4 +151,4 @@ void AsyncAcceptor::AsyncAccept()
}); });
} }
#endif /* __ASYNCACCEPT_H_ */ #endif /* __ASYNC ACCEPT_H_ */
+4 -4
View File
@@ -73,12 +73,12 @@ public:
return true; return true;
} }
boost::asio::ip::address GetRemoteIpAddress() const [[nodiscard]] boost::asio::ip::address GetRemoteIpAddress() const
{ {
return _remoteAddress; return _remoteAddress;
} }
uint16 GetRemotePort() const [[nodiscard]] uint16 GetRemotePort() const
{ {
return _remotePort; return _remotePort;
} }
@@ -120,7 +120,7 @@ public:
#endif #endif
} }
bool IsOpen() const { return !_closed && !_closing; } [[nodiscard]] bool IsOpen() const { return !_closed && !_closing; }
void CloseSocket() void CloseSocket()
{ {
@@ -146,7 +146,7 @@ protected:
virtual void OnClose() { } virtual void OnClose() { }
virtual void ReadHandler() = 0; virtual void ReadHandler() = 0;
bool AsyncProcessQueue() [[nodiscard]] bool AsyncProcessQueue()
{ {
if (_isWritingAsync) if (_isWritingAsync)
return false; return false;
+2 -2
View File
@@ -104,9 +104,9 @@ public:
} }
} }
int32 GetNetworkThreadCount() const { return _threadCount; } [[nodiscard]] int32 GetNetworkThreadCount() const { return _threadCount; }
uint32 SelectThreadWithMinConnections() const [[nodiscard]] uint32 SelectThreadWithMinConnections() const
{ {
uint32 min = 0; uint32 min = 0;
+2 -2
View File
@@ -78,7 +78,7 @@ std::string ByteBuffer::ReadCString(bool requireValidUtf8 /*= true*/)
{ {
std::string value; std::string value;
while (rpos() < size()) // prevent crash at wrong string format in packet while (rpos() < size()) // prevent crash the wrong string format in a packet
{ {
char c = read<char>(); char c = read<char>();
if (c == 0) if (c == 0)
@@ -94,7 +94,7 @@ std::string ByteBuffer::ReadCString(bool requireValidUtf8 /*= true*/)
uint32 ByteBuffer::ReadPackedTime() uint32 ByteBuffer::ReadPackedTime()
{ {
uint32 packedDate = read<uint32>(); auto packedDate = read<uint32>();
tm lt = tm(); tm lt = tm();
lt.tm_min = packedDate & 0x3F; lt.tm_min = packedDate & 0x3F;
+3 -3
View File
@@ -69,7 +69,7 @@ public:
class AC_SHARED_API ByteBuffer class AC_SHARED_API ByteBuffer
{ {
public: public:
constexpr static size_t DEFAULT_SIZE = 0x1000; constexpr static std::size_t DEFAULT_SIZE = 0x1000;
// constructor // constructor
ByteBuffer() ByteBuffer()
@@ -77,7 +77,7 @@ public:
_storage.reserve(DEFAULT_SIZE); _storage.reserve(DEFAULT_SIZE);
} }
ByteBuffer(size_t reserve) : _rpos(0), _wpos(0) explicit ByteBuffer(std::size_t reserve) : _rpos(0), _wpos(0)
{ {
_storage.reserve(reserve); _storage.reserve(reserve);
} }
@@ -90,7 +90,7 @@ public:
} }
ByteBuffer(ByteBuffer const& right) = default; ByteBuffer(ByteBuffer const& right) = default;
ByteBuffer(MessageBuffer&& buffer); explicit ByteBuffer(MessageBuffer&& buffer);
virtual ~ByteBuffer() = default; virtual ~ByteBuffer() = default;
ByteBuffer& operator=(ByteBuffer const& right) ByteBuffer& operator=(ByteBuffer const& right)
+2 -2
View File
@@ -24,7 +24,7 @@ boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::addres
{ {
boost::asio::ip::address realmIp; boost::asio::ip::address realmIp;
// Attempt to send best address for client // Attempt to send best address for a client
if (clientAddr.is_loopback()) if (clientAddr.is_loopback())
{ {
// Try guessing if realm is also connected locally // Try guessing if realm is also connected locally
@@ -52,5 +52,5 @@ boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::addres
} }
// Return external IP // Return external IP
return boost::asio::ip::tcp_endpoint(realmIp, Port); return { realmIp, Port };
} }
+6 -6
View File
@@ -92,7 +92,7 @@ void RealmList::LoadBuildInfo()
void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name, void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name,
boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask, boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask,
uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population) uint16 port, uint8 icon, RealmFlags flag, uint8 realmTimezone, AccountTypes allowedSecurityLevel, float population)
{ {
// Create new if not exist or update existed // Create new if not exist or update existed
Realm& realm = _realms[id]; Realm& realm = _realms[id];
@@ -102,7 +102,7 @@ void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string con
realm.Name = name; realm.Name = name;
realm.Type = icon; realm.Type = icon;
realm.Flags = flag; realm.Flags = flag;
realm.Timezone = timezone; realm.Timezone = realmTimezone;
realm.AllowedSecurityLevel = allowedSecurityLevel; realm.AllowedSecurityLevel = allowedSecurityLevel;
realm.PopulationLevel = population; realm.PopulationLevel = population;
@@ -192,8 +192,8 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
icon = REALM_TYPE_NORMAL; icon = REALM_TYPE_NORMAL;
} }
RealmFlags flag = RealmFlags(fields[7].Get<uint8>()); auto flag = RealmFlags(fields[7].Get<uint8>());
uint8 timezone = fields[8].Get<uint8>(); uint8 realmTimezone = fields[8].Get<uint8>();
uint8 allowedSecurityLevel = fields[9].Get<uint8>(); uint8 allowedSecurityLevel = fields[9].Get<uint8>();
float pop = fields[10].Get<float>(); float pop = fields[10].Get<float>();
uint32 build = fields[11].Get<uint32>(); uint32 build = fields[11].Get<uint32>();
@@ -201,7 +201,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
RealmHandle id{ realmId }; RealmHandle id{ realmId };
UpdateRealm(id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon, flag, UpdateRealm(id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon, flag,
timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop); realmTimezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop);
if (!existingRealms.count(id)) if (!existingRealms.count(id))
{ {
@@ -228,7 +228,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
if (_updateInterval) if (_updateInterval)
{ {
_updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval)); _updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval));
_updateTimer->async_wait(std::bind(&RealmList::UpdateRealms, this, std::placeholders::_1)); _updateTimer->async_wait([this](boost::system::error_code const& errorCode){ UpdateRealms(errorCode); });
} }
} }
+1 -1
View File
@@ -65,7 +65,7 @@ private:
void UpdateRealms(boost::system::error_code const& error); void UpdateRealms(boost::system::error_code const& error);
void UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name, void UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name,
boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask, boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask,
uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population); uint16 port, uint8 icon, RealmFlags flag, uint8 realmTimezone, AccountTypes allowedSecurityLevel, float population);
std::vector<RealmBuildInfo> _builds; std::vector<RealmBuildInfo> _builds;
RealmMap _realms; RealmMap _realms;