Fixed bug where a file handle would stay opened on error; added id validations to MNF player natives

This commit is contained in:
Pavol Marko 2004-05-28 11:27:50 +00:00
parent 7695d24a50
commit 14e59c6967

View File

@ -43,6 +43,7 @@ ModuleCallReason g_ModuleCallReason;
extern const char* no_function; // stupid work around extern const char* no_function; // stupid work around
void report_error( int code, char* fmt, ... ) void report_error( int code, char* fmt, ... )
{ {
va_list argptr; va_list argptr;
@ -88,7 +89,6 @@ void free_amxmemory(void **ptr)
int load_amxscript(AMX *amx, void **program, const char *filename, char error[64]){ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64]){
AMX_HEADER hdr;
int err; int err;
FILE *fp; FILE *fp;
@ -119,6 +119,7 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
//if ( (*program = malloc( (int)hdr.stp )) == 0 ) //if ( (*program = malloc( (int)hdr.stp )) == 0 )
{ {
strcpy(error,"Failed to allocate memory"); strcpy(error,"Failed to allocate memory");
fclose(fp);
return (amx->error = AMX_ERR_MEMORY); return (amx->error = AMX_ERR_MEMORY);
} }
@ -681,82 +682,118 @@ void MNF_CopyAmxMemory(cell * dest, const cell * src, int len)
int MNF_IsPlayerValid(int id) int MNF_IsPlayerValid(int id)
{ {
if (id < 0 || id > gpGlobals->maxClients) if (id < 1 || id > gpGlobals->maxClients)
return 0; return 0;
CPlayer *pPlayer = GET_PLAYER_POINTER_I(id); CPlayer *pPlayer = GET_PLAYER_POINTER_I(id);
return (pPlayer->initialized) ? 1 : 0; return (pPlayer->initialized) ? 1 : 0;
} }
const char * MNF_GetPlayerName(int id) const char * MNF_GetPlayerName(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return NULL;
return GET_PLAYER_POINTER_I(id)->name.str(); return GET_PLAYER_POINTER_I(id)->name.str();
} }
const char * MNF_GetPlayerIP(int id) const char * MNF_GetPlayerIP(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return NULL;
return GET_PLAYER_POINTER_I(id)->ip.str(); return GET_PLAYER_POINTER_I(id)->ip.str();
} }
int MNF_IsPlayerInGame(int id) int MNF_IsPlayerInGame(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->ingame ? 1 : 0; return GET_PLAYER_POINTER_I(id)->ingame ? 1 : 0;
} }
int MNF_IsPlayerBot(int id) int MNF_IsPlayerBot(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->IsBot() ? 1 : 0; return GET_PLAYER_POINTER_I(id)->IsBot() ? 1 : 0;
} }
int MNF_IsPlayerAuthorized(int id) int MNF_IsPlayerAuthorized(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->authorized ? 1 : 0; return GET_PLAYER_POINTER_I(id)->authorized ? 1 : 0;
} }
float MNF_GetPlayerTime(int id) float MNF_GetPlayerTime(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->time; return GET_PLAYER_POINTER_I(id)->time;
} }
float MNF_GetPlayerPlayTime(int id) float MNF_GetPlayerPlayTime(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->playtime; return GET_PLAYER_POINTER_I(id)->playtime;
} }
int MNF_GetPlayerCurweapon(int id) int MNF_GetPlayerCurweapon(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->current; return GET_PLAYER_POINTER_I(id)->current;
} }
int MNF_GetPlayerTeamID(int id) int MNF_GetPlayerTeamID(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->teamId; return GET_PLAYER_POINTER_I(id)->teamId;
} }
int MNF_GetPlayerDeaths(int id) int MNF_GetPlayerDeaths(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->deaths; return GET_PLAYER_POINTER_I(id)->deaths;
} }
int MNF_GetPlayerMenu(int id) int MNF_GetPlayerMenu(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->menu; return GET_PLAYER_POINTER_I(id)->menu;
} }
int MNF_GetPlayerKeys(int id) int MNF_GetPlayerKeys(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->keys; return GET_PLAYER_POINTER_I(id)->keys;
} }
int MNF_IsPlayerAlive(int id) int MNF_IsPlayerAlive(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return GET_PLAYER_POINTER_I(id)->IsAlive() ? 1 : 0; return GET_PLAYER_POINTER_I(id)->IsAlive() ? 1 : 0;
} }
float MNF_GetPlayerFrags(int id) float MNF_GetPlayerFrags(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return GET_PLAYER_POINTER_I(id)->pEdict->v.frags; return GET_PLAYER_POINTER_I(id)->pEdict->v.frags;
} }
int MNF_IsPlayerConnecting(int id) int MNF_IsPlayerConnecting(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
CPlayer * pPlayer = GET_PLAYER_POINTER_I(id); CPlayer * pPlayer = GET_PLAYER_POINTER_I(id);
return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0; return (!pPlayer->ingame && pPlayer->initialized && (GETPLAYERUSERID(pPlayer->pEdict) > 0)) ? 1 : 0;
} }
int MNF_IsPlayerHLTV(int id) 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; return (GET_PLAYER_POINTER_I(id)->pEdict->v.flags & FL_PROXY) ? 1 : 0;
} }
float MNF_GetPlayerArmor(int id) float MNF_GetPlayerArmor(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0.0f;
return (GET_PLAYER_POINTER_I(id)->pEdict->v.armorvalue); return (GET_PLAYER_POINTER_I(id)->pEdict->v.armorvalue);
} }
float MNF_GetPlayerHealth(int id) float MNF_GetPlayerHealth(int id)
{ {
if (id < 1 || id > gpGlobals->maxClients)
return 0;
return (GET_PLAYER_POINTER_I(id)->pEdict->v.health); return (GET_PLAYER_POINTER_I(id)->pEdict->v.health);
} }