From 2c4e99fe8dcb957b49f1f1249ba0698625bb9e5a Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sat, 19 Jul 2014 19:46:40 +0200 Subject: [PATCH 1/3] Add some generic constants to amxconst.inc file. --- amxmodx/CPlugin.cpp | 8 ++++++++ amxmodx/amxmodx.cpp | 2 +- plugins/include/amxconst.inc | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index c9ecfa66..6c804322 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -167,6 +167,14 @@ int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn) plugin->setError(errorMsg); AMXXLOG_Error("[AMXX] %s", plugin->getError()); } + else + { + cell addr; + if (amx_FindPubVar(plugin->getAMX(), "MaxClients", &addr) != AMX_ERR_NOTFOUND) + { + *get_amxaddr(plugin->getAMX(), addr) = gpGlobals->maxClients; + } + } } fclose(fp); diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index d491be17..5f5c1d34 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -72,7 +72,7 @@ static cell AMX_NATIVE_CALL get_xvar_id(AMX *amx, cell *params) for (CPluginMngr::iterator a = g_plugins.begin(); a ; ++a) { - if ((*a).isValid() && amx_FindPubVar((*a).getAMX(), sName, &ptr) == AMX_ERR_NONE) + if ((*a).isValid() && amx_FindPubVar((*a).getAMX(), sName, &ptr) == AMX_ERR_NONE && strcmp(sName, "MaxClients")) return g_xvars.put((*a).getAMX(), get_amxaddr((*a).getAMX(), ptr)); } diff --git a/plugins/include/amxconst.inc b/plugins/include/amxconst.inc index 8e7ce17c..1fcadbb1 100755 --- a/plugins/include/amxconst.inc +++ b/plugins/include/amxconst.inc @@ -25,6 +25,16 @@ */ #define MAX_STRING_LENGTH 16384 +/** + * MAX_PLAYERS is not the same as MaxClients. + * MAX_PLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server. + */ +#define MAX_PLAYERS 32 /* Maximum number of players Half-Life 1 based games support */ +#define MAX_NAME_LENGTH 32 /* Maximum buffer required to store a client name */ + +public const MaxClients; /* Maximum number of players the server supports (dynamic) */ + + #define M_PI 3.1415926535 #define ADMIN_ALL 0 /* everyone */ From 8cef1af95d9f5a1dbe06e9791554e26ad2108661 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sat, 19 Jul 2014 19:54:57 +0200 Subject: [PATCH 2/3] Move check out the loop. --- amxmodx/amxmodx.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 5f5c1d34..b7614b28 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -70,9 +70,14 @@ static cell AMX_NATIVE_CALL get_xvar_id(AMX *amx, cell *params) char* sName = get_amxstring(amx, params[1], 0, len); cell ptr; + if (!strcmp(sName, "MaxClients")) + { + return -1; + } + for (CPluginMngr::iterator a = g_plugins.begin(); a ; ++a) { - if ((*a).isValid() && amx_FindPubVar((*a).getAMX(), sName, &ptr) == AMX_ERR_NONE && strcmp(sName, "MaxClients")) + if ((*a).isValid() && amx_FindPubVar((*a).getAMX(), sName, &ptr) == AMX_ERR_NONE) return g_xvars.put((*a).getAMX(), get_amxaddr((*a).getAMX(), ptr)); } From ee99ee93e430977979da79bcb0ca4b165715af73 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Sat, 19 Jul 2014 19:58:22 +0200 Subject: [PATCH 3/3] Add :+1: to MAX_PLAYERS for the sake of convenience. --- plugins/include/amxconst.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/amxconst.inc b/plugins/include/amxconst.inc index 1fcadbb1..9911f084 100755 --- a/plugins/include/amxconst.inc +++ b/plugins/include/amxconst.inc @@ -29,7 +29,7 @@ * MAX_PLAYERS is not the same as MaxClients. * MAX_PLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server. */ -#define MAX_PLAYERS 32 /* Maximum number of players Half-Life 1 based games support */ +#define MAX_PLAYERS 33 /* Maximum number of players AMX Mod X supports */ #define MAX_NAME_LENGTH 32 /* Maximum buffer required to store a client name */ public const MaxClients; /* Maximum number of players the server supports (dynamic) */