Rework build pathname functions (#422)

* Rework build_pathname* functions

* Replace old platform defines with the new ones

* Correct usage of build_pathname_r()

* Fix inconsistencies (white spaces)

* Remove useless defines
This commit is contained in:
Karol Szuster 2017-03-11 19:26:25 +01:00 committed by Vincent Herbet
parent fa3d28872e
commit 9551c70c59
13 changed files with 688 additions and 734 deletions

View File

@ -19,14 +19,14 @@
extern const char *no_function;
CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error, int debug)
{
{
CPlugin** a = &head;
while (*a)
a = &(*a)->next;
*a = new CPlugin(pCounter++, path, name, error, debug);
return (*a);
}
@ -42,10 +42,10 @@ void CPluginMngr::Finalize()
{
if (m_Finalized)
return;
pNatives = BuildNativeTable();
CPlugin *a = head;
while (a)
{
if (a->getStatusCode() == ps_running)
@ -55,16 +55,16 @@ void CPluginMngr::Finalize()
}
a = a->next;
}
m_Finalized = true;
}
int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
{
char file[256];
FILE *fp = fopen(build_pathname_r(file, sizeof(file) - 1, "%s", filename), "rt");
char file[PLATFORM_MAX_PATH];
FILE *fp = fopen(build_pathname_r(file, sizeof(file), "%s", filename), "rt");
if (!fp)
if (!fp)
{
if (warn)
{
@ -72,23 +72,23 @@ int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
}
return 1;
}
// Find now folder
char pluginName[256], error[256], debug[256];
int debugFlag = 0;
const char *pluginsDir = get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins");
char line[512];
List<ke::AString *>::iterator block_iter;
while (!feof(fp))
while (!feof(fp))
{
pluginName[0] = '\0';
debug[0] = '\0';
debugFlag = 0;
line[0] = '\0';
fgets(line, sizeof(line), fp);
@ -104,7 +104,7 @@ int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
}
}
sscanf(line, "%s %s", pluginName, debug);
if (!isalnum(*pluginName))
{
continue;
@ -138,7 +138,7 @@ int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
}
CPlugin* plugin = loadPlugin(pluginsDir, pluginName, error, debugFlag);
if (plugin->getStatusCode() == ps_bad_load)
{
char errorMsg[255];
@ -173,13 +173,13 @@ int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
void CPluginMngr::clear()
{
CPlugin**a = &head;
CPlugin**a = &head;
while (*a)
unloadPlugin(a);
m_Finalized = false;
if (pNatives)
{
delete [] pNatives;
@ -198,20 +198,20 @@ void CPluginMngr::clear()
CPluginMngr::CPlugin* CPluginMngr::findPlugin(AMX *amx)
{
CPlugin*a = head;
while (a && &a->amx != amx)
a = a->next;
return a;
}
CPluginMngr::CPlugin* CPluginMngr::findPlugin(int index)
{
CPlugin*a = head;
while (a && index--)
a = a->next;
return a;
}
@ -219,17 +219,17 @@ CPluginMngr::CPlugin* CPluginMngr::findPlugin(const char* name)
{
if (!name)
return 0;
int len = strlen(name);
if (!len)
return 0;
CPlugin*a = head;
while (a && strncmp(a->name.chars(), name, len))
a = a->next;
return a;
}
@ -248,7 +248,7 @@ const char* CPluginMngr::CPlugin::getStatus() const
{
switch (status)
{
case ps_running:
case ps_running:
{
if (m_Debug)
{
@ -263,42 +263,42 @@ const char* CPluginMngr::CPlugin::getStatus() const
case ps_stopped: return "stopped";
case ps_locked: return "locked";
}
return "error";
}
CPluginMngr::CPlugin::CPlugin(int i, const char* p, const char* n, char* e, int d) : name(n), title(n), m_pNullStringOfs(nullptr), m_pNullVectorOfs(nullptr)
{
const char* unk = "unknown";
failcounter = 0;
title = unk;
author = unk;
version = unk;
char file[256];
char* path = build_pathname_r(file, sizeof(file) - 1, "%s/%s", p, n);
char file[PLATFORM_MAX_PATH];
char* path = build_pathname_r(file, sizeof(file), "%s/%s", p, n);
code = 0;
memset(&amx, 0, sizeof(AMX));
int err = load_amxscript(&amx, &code, path, e, d);
if (err == AMX_ERR_NONE)
{
status = ps_running;
} else {
status = ps_bad_load;
}
amx.userdata[UD_FINDPLUGIN] = this;
paused_fun = 0;
next = 0;
id = i;
if (status == ps_running)
{
m_PauseFwd = registerSPForwardByName(&amx, "plugin_pause", FP_DONE);
m_UnpauseFwd = registerSPForwardByName(&amx, "plugin_unpause", FP_DONE);
if (amx.flags & AMX_FLAG_DEBUG)
{
m_Debug = true;
@ -368,17 +368,17 @@ void CPluginMngr::CPlugin::Finalize()
{
char buffer[128];
int old_status = status;
if (CheckModules(&amx, buffer))
{
if (amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE)
{
Handler *pHandler = (Handler *)amx.userdata[UD_HANDLER];
int res = 0;
if (pHandler->IsNativeFiltering())
res = amx_CheckNatives(&amx, native_handler);
if (!res)
{
status = ps_bad_load;
@ -394,7 +394,7 @@ void CPluginMngr::CPlugin::Finalize()
errorMsg = buffer;
amx.error = AMX_ERR_NOTFOUND;
}
if (old_status != status)
{
AMXXLOG_Log("[AMXX] Plugin \"%s\" failed to load: %s", name.chars(), errorMsg.chars());
@ -402,7 +402,7 @@ void CPluginMngr::CPlugin::Finalize()
}
void CPluginMngr::CPlugin::pauseFunction(int id)
{
{
}
void CPluginMngr::CPlugin::unpauseFunction(int id)
@ -410,8 +410,8 @@ void CPluginMngr::CPlugin::unpauseFunction(int id)
}
void CPluginMngr::CPlugin::setStatus(int a)
{
status = a;
{
status = a;
g_commands.clearBufforedInfo(); // ugly way
}
@ -423,7 +423,7 @@ void CPluginMngr::CPlugin::pausePlugin()
// call plugin_pause if provided
if (m_PauseFwd != -1)
executeForwards(m_PauseFwd);
setStatus(ps_paused);
}
}
@ -435,7 +435,7 @@ void CPluginMngr::CPlugin::unpausePlugin()
{
// set status first so the function will be marked executable
setStatus(ps_running);
// call plugin_unpause if provided
if (m_UnpauseFwd != -1)
{
@ -597,7 +597,7 @@ void CPluginMngr::CacheAndLoadModules(const char *plugin)
{
return;
}
if ((hdr.defsize != sizeof(AMX_FUNCSTUB)) &&
if ((hdr.defsize != sizeof(AMX_FUNCSTUB)) &&
(hdr.defsize != sizeof(AMX_FUNCSTUBNT)))
{
return;
@ -610,7 +610,7 @@ void CPluginMngr::CacheAndLoadModules(const char *plugin)
{
return;
}
if (hdr.stp <= 0)
{
return;
@ -655,7 +655,7 @@ void CPluginMngr::CacheAndLoadModules(const char *plugin)
{
RunLibCommand(dc);
} else if ( (dc->cmd == LibCmd_ExpectClass) ||
(dc->cmd == LibCmd_ExpectLib) )
(dc->cmd == LibCmd_ExpectLib) )
{
expects.append(dc);
} else if (dc->cmd == LibCmd_DefaultLib) {
@ -688,10 +688,10 @@ void CPluginMngr::CacheAndLoadModules(const char *plugin)
void CPluginMngr::CALMFromFile(const char *file)
{
char filename[256];
FILE *fp = fopen(build_pathname_r(filename, sizeof(filename) - 1, "%s", file), "rt");
char filename[PLATFORM_MAX_PATH];
FILE *fp = fopen(build_pathname_r(filename, sizeof(filename), "%s", file), "rt");
if (!fp)
if (!fp)
{
return;
}
@ -701,7 +701,7 @@ void CPluginMngr::CALMFromFile(const char *file)
char line[256];
char rline[256];
while (!feof(fp))
while (!feof(fp))
{
fgets(line, sizeof(line)-1, fp);
if (line[0] == ';' || line[0] == '\n' || line[0] == '\0')
@ -751,7 +751,7 @@ void CPluginMngr::CALMFromFile(const char *file)
continue;
}
build_pathname_r(filename, sizeof(filename)-1, "%s/%s", get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins"), pluginName);
build_pathname_r(filename, sizeof(filename), "%s/%s", get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins"), pluginName);
CacheAndLoadModules(filename);
}

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
#ifndef AMXMODX_H
#define AMXMODX_H
#if defined(__linux__) || defined(__APPLE__)
#if defined PLATFORM_POSIX
#include <unistd.h>
#include <stdlib.h>
#include "sclinux.h"
@ -23,7 +23,7 @@
#ifdef _MSC_VER
// MSVC8 - replace POSIX functions with ISO C++ conformant ones as they are deprecated
#if _MSC_VER >= 1400
#define unlink _unlink
#define unlink _unlink
#define mkdir _mkdir
#define strdup _strdup
#endif
@ -75,7 +75,7 @@ extern AMX_NATIVE_INFO g_TextParserNatives[];
extern AMX_NATIVE_INFO g_CvarNatives[];
extern AMX_NATIVE_INFO g_GameConfigNatives[];
#if defined(_WIN32)
#if defined PLATFORM_WINDOWS
#define DLLOAD(path) (DLHANDLE)LoadLibrary(path)
#define DLPROC(m, func) GetProcAddress(m, func)
#define DLFREE(m) FreeLibrary(m)
@ -96,21 +96,13 @@ extern AMX_NATIVE_INFO g_GameConfigNatives[];
#endif
#endif
#if defined(_WIN32)
#if defined PLATFORM_WINDOWS
typedef HINSTANCE DLHANDLE;
#else
typedef void* DLHANDLE;
#define INFINITE 0xFFFFFFFF
#endif
#if defined(_WIN32)
#define PATH_SEP_CHAR '\\'
#define ALT_SEP_CHAR '/'
#else
#define PATH_SEP_CHAR '/'
#define ALT_SEP_CHAR '\\'
#endif
#ifndef GETPLAYERAUTHID
#define GETPLAYERAUTHID (*g_engfuncs.pfnGetPlayerAuthId)
#endif
@ -136,7 +128,7 @@ void UTIL_ShowMenu(edict_t* pEntity, int slots, int time, char *menu, int mlen);
void UTIL_ClientSayText(edict_t *pEntity, int sender, char *msg);
void UTIL_TeamInfo(edict_t *pEntity, int playerIndex, const char *pszTeamName);
template <typename D> int UTIL_CheckValidChar(D *c);
template <typename D> int UTIL_CheckValidChar(D *c);
template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, size_t count);
unsigned int UTIL_GetUTF8CharBytes(const char *stream);
unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive);

View File

@ -44,7 +44,7 @@ void CLog::CloseFile()
if (m_LogFile.length())
{
FILE *fp = fopen(m_LogFile.chars(), "r");
if (fp)
{
fclose(fp);
@ -61,7 +61,7 @@ void CLog::CloseFile()
fprintf(fp, "L %s: %s\n", date, "Log file closed.");
fclose(fp);
}
m_LogFile = nullptr;
}
}
@ -69,33 +69,33 @@ void CLog::CloseFile()
void CLog::CreateNewFile()
{
CloseFile();
// build filename
time_t td;
time(&td);
tm *curTime = localtime(&td);
char file[256];
char file[PLATFORM_MAX_PATH];
char name[256];
int i = 0;
while (true)
{
ke::SafeSprintf(name, sizeof(name), "%s/L%02d%02d%03d.log", g_log_dir.chars(), curTime->tm_mon + 1, curTime->tm_mday, i);
build_pathname_r(file, sizeof(file)-1, "%s", name);
build_pathname_r(file, sizeof(file), "%s", name);
FILE *pTmpFile = fopen(file, "r"); // open for reading to check whether the file exists
if (!pTmpFile)
break;
fclose(pTmpFile);
++i;
}
m_LogFile = file;
// Log logfile start
FILE *fp = fopen(m_LogFile.chars(), "w");
if (!fp)
{
ALERT(at_logged, "[AMXX] Unexpected fatal logging error. AMXX Logging disabled.\n");
@ -108,8 +108,8 @@ void CLog::CreateNewFile()
void CLog::UseFile(const ke::AString &fileName)
{
static char file[256];
m_LogFile = build_pathname_r(file, sizeof(file) - 1, "%s/%s", g_log_dir.chars(), fileName.chars());
static char file[PLATFORM_MAX_PATH];
m_LogFile = build_pathname_r(file, sizeof(file), "%s/%s", g_log_dir.chars(), fileName.chars());
}
void CLog::SetLogType(const char* localInfo)
@ -128,11 +128,11 @@ void CLog::SetLogType(const char* localInfo)
void CLog::MapChange()
{
// create dir if not existing
char file[256];
char file[PLATFORM_MAX_PATH];
#if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname_r(file, sizeof(file)-1, "%s", g_log_dir.chars()), 0700);
mkdir(build_pathname_r(file, sizeof(file), "%s", g_log_dir.chars()), 0700);
#else
mkdir(build_pathname_r(file, sizeof(file) - 1, "%s", g_log_dir.chars()));
mkdir(build_pathname_r(file, sizeof(file), "%s", g_log_dir.chars()));
#endif
SetLogType("amxx_logging");
@ -152,8 +152,8 @@ void CLog::MapChange()
void CLog::Log(const char *fmt, ...)
{
static char file[256];
static char file[PLATFORM_MAX_PATH];
if (m_LogType == 1 || m_LogType == 2)
{
// get time
@ -180,7 +180,7 @@ void CLog::Log(const char *fmt, ...)
{
CreateNewFile();
pF = fopen(m_LogFile.chars(), "a+");
if (!pF)
{
ALERT(at_logged, "[AMXX] Unexpected fatal logging error (couldn't open %s for a+). AMXX Logging disabled for this map.\n", m_LogFile.chars());
@ -189,10 +189,10 @@ void CLog::Log(const char *fmt, ...)
}
}
} else {
build_pathname_r(file, sizeof(file) - 1, "%s/L%04d%02d%02d.log", g_log_dir.chars(), (curTime->tm_year + 1900), curTime->tm_mon + 1, curTime->tm_mday);
build_pathname_r(file, sizeof(file), "%s/L%04d%02d%02d.log", g_log_dir.chars(), (curTime->tm_year + 1900), curTime->tm_mon + 1, curTime->tm_mday);
pF = fopen(file, "a+");
}
if (pF)
{
fprintf(pF, "L %s: %s\n", date, msg);
@ -218,7 +218,7 @@ void CLog::Log(const char *fmt, ...)
void CLog::LogError(const char *fmt, ...)
{
static char file[256];
static char file[PLATFORM_MAX_PATH];
static char name[256];
if (m_FoundError)
@ -244,7 +244,7 @@ void CLog::LogError(const char *fmt, ...)
FILE *pF = NULL;
ke::SafeSprintf(name, sizeof(name), "%s/error_%04d%02d%02d.log", g_log_dir.chars(), curTime->tm_year + 1900, curTime->tm_mon + 1, curTime->tm_mday);
build_pathname_r(file, sizeof(file)-1, "%s", name);
build_pathname_r(file, sizeof(file), "%s", name);
pF = fopen(file, "a+");
if (pF)
@ -266,4 +266,3 @@ void CLog::LogError(const char *fmt, ...)
// print on server console
print_srvconsole("L %s: %s\n", date, msg);
}

View File

@ -49,9 +49,9 @@ int LookupFile(AMX_DBG *amxdbg, ucell address)
bool BinLog::Open()
{
const char *data = get_localinfo("amxmodx_datadir", "addons/amxmodx/data");
char path[255];
build_pathname_r(path, sizeof(path)-1, "%s/binlogs", data);
char path[PLATFORM_MAX_PATH];
build_pathname_r(path, sizeof(path), "%s/binlogs", data);
if (!DirExists(path))
{
mkdir(path
@ -63,8 +63,8 @@ bool BinLog::Open()
return false;
}
char file[255];
build_pathname_r(file, sizeof(file)-1, "%s/binlogs/lastlog", data);
char file[PLATFORM_MAX_PATH];
build_pathname_r(file, sizeof(file), "%s/binlogs/lastlog", data);
unsigned int lastcntr = 0;
FILE *lastlog = fopen(file, "rb");
@ -81,7 +81,7 @@ bool BinLog::Open()
fwrite(&lastcntr, sizeof(int), 1, lastlog);
fclose(lastlog);
}
build_pathname_r(file, sizeof(file)-1, "%s/binlogs/binlog%04d.blg", data, lastcntr);
build_pathname_r(file, sizeof(file), "%s/binlogs/binlog%04d.blg", data, lastcntr);
m_logfile = file;
/**

View File

@ -678,7 +678,7 @@ static cell AMX_NATIVE_CALL amx_fprintf(AMX *amx, cell *params)
{
assert(false);
}
return 0;
}
@ -1015,8 +1015,8 @@ static cell AMX_NATIVE_CALL rename_file(AMX *amx, cell *params)
if (params[0] / sizeof(cell) >= 3 && params[3] > 0)
{
build_pathname_r(file_old_r, sizeof(file_old_r) - 1, "%s", file_old);
build_pathname_r(file_new_r, sizeof(file_new_r) - 1, "%s", file_new);
build_pathname_r(file_old_r, sizeof(file_old_r), "%s", file_old);
build_pathname_r(file_new_r, sizeof(file_new_r), "%s", file_new);
}
else
{
@ -1205,7 +1205,7 @@ AMX_NATIVE_INFO file_Natives[] =
{"fungetc", amx_ungetc},
{"fputs", amx_fputs},
{"fflush", amx_fflush},
{"build_pathname", amx_build_pathname},
{"dir_exists", dir_exists},

View File

@ -35,7 +35,7 @@
#include <resdk/mod_rehlds_api.h>
#include <amtl/am-utility.h>
plugin_info_t Plugin_info =
plugin_info_t Plugin_info =
{
META_INTERFACE_VERSION, // ifvers
"AMX Mod X", // name
@ -162,7 +162,7 @@ bool ColoredMenus(const char *ModName)
for (size_t i = 0; i < ModsCount; ++i)
{
if (strcmp(ModName, pModNames[i]) == 0)
return true; // this game modification currently supports colored menus
return true; // this game modification currently supports colored menus
}
return false; // no colored menus are supported for this game modification
@ -187,9 +187,9 @@ void ParseAndOrAdd(CStack<ke::AString *> & files, const char *name)
void BuildPluginFileList(const char *initialdir, CStack<ke::AString *> & files)
{
char path[255];
char path[PLATFORM_MAX_PATH];
#if defined WIN32
build_pathname_r(path, sizeof(path)-1, "%s/*.ini", initialdir);
build_pathname_r(path, sizeof(path), "%s/*.ini", initialdir);
_finddata_t fd;
intptr_t handle = _findfirst(path, &fd);
@ -205,7 +205,7 @@ void BuildPluginFileList(const char *initialdir, CStack<ke::AString *> & files)
_findclose(handle);
#elif defined(__linux__) || defined(__APPLE__)
build_pathname_r(path, sizeof(path)-1, "%s/", initialdir);
build_pathname_r(path, sizeof(path), "%s/", initialdir);
struct dirent *ep;
DIR *dp;
@ -285,7 +285,7 @@ int C_PrecacheSound(const char *s)
PRECACHE_SOUND((char*)(*a).getFilename());
ENGINE_FORCE_UNMODIFIED((*a).getForceType(), (*a).getMin(), (*a).getMax(), (*a).getFilename());
}
if (!g_bmod_cstrike)
{
PRECACHE_SOUND("weapons/cbar_hitbod1.wav");
@ -310,7 +310,7 @@ int C_InconsistentFile(const edict_t *player, const char *filename, char *discon
if (executeForwards(FF_InconsistentFile, static_cast<cell>(pPlayer->index),
filename, disconnect_message) == 1)
RETURN_META_VALUE(MRES_SUPERCEDE, FALSE);
RETURN_META_VALUE(MRES_SUPERCEDE, TRUE);
}
@ -455,7 +455,7 @@ int C_Spawn(edict_t *pent)
g_plugins.CALMFromFile(map_pluginsfile_path);
int loaded = countModules(CountModules_Running); // Call after attachModules so all modules don't have pending stat
// Set some info about amx version and modules
CVAR_SET_STRING(init_amxmodx_version.name, AMXX_VERSION);
char buffer[32];
@ -463,8 +463,8 @@ int C_Spawn(edict_t *pent)
CVAR_SET_STRING(init_amxmodx_modules.name, buffer);
// ###### Load Vault
char file[255];
g_vault.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
char file[PLATFORM_MAX_PATH];
g_vault.setSource(build_pathname_r(file, sizeof(file), "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
g_vault.loadVault();
// ###### Init time and freeze tasks
@ -550,7 +550,7 @@ struct sUserMsg
funEventCall func;
bool endmsg;
bool cstrike;
} g_user_msg[] =
} g_user_msg[] =
{
{"CurWeapon", &gmsgCurWeapon, Client_CurWeapon, false, false},
{"Damage", &gmsgDamage, Client_DamageEnd, true, true},
@ -607,13 +607,13 @@ plugin_init forward function from plugins
void C_ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
int id;
for (int i = 0; g_user_msg[i].name; ++i)
{
if ((*g_user_msg[i].id == 0) && (id = GET_USER_MSG_ID(PLID, g_user_msg[i].name, NULL)) != 0)
{
*g_user_msg[i].id = id;
if (!g_user_msg[i].cstrike || g_bmod_cstrike)
{
if (g_user_msg[i].endmsg)
@ -674,7 +674,7 @@ void C_ServerDeactivate()
{
if (!g_activated)
RETURN_META(MRES_IGNORED);
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
@ -752,7 +752,7 @@ void C_ServerDeactivate_Post()
modules_callPluginsUnloaded();
ClearMessages();
// Flush the dynamic admins list
for (size_t iter=DynamicAdmins.length();iter--; )
{
@ -807,15 +807,15 @@ void C_ServerDeactivate_Post()
}
}
g_memreport_dir = buffer;
// g_memreport_dir should be valid now
break;
}
}
m_dumpMemoryReport(build_pathname("%s/r%03d.txt", g_memreport_dir.chars(), g_memreport_count));
AMXXLOG_Log("Memreport #%d created (file \"%s/r%03d.txt\") (interval %f)", g_memreport_count + 1, g_memreport_dir.chars(), g_memreport_count, MEMREPORT_INTERVAL);
g_memreport_count++;
}
#endif // MEMORY_TEST
@ -836,11 +836,11 @@ BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *psz
{
bool a = pPlayer->Connect(pszName, pszAddress);
executeForwards(FF_ClientConnect, static_cast<cell>(pPlayer->index));
if (a)
{
CPlayer** aa = new CPlayer*(pPlayer);
if (aa)
if (aa)
g_auth.put(aa);
} else {
pPlayer->Authorize();
@ -858,7 +858,7 @@ BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *psz
executeForwards(FF_ClientAuthorized, static_cast<cell>(pPlayer->index), authid);
}
}
RETURN_META_VALUE(MRES_IGNORED, TRUE);
}
@ -880,7 +880,7 @@ void C_ClientDisconnect(edict_t *pEntity)
{
// deprecated
executeForwards(FF_ClientDisconnect, static_cast<cell>(pPlayer->index));
if (DropClientDetour && !pPlayer->disconnecting)
{
executeForwards(FF_ClientDisconnected, static_cast<cell>(pPlayer->index), FALSE, prepareCharArray(const_cast<char*>(""), 0), 0);
@ -967,7 +967,7 @@ void C_ClientPutInServer_Post(edict_t *pEntity)
++g_players_num;
executeForwards(FF_ClientPutInServer, static_cast<cell>(pPlayer->index));
}
RETURN_META(MRES_IGNORED);
}
@ -1012,10 +1012,10 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer)
void C_ClientCommand(edict_t *pEntity)
{
CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity);
META_RES result = MRES_IGNORED;
cell ret = 0;
const char* cmd = CMD_ARGV(0);
const char* arg = CMD_ARGV(1);
@ -1027,7 +1027,7 @@ void C_ClientCommand(edict_t *pEntity)
// Print version
static char buf[1024];
size_t len = 0;
sprintf(buf, "%s %s\n", Plugin_info.name, Plugin_info.version);
CLIENT_PRINT(pEntity, print_console, buf);
len = sprintf(buf, "Authors: \n David \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko, Felix \"SniperBeamer\" Geyer\n");
@ -1057,7 +1057,7 @@ void C_ClientCommand(edict_t *pEntity)
/* check for command and if needed also for first argument and call proper function */
CmdMngr::iterator aa = g_commands.clcmdprefixbegin(cmd);
if (!aa)
aa = g_commands.clcmdbegin();
@ -1089,7 +1089,7 @@ void C_ClientCommand(edict_t *pEntity)
pMenu->Close(pPlayer->index);
RETURN_META(MRES_SUPERCEDE);
}
}
else if (pPlayer->menu > 0 && !pPlayer->vgui)
{
pPlayer->menu = 0;
@ -1098,7 +1098,7 @@ void C_ClientCommand(edict_t *pEntity)
RETURN_META(MRES_SUPERCEDE);
}
}
int menuid = pPlayer->menu;
pPlayer->menu = 0;
@ -1126,12 +1126,12 @@ void C_ClientCommand(edict_t *pEntity)
}
}
/**
* No matter what we marked it as executed, since the callback styles are
* No matter what we marked it as executed, since the callback styles are
* entirely different. After all, this is a backwards compat shim.
*/
func_was_executed = pMenu->func;
}
}
}
/* Now, do old menus */
MenuMngr::iterator a = g_menucmds.begin();
@ -1139,15 +1139,15 @@ void C_ClientCommand(edict_t *pEntity)
while (a)
{
g_menucmds.SetWatchIter(a);
if ((*a).matchCommand(menuid, bit_key)
if ((*a).matchCommand(menuid, bit_key)
&& (*a).getPlugin()->isExecutable((*a).getFunction())
&& (func_was_executed == -1
&& (func_was_executed == -1
|| !g_forwards.isSameSPForward(func_was_executed, (*a).getFunction()))
)
{
ret = executeForwards((*a).getFunction(), static_cast<cell>(pPlayer->index),
static_cast<cell>(pressed_key), 0);
if (ret & 2) result = MRES_SUPERCEDE;
if (ret & 1) RETURN_META(MRES_SUPERCEDE);
}
@ -1197,7 +1197,7 @@ void C_StartFrame_Post(void)
}
executeForwards(FF_ClientAuthorized, static_cast<cell>((*a)->index), auth);
a.remove();
continue;
}
++a;
@ -1208,14 +1208,14 @@ void C_StartFrame_Post(void)
if (g_memreport_enabled && g_next_memreport_time <= gpGlobals->time)
{
g_next_memreport_time = gpGlobals->time + MEMREPORT_INTERVAL;
if (g_memreport_count == 0)
{
// make new directory
time_t td;
time(&td);
tm *curTime = localtime(&td);
int i = 0;
#if defined(__linux__) || defined(__APPLE__)
mkdir(build_pathname("%s/memreports", get_localinfo("amxx_basedir", "addons/amxmodx")), 0700);
@ -1251,10 +1251,10 @@ void C_StartFrame_Post(void)
break;
}
}
m_dumpMemoryReport(build_pathname("%s/r%03d.txt", g_memreport_dir.chars(), g_memreport_count));
AMXXLOG_Log("Memreport #%d created (file \"%s/r%03d.txt\") (interval %f)", g_memreport_count + 1, g_memreport_dir.chars(), g_memreport_count, MEMREPORT_INTERVAL);
g_memreport_count++;
}
#endif // MEMORY_TEST
@ -1282,14 +1282,14 @@ void C_MessageBegin_Post(int msg_dest, int msg_type, const float *pOrigin, edict
mPlayerIndex = 0;
mPlayer = 0;
}
if (msg_type < 0 || msg_type >= MAX_REG_MSGS)
msg_type = 0;
mState = 0;
function = modMsgs[msg_type];
endfunction = modMsgsEnd[msg_type];
g_events.parserInit(msg_type, &gpGlobals->time, mPlayer, mPlayerIndex);
RETURN_META(MRES_IGNORED);
@ -1299,7 +1299,7 @@ void C_WriteByte_Post(int iValue)
{
g_events.parseValue(iValue);
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
@ -1315,7 +1315,7 @@ void C_WriteShort_Post(int iValue)
{
g_events.parseValue(iValue);
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
@ -1323,7 +1323,7 @@ void C_WriteLong_Post(int iValue)
{
g_events.parseValue(iValue);
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
@ -1331,7 +1331,7 @@ void C_WriteAngle_Post(float flValue)
{
g_events.parseValue(flValue);
if (function) (*function)((void *)&flValue);
RETURN_META(MRES_IGNORED);
}
@ -1355,7 +1355,7 @@ void C_WriteEntity_Post(int iValue)
{
g_events.parseValue(iValue);
if (function) (*function)((void *)&iValue);
RETURN_META(MRES_IGNORED);
}
@ -1363,7 +1363,7 @@ void C_MessageEnd_Post(void)
{
g_events.executeEvents();
if (endfunction) (*endfunction)(NULL);
RETURN_META(MRES_IGNORED);
}
@ -1372,7 +1372,7 @@ const char *C_Cmd_Args(void)
// if the global "fake" flag is set, which means that engclient_cmd was used, supercede the function
if (g_fakecmd.fake)
RETURN_META_VALUE(MRES_SUPERCEDE, (g_fakecmd.argc > 1) ? g_fakecmd.args : g_fakecmd.argv[0]);
// otherwise ignore it
RETURN_META_VALUE(MRES_IGNORED, NULL);
}
@ -1382,7 +1382,7 @@ const char *C_Cmd_Argv(int argc)
// if the global "fake" flag is set, which means that engclient_cmd was used, supercede the function
if (g_fakecmd.fake)
RETURN_META_VALUE(MRES_SUPERCEDE, (argc < 3) ? g_fakecmd.argv[argc] : "");
// otherwise ignore it
RETURN_META_VALUE(MRES_IGNORED, NULL);
}
@ -1392,7 +1392,7 @@ int C_Cmd_Argc(void)
// if the global "fake" flag is set, which means that engclient_cmd was used, supercede the function
if (g_fakecmd.fake)
RETURN_META_VALUE(MRES_SUPERCEDE, g_fakecmd.argc);
// otherwise ignore it
RETURN_META_VALUE(MRES_IGNORED, 0);
}
@ -1403,7 +1403,7 @@ void C_SetModel(edict_t *e, const char *m)
{
if (e->v.owner && m[7]=='w' && m[8]=='_' && m[9]=='h')
g_grenades.put(e, 1.75, 4, GET_PLAYER_POINTER(e->v.owner));
RETURN_META(MRES_IGNORED);
}
@ -1413,10 +1413,10 @@ void C_TraceLine_Post(const float *v1, const float *v2, int fNoMonsters, edict_t
if (e && (e->v.flags & (FL_CLIENT | FL_FAKECLIENT)))
{
CPlayer* pPlayer = GET_PLAYER_POINTER(e);
if (ptr->pHit && (ptr->pHit->v.flags & (FL_CLIENT | FL_FAKECLIENT)))
pPlayer->aiming = ptr->iHitgroup;
pPlayer->lastTrace = ptr->vecEndPos;
}
@ -1515,7 +1515,7 @@ C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_
*pPlugInfo = &Plugin_info;
int mmajor = 0, mminor = 0, pmajor = 0, pminor = 0;
sscanf(ifvers, "%d:%d", &mmajor, &mminor);
sscanf(Plugin_info.ifvers, "%d:%d", &pmajor, &pminor);
@ -1530,7 +1530,7 @@ C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo, mutil_
LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
return (FALSE);
} else if (pmajor == mmajor) {
if (pminor > mminor)
if (pminor > mminor)
{
LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
return FALSE;
@ -1573,21 +1573,21 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
CVAR_REGISTER(&init_amxmodx_mldebug);
CVAR_REGISTER(&init_amxmodx_language);
CVAR_REGISTER(&init_amxmodx_cl_langs);
amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);
amxmodx_language = CVAR_GET_POINTER(init_amxmodx_language.name);
REG_SVR_COMMAND("amxx", amx_command);
char gameDir[512];
GET_GAME_DIR(gameDir);
char *a = gameDir;
int i = 0;
while (gameDir[i])
if (gameDir[i++] == '/')
a = &gameDir[i];
g_mod_name = a;
g_coloredmenus = ColoredMenus(g_mod_name.chars()); // whether or not to use colored menus
@ -1605,7 +1605,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m
if (amx_config.loadVault())
{
Vault::iterator a = amx_config.begin();
while (a != amx_config.end())
{
SET_LOCALINFO((char*)a.key().chars(), (char*)a.value().chars());
@ -1870,7 +1870,7 @@ C_DLLEXPORT int GetEngineFunctions_Post(enginefuncs_t *pengfuncsFromEngine, int
meta_engfuncs_post.pfnWriteByte = C_WriteByte_Post;
meta_engfuncs_post.pfnWriteChar = C_WriteChar_Post;
meta_engfuncs_post.pfnWriteShort = C_WriteShort_Post;
meta_engfuncs_post.pfnWriteLong = C_WriteLong_Post;
meta_engfuncs_post.pfnWriteLong = C_WriteLong_Post;
meta_engfuncs_post.pfnWriteAngle = C_WriteAngle_Post;
meta_engfuncs_post.pfnWriteCoord = C_WriteCoord_Post;
meta_engfuncs_post.pfnWriteString = C_WriteString_Post;
@ -1889,7 +1889,7 @@ NEW_DLL_FUNCTIONS gNewDLLFunctionTable;
C_DLLEXPORT int GetNewDLLFunctions(NEW_DLL_FUNCTIONS *pNewFunctionTable, int *interfaceVersion)
{
memset(&gNewDLLFunctionTable, 0, sizeof(NEW_DLL_FUNCTIONS));
// default metamod does not call this if the gamedll doesn't provide it
if (g_engfuncs.pfnQueryClientCvarValue2)
{

View File

@ -31,6 +31,7 @@
#include "trie_natives.h"
#include "CDataPack.h"
#include "CGameConfigs.h"
#include <amtl/os/am-path.h>
CList<CModule, const char*> g_modules;
CList<CScript, AMX*> g_loadedscripts;
@ -52,7 +53,7 @@ void report_error(int code, const char* fmt, ...)
vsnprintf(string, 255, fmt, argptr);
string[255] = 0;
va_end(argptr);
if (*string)
{
AMXXLOG_Log("Error:");
@ -71,7 +72,7 @@ void print_srvconsole(const char *fmt, ...)
vsnprintf(string, sizeof(string) - 1, fmt, argptr);
string[sizeof(string) - 1] = '\0';
va_end(argptr);
SERVER_PRINT(string);
}
@ -111,7 +112,7 @@ void BinLog_LogParams(AMX *amx, cell *params)
}
}
static binlogfuncs_t logfuncs =
static binlogfuncs_t logfuncs =
{
BinLog_LogNative,
BinLog_LogReturn,
@ -127,25 +128,25 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
if (!*program)
{
CAmxxReader reader(filename, PAWN_CELL_SIZE / 8);
if (reader.GetStatus() == CAmxxReader::Err_None)
{
bufSize = reader.GetBufferSize();
if (bufSize != 0)
{
*program = (void*) (new char[bufSize]);
if (!*program)
{
strcpy(error, "Failed to allocate memory");
return (amx->error = AMX_ERR_MEMORY);
}
reader.GetSection(*program);
}
}
switch (reader.GetStatus())
{
case CAmxxReader::Err_None:
@ -186,7 +187,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
AMX_HEADER *hdr = (AMX_HEADER*)*program;
uint16_t magic = hdr->magic;
amx_Align16(&magic);
if (magic != AMX_MAGIC)
{
strcpy(error, "Invalid Plugin");
@ -208,10 +209,10 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
else if ((hdr->flags & AMX_FLAG_DEBUG) != 0)
{
will_be_debugged = true;
char *addr = (char *)hdr + hdr->size;
pDbg = new tagAMX_DBG;
memset(pDbg, 0, sizeof(AMX_DBG));
int err = dbg_LoadInfo(pDbg, addr);
@ -248,7 +249,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
dbg_FreeInfo(pDbg);
delete pDbg;
}
sprintf(error, "Load error %d (invalid file format or version)", err);
return (amx->error = AMX_ERR_INIT);
}
@ -282,17 +283,17 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
{
char *np = new char[amx->code_size];
char *rt = new char[amx->reloc_size];
if (!np || (!rt && amx->reloc_size > 0))
{
delete[] np;
delete[] rt;
strcpy(error, "Failed to initialize JIT'd plugin");
return (amx->error = AMX_ERR_INIT);
}
if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE)
if ((err = amx_InitJIT(amx, (void *)rt, (void *)np)) == AMX_ERR_NONE)
{
//amx->base = (unsigned char FAR *)realloc(np, amx->code_size);
#if defined(_WIN32)
@ -307,15 +308,15 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
#endif
if (amx->base)
memcpy(amx->base, np, amx->code_size);
delete [] np;
delete [] rt;
char *prg = (char *)(*program);
delete [] prg;
(*program) = amx->base;
if (*program == 0)
{
strcpy(error, "Failed to allocate memory");
@ -324,9 +325,9 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
} else {
delete[] np;
delete[] rt;
sprintf(error, "Failed to initialize plugin (%d)", err);
return (amx->error = AMX_ERR_INIT_JIT);
}
}
@ -341,7 +342,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
if (g_plugins.m_Finalized)
{
amx_Register(amx, g_plugins.pNatives, -1);
if (CheckModules(amx, error))
{
if (amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE)
@ -371,7 +372,7 @@ const char *StrCaseStr(const char *as, const char *bs)
{
a[i] = tolower(as[i]);
}
a[len] = 0;
len = strlen(bs);
@ -383,7 +384,7 @@ const char *StrCaseStr(const char *as, const char *bs)
{
b[i] = tolower(bs[i]);
}
b[len] = 0;
return strstr(a, b);
@ -396,14 +397,14 @@ int CheckModules(AMX *amx, char error[128])
char buffer[64];
LibType expect;
bool found;
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
/** decode old style plugins */
for (int i = 0; i < numLibraries; i++)
{
amx_GetLibrary(amx, i, buffer, sizeof(buffer) - 1);
if (stricmp(buffer, "float") == 0)
continue;
@ -428,8 +429,8 @@ int CheckModules(AMX *amx, char error[128])
++a;
continue;
}
if (cm.getInfoNew() &&
cm.getInfoNew()->logtag &&
if (cm.getInfoNew() &&
cm.getInfoNew()->logtag &&
!strcasecmp(cm.getInfoNew()->logtag, buffer))
{
found = true;
@ -438,7 +439,7 @@ int CheckModules(AMX *amx, char error[128])
++a;
}
}
if (!found)
{
if (expect == LibType_Library)
@ -452,7 +453,7 @@ int CheckModules(AMX *amx, char error[128])
}
}
}
if (!found)
{
const char *type = "Module/Library";
@ -541,7 +542,7 @@ int set_amxnatives(AMX* amx, char error[128])
Debugger *pd;
pd = DisableDebugHandler(amx);
if (amx_FindPublic(amx, "plugin_natives", &idx) == AMX_ERR_NONE)
{
if ((err = amx_Exec(amx, &retval, idx)) != AMX_ERR_NONE)
@ -559,7 +560,7 @@ int set_amxnatives(AMX* amx, char error[128])
}
int unload_amxscript(AMX* amx, void** program)
{
{
#if defined JIT
int flags = amx->flags;
long code_size = amx->code_size;
@ -568,7 +569,7 @@ int unload_amxscript(AMX* amx, void** program)
Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER];
if (pDebugger)
delete pDebugger;
Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];
if (pHandler)
delete pHandler;
@ -576,14 +577,14 @@ int unload_amxscript(AMX* amx, void** program)
optimizer_s *opt = (optimizer_s *)amx->usertags[UT_OPTIMIZER];
if (opt)
delete opt;
CList<CScript, AMX*>::iterator a = g_loadedscripts.find(amx);
if (a)
a.remove();
char *prg = (char *)*program;
if (!prg)
return AMX_ERR_NONE;
@ -606,7 +607,7 @@ int unload_amxscript(AMX* amx, void** program)
#endif
}
#elif defined WIN32
if ((flags & AMX_FLAG_JITC) != AMX_FLAG_JITC)
{
delete [] prg;
@ -628,18 +629,18 @@ int unload_amxscript(AMX* amx, void** program)
AMX* get_amxscript(int id, void** code, const char** filename)
{
CList<CScript, AMX*>::iterator a = g_loadedscripts.begin();
while (a && id--)
++a;
if (a)
{
*filename = (*a).getName();
*code = (*a).getCode();
return (*a).getAMX();
}
return 0;
}
@ -647,7 +648,7 @@ const char* GetFileName(AMX *amx)
{
const char *filename = "";
CPluginMngr::CPlugin *pl = g_plugins.findPluginFast(amx);
if (pl)
{
filename = pl->getName();
@ -671,77 +672,41 @@ void get_modname(char* buffer)
strcpy(buffer, g_mod_name.chars());
}
char* build_pathname(const char *fmt, ...)
char *build_pathname(const char *fmt, ...)
{
static char string[256];
int b;
int a = b = ke::SafeSprintf(string, sizeof(string), "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
static char string[PLATFORM_MAX_PATH];
auto len = ke::path::Format(string, sizeof(string), "%s/", g_mod_name.chars());
va_list argptr;
va_start(argptr, fmt);
a += vsnprintf (&string[a], 255 - a, fmt, argptr);
string[a] = 0;
ke::path::FormatVa(&string[len], sizeof(string) - len, fmt, argptr);
va_end(argptr);
char* path = &string[b];
while (*path)
{
if (*path == ALT_SEP_CHAR)
{
*path = PATH_SEP_CHAR;
}
++path;
}
return string;
}
char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...)
{
ke::SafeSprintf(buffer, maxlen, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
size_t len = strlen(buffer);
char *ptr = buffer + len;
auto len = ke::path::Format(buffer, maxlen, "%s/", g_mod_name.chars());
va_list argptr;
va_start(argptr, fmt);
vsnprintf (ptr, maxlen-len, fmt, argptr);
ke::path::FormatVa(&buffer[len], maxlen - len, fmt, argptr);
va_end (argptr);
while (*ptr)
{
if (*ptr == ALT_SEP_CHAR)
{
*ptr = PATH_SEP_CHAR;
}
++ptr;
}
return buffer;
}
// build pathname based on addons dir
char* build_pathname_addons(const char *fmt, ...)
char *build_pathname_addons(const char *fmt, ...)
{
static char string[256];
static char string[PLATFORM_MAX_PATH];
va_list argptr;
va_start(argptr, fmt);
vsnprintf (string, 255, fmt, argptr);
ke::path::FormatVa(string, sizeof(string), fmt, argptr);
va_end(argptr);
char* path = string;
while (*path)
{
if (*path == ALT_SEP_CHAR)
{
*path = PATH_SEP_CHAR;
}
++path;
}
return string;
}
@ -762,7 +727,7 @@ bool ConvertModuleName(const char *pathString, char *path)
/* run to filename instead of dir */
char *ptr = tmpname;
ptr = tmpname + len - 1;
while (ptr >= tmpname && *ptr != PATH_SEP_CHAR)
while (ptr >= tmpname && *ptr != PLATFORM_SEP_CHAR)
ptr--;
if (ptr >= tmpname)
{
@ -822,7 +787,7 @@ bool ConvertModuleName(const char *pathString, char *path)
*ptr = '\0';
}
size_t length = ke::SafeSprintf(path, PLATFORM_MAX_PATH, "%s%c%s_amxx", orig_path, PATH_SEP_CHAR, tmpname);
auto length = ke::path::Format(path, PLATFORM_MAX_PATH, "%s/%s_amxx", orig_path, tmpname);
#if defined PLATFORM_LINUX
# if defined AMD64 || PAWN_CELL_SIZE == 64
@ -842,8 +807,8 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
char path[PLATFORM_MAX_PATH];
build_pathname_r(
pathString,
sizeof(pathString)-1,
pathString,
sizeof(pathString),
"%s/%s",
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
shortname);
@ -919,8 +884,8 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
if (cc->IsMetamod())
{
char *mmpathname = build_pathname_addons(
"%s/%s",
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
"%s/%s",
get_localinfo("amxx_modulesdir", "addons/amxmodx/modules"),
shortname);
ConvertModuleName(mmpathname, path);
cc->attachMetamod(path, now);
@ -933,7 +898,7 @@ bool LoadModule(const char *shortname, PLUG_LOADTIME now, bool simplify, bool no
switch (cc->getStatusValue())
{
case MODULE_FUNCNOTPRESENT:
report_error(1, "[AMXX] Module requested a not existing function (file \"%s\")%s%s%s", cc->getFilename(), cc->getMissingFunc() ? " (func \"" : "",
report_error(1, "[AMXX] Module requested a not existing function (file \"%s\")%s%s%s", cc->getFilename(), cc->getMissingFunc() ? " (func \"" : "",
cc->getMissingFunc() ? cc->getMissingFunc() : "", cc->getMissingFunc() ? "\")" : "");
break;
case MODULE_INTERROR:
@ -982,17 +947,17 @@ int loadModules(const char* filename, PLUG_LOADTIME now)
{
simplify = false;
strncopy(line, &buffer[1], sizeof(line));
}
else
}
else
{
strncopy(line, buffer, sizeof(line));
}
*moduleName = '\0';
if (sscanf(line, "%s", moduleName) == EOF)
continue;
if (LoadModule(moduleName, now, simplify))
loaded++;
}
@ -1023,7 +988,7 @@ void detachReloadModules()
{
(*a).detachModule();
a.remove();
continue;
}
++a;
@ -1033,7 +998,7 @@ void detachReloadModules()
const char* strip_name(const char* a)
{
const char* ret = a;
while (*a)
{
if (*a == '/' || *a == '\\')
@ -1043,7 +1008,7 @@ const char* strip_name(const char* a)
}
++a;
}
return ret;
}
@ -1052,7 +1017,7 @@ int countModules(CountModulesMode mode)
{
CList<CModule, const char *>::iterator iter;
int num;
switch (mode)
{
case CountModules_All:
@ -1060,29 +1025,29 @@ int countModules(CountModulesMode mode)
case CountModules_Running:
iter = g_modules.begin();
num = 0;
while (iter)
{
if ((*iter).getStatusValue() == MODULE_LOADED)
++num;
++iter;
}
return num;
case CountModules_Stopped:
iter = g_modules.begin();
num = 0;
while (iter)
{
if ((*iter).getStatusValue() != MODULE_LOADED)
++num;
++iter;
}
return num;
}
return 0;
}
@ -1090,7 +1055,7 @@ int countModules(CountModulesMode mode)
void modules_callPluginsLoaded()
{
CList<CModule, const char *>::iterator iter = g_modules.begin();
while (iter)
{
(*iter).CallPluginsLoaded();
@ -1128,7 +1093,7 @@ int MNF_AddNatives(AMX_NATIVE_INFO* natives)
return FALSE; // may only be called from attach
g_CurrentlyCalledModule->m_Natives.append(natives);
return TRUE;
}
@ -1150,26 +1115,26 @@ const char *MNF_GetModname(void)
AMX *MNF_GetAmxScript(int id)
{
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
while (iter && id--)
++iter;
if (iter == 0)
return NULL;
return (*iter).getAMX();
}
const char *MNF_GetAmxScriptName(int id)
{
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
while (iter && id--)
++iter;
if (iter == 0)
return NULL;
return (*iter).getName();
}
@ -1178,7 +1143,7 @@ int MNF_FindAmxScriptByName(const char *name)
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
bool found = false;
int i = 0;
while (iter)
{
if (stricmp((*iter).getName(), name) == 0)
@ -1189,10 +1154,10 @@ int MNF_FindAmxScriptByName(const char *name)
++iter;
++i;
}
if (!found)
return -1;
return i;
}
@ -1201,9 +1166,9 @@ int MNF_FindAmxScriptByAmx(const AMX *amx)
CList<CScript, AMX*>::iterator iter = g_loadedscripts.begin();
bool found = false;
int i = 0;
while (iter)
{
if (amx == (*iter).getAMX())
{
@ -1213,10 +1178,10 @@ int MNF_FindAmxScriptByAmx(const AMX *amx)
++iter;
++i;
}
if (!found)
return -1;
return i;
}
@ -1224,10 +1189,10 @@ extern "C" char *MNF_GetAmxString(AMX *amx, cell amx_addr, int bufferId, int *pL
{
int len;
char *retVal = get_amxstring(amx, amx_addr, bufferId, len);
if (pLen)
*pLen = len;
return retVal;
}
@ -1245,10 +1210,10 @@ extern "C" char *MNF_GetAmxStringNull(AMX *amx, cell amx_addr, int bufferId, int
int MNF_GetAmxStringLen(const cell *ptr)
{
register int c = 0;
while (ptr[c])
++c;
return c;
}
@ -1267,10 +1232,10 @@ char *MNF_FormatAmxString(AMX *amx, cell *params, int startParam, int *pLen)
{
int len;
char *retVal = format_amxstring(amx, params, startParam, len);
if (pLen)
*pLen = len;
return retVal;
}
@ -1278,9 +1243,9 @@ int MNF_GetPlayerFlags(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
return (pPlayer->flags[0]);
}
@ -1293,9 +1258,9 @@ int MNF_IsPlayerValid(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
return (pPlayer->initialized) ? 1 : 0;
}
@ -1303,7 +1268,7 @@ const char * MNF_GetPlayerName(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return NULL;
return GET_PLAYER_POINTER_I(id)->name.chars();
}
@ -1329,7 +1294,7 @@ const char * MNF_GetPlayerIP(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return NULL;
return GET_PLAYER_POINTER_I(id)->ip.chars();
}
@ -1337,7 +1302,7 @@ int MNF_IsPlayerInGame(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->ingame ? 1 : 0;
}
@ -1345,7 +1310,7 @@ int MNF_IsPlayerBot(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->IsBot() ? 1 : 0;
}
@ -1353,7 +1318,7 @@ int MNF_IsPlayerAuthorized(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->authorized ? 1 : 0;
}
@ -1361,7 +1326,7 @@ float MNF_GetPlayerTime(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->time;
}
@ -1369,7 +1334,7 @@ float MNF_GetPlayerPlayTime(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->playtime;
}
@ -1377,7 +1342,7 @@ int MNF_GetPlayerCurweapon(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->current;
}
@ -1385,7 +1350,7 @@ int MNF_GetPlayerTeamID(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->teamId;
}
@ -1393,7 +1358,7 @@ int MNF_GetPlayerDeaths(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->deaths;
}
@ -1401,7 +1366,7 @@ int MNF_GetPlayerMenu(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->menu;
}
@ -1409,7 +1374,7 @@ int MNF_GetPlayerKeys(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->keys;
}
@ -1417,7 +1382,7 @@ int MNF_IsPlayerAlive(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->IsAlive() ? 1 : 0;
}
@ -1425,7 +1390,7 @@ float MNF_GetPlayerFrags(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->pEdict->v.frags;
}
@ -1433,9 +1398,9 @@ int MNF_IsPlayerConnecting(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
CPlayer * pPlayer = GET_PLAYER_POINTER_I(id);
return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0;
}
@ -1443,7 +1408,7 @@ int MNF_IsPlayerHLTV(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return (GET_PLAYER_POINTER_I(id)->pEdict->v.flags & FL_PROXY) ? 1 : 0;
}
@ -1451,7 +1416,7 @@ float MNF_GetPlayerArmor(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return (GET_PLAYER_POINTER_I(id)->pEdict->v.armorvalue);
}
@ -1459,7 +1424,7 @@ float MNF_GetPlayerHealth(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return (GET_PLAYER_POINTER_I(id)->pEdict->v.health);
}
@ -1481,7 +1446,7 @@ void MNF_Log(const char *fmt, ...)
_vsnprintf(msg, sizeof(msg) - 1, fmt, arglst);
//vsprintf(msg, fmt, arglst);
va_end(arglst);
AMXXLOG_Log("%s", msg);
}
@ -1496,7 +1461,7 @@ extern "C" void LogError(AMX *amx, int err, const char *fmt, ...)
char msg_buffer[2048];
msg_buffer[0] = '\0';
if (fmt != NULL)
{
va_list ap;
@ -1534,7 +1499,7 @@ extern "C" void LogError(AMX *amx, int err, const char *fmt, ...)
return;
}
//give the user a first-chance at blocking the error from displaying
if (pHandler->HandleError(fmt ? msg_buffer : NULL) != 0)
{
@ -1550,7 +1515,7 @@ extern "C" void LogError(AMX *amx, int err, const char *fmt, ...)
{
AMXXLOG_Error("%s", msg_buffer);
}
Debugger::GenericMessage(amx, err);
if (err != AMX_ERR_EXIT)
{
@ -1590,7 +1555,7 @@ edict_t* MNF_GetPlayerEdict(int id)
{
if (id < 1 || id > gpGlobals->maxClients)
return NULL;
return (GET_PLAYER_POINTER_I(id)->pEdict);
}
@ -1639,7 +1604,7 @@ inline bool operator ==(func_s &arg1, const char *desc)
{
if (strcmp(arg1.desc, desc) == 0)
return true;
return false;
}
@ -1920,11 +1885,11 @@ void *Module_ReqFnptr(const char *funcName)
{
// code
// ^---- really? wow!
g_LastRequestedFunc = funcName;
CList<func_s, const char *>::iterator iter;
for (iter = g_functions.begin(); iter; ++iter)
{
if (strcmp(funcName, iter->desc) == 0)
@ -1937,7 +1902,7 @@ void *Module_ReqFnptr(const char *funcName)
Debugger *DisableDebugHandler(AMX *amx)
{
Debugger *pd = static_cast<Debugger *>(amx->userdata[UD_DEBUGGER]);
amx->userdata[UD_DEBUGGER] = NULL;
amx->flags &= ~(AMX_FLAG_DEBUG);
amx_SetDebugHook(amx, NULL);
@ -1957,12 +1922,12 @@ void EnableDebugHandler(AMX *amx, Debugger *pd)
#if !defined MEMORY_TEST && !defined WIN32
void * operator new(size_t size)
{
return (calloc(1, size));
return (calloc(1, size));
}
void * operator new[](size_t size)
{
return (calloc(1, size));
return (calloc(1, size));
}
void operator delete(void * ptr)

View File

@ -242,7 +242,7 @@ int read_number(char *input)
char *end; /* Temporary pointer, needed for strtoul(). */
// if begins with 0x or 0X it's to be interpretted as hex
if (*input=='0' &&
if (*input=='0' &&
(*(input+1)=='x' || *(input+1)=='X'))
{
return strtoul(input,&end,16);
@ -307,7 +307,7 @@ int ReadConfig(void)
{
char FileName[512];
MF_BuildPathnameR(FileName,sizeof(FileName)-1,"%s",get_localinfo("amxx_configsdir","addons/amxmodx/configs"));
MF_BuildPathnameR(FileName,sizeof(FileName),"%s",get_localinfo("amxx_configsdir","addons/amxmodx/configs"));
strncat(FileName,"/hamdata.ini",sizeof(FileName)-1);

View File

@ -46,13 +46,13 @@ static cell nvault_open(AMX *amx, cell *params)
int len, id=-1;
char *name = MF_GetAmxString(amx, params[1], 0, &len);
char path[255], file[255];
MF_BuildPathnameR(path, sizeof(path)-1, "%s/vault", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"));
MF_BuildPathnameR(path, sizeof(path), "%s/vault", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"));
sprintf(file, "%s/%s.vault", path, name);
for (size_t i=0; i<g_Vaults.length(); i++)
{
if (!g_Vaults[i])
continue;
if (strcmp(g_Vaults.at(i)->GetFilename(), file) == 0)
if (strcmp(g_Vaults.at(i)->GetFilename(), file) == 0)
return i;
}
NVault *v = (NVault *)g_VaultMngr.OpenVault(file);

View File

@ -59,13 +59,13 @@ static cell AMX_NATIVE_CALL SQL_MakeDbTuple(AMX *amx, cell *params)
char path[255];
FILE *fp;
MF_BuildPathnameR(path, sizeof(path)-1, "%s", db);
MF_BuildPathnameR(path, sizeof(path), "%s", db);
if ((fp=fopen(path, "rb")))
{
fclose(fp);
sql->db = strdup(path);
} else {
MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3/%s.sq3",
MF_BuildPathnameR(path, sizeof(path), "%s/sqlite3/%s.sq3",
MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"),
db);
sql->db = strdup(path);
@ -601,7 +601,7 @@ static cell AMX_NATIVE_CALL SQL_SetCharset(AMX *amx, cell *params)
return 0;
}
AMX_NATIVE_INFO g_BaseSqlNatives[] =
AMX_NATIVE_INFO g_BaseSqlNatives[] =
{
{"SQL_MakeDbTuple", SQL_MakeDbTuple},
{"SQL_FreeHandle", SQL_FreeHandle},
@ -630,4 +630,3 @@ AMX_NATIVE_INFO g_BaseSqlNatives[] =
{NULL, NULL},
};

View File

@ -17,7 +17,7 @@
static int g_ident = 0;
SqlFunctions g_SqliteFuncs =
SqlFunctions g_SqliteFuncs =
{
&g_Sqlite,
SetMysqlAffinity,
@ -69,7 +69,7 @@ void OnAmxxAttach()
MF_OverrideNatives(g_OldCompatNatives, MODULE_NAME);
char path[255];
MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"));
MF_BuildPathnameR(path, sizeof(path), "%s/sqlite3", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"));
if (!DirExists(path))
{
mkdir(path
@ -96,4 +96,3 @@ void OnPluginsUnloaded()
extern "C" void __cxa_pure_virtual(void)
{
}

View File

@ -73,14 +73,14 @@ static cell AMX_NATIVE_CALL dbi_connect(AMX *amx, cell *params)
int err;
char error[512];
/** if there is an older database, read there instead of the new path */
MF_BuildPathnameR(path, sizeof(path)-1, "%s", info.database);
MF_BuildPathnameR(path, sizeof(path), "%s", info.database);
FILE *fp = fopen(path, "rb");
if (fp)
{
fclose(fp);
info.database = path;
} else {
MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3/%s.sq3",
MF_BuildPathnameR(path, sizeof(path), "%s/sqlite3/%s.sq3",
MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"),
info.database);
info.database = path;
@ -439,14 +439,14 @@ static cell AMX_NATIVE_CALL dbi_field_name(AMX *amx, cell *params)
return 1;
}
AMX_NATIVE_INFO g_OldCompatNatives[] =
AMX_NATIVE_INFO g_OldCompatNatives[] =
{
{ "dbi_connect", dbi_connect },
{ "dbi_query", dbi_query },
{ "dbi_query2", dbi_query2 },
{ "dbi_field", dbi_field },
{ "dbi_nextrow", dbi_nextrow },
{ "dbi_close", dbi_close },
{ "dbi_field", dbi_field },
{ "dbi_nextrow", dbi_nextrow },
{ "dbi_close", dbi_close },
{ "dbi_error", dbi_error },
{ "dbi_type", dbi_type },
{ "dbi_free_result", dbi_free_result },