.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   new CS update screws up intercepting chat messages!? (http://forums.bots-united.com/showthread.php?t=1978)

stefanhendriks 15-06-2004 11:48

new CS update screws up intercepting chat messages!?
 
Hey guys,

I upgraded my CS version today on STEAM. Ran my bot, everything is fine. I say something to my bot... and BAM. it crashes

Code:

void BotClient_CS_SayText(void *p, int bot_index)
{
static unsigned char ucEntIndex;
static int state = 0; // current state machine state
if (state == 0)
{
ucEntIndex = *(unsigned char *)p;
}
else if (state == 1)
{
cBot *pBot=&bots[bot_index];
if(ENTINDEX(pBot->pEdict) != ucEntIndex)
{
char sentence[80];
char chSentence[80];
char netname[30];
memset (sentence, 0, sizeof (sentence));
memset (chSentence, 0, sizeof (chSentence));
memset (netname, 0, sizeof (netname));
 
strcpy(sentence,(char *)p);
// remove first part of sentence.
int length = strlen (sentence) - strlen (strstr (sentence, " : "));
 
int tc=0;
int c;
for (c=length; c < 80; c++)
{
        chSentence[tc] = sentence[c];
        tc++;
}
//strncpy (chSentence, (char *)sentence[length], 80-length);
//strcpy(netname, STRING(pBot->pEdict->v.netname));
//strcpy(netname, sentence, strlen(strstr(sentence, " : "));
 
int nc=0;
c=2;
if (strstr(sentence, "*DEAD*"))
        c+= 6;
 
if (counterstrike == 0)
        c=1;
for (c; c < length; c++)
{
        netname[nc] = sentence[c];
        nc++;
}
ChatEngine.set_sentence(netname, chSentence);
state = -1;
}
}
state++;
}

this is the code i used, and it worked fine.

Even when my bots are not supposed to chat, and i type a message there is something going horribly wrong.

I am not sure WHERE it crashes as all i get is a 'read' error and no specific indications from CS/HL.EXE

edit:
i have sent cliffe a mail about this, i hope he responds at all... and if he does, with something that can help us out.

minorgod 15-06-2004 22:51

Re: new CS update screws up intercepting chat messages!?
 
Glad it's not just me! I'm getting the exact same behavior with the latest CVS update. I'm getting a segfault whenever I try to chat. I have no clue why, but I thought it might be a Linux-only problem. Guess it could be steam, but I didn't notice the problem until I updated and recompiled from the latest CVS. I was going to try a rollback, but I didn't save the previous version.

stefanhendriks 16-06-2004 11:02

Re: new CS update screws up intercepting chat messages!?
 
well, as soon asi disable catching this message in my code, everything runs fine. So its definatly something wrong there.

Also Cheating-Death does not work with this CS anymore (ver 4.22.0), so i guess they DID change something.. i still have no word of Cliffe. Dammit

Whistler 16-06-2004 11:08

Re: new CS update screws up intercepting chat messages!?
 
perhaps it's because of strcpy(). try using strncpy() instead.

stefanhendriks 16-06-2004 11:17

Re: new CS update screws up intercepting chat messages!?
 
Whistler, i can try that, but i don't think it will work. As i said, the code *worked* already, until the new CS update came around.

Too bad i threw out that engine interception stuff of Botman to figure out how engine messages are build up. Now i have to regrab that code or something. I think they have changed the chat message handler, perhaps a state more or less.

Perhaps you are right and something is wrong with my code, although it worked perfectly before. Anyway, gtg check it out.

Pierre-Marie Baty 16-06-2004 14:10

Re: new CS update screws up intercepting chat messages!?
 
Message interception still seem to work fine here with my bot...
I'd advise to rewrite this function in a cleaner way anyway. And don't start reading the message at the first character, since the first character has always been a non-printable formatting character (color code).

stefanhendriks 16-06-2004 15:28

Re: new CS update screws up intercepting chat messages!?
 
@PMB;

I have added lots of debug lines, and guess what. The format HAS changed. Instead of sending the actual chat string when state = 1. I now get a string saying for "WHO" it is...

ie, in CS 1.5 my debug lines say:
Quote:

------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'Dumb : hello
'
Going to find : in the sentence...Found!
------END state=1------

and in CS 1.6, the same situation, same chat sentence, says:
Quote:

------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'#Cstrike_Chat_All'
Going to find : in the sentence...Not found!
------END state=1------
------State=0------
Passed
------State=1------
Dunno
Passed memset
Copied string
Length check of sentence:'hello
'
Going to find : in the sentence...Not found!
------END state=1------
Notice that in CS 1.6 the chat message gets sent TWICE?

So yes, you are correct in CS 1.5 and former CS 1.6 (former=before 14th june) you could do this. I bet they DID change in CS 1.6 the format... perhaps in 4 or maybe 5 states.. something like:

state=0 remains same
state=1 for who?
state=2 sentence
state=3 netname who sent message?

i gtg figure this out soon.

EDIT:
what crashed my code was that strstr did NOT find ":" in the new sentence of CS 1.6, therefor returning NULL to strlen, which caused a crash...

stefanhendriks 16-06-2004 16:06

Re: new CS update screws up intercepting chat messages!?
 
I had to reimplement the engine debugging stuff, but eventually i got what i wanted:

Quote:

ENGINE: pfnMessageBegin(), dest=1, msg_type=76
ENGINE: pfnWriteByte() - '1'
ENGINE: pfnWriteByte() - '#Cstrike_Chat_All'
ENGINE: pfnWriteByte() - ''
ENGINE: pfnWriteByte() - 'hello everybody
'
ENGINE: pfnMessageEnd()
I guess its all you need:
1 is entity index
2 some flag, so ya know to who and what, etc
3 don't know
4 the actual sentence

stefanhendriks 16-06-2004 16:27

Re: new CS update screws up intercepting chat messages!?
 
okay, i have fixed my bug. Here is my code now:

Code:

void BotClient_CS_SayText(void *p, int bot_index)
{
 static unsigned char ucEntIndex;
 static int state = 0;  // current state machine state
 // Different Counter-Strike versions mean different
 // handling of this "SayText" thingy.
 if (counterstrike==0)
 {
  if (state == 0)
  {
  ucEntIndex = *(unsigned char *)p;
  }
  else if (state == 1)
  { 
  cBot *pBot=&bots[bot_index];
 
  if (ENTINDEX(pBot->pEdict) != ucEntIndex)
  {
        log("Dunno\n");
        char sentence[80];
        char chSentence[80];
        char netname[30]; 
        memset (sentence, 0, sizeof (sentence));
        memset (chSentence, 0, sizeof (chSentence));
        memset (netname, 0, sizeof (netname));
               
        strcpy(sentence,(char *)p);
                 
        int length=0;
        // FIXED: In any case that this might return NULL, do not crash the server
        if (strstr (sentence, " : "))
        length = strlen (sentence) - strlen (strstr (sentence, " : "));
       
        int tc=0,c;
        for (c=length; c < 80; c++)
        {
        chSentence[tc] = sentence[c];
        tc++;
        }
        edict_t *pPlayer = INDEXENT (ucEntIndex);
        strcpy(netname, STRING(pPlayer->v.netname));
        ChatEngine.set_sentence(netname, chSentence);
        state = -1;
  }
  }
 }
 else if (counterstrike==1)
 {
  // CS 1.6
  if (state == 0)
  {
  // who sent this message?
  ucEntIndex = *(unsigned char *)p;
  }
  // to who?
  else if (state == 1)
  {
  // here must be some team check so we do not let bots
  // of the other team react to this somehow..
 
  }
  // don't know?
  else if (state == 2)
  {
  // do nothing here
  }
  // the actual sentence
  else if (state == 3)
  {
  // sentence
  char sentence[80];
  char netname[30]; 
       
  // init
  memset (sentence, 0, sizeof (sentence));
  memset (netname, 0, sizeof (netname));
 
  // copy in memory
  strcpy(sentence,(char *)p);
  // copy netname
  edict_t *pPlayer = INDEXENT (ucEntIndex);
  strcpy(netname, STRING(pPlayer->v.netname));
 
  // and give chatengine something to do
  ChatEngine.set_sentence(netname, sentence);
  state=-1;
  }
 }
 state++;
}

note, it still needs to be optimized so that bots do NOT hear you when you are talking on team messages and such, but that should not be a real problem. Its just a bit of comparing strings "#Cstrike_Chat_All" and such. I might post an update of my source when that works too ;)

