• Welcome to Valhalla Legends Archive.
 

Sending SID_CHATCOMMAND via chat client

Started by Insolence, July 25, 2005, 02:23 AM

Previous topic - Next topic

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):
BNetConn.Send ( "some text" );

Using this method:
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 ");
}
}


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

// 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
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 :)

Mephisto

Show us your actual Send method and the full hex dump of the packet sent/received without the comments and such.

Insolence

#2
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 :)

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.

Insolence

Thanks guys.

The C++ bot I can vaguely understand, but the part I really need is totally confusing me:
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;
}


QuoteIf 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.
So I'd send it like this? (which doesn't work)
BNetConn.Send("Some text...\x00"); ?

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.

MyndFyre

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));
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Insolence

#7
Quote from: Arta[vL] on July 25, 2005, 03:42 PM
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.
Oh I got that much, used it before in PHP/C#.

I just didn't get this part:
  va_start(argptr, lpszFmt);
  vsprintf(szOutStr, lpszFmt, argptr);
  va_end(argptr);
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" );

Elneroth

Quote from: Elneroth on July 25, 2005, 06:31 AM
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.

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.
frmCon.sckCon.SendData Data & vbCrLf

Arta

Quote from: Insolence on July 25, 2005, 04:59 PM
I just didn't get this part:
va_start(argptr, lpszFmt);
vsprintf(szOutStr, lpszFmt, argptr);
va_end(argptr);
Not familiar with those at all =\

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.

MyndFyre

Quote from: Insolence on July 25, 2005, 04:59 PM
BNetConn.Send ( textBox1.Text + "\r\n" );
Save your memory.  The system-supplied Environment.NewLine string will work just as well.  ;)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

K

Quote from: MyndFyre on July 25, 2005, 07:35 PM
Quote from: Insolence on July 25, 2005, 04:59 PM
BNetConn.Send ( textBox1.Text + "\r\n" );
Save your memory. The system-supplied Environment.NewLine string will work just as well. ;)

Unless you're running on a platform where Environment.NewLine is not a carriage return followed by a newline, such as *nix or macintosh?

Insolence

Quote from: MyndFyre on July 25, 2005, 07:35 PM
Quote from: Insolence on July 25, 2005, 04:59 PM
BNetConn.Send ( textBox1.Text + "\r\n" );
Save your memory.  The system-supplied Environment.NewLine string will work just as well.  ;)
Oh that's trivial, besides, this is my first bot.  I'm allowed to be lazy :)