Merge branch 'master' into Playerbot

This commit is contained in:
Yunfan Li
2024-03-03 11:58:01 +08:00
59 changed files with 3523 additions and 450 deletions

View File

@@ -38,7 +38,7 @@ char* DBCDatabaseLoader::Load(uint32& records, char**& indexTable)
std::string query = Acore::StringFormat("SELECT * FROM `%s` ORDER BY `ID` DESC", _sqlTableName);
// no error if empty set
QueryResult result = WorldDatabase.Query(query.c_str());
QueryResult result = WorldDatabase.Query(query);
if (!result)
return nullptr;

View File

@@ -21,20 +21,12 @@
#include "Define.h"
#pragma pack(push, 1)
struct DBCPosition2D
{
float X;
float Y;
};
struct DBCPosition3D
{
float X;
float Y;
float Z;
};
#pragma pack(pop)
// Client expected level limitation, like as used in DBC item max levels for "until max player level"

View File

@@ -27,11 +27,7 @@
using boost::asio::ip::tcp;
#if BOOST_VERSION >= 106600
#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
constexpr auto ACORE_MAX_LISTEN_CONNECTIONS = boost::asio::socket_base::max_listen_connections;
class AsyncAcceptor
{
@@ -40,7 +36,7 @@ public:
AsyncAcceptor(Acore::Asio::IoContext& ioContext, std::string const& bindIp, uint16 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; }
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::endpoint _endpoint;
@@ -155,4 +151,4 @@ void AsyncAcceptor::AsyncAccept()
});
}
#endif /* __ASYNCACCEPT_H_ */
#endif /* __ASYNC ACCEPT_H_ */

View File

@@ -73,12 +73,12 @@ public:
return true;
}
boost::asio::ip::address GetRemoteIpAddress() const
[[nodiscard]] boost::asio::ip::address GetRemoteIpAddress() const
{
return _remoteAddress;
}
uint16 GetRemotePort() const
[[nodiscard]] uint16 GetRemotePort() const
{
return _remotePort;
}
@@ -120,7 +120,7 @@ public:
#endif
}
bool IsOpen() const { return !_closed && !_closing; }
[[nodiscard]] bool IsOpen() const { return !_closed && !_closing; }
void CloseSocket()
{
@@ -146,7 +146,7 @@ protected:
virtual void OnClose() { }
virtual void ReadHandler() = 0;
bool AsyncProcessQueue()
[[nodiscard]] bool AsyncProcessQueue()
{
if (_isWritingAsync)
return false;

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;

View File

@@ -78,7 +78,7 @@ std::string ByteBuffer::ReadCString(bool requireValidUtf8 /*= true*/)
{
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>();
if (c == 0)
@@ -94,7 +94,7 @@ std::string ByteBuffer::ReadCString(bool requireValidUtf8 /*= true*/)
uint32 ByteBuffer::ReadPackedTime()
{
uint32 packedDate = read<uint32>();
auto packedDate = read<uint32>();
tm lt = tm();
lt.tm_min = packedDate & 0x3F;

View File

@@ -69,7 +69,7 @@ public:
class AC_SHARED_API ByteBuffer
{
public:
constexpr static size_t DEFAULT_SIZE = 0x1000;
constexpr static std::size_t DEFAULT_SIZE = 0x1000;
// constructor
ByteBuffer()
@@ -77,7 +77,7 @@ public:
_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);
}
@@ -90,7 +90,7 @@ public:
}
ByteBuffer(ByteBuffer const& right) = default;
ByteBuffer(MessageBuffer&& buffer);
explicit ByteBuffer(MessageBuffer&& buffer);
virtual ~ByteBuffer() = default;
ByteBuffer& operator=(ByteBuffer const& right)

View File

@@ -24,7 +24,7 @@ boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::addres
{
boost::asio::ip::address realmIp;
// Attempt to send best address for client
// Attempt to send best address for a client
if (clientAddr.is_loopback())
{
// 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 boost::asio::ip::tcp_endpoint(realmIp, Port);
return { realmIp, Port };
}

View File

@@ -92,7 +92,7 @@ void RealmList::LoadBuildInfo()
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,
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
Realm& realm = _realms[id];
@@ -102,7 +102,7 @@ void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string con
realm.Name = name;
realm.Type = icon;
realm.Flags = flag;
realm.Timezone = timezone;
realm.Timezone = realmTimezone;
realm.AllowedSecurityLevel = allowedSecurityLevel;
realm.PopulationLevel = population;
@@ -192,8 +192,8 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
icon = REALM_TYPE_NORMAL;
}
RealmFlags flag = RealmFlags(fields[7].Get<uint8>());
uint8 timezone = fields[8].Get<uint8>();
auto flag = RealmFlags(fields[7].Get<uint8>());
uint8 realmTimezone = fields[8].Get<uint8>();
uint8 allowedSecurityLevel = fields[9].Get<uint8>();
float pop = fields[10].Get<float>();
uint32 build = fields[11].Get<uint32>();
@@ -201,7 +201,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
RealmHandle id{ realmId };
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))
{
@@ -228,7 +228,7 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
if (_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); });
}
}

View File

@@ -65,7 +65,7 @@ private:
void UpdateRealms(boost::system::error_code const& error);
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,
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;
RealmMap _realms;