Pierre-Marie Baty 16-06-2004 20:07

Re: new CS update screws up intercepting chat messages!?
 
Thanks for the fix! It simplified this part of my code a LOT. :)

stefanhendriks 16-06-2004 21:19

Re: new CS update screws up intercepting chat messages!?
 
no probs ;) will send the bill later :D

Whistler 17-06-2004 13:25

Re: new CS update screws up intercepting chat messages!?
 
[ double post is deleted ]

Whistler 17-06-2004 13:26

Re: new CS update screws up intercepting chat messages!?
 
...and it isn't just "#Cstrike_Chat_All", here's what I've found in the new cstrike_english.txt file, go figure them out yourself ;)
Code:

// Radio and chat strings can have control characters embedded to set colors.  For the control characters to be used, one must be at the start of the string.
// The control characters can be copied and pasted in notepad.
//  = 0x02 (STX) - Use team color up to the end of the player name.  This only works at the start of the string, and precludes using the other control characters.
//  = 0x03 (ETX) - Use team color from this point forward
//  = 0x04 (EOT) - Use location color from this point forward
//  = 0x01 (SOH) - Use normal color from this point forward

"Game_radio"                                        "%s1 (RADIO): %s2"
"Cstrike_Chat_CT"                                "(Counter-Terrorist) %s1 :  %s2"
"Cstrike_Chat_T"                                "(Terrorist) %s1 :  %s2"
"Cstrike_Chat_CT_Dead"                                "*DEAD*(Counter-Terrorist) %s1 :  %s2"
"Cstrike_Chat_T_Dead"                                "*DEAD*(Terrorist) %s1 :  %s2"
"Cstrike_Chat_Spec"                                "(Spectator) %s1 :  %s2"
"Cstrike_Chat_All"                                "%s1 :  %s2"
"Cstrike_Chat_AllDead"                                "*DEAD* %s1 :  %s2"
"Cstrike_Chat_AllSpec"                                "*SPEC* %s1 :  %s2"
"Cstrike_Name_Change"                                "* %s1 changed name to %s2"


Whistler 18-06-2004 00:39

Re: new CS update screws up intercepting chat messages!?
 
well, I think catching the chat messages in ClientCommand() DLL function may be a good idea, and that should work in any versions of HL/CS/OP4 and whatever MOD. Just catch the "say" and "say_team" command and use pfnCmd_Args() to get the text.

Pierre-Marie Baty 18-06-2004 02:11

Re: new CS update screws up intercepting chat messages!?
 
Probably yes, but you would have to take care of who receives what yourself, then.

stefanhendriks 18-06-2004 08:35

Re: new CS update screws up intercepting chat messages!?
 
i got word of turtlerock about the exact format:

Quote:

The SayText message changed to allow for localization, and place names. Before, it looked like this, where the first character of 'text' was 0x02, and it included the player name and chat text:

Code:

MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev );
 WRITE_BYTE( ENTINDEX( pEntity ));
 WRITE_STRING( text );
MESSAGE_END();

Now, the message is constructed like this:

Code:

MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev );
 WRITE_BYTE( ENTINDEX( pEntity ));
 WRITE_STRING( pszFormat );
 WRITE_STRING( "" ); // will be filled in with player name
 WRITE_STRING( text );
 if ( placeName )
 {
  WRITE_STRING( placeName );
 }
MESSAGE_END();

The format string (pszFormat above) is something like "#Cstrike_Chat_CT", so if you are doing a strstr() for the player name in that string and not NULL checking, you would now crash. I don't have the RealBot source, so I can't tell if that's the problem or not.

Please let me know if this helps or if you need more info.

Matt Campbell



@$3.1415rin 18-06-2004 10:45

Re: new CS update screws up intercepting chat messages!?
 
thx to stefan for that info :D

minorgod 18-06-2004 17:34

Re: new CS update screws up intercepting chat messages!?
 
Stefan, I copied your bug fix and recompiled, but there's still some problem with the bot on Linux. It seems to work fine until you get about 6 bots on the server. Then suddenly, the human players start pinging over 300. Each additional bot increases the ping and it quickly becomes unplayable. I actually tried commenting out the entire contents of the BotClient_CS_SayText function, but that had no effect, so I think the problem lies elsewhere.

stefanhendriks 18-06-2004 23:25

Re: new CS update screws up intercepting chat messages!?
 
perhaps its in the debugging info. Did you try my new CVS updated source? (btw, post about this on the RealBot Source forum)

cruft 20-06-2004 23:41

Re: new CS update screws up intercepting chat messages!?
 
Does anyone know if the UTIL_SayText utility function must also be revised to the new message format?

stefanhendriks 21-06-2004 00:05

Re: new CS update screws up intercepting chat messages!?
 
Yes it should be revised, but thats merely for the looks, not for the game to work properly.

Pierre-Marie Baty 21-06-2004 03:05

Re: new CS update screws up intercepting chat messages!?
 
I don't think so. I use the same TextMsg message that botman's UTIL_SayText uses to display a lot of debugging stuff for my bot, and so far all my messages display fine.

stefanhendriks 21-06-2004 09:01

Re: new CS update screws up intercepting chat messages!?
 
sure they display fine... but have you taken a look at the new format in CS 1.6? If you use that format the 'looks' are different.. thats what i said ;)

Whistler 21-06-2004 10:51

Re: new CS update screws up intercepting chat messages!?
 
Code:


void ClientCommand( edict_t *pEntity )
{
  const char *pcmd = CMD_ARGV(0);
  const char *arg1 = CMD_ARGV(1);

  static int iFillServerTeam = 5;

  if (isFakeClientCommand == 0)
  {
      if (FStrEq(pcmd, "say") || FStrEq(pcmd, "say_team"))
      {
        bool bAlive = IsAlive(pEntity);
        int iTeam = -1;
        if (FStrEq(pcmd, "say_team"))
            iTeam = UTIL_GetTeam(pEntity);

        for (int i = 0; i < gpGlobals->maxClients; i++)
        {
            if (!ThreatTab[i].IsUsed ||
              (iTeam != -1 && iTeam != ThreatTab[i].iTeam) ||
              bAlive != IsAlive(ThreatTab[i].pEdict))
              continue;
            CBaseBot *pBot = g_rgpBots[i];
            if (pBot)
            {
              pBot->m_SaytextBuffer.iEntityIndex = ENTINDEX(pEntity);
              strcpy(pBot->m_SaytextBuffer.szSayText, CMD_ARGS());
              pBot->m_SaytextBuffer.fTimeNextChat = gpGlobals->time + pBot->m_SaytextBuffer.fChatDelay;
            }
        }
      }

I prefer this one since it's much simpler, and the POD-Bot already has code to deal with what bots said.
The only problem is it won't catch other bots' messages if other bots use botman's chat code.

Pierre-Marie Baty 21-06-2004 12:05

Re: new CS update screws up intercepting chat messages!?
 
just remove the if (isFakeClientCommand) check then... :)


All times are GMT +2. The time now is 20:19.

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