.:: 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
new CS update screws up intercepting chat messages!?
Old
  (#1)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default new CS update screws up intercepting chat messages!? - 15-06-2004

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.


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

Last edited by stefanhendriks; 15-06-2004 at 12:55..
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#2)
minorgod
Member
 
minorgod's Avatar
 
Status: Offline
Posts: 43
Join Date: Jan 2004
Default Re: new CS update screws up intercepting chat messages!? - 15-06-2004

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.


Nowhere does science promise emancipation.
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#3)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#4)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

perhaps it's because of strcpy(). try using strncpy() instead.
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#5)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

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.


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#6)
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: new CS update screws up intercepting chat messages!? - 16-06-2004

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).



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: new CS update screws up intercepting chat messages!?
Old
  (#7)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

@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...


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

Last edited by stefanhendriks; 16-06-2004 at 16:29..
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#8)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#9)
stefanhendriks
RealBot Author
 
stefanhendriks's Avatar
 
Status: Offline
Posts: 3,088
Join Date: Nov 2003
Location: Netherlands
Default Re: new CS update screws up intercepting chat messages!? - 16-06-2004

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


Author of RealBot, "Arrakis" and "Dune 2 - The Maker" | co-Founder of Bots-United | Fundynamic | Blog | E-Mail me
  
Reply With Quote
Re: new CS update screws up intercepting chat messages!?
Old
  (#10)
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: new CS update screws up intercepting chat messages!? - 16-06-2004

Thanks for the fix! It simplified this part of my code a LOT.



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
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