.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   pfnAddServerCommand (http://forums.bots-united.com/showthread.php?t=62)

stefanhendriks 24-12-2003 18:12

pfnAddServerCommand
 
Okay, so i have been diggin into this piece of junk ;) I have this code, and it does not work in CS 1.5 listen server or dedicated server. I issue the command:

rbcm rb_addbot

which should add a bot ;)

ps. do not mind the CVAR_REGISTER function.... ;)
Code:

// SERVER Command: RealBot
void rbcm ( void )
{
    const char *pcmd = Cmd_Argv(0);
    const char *arg1 = Cmd_Argv(1);
    const char *arg2 = Cmd_Argv(2);
    const char *arg3 = Cmd_Argv(3);
    const char *arg4 = Cmd_Argv(4);

    edict_t *pEntity = listenserver_edict; //
     
    // Handle command here
    if (FStrEq(pcmd, "rb_addbot"))
    {
        Game.CreateBot( pEntity, arg1, arg2, arg3, arg4 );
        bot_check_time = gpGlobals->time + 5.0;
        return;
    }

    return;
}


void GameDLLInit( void )
{

  CVAR_REGISTER (&sv_bot);

  for (int i=0; i<32; i++)
      clients[i] = NULL; 

  // initialize the bots array of structures...
  memset(bots, 0, sizeof(bots));

  Game.LoadNames();
  Game.LoadChat();
  Game.LoadBuyTable();

  // NodeMachine
  NodeMachine.init(); // INIT on load up
  NodeMachine.init_players();

  // Register server command
  (*g_engfuncs.pfnAddServerCommand)( "rbcm", rbcm );

  (*other_gFunctionTable.pfnGameInit)();
}


Pierre-Marie Baty 24-12-2003 21:05

Re: pfnAddServerCommand
 
Do NOT use your own (hooked) versions of pfnCmd_Argv and pfnCmd_Argc, instead use the CMD_ARGV and CMD_ARGC macros to the direct engine functions... also notice that if your sv_bot CVAR is called "rbcm", registering a rbcm server command may not work...

Other than that what you have here should work :)

botmeister 28-12-2003 07:07

Re: pfnAddServerCommand
 
I built a general purpose server/client command registration and dispatch system for the mean bot/admin mod, there's a few hundred lines of code which is too much to post in here, but here's some bits which show how I get agruments for custom server and client commands. Each command that is executed, is passed an array of strings "vtxArgList" (in my case using the standard C++ string class, not the C style strings). The nice part about this system is ALL my custom commands use the exact same argument header and dispatch function. In otherwords, I only register one standard dispatch function associated with each command name. When a server command is executed, it calls the dispatch function, the dispatch function then looks up the command in an array of registered commands (which include security settings and other nice things). When a match is found, it gets the arguments and passes it to the custom command function as a standard array of strings. From there, the custom command function simply does whatever it is supposed to do using as its arguments the array of strings. It's VERY simple to use, but was a bit complicated to figure out at first. I've been using it for so long now I've almost forgottem how it works!

Anyway here's the code that gets the arguments, hope you can read the non standard naming convention I've been using :)

Code:

int finGetCmdLineArgCount( void )
 { // returns number of command line arguments including the command itself;
  return CMD_ARGC();
 }
 
 string ftxGetCmdLineArgValue( int pinIdx )
 {
  return CMD_ARGV( pinIdx );
 }
 
 string ftxGetCmdLineString( void )
 { // returns the command line argument list;
  // does *not* include the command portion;
  return CMD_ARGS( );
 }
 
 void tclCommand::fvoGetArgs( void )
 {
  vinNumArgs = finGetCmdLineArgCount( );
  if ( vinNumArgs > cinMaxArgs )
  // ensure our buffer does not overflow
  vinNumArgs = cinMaxArgs;
  else
  if ( vinNumArgs < cinMinArgs )
  // ensure our buffer does not overflow
  vinNumArgs = cinMinArgs;
  int vinIdx;
  for ( vinIdx = 0; vinIdx < vinNumArgs; vinIdx++ )
  {
  vtxArgList[ vinIdx ] = ftxGetCmdLineArgValue( vinIdx );
        fvoToLower( vtxArgList[ vinIdx ] );
  }
  for (; vinIdx <= cinMaxArg_Idx; vinIdx++ )
  {
  vtxArgList[ vinIdx ] = "";
  }
  if ( vinNumArgs > 1 )
  {
  vtxArgString = ftxGetCmdLineString( );
  }
  else
  {
  vtxArgString.erase( );
  }
 
 } // tclCommand::fvoGetArgs


Fierce Recon 11-01-2004 08:05

Re: pfnAddServerCommand
 
Code:

const char *pcmd = Cmd_Argv(1);
const char *arg1 = Cmd_Argv(2);
const char *arg2 = Cmd_Argv(3);
const char *arg3 = Cmd_Argv(4);
const char *arg4 = Cmd_Argv(5);


Hope this helps

P.S. 0th argument is the command name, like rbcm

In your case it'll be: (lets pretend abcde is his name, and 1 is his team)
rbcm rb_addbot abcde 1
Code:

*pcmd = "rb_addbot";
*arg1 = "abcde";
*arg2 = "1";
*arg3 = UNDEFINED; //(DONT EVEN TRY THIS)
*arg4 = UNDEFINED; //(DONT EVEN TRY THIS)

:RTFM:

Pierre-Marie Baty 12-01-2004 03:39

Re: pfnAddServerCommand
 
nonono, if you're using your own registered server command, DON'T use your own Cmd_Argv(), Cmd_Argc() and Cmd_Args(). Use the MACROS which call the direct engine functions, CMD_ARGV(), CMD_ARGC() and CMD_ARGS(). If you don't, your code will work, but NOT if a bot is issuing a Client Command at the same time. You will have unpredictable results if this happens, and it will.

Cheeseh 13-01-2004 19:04

Re: pfnAddServerCommand
 
Fierce recon is correct about the pcmd you want being the first argument and not the 0th.

If using your own CMD_ARG.. functions they will work ok as long as you dont use metamod since they call the engine function anyway.

If using metamod though you need to call the engine cmd_args functions as your versions of cmd_arg under metamod will probably just do nothing as they RETURN_META.


All times are GMT +2. The time now is 11:53.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.