mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
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:
parent
8c600f90c3
commit
9307994060
@ -56,6 +56,9 @@ void UTIL_ShowMenu( edict_t* pEdict, int slots, int time, char *menu, int mlen )
|
||||
char c = 0;
|
||||
int a;
|
||||
|
||||
if (!gmsgShowMenu)
|
||||
return; // some games don't support ShowMenu (Firearms)
|
||||
|
||||
while ( *n ) {
|
||||
a = mlen;
|
||||
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 */
|
||||
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 );
|
||||
WRITE_STRING(name);
|
||||
MESSAGE_END();
|
||||
@ -219,9 +225,12 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
|
||||
}
|
||||
|
||||
/* warning - buffer of msg must be longer than 190 chars!
|
||||
(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 )
|
||||
{
|
||||
if (!gmsgTextMsg)
|
||||
return; // :TODO: Maybe output a warning log?
|
||||
|
||||
char c = msg[190];
|
||||
msg[190] = 0; // truncate without checking with strlen()
|
||||
if ( pEntity )
|
||||
@ -234,38 +243,56 @@ void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg )
|
||||
msg[190] = c;
|
||||
}
|
||||
|
||||
void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1, const char *arg2) {
|
||||
if (!cmd) return;
|
||||
//strncpy(g_fakecmd.argv[0], cmd, 127 );
|
||||
//g_fakecmd.argv[0][ 127 ] = 0;
|
||||
// UTIL_FakeClientCommand
|
||||
// PURPOSE: Sends a fake client command to GameDLL
|
||||
// HOW DOES IT WORK:
|
||||
// 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;
|
||||
if (arg2){
|
||||
g_fakecmd.argc = 3;
|
||||
// if only arg2 is passed, swap the arguments
|
||||
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[2] = arg2;
|
||||
snprintf( g_fakecmd.args ,255 , "%s %s",arg1,arg2 );
|
||||
// build argument line
|
||||
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;
|
||||
//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){
|
||||
g_fakecmd.argc = 2;
|
||||
else if (arg1)
|
||||
{ // only one argument passed
|
||||
g_fakecmd.argc = 2; // 1 argument + 1 command
|
||||
// store argument
|
||||
g_fakecmd.argv[1] = arg1;
|
||||
snprintf( g_fakecmd.args ,255 , "%s" , arg1 );
|
||||
// build argument line
|
||||
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;
|
||||
//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
|
||||
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;
|
||||
// tell the GameDLL that the client sent a command
|
||||
MDLL_ClientCommand(pEdict);
|
||||
// unset the global "fake" flag
|
||||
g_fakecmd.fake = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user