Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
free chat function

 
Post new topic   Reply to topic Printable version
 View previous topic  Areawarp plugin doesn't work Post :: Post second bot in arena  View next topic  
Author Message
Cheese
Wow Cheese is so helpful!


Joined: Mar 18 2007
Posts: 1012
Offline

PostPosted: Wed Sep 10, 2008 11:45 pm    Post subject: free chat function Reply to topic Reply with quote

free chat function!

wrote it a few nights ago.
questions/comments/suggestions?


Code: Show/Hide

void botInfo::UnpackChatMsg(char* in_msg, int& channel, char* name, char* msg, char* bigmsg)
{ //Channel Message Unpacker by Cheese
   char buf;
   char buf1;
   char incomingbuf[255]="";
   char chatbuf[2]="";
   char namebuf[20]="";
   char msgbuf[255]="";
   int flag=0;
   int inum=100;
   int c1=0;
   int c2=0;
   int c3=0;
   
   int len=strlen(in_msg);
   for(int i=0; i < len; i++)
   {
      buf=*(in_msg+i);
      buf1=*(in_msg+i+1);
     
      incomingbuf[i]=buf;
      if(i<=1 && buf!=':')
      {
         chatbuf[c1]=buf;
         c1++;
         continue;
      }
      if(buf=='>' && buf1==' ')
      {
         flag=1;
      }
      if(i>=2 && flag==0)
      {
         namebuf[c2]=buf;
         inum=i+2;
         c2++;
         continue;
      }
      if(i>inum)
      {
         namebuf[c2]='\0';
         msgbuf[c3]=buf;
         c3++;
         continue;
      }
   }
   
   
   for(int i4 = 0; i4 < 255; i4++)
   {
      bigmsg[i4] = incomingbuf[i4];
   }
   //sendPublic(incomingbuf);
   //sendPublic("Stuff: Chat#="+(String)chatbuf+" Name="+(String)namebuf+" Message="+(String)msgbuf);
   
   channel=int(chatbuf[0]-48);
   for(int i2 = 0; i2 < 20; i2++)
   {
      name[i2] = namebuf[i2];
   }
   for(int i3 = 0; i3 < 255; i3++)
   {
      msg[i3] = msgbuf[i3];
   }
   
   return;
}


just put the message in the call, and it will return the channel number, person who said it, their message, and the whole undigested part by reference!
_________________
SSC Distension Owner
SSCU Trench Wars Developer
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address
Snrrrub
Novice


Joined: May 29 2008
Posts: 37
Offline

PostPosted: Thu Sep 11, 2008 11:57 am    Post subject: Reply to topic Reply with quote

There's an out-of-bounds array access when you do:

Code: Show/Hide

buf1=*(in_msg+i+1);


On the last iteration of the loop, you're accessing an array element one past the end of the supplied buffer which could result in a crash.

The "namebuf" should be at least 25 bytes long since client <--> game server protocol assumes names with a max length of 24.

The "incomingbuf" variable should be eliminated - it's not necessary since you're just copying "in_msg" into it.

I haven't looked at the entire thing to be completely honest but you don't need to set flags and have strange control flow (continue, break, loops, etc.) to make something like this work - instead you should probably use sscanf and you'll accomplish the same in just a few lines.

I'd post a solution here but then where's the fun in learning about sscanf? icon_smile.gif

-Snrrrub
Back to top
View users profile Send private message Add User to Ignore List
Cheese
Wow Cheese is so helpful!


Joined: Mar 18 2007
Posts: 1012
Offline

PostPosted: Thu Sep 11, 2008 4:10 pm    Post subject: Reply to topic Reply with quote

well, this was written in mervbot initially, so ill keep [20] over [25] for awhile =P
also gonna keep incomingbuf, because its exclusively for debugging(commented out part)

why use sscanf if -2ez-? icon_razz.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address
Samapico
No, these DO NOT look like penises, ok?


Age:32
Gender:Gender:Male
Joined: May 08 2003
Posts: 1252
Location: Montreal, Canada
Offline

PostPosted: Thu Sep 11, 2008 4:59 pm    Post subject: Reply to topic Reply with quote

Quote:
well, this was written in mervbot initially, so ill keep [20] over [25] for awhile =P
But incoming CHAT messages might not have the same format... you receive the whole name of the player, and its message. So if you send messages from the Event_Chat to there, it might go BOOM
_________________
DCME co-developer
17th Parallel Head Sysop
Subspace: The Future
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 168 page(s) served in previous 5 minutes.

phpBB Created this page in 0.118996 seconds : 28 queries executed (66.8%): GZIP compression disabled