Cleaned up some code, added checks for msgid != 0 (so AMXX doesn't crash mods which don't support text based menus for example)

This commit is contained in:
Pavol Marko 2004-05-28 11:29:44 +00:00
parent 8c600f90c3
commit 9307994060

View File

@ -56,6 +56,9 @@ void UTIL_ShowMenu( edict_t* pEdict, int slots, int time, char *menu, int mlen )
char c = 0; char c = 0;
int a; int a;
if (!gmsgShowMenu)
return; // some games don't support ShowMenu (Firearms)
while ( *n ) { while ( *n ) {
a = mlen; a = mlen;
if ( a > 175 ) a = 175; if ( a > 175 ) a = 175;
@ -76,6 +79,9 @@ void UTIL_ShowMenu( edict_t* pEdict, int slots, int time, char *menu, int mlen )
/* warning - don't pass here const string */ /* warning - don't pass here const string */
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name) void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name)
{ {
if (!gmsgServerName)
return; // :TODO: Maybe output a warning log?
MESSAGE_BEGIN( MSG_ONE , gmsgServerName, NULL, client ); MESSAGE_BEGIN( MSG_ONE , gmsgServerName, NULL, client );
WRITE_STRING(name); WRITE_STRING(name);
MESSAGE_END(); MESSAGE_END();
@ -222,6 +228,9 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
(here in AMX it is always longer) */ (here in AMX it is always longer) */
void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg ) void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg )
{ {
if (!gmsgTextMsg)
return; // :TODO: Maybe output a warning log?
char c = msg[190]; char c = msg[190];
msg[190] = 0; // truncate without checking with strlen() msg[190] = 0; // truncate without checking with strlen()
if ( pEntity ) if ( pEntity )
@ -234,38 +243,56 @@ void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg )
msg[190] = c; msg[190] = c;
} }
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, const char *arg2) { // UTIL_FakeClientCommand
if (!cmd) return; // PURPOSE: Sends a fake client command to GameDLL
//strncpy(g_fakecmd.argv[0], cmd, 127 ); // HOW DOES IT WORK:
//g_fakecmd.argv[0][ 127 ] = 0; // 1) Stores command and arguments into a global and sets the global "fake" flag to true
// 2) Invokes ClientCommand in GameDLL
// 3) meta_api.cpp overrides Cmd_Args, Cmd_Argv, Cmd_Argc and gives them fake values if the "fake" flag is set
// 4) unsets the global "fake" flag
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, const char *arg2)
{
if (!cmd)
return; // no command
// store command
g_fakecmd.argv[0] = cmd; g_fakecmd.argv[0] = cmd;
if (arg2){ // if only arg2 is passed, swap the arguments
g_fakecmd.argc = 3; if (!arg1 && arg2)
{
arg1 = arg2;
arg2 = NULL;
}
// store arguments
if (arg2)
{ // both arguments passed
g_fakecmd.argc = 3; // 2 arguments + 1 command
// store arguments
g_fakecmd.argv[1] = arg1; g_fakecmd.argv[1] = arg1;
g_fakecmd.argv[2] = arg2; g_fakecmd.argv[2] = arg2;
// build argument line
snprintf(g_fakecmd.args, 255, "%s %s", arg1, arg2); snprintf(g_fakecmd.args, 255, "%s %s", arg1, arg2);
// if snprintf reached 255 chars limit, this will make sure there will be no access violation
g_fakecmd.args[255] = 0; g_fakecmd.args[255] = 0;
//strncpy(g_fakecmd.argv[1], arg1 , 127 );
//g_fakecmd.argv[1][ 127 ] = 0;
//strncpy(g_fakecmd.argv[2], arg2 , 127 );
//g_fakecmd.argv[2][ 127 ] = 0;
//snprintf(g_fakecmd.args, 255 , "%s %s",arg1,arg2);
//g_fakecmd.args[255] = 0;
} }
else if (arg1){ else if (arg1)
g_fakecmd.argc = 2; { // only one argument passed
g_fakecmd.argc = 2; // 1 argument + 1 command
// store argument
g_fakecmd.argv[1] = arg1; g_fakecmd.argv[1] = arg1;
// build argument line
snprintf( g_fakecmd.args, 255, "%s", arg1); snprintf( g_fakecmd.args, 255, "%s", arg1);
// if snprintf reached 255 chars limit, this will make sure there will be no access violation
g_fakecmd.args[255] = 0; g_fakecmd.args[255] = 0;
//strncpy(g_fakecmd.argv[1], arg1, 127 );
//g_fakecmd.argv[1][ 127 ] = 0;
//*g_fakecmd.argv[2] = 0;
//snprintf(g_fakecmd.args, 255 ,"%s",arg1);
//g_fakecmd.args[255] = 0;
} }
else else
g_fakecmd.argc = 1; g_fakecmd.argc = 1; // no argmuents -> only one command
// set the global "fake" flag so the Cmd_Arg* functions will be superceded
g_fakecmd.fake = true; g_fakecmd.fake = true;
// tell the GameDLL that the client sent a command
MDLL_ClientCommand(pEdict); MDLL_ClientCommand(pEdict);
// unset the global "fake" flag
g_fakecmd.fake = false; g_fakecmd.fake = false;
} }