diff --git a/amxmodx/CMisc.cpp b/amxmodx/CMisc.cpp index e5d1d385..e91a1ef9 100755 --- a/amxmodx/CMisc.cpp +++ b/amxmodx/CMisc.cpp @@ -40,7 +40,8 @@ void CPlayer::Init(edict_t* e, int i) pEdict = e; initialized = false; ingame = false; - bot = false; + bot_value = false; + bot_cached = false; authorized = false; current = 0; @@ -88,7 +89,8 @@ void CPlayer::Disconnect() } queries.clear(); - bot = 0; + bot_value = false; + bot_cached = false; menu = 0; newmenu = -1; } @@ -114,10 +116,11 @@ int CPlayer::NextHUDChannel() bool CPlayer::Connect(const char* connectname, const char* ipaddress) { + bot_value = false; + bot_cached = false; name.assign(connectname); ip.assign(ipaddress); time = gpGlobals->time; - bot = IsBot(); death_killer = 0; menu = 0; newmenu = -1; diff --git a/amxmodx/CMisc.h b/amxmodx/CMisc.h index 453b12a4..b2a0d2ac 100755 --- a/amxmodx/CMisc.h +++ b/amxmodx/CMisc.h @@ -83,7 +83,8 @@ public: bool initialized; bool ingame; - bool bot; + bool bot_cached; + bool bot_value; bool authorized; bool vgui; @@ -131,7 +132,23 @@ public: inline bool IsBot() { - return ((pEdict->v.flags & FL_FAKECLIENT) ? true : false); + if (!bot_cached) + { + bot_value = false; + if (pEdict->v.flags & FL_FAKECLIENT) + { + bot_value = true; + } else { + const char *auth = GETPLAYERAUTHID(pEdict); + if (auth && (strcmp(auth, "BOT") == 0)) + { + bot_value = true; + } + } + bot_cached = true; + } + + return bot_value; } inline bool IsAlive() diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 449cac4b..963c2240 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -177,7 +177,7 @@ static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */ } else { CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (!pPlayer->bot && pPlayer->initialized) + if (!pPlayer->IsBot() && pPlayer->initialized) CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd); } @@ -516,7 +516,7 @@ static cell AMX_NATIVE_CALL is_user_bot(AMX *amx, cell *params) /* 1 param */ if (index < 1 || index > gpGlobals->maxClients) return 0; - return (GET_PLAYER_POINTER_I(index)->bot ? 1 : 0); + return (GET_PLAYER_POINTER_I(index)->IsBot() ? 1 : 0); } static cell AMX_NATIVE_CALL is_user_hltv(AMX *amx, cell *params) /* 1 param */ @@ -1506,7 +1506,7 @@ static cell AMX_NATIVE_CALL client_cmd(AMX *amx, cell *params) /* 2 param */ for (int i = 1; i <= gpGlobals->maxClients; ++i) { CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); - if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/) + if (!pPlayer->IsBot() && pPlayer->initialized /*&& pPlayer->ingame*/) CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd); } } else { @@ -1520,7 +1520,7 @@ static cell AMX_NATIVE_CALL client_cmd(AMX *amx, cell *params) /* 2 param */ CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); - if (!pPlayer->bot && pPlayer->initialized /*&& pPlayer->ingame*/) + if (!pPlayer->IsBot() && pPlayer->initialized /*&& pPlayer->ingame*/) CLIENT_COMMAND(pPlayer->pEdict, "%s", cmd); } @@ -1883,7 +1883,7 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */ { if (pPlayer->IsAlive() ? (flags & 2) : (flags & 1)) continue; - if (pPlayer->bot ? (flags & 4) : (flags & 8)) + if (pPlayer->IsBot() ? (flags & 4) : (flags & 8)) continue; if ((flags & 16) && (pPlayer->teamId != team)) continue; @@ -1940,7 +1940,7 @@ static cell AMX_NATIVE_CALL find_player(AMX *amx, cell *params) /* 1 param */ if (pPlayer->IsAlive() ? (flags & 64) : (flags & 32)) continue; - if (pPlayer->bot ? (flags & 128) : (flags & 256)) + if (pPlayer->IsBot() ? (flags & 128) : (flags & 256)) continue; if (flags & 1) @@ -3606,7 +3606,7 @@ static cell AMX_NATIVE_CALL query_client_cvar(AMX *amx, cell *params) CPlayer *pPlayer = GET_PLAYER_POINTER_I(id); - if (!pPlayer->initialized || pPlayer->bot) + if (!pPlayer->initialized || pPlayer->IsBot()) { LogError(amx, AMX_ERR_NATIVE, "Player %d is either not connected or a bot", id); return 0; @@ -4261,8 +4261,8 @@ AMX_NATIVE_INFO amxmodx_Natives[] = {"CreateOneForward", CreateOneForward}, {"DestroyForward", DestroyForward}, {"ExecuteForward", ExecuteForward}, + {"LibraryExists", LibraryExists}, {"PrepareArray", PrepareArray}, {"ShowSyncHudMsg", ShowSyncHudMsg}, - {"LibraryExists", LibraryExists}, {NULL, NULL} }; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 3314873d..6763d433 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -693,7 +693,7 @@ void C_ServerDeactivate_Post() BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) { CPlayer* pPlayer = GET_PLAYER_POINTER(pEntity); - if (!pPlayer->bot) + if (!pPlayer->IsBot()) { bool a = pPlayer->Connect(pszName, pszAddress); executeForwards(FF_ClientConnect, static_cast(pPlayer->index)); @@ -741,7 +741,7 @@ void C_ClientDisconnect(edict_t *pEntity) void C_ClientPutInServer_Post(edict_t *pEntity) { CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity); - if (!pPlayer->bot) + if (!pPlayer->IsBot()) { pPlayer->PutInServer(); ++g_players_num; @@ -761,9 +761,7 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer) if (pPlayer->ingame) { pPlayer->name.assign(name); // Make sure player have name up to date - } - else if (pPlayer->IsBot()) - { + } else if (pPlayer->IsBot()) { pPlayer->Connect(name, "127.0.0.1"/*CVAR_GET_STRING("net_address")*/); executeForwards(FF_ClientConnect, static_cast(pPlayer->index)); diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index f37b32fb..ba2ef149 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -347,3 +347,4 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, // unset the global "fake" flag g_fakecmd.fake = false; } +