Valhalla Legends Forums Archive | Battle.net Bot Development | Sending SID_CHATCOMMAND via chat client

AuthorMessageTime
Insolence
I can connect to B.Net as a chat client now, many hours of trying.  I hope that's appriciated around here, found everything myself :)

But I can't figure out how to send a message, I'm trying this, after reading on BNetDocs it's simply (String):
[code]BNetConn.Send ( "some text" );[/code]

Using this method:
[code] public void Send(string mystring)
{
try
{
// send it through the socket to battle.net
byte[] msg = Encoding.ASCII.GetBytes(mystring);

this.BNetSocket.Send(msg);
}
catch
{
MessageBox.Show("There was a problem sending data through socket.\r\n ");
}
}[/code]

I know that's probably not right, I've been trying to dissect the packets:

[code] // asdfasdf
// 0a 55 17 e0 7c 24 92 [dc e6 42 2f 13] 50 18 [fe 6b] 54 [2d] 00 00

            // Something.
// 0a 55 17 e0 7c 24 92 [99 e6 42 2e 49] 50 18 [ff 35] 54 [2e] 00 00

// Like it should be SAYING stuff, but she aint
// 0a 55 17 e0 7c 24 92 [ab e6 42 2f 13] 50 18 [fe 6b] 54 [51] 00 00
[/code]Marking in brackets what's changed, but I figure the packets are different because I'm using a D2XP client to get my packets.

I've been trying really hard, once again, I hope it's appriciated.  You've all been a good help before, and I hope I can expect the same this time.  Thanks guys :)
July 25, 2005, 7:23 AM
Mephisto
Show us your actual Send method and the full hex dump of the packet sent/received without the comments and such.
July 25, 2005, 8:45 AM
Insolence
That is the actual send method.

The packets are packets I captured from Stealthbot, using D2XP.

EDIT:
Also, the commented packets are messages I was sending on SB.  I suppose I should've said that, probably doesn't make much sense :)
July 25, 2005, 9:34 AM
Arta
It looks to me like you're trying to write a chat client (good idea -- it's much simpler) in which case, BnetDocs isn't going to be of much help. It only documents the binary protocols.

Since you're using C#, I assume you'll be familiar enough with C++ at least to be able to read it, so try downloading greetbot and reading through the source code for that. It shows you how to log on, and how to parse the information you receive.
July 25, 2005, 3:49 PM
Insolence
Thanks guys.

The C++ bot I can vaguely understand, but the part I really need is totally confusing me:
[code]int __cdecl BnBot::Send(char *lpszFmt, ...) {
  char szOutStr[MAXTEXTLENGTH];
  va_list argptr;

  va_start(argptr, lpszFmt);
  vsprintf(szOutStr, lpszFmt, argptr);
  va_end(argptr);

  if (send(s, szOutStr, strlen(szOutStr), 0) < 0)
    return 0;

  return 1;
}[/code]

[quote]If you're using a pure chat connection, you need to add a chr(0) at the end of the string, and chat connections are in plain text. So people would be viewing your message in HEX.[/quote]So I'd send it like this? (which doesn't work)
[code]BNetConn.Send("Some text...\x00");[/code] ?
July 25, 2005, 7:32 PM
Arta
iirc, you need to convert the encoding to 8-bit ascii first.

That function allows you to send information using a printf-style format string, like: Send("%s%u", szUsername, iSomeNumber), which would concatenate the username and the number. You don't really need to do that unless you want to. Just think of it as a send function.
July 25, 2005, 8:42 PM
Myndfyr
In a chat connection, don't you need to append CRLF to a string, not NULL?

In which case, you'd want to Send(String.Concat(text, Environment.NewLine));
July 25, 2005, 9:48 PM
Insolence
[quote author=Arta[vL] link=topic=12328.msg121975#msg121975 date=1122324166]
iirc, you need to convert the encoding to 8-bit ascii first.

That function allows you to send information using a printf-style format string, like: Send("%s%u", szUsername, iSomeNumber), which would concatenate the username and the number. You don't really need to do that unless you want to. Just think of it as a send function.
[/quote]Oh I got that much, used it before in PHP/C#.

I just didn't get this part:
[code]  va_start(argptr, lpszFmt);
  vsprintf(szOutStr, lpszFmt, argptr);
  va_end(argptr);[/code] Not familiar with those at all =\

Anyway, I'll try the 8bit thing, and the newline thing.  Thanks :)


EDIT: Newline thing worked:
BNetConn.Send ( textBox1.Text + "\r\n" );
July 25, 2005, 9:59 PM
Elneroth
[quote author=Elneroth link=topic=12328.msg121950#msg121950 date=1122291107]
If you're using a pure chat connection, you need to add a chr(0) at the end of the string, and chat connections are in plain text. So people would be viewing your message in HEX.
[/quote]

Yeah, MyndFire is right.
Sorry, I wasn't looking at my source when I posted that and I haven't worked with chat in a long time.
[code]frmCon.sckCon.SendData Data & vbCrLf[/code]
July 25, 2005, 11:08 PM
Arta
[quote author=Insolence link=topic=12328.msg121990#msg121990 date=1122328778]
I just didn't get this part:
[code] va_start(argptr, lpszFmt);
vsprintf(szOutStr, lpszFmt, argptr);
va_end(argptr);[/code] Not familiar with those at all =\
[/quote]

That's the bit that parses the arguments (vsprintf). va_start and va_end are macros that prepare the varargs so that they can be passed to vsprintf (argptr). The final product ends up in szOutStr.
July 26, 2005, 12:30 AM
Myndfyr
[quote author=Insolence link=topic=12328.msg121990#msg121990 date=1122328778]
BNetConn.Send ( textBox1.Text + "\r\n" );
[/quote]
Save your memory.  The system-supplied Environment.NewLine string will work just as well.  ;)
July 26, 2005, 12:35 AM
K
[quote author=MyndFyre link=topic=12328.msg122008#msg122008 date=1122338126]
[quote author=Insolence link=topic=12328.msg121990#msg121990 date=1122328778]
BNetConn.Send ( textBox1.Text + "\r\n" );
[/quote]
Save your memory. The system-supplied Environment.NewLine string will work just as well. ;)
[/quote]

Unless you're running on a platform where Environment.NewLine is not a carriage return followed by a newline, such as *nix or macintosh?
July 26, 2005, 4:43 AM
Insolence
[quote author=MyndFyre link=topic=12328.msg122008#msg122008 date=1122338126]
[quote author=Insolence link=topic=12328.msg121990#msg121990 date=1122328778]
BNetConn.Send ( textBox1.Text + "\r\n" );
[/quote]
Save your memory.  The system-supplied Environment.NewLine string will work just as well.  ;)
[/quote]Oh that's trivial, besides, this is my first bot.  I'm allowed to be lazy :)
July 26, 2005, 5:56 AM

Search