.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
A fix for FakeClientCommand() code.
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default A fix for FakeClientCommand() code. - 05-08-2004

Code:
void CGeneral::FakeClientCommand(CClient *pClient, const char *fmt, ...)
{
   if (!pClient->Valid())
      return; // reliability check

   edict_t *pFakeClient = pClient->edict();

   va_list argptr;
   char command[256];
   int length, fieldstart, fieldstop, i, index, stringindex = 0;

   // concatenate all the arguments in one string
   va_start(argptr, fmt);
   _vsnprintf(command, sizeof(command), fmt, argptr);
   va_end(argptr);

   if (*command == 0)
      return; // if nothing in the command buffer, return

   m_bIsFakeClientCommand = TRUE; // set the "fakeclient command" flag
   length = strlen(command); // get the total length of the command string

   // process all individual commands (separated by a semicolon) one each a time
   while (stringindex < length) {
      fieldstart = stringindex; // save field start position (first character)
      while (stringindex < length && command[stringindex] != ';')
         stringindex++; // reach end of field
      if (command[stringindex - 1] == '\n')
         fieldstop = stringindex - 2; // discard any trailing '\n' if needed
      else
         fieldstop = stringindex - 1; // save field stop position (last character before semicolon or end)
      for (i = fieldstart; i <= fieldstop; i++)
         m_szCmdArgv[i - fieldstart] = command[i]; // store the field value in the g_argv global string
      m_szCmdArgv[i - fieldstart] = 0; // terminate the string
      stringindex++; // move the overall string index one step further to bypass the semicolon

      index = 0;
      m_iCmdArgc = 0; // let's now parse that command and count the different arguments
+      m_pszCmdArgs = "";

      // count the number of arguments
      while (index < i - fieldstart) {
         while (index < i - fieldstart && m_szCmdArgv[index] == ' ')
            index++; // ignore spaces

+         if (m_iCmdArgc == 1) {
+            m_pszCmdArgs = &m_szCmdArgv[index];
+         }

         // is this field a group of words between quotes or a single word ?
         if (m_szCmdArgv[index] == '"') {
            index++; // move one step further to bypass the quote
            while (index < i - fieldstart && m_szCmdArgv[index] != '"')
               index++; // reach end of field
            index++; // move one step further to bypass the quote
         } else {
            while (index < i - fieldstart && m_szCmdArgv[index] != ' ')
               index++; // this is a single word, so reach the end of field
         }

         m_iCmdArgc++; // we have processed one argument more
      }

      ClientCommand(pFakeClient); // tell now the MOD DLL to execute this ClientCommand...
   }

   m_szCmdArgv[0] = 0; // when it's done, reset the g_argv field
   m_bIsFakeClientCommand = FALSE; // reset the "fakeclient command" flag
   m_iCmdArgc = 0; // and the argument count
}
...and:
Code:
const char *pfnCmd_Args(void)
{
   if (g_General.IsFakeClientCommand())
      return g_General.m_pszArgs;
   return (*g_engfuncs.pfnCmd_Args)();
}
m_pszCmdArgs is (char *m_pszCmdArgs

Note that the pfnCmd_Args() isn't supposed to return the command name (not only "say" "say_team" but also whatever command name). It isn't "bug in HL engine". You can look at the cmd.c file in Quake1 source code to find it out.

PS, This is PMB's code, however botman's original one also has this bug. It won't affect too much to CS, but if some MOD use pfnCmd_Args() to do something this will cause problem for bots.
  
Reply With Quote
Re: A fix for FakeClientCommand() code.
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: A fix for FakeClientCommand() code. - 05-08-2004

I don't get it here... what are the symptoms of the bug, and how are you fixing it ?



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: A fix for FakeClientCommand() code.
Old
  (#3)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: A fix for FakeClientCommand() code. - 07-08-2004

eg, when you typed "command arg1 arg2 arg3" in the console, the pfnCmd_Args() just returns "arg1 arg2 arg3" and NOT "command arg1 arg3 arg3".

That doesn't only happen when command is "say" or "say_team" but whatever command.
  
Reply With Quote
Re: A fix for FakeClientCommand() code.
Old
  (#4)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: A fix for FakeClientCommand() code. - 07-08-2004

yes, that bug was known but somehow nobody wanted to fix it or did not see any advantage in it. The only advantage i see in this now, is that you can make chatting a lot easier:

FakeClientCOmmand("say", text, null, null);

will make bots chat in the proper CS 1.x format... And you dont have to worry about sending this message to other clients.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com