Skip to content

Commit

Permalink
Internal: Various linux compile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlikely4r committed Jan 21, 2025
1 parent 48a119b commit af6817b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 166 deletions.
1 change: 1 addition & 0 deletions playerbot/MemoryMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <unordered_map>
#include <map>
#include <thread>
#include <list>

class MemoryMonitor
{
Expand Down
4 changes: 4 additions & 0 deletions playerbot/PlayerbotLLMInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <cstring>
#include <fcntl.h>
#include <errno.h>
#include <thread>
#include "Log/Log.h"
#include "PlayerbotAIConfig.h"
#include "PlayerbotTextMgr.h"
#endif

std::string PlayerbotLLMInterface::SanitizeForJson(const std::string& input) {
Expand Down
5 changes: 5 additions & 0 deletions playerbot/PlayerbotLoginMgr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "PlayerbotLoginMgr.h"
#include "Database/DatabaseImpl.h"
#include "PlayerbotMgr.h"
#include "PlayerbotAIConfig.h"
#include "RandomPlayerbotMgr.h"

using namespace ai;

class LoginQueryHolder : public SqlQueryHolder
{
Expand Down
335 changes: 169 additions & 166 deletions playerbot/PlayerbotLoginMgr.h
Original file line number Diff line number Diff line change
@@ -1,171 +1,174 @@
#include "WorldPosition.h"

typedef std::map<uint32, Player*> RealPlayers;

class PlayerLoginInfo;

typedef std::map<uint32, PlayerLoginInfo> BotPool;
typedef std::vector<PlayerLoginInfo> RealPlayerInfos;
typedef std::vector<PlayerLoginInfo*> BotInfos;

struct LoginSpace
{
int32 currentSpace;
int32 totalSpace;
int32 classRaceBucket[MAX_CLASSES][MAX_RACES];
int32 levelBucket[DEFAULT_MAX_LEVEL + 1];
RealPlayerInfos realPlayerInfos;
};

enum class HolderState : uint8
{
HOLDER_EMPTY = 0,
HOLDER_SENT = 1,
HOLDER_RECEIVED = 2
};

enum class LoginState : uint8
{
BOT_OFFLINE = 0,
BOT_ON_LOGINQUEUE = 1,
BOT_ONLINE = 2,
BOT_ON_LOGOUTQUEUE = 3
};

enum class FillStep : uint8
{
NOW = 0,
NEXT_STEP = 1,
ALL_POTENTIAL = 2
};

enum class LoginCriterionFailType : uint8
{
UNKNOWN = 0,
MAX_BOTS = 1,
SPARE_ROOM,
ONLINE,
RANDOM_TIMED_LOGOUT,
RANDOM_TIMED_OFFLINE,
CLASSRACE,
LEVEL,
RANGE,
MAP,
GROUP,
GUILD,
BG,
ARENA,
INSTANCE,
LOGIN_OK
};

static std::unordered_map<LoginCriterionFailType, std::string> failName = {
{LoginCriterionFailType::UNKNOWN, "UNKNOWN"}
,{LoginCriterionFailType::MAX_BOTS, "MAX_BOTS"}
,{LoginCriterionFailType::SPARE_ROOM, "SPARE_ROOM"}
,{LoginCriterionFailType::ONLINE, "ONLINE"}
,{LoginCriterionFailType::RANDOM_TIMED_LOGOUT, "RANDOM_TIMED_LOGOUT"}
,{LoginCriterionFailType::RANDOM_TIMED_OFFLINE , "RANDOM_TIMED_OFFLINE"}
,{LoginCriterionFailType::CLASSRACE, "CLASSRACE"}
,{LoginCriterionFailType::LEVEL, "LEVEL"}
,{LoginCriterionFailType::RANGE , "RANGE"}
,{LoginCriterionFailType::MAP , "MAP"}
,{LoginCriterionFailType::GUILD , "GUILD"}
,{LoginCriterionFailType::GROUP , "GROUP"}
,{LoginCriterionFailType::BG , "BG"}
,{LoginCriterionFailType::ARENA , "ARENA"}
,{LoginCriterionFailType::INSTANCE , "INSTANCE"}
,{LoginCriterionFailType::LOGIN_OK, "LOGIN_OK"} };

typedef std::vector <std::pair<LoginCriterionFailType, std::function<bool(const PlayerLoginInfo&, const LoginSpace&)>>> LoginCriteria;

class PlayerLoginInfo
{
public:
PlayerLoginInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position, const uint32 guildId);

PlayerLoginInfo(Player* player);

ObjectGuid GetGuid() const { return ObjectGuid(HIGHGUID_PLAYER, guid); }
uint32 GetId() const { return guid; }
uint8 GetRace() const { return race; }
uint8 GetClass() const { return cls; }
uint32 GetLevel() const;
Player* GetPlayer() const { return sObjectMgr.GetPlayer(ObjectGuid(HIGHGUID_PLAYER, guid), false); }
bool IsNearPlayer(const LoginSpace& space) const;
bool IsOnPlayerMap(const LoginSpace& space) const;
bool IsInPlayerGroup(const LoginSpace& space) const;
bool IsInPlayerGuild(const LoginSpace& space) const;
bool IsInBG() const;
bool IsInArena() const;
bool IsInInstance() const;
bool IsOnline() const { return loginState == LoginState::BOT_ONLINE || loginState == LoginState::BOT_ON_LOGOUTQUEUE; }
LoginState GetLoginState() const { return loginState; }

bool SendHolder();
void HandlePlayerBotLoginCallback(QueryResult* /*dummy*/, SqlQueryHolder* holder);

void ResetLoginState();
void FillLoginSpace(LoginSpace& space, FillStep step = FillStep::NOW) const;
void EmptyLoginSpace(LoginSpace& space, FillStep step = FillStep::NOW) const;

void SetQueue(bool isWanted, LoginSpace& space);
bool IsQueued() const;

LoginCriterionFailType MatchNoCriteria(const LoginSpace& space, const LoginCriteria& criteria) const;

void Update(Player* player);
bool LoginBot();
bool LogoutBot();
private:

uint32 account;
uint32 guid;
uint8 race;
uint8 cls;
uint32 level;
bool isNew = false;
WorldPosition position;
uint32 groupId;
uint32 guildId;

SqlQueryHolder* holder = nullptr;
HolderState holderState = HolderState::HOLDER_EMPTY;
LoginState loginState = LoginState::BOT_OFFLINE;
};

class PlayerBotLoginMgr
namespace ai
{
public:
void Update(RealPlayers& realPlayers);
void ToggleDebug() {debug = !debug;}
private:
static BotPool LoadBotsFromDb();
void UpdateOnlineBots();
static BotInfos FillLoginLogoutQueue(BotPool* pool, const RealPlayers& realPlayers);
void LoginLogoutBots(const BotInfos& queue);

static RealPlayerInfos GetPlayerInfos(const RealPlayers& realPlayers);
static uint32 GetLoginCriteriaSize();
static std::vector<std::string> GetVariableLoginCriteria(const uint8 attempt);
static LoginCriteria GetLoginCriteria(const uint8 attempt);
static bool CriteriaStillValid(const LoginCriterionFailType oldFailType, const LoginCriteria& criteria);

static uint32 GetMaxOnlineBotCount();
static uint32 GetMaxLevel();
static uint32 GetClassRaceBucketSize(uint8 cls, uint8 race);
static uint32 GetLevelBucketSize(uint32 level);
static void FillLoginSpace(BotPool* pool, LoginSpace& space, FillStep step);

static void SendHolders(const BotInfos& queue);
static void SendHolders(BotPool* pool);

std::future<BotInfos> futureQueue;
std::future<BotPool> futurePool;

bool debug = false;
BotInfos onlineBots;
BotPool botPool;
};
typedef std::map<uint32, Player*> RealPlayers;

class PlayerLoginInfo;

typedef std::map<uint32, PlayerLoginInfo> BotPool;
typedef std::vector<PlayerLoginInfo> RealPlayerInfos;
typedef std::vector<PlayerLoginInfo*> BotInfos;

struct LoginSpace
{
int32 currentSpace;
int32 totalSpace;
int32 classRaceBucket[MAX_CLASSES][MAX_RACES];
int32 levelBucket[DEFAULT_MAX_LEVEL + 1];
RealPlayerInfos realPlayerInfos;
};

enum class HolderState : uint8
{
HOLDER_EMPTY = 0,
HOLDER_SENT = 1,
HOLDER_RECEIVED = 2
};

enum class LoginState : uint8
{
BOT_OFFLINE = 0,
BOT_ON_LOGINQUEUE = 1,
BOT_ONLINE = 2,
BOT_ON_LOGOUTQUEUE = 3
};

enum class FillStep : uint8
{
NOW = 0,
NEXT_STEP = 1,
ALL_POTENTIAL = 2
};

enum class LoginCriterionFailType : uint8
{
UNKNOWN = 0,
MAX_BOTS = 1,
SPARE_ROOM,
ONLINE,
RANDOM_TIMED_LOGOUT,
RANDOM_TIMED_OFFLINE,
CLASSRACE,
LEVEL,
RANGE,
MAP,
GROUP,
GUILD,
BG,
ARENA,
INSTANCE,
LOGIN_OK
};

static std::unordered_map<LoginCriterionFailType, std::string> failName = {
{LoginCriterionFailType::UNKNOWN, "UNKNOWN"}
,{LoginCriterionFailType::MAX_BOTS, "MAX_BOTS"}
,{LoginCriterionFailType::SPARE_ROOM, "SPARE_ROOM"}
,{LoginCriterionFailType::ONLINE, "ONLINE"}
,{LoginCriterionFailType::RANDOM_TIMED_LOGOUT, "RANDOM_TIMED_LOGOUT"}
,{LoginCriterionFailType::RANDOM_TIMED_OFFLINE , "RANDOM_TIMED_OFFLINE"}
,{LoginCriterionFailType::CLASSRACE, "CLASSRACE"}
,{LoginCriterionFailType::LEVEL, "LEVEL"}
,{LoginCriterionFailType::RANGE , "RANGE"}
,{LoginCriterionFailType::MAP , "MAP"}
,{LoginCriterionFailType::GUILD , "GUILD"}
,{LoginCriterionFailType::GROUP , "GROUP"}
,{LoginCriterionFailType::BG , "BG"}
,{LoginCriterionFailType::ARENA , "ARENA"}
,{LoginCriterionFailType::INSTANCE , "INSTANCE"}
,{LoginCriterionFailType::LOGIN_OK, "LOGIN_OK"} };

typedef std::vector <std::pair<LoginCriterionFailType, std::function<bool(const PlayerLoginInfo&, const LoginSpace&)>>> LoginCriteria;

class PlayerLoginInfo
{
public:
PlayerLoginInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position, const uint32 guildId);

PlayerLoginInfo(Player* player);

ObjectGuid GetGuid() const { return ObjectGuid(HIGHGUID_PLAYER, guid); }
uint32 GetId() const { return guid; }
uint8 GetRace() const { return race; }
uint8 GetClass() const { return cls; }
uint32 GetLevel() const;
Player* GetPlayer() const { return sObjectMgr.GetPlayer(ObjectGuid(HIGHGUID_PLAYER, guid), false); }
bool IsNearPlayer(const LoginSpace& space) const;
bool IsOnPlayerMap(const LoginSpace& space) const;
bool IsInPlayerGroup(const LoginSpace& space) const;
bool IsInPlayerGuild(const LoginSpace& space) const;
bool IsInBG() const;
bool IsInArena() const;
bool IsInInstance() const;
bool IsOnline() const { return loginState == LoginState::BOT_ONLINE || loginState == LoginState::BOT_ON_LOGOUTQUEUE; }
LoginState GetLoginState() const { return loginState; }

bool SendHolder();
void HandlePlayerBotLoginCallback(QueryResult* /*dummy*/, SqlQueryHolder* holder);

void ResetLoginState();
void FillLoginSpace(LoginSpace& space, FillStep step = FillStep::NOW) const;
void EmptyLoginSpace(LoginSpace& space, FillStep step = FillStep::NOW) const;

void SetQueue(bool isWanted, LoginSpace& space);
bool IsQueued() const;

LoginCriterionFailType MatchNoCriteria(const LoginSpace& space, const LoginCriteria& criteria) const;

void Update(Player* player);
bool LoginBot();
bool LogoutBot();
private:

uint32 account;
uint32 guid;
uint8 race;
uint8 cls;
uint32 level;
bool isNew = false;
WorldPosition position;
uint32 groupId;
uint32 guildId;

SqlQueryHolder* holder = nullptr;
HolderState holderState = HolderState::HOLDER_EMPTY;
LoginState loginState = LoginState::BOT_OFFLINE;
};

class PlayerBotLoginMgr
{
public:
void Update(RealPlayers& realPlayers);
void ToggleDebug() { debug = !debug; }
private:
static BotPool LoadBotsFromDb();
void UpdateOnlineBots();
static BotInfos FillLoginLogoutQueue(BotPool* pool, const RealPlayers& realPlayers);
void LoginLogoutBots(const BotInfos& queue);

static RealPlayerInfos GetPlayerInfos(const RealPlayers& realPlayers);
static uint32 GetLoginCriteriaSize();
static std::vector<std::string> GetVariableLoginCriteria(const uint8 attempt);
static LoginCriteria GetLoginCriteria(const uint8 attempt);
static bool CriteriaStillValid(const LoginCriterionFailType oldFailType, const LoginCriteria& criteria);

static uint32 GetMaxOnlineBotCount();
static uint32 GetMaxLevel();
static uint32 GetClassRaceBucketSize(uint8 cls, uint8 race);
static uint32 GetLevelBucketSize(uint32 level);
static void FillLoginSpace(BotPool* pool, LoginSpace& space, FillStep step);

static void SendHolders(const BotInfos& queue);
static void SendHolders(BotPool* pool);

std::future<BotInfos> futureQueue;
std::future<BotPool> futurePool;

bool debug = false;
BotInfos onlineBots;
BotPool botPool;
};
}

#define sPlayerBotLoginMgr MaNGOS::Singleton<PlayerBotLoginMgr>::Instance()
1 change: 1 addition & 0 deletions playerbot/strategy/values/TravelValues.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "playerbot/strategy/Value.h"
#include "playerbot/strategy/AiObjectContext.h"

namespace ai
{
Expand Down

0 comments on commit af6817b

Please sign in to comment.