AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Trying to catch ServerCommand (https://forums.alliedmods.net/showthread.php?t=10168)

Geesu 02-10-2005 10:54

Trying to catch ServerCommand
 
OK I uncommented this link in my moduleconfig.h:
Code:
#define FN_ServerCommand            ServerCommand

ANd this is my code:
Code:
void ServerCommand(char *crap) {     const char *szCmd = CMD_ARGV(0);     SERVER_PRINT(szCmd);     if ( strcmp(szCmd, "debugit") == 0 )     {         char msg[512];         int pos = 0;         // Loop through all the races         for(int i = 0; i < 20; i++)         {             IRace *race = manager.GetRace(i);             if ( race != NULL )             {                 pos += sprintf(msg + pos, "Race: %s found at %i\n", race->racename, i);             }             else             {                 pos += sprintf(msg + pos, "Null race at %i\n", i);             }         }         SERVER_PRINT(msg);     }     RETURN_META(MRES_IGNORED); }

But when I type ANY command I can't catch anything, even if I try SERVER_PRINT(crap). When I type a command in the server console and hit enter it doesn't print anything. I have done this before so I'm confused as to what I'm doing wrong. Help pls.

Da Bishop 02-10-2005 17:48

ummm perhaps

Code:

CMD_ARGV(0)

be

Code:

CMD_ARGV[0]
just thinking

Freecode 02-10-2005 23:19

try printing crap since its passed into the function
Code:
void ServerCommand(char *crap)

PM 02-11-2005 04:02

As I have told you on IRC, the function you are hooking is the one AMXX invokes when you run the server_cmd native. That is, external DLLs can tell the engine to send some crap to its command parser as a server command - without the need to type it into the console. Note that you would only be able to intercept it when the gamedll calls it - which is pretty unlikely. There is no generic server command hook, like ClientCommand.

AMX/AMXX does this by calling REG_SVR_COMMAND for every registered server command / client command. They register every command to a central hook (plugin_srvcmd in srvcmd.cpp), which does a similar action to the function you have posted.

Geesu 02-11-2005 08:26

Re: Trying to catch ServerCommand
 
Quote:

Originally Posted by Geesu
even if I try SERVER_PRINT(crap)

Come on freecode :P :P You wouldn't think I'd try that. Yea thanks for the heads up PM.

Owyn 09-06-2009 07:33

Re: Trying to catch ServerCommand
 
so did you guys succeed hooking server commands? ^^ i need it

Exolent[jNr] 09-06-2009 14:49

Re: Trying to catch ServerCommand
 
Quote:

Originally Posted by PM (Post 88430)
As I have told you on IRC, the function you are hooking is the one AMXX invokes when you run the server_cmd native. That is, external DLLs can tell the engine to send some crap to its command parser as a server command - without the need to type it into the console. Note that you would only be able to intercept it when the gamedll calls it - which is pretty unlikely. There is no generic server command hook, like ClientCommand.

AMX/AMXX does this by calling REG_SVR_COMMAND for every registered server command / client command. They register every command to a central hook (plugin_srvcmd in srvcmd.cpp), which does a similar action to the function you have posted.



All times are GMT -4. The time now is 20:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.