Valhalla Legends Forums Archive | Battle.net Bot Development | [c++] problem with sending data

AuthorMessageTime
mentalCo.
ok im connected and in a channel... when i send this exact packet: "FF 0E 09 41 41 41 41 41 00" nothing happens... theoretically it should send 5 'A's to the channel... am i doing this wrong?
June 10, 2004, 4:18 AM
Eli_1
I believe your packet header is wrong.

It goes like this:

Byte 1 = FF
Byte 2 = Packet ID (0E in your example)
Bytes 3-4 (WORD) = Packet size including this header

Then your null-terminated string.

[Edit]
The dump of your packet shoud actually look like this:
FF 0E 00 09 41 41 41 41 41 00 ÿ...AAAAA.

(I think)
June 10, 2004, 4:25 AM
mentalCo.
size is two bytes? how does that work? just the size as first byte then 00 as second?
June 10, 2004, 4:29 AM
Eli_1
Yes, two bytes - allowing for a much larger packet.

[Edit]
Assuming you're using a packetbuffer class, it probably adds the header on for you.

[code]
PacketBuffer.InsertNTString "AAAAA"
PacketBuffer.SendPacket &H0E
[/code]
June 10, 2004, 4:36 AM
mentalCo.
damn this is complicated... how would i put together a packet then lol. can i put all the bytes into a string then put that into a char then send it. no that wouldnt work... ::pulls hair out::
June 10, 2004, 4:40 AM
Eli_1
I forgot this was C++ - oops.
June 10, 2004, 4:41 AM
Maddox
Should be FF 0E 0A 00 41 41 41 41 41 00

The size is an unsigned short (WORD) in little endian byte order.
June 10, 2004, 5:06 AM
Moonshine
You're going to want to store the packet size in a 2 byte (16-bit) variable. In C++ this means (assuming you're using win32 or linux, and a fairly recent processor/compiler) an unsigned short variable.

So you'll want something like this:

FF 0E 0A 00 41 41 41 41 41 00 ÿ...AAAAA.

Note that it's not 00 0A, eli, since we're using little endian here.

Here's a quick example I whipped up to show you the basics of forming a bnet packet in C++:

[code]
unsigned short PacketSize = 10;

unsigned char szBuffer[MAXSIZE] = ""; // initialize a canned buffer (unsigned char since we're dealing with >127 ascii character values)
szBuffer[0] = 0xFF; // insert magic&packetID
szBuffer[1] = 0x0E;
*(unsigned short *)(szBuffer + 2) = PacketSize; // insert packet size (ushort) starting at buffer[2]
strcpy((char *)szBuffer + 4, "AAAAA"); // copy the string onto the end of the buffer (just past the header)

/* do error checking here */ send(mysock, szBuffer, PacketSize, 0); // Send data off to bnet
[/code]

Also note putting regular packet construction routines in a class would be highly recommended (similar to DM's packet buffer thingy (tm))

Edit: maddox correct eli at the same time, sorry for the repeat
June 10, 2004, 5:11 AM
Eli_1
Thanks for correcting me, I thought I might have had it wrong. :-\

Blah, I also just realized I wasn't counting the null character, which is why I had 9 and not 10.
June 10, 2004, 5:16 AM
Moonshine
An honest mistake :)
June 10, 2004, 5:18 AM
mentalCo.

when i compile i get error that send() cant use unisigned char, it needs just char. what to do?
June 10, 2004, 5:23 AM
Moonshine
[quote author=mentalCo. link=board=17;threadid=7182;start=0#msg64515 date=1086845033]

when i compile i get error that send() cant use unisigned char, it needs just char. what to do?
[/quote]

Oh sorry, i forgot to account for the needed typecast (I believe it's actually a void * argument in send() on linux?)

so you'll need to put send(mysock, (char *) szBuffer, PacketSize, 0);

Edit: Yes, on linux it's const void* :

[code]
*nix/bsd:

ssize_t
send(int s, const void *msg, size_t len, int flags);
[/code]
VS.
[code]
win32:
int send(
SOCKET s,
const char* buf,
int len,
int flags
);
[/code]
June 10, 2004, 5:31 AM
mentalCo.
oy... ok the screenname im using is mentalco. when i send text all that shows up in channel is "<mentalco.> " with no text.
June 10, 2004, 5:33 AM
Moonshine
[quote author=mentalCo. link=board=17;threadid=7182;start=0#msg64517 date=1086845633]
oy... ok the screenname im using is mentalco. when i send text all that shows up in channel is "<mentalco.> " with no text.
[/quote]

Are you sure you're changing the PacketSize variable to account for your different lengthed text messages? If you have "VERY LONG MESSAGE HERE," you'll definitely need to increase the size of PacketSize accordingly.
June 10, 2004, 6:13 AM
mentalCo.
do i have to convert packetsize to a hex value?

ok i can get it to say a message 5 letters long... but if i type, for example, "hellohello" it will replace the first 5 letters with "?"... so it will look like "<mentalco.>?hello" heres the code...

[code]

void SEND(char szText[500])
{
unsigned short PacketSize = strlen(szText)+5;
szText[strlen(szText)]='\n';
unsigned char szBuffer[MAXSIZE] = ""; // initialize a canned buffer (unsigned char since we're dealing with >127 ascii character values)
szBuffer[0] = 0xFF; // insert magic&packetID
szBuffer[1] = 0x0E;
*(unsigned short *)(szBuffer + 2) = PacketSize; // insert packet size (ushort) starting at buffer[2]
strcpy((char *)szBuffer + 4, szText); // copy the string onto the end of the buffer (just past the header)
//if((send(sockfd, (char *)szBuffer, PacketSize, 0))==-1){cout<<"disconnected";}

}[/code]

June 10, 2004, 7:53 AM
UserLoser.
[quote author=mentalCo. link=board=17;threadid=7182;start=0#msg64498 date=1086841097]
ok im connected and in a channel... when i send this exact packet: "FF 0E 09 41 41 41 41 41 00" nothing happens... theoretically it should send 5 'A's to the channel... am i doing this wrong?
[/quote]

Remember that Battle.net doesn't echo back your own chat messages, so you would have to display your name and your message without an event being triggered
June 10, 2004, 1:52 PM
mentalCo.
ya...

my only problem now is that it takes the first 5 letters of whatever i send and replaces them with a question mark followed by the rest of the text. has this happened to anyone?
edit

i fixed it heres my code

[code]
void SEND(char szText[500])
{

unsigned short PacketSize = strlen(sBuf);
szText[strlen(sBuf)]='\n';
unsigned char szBuffer[MAXSIZE] = ""; // initialize a canned buffer (unsigned char since we're dealing with >127 ascii character values)
szBuffer[0] = 0xFF; // insert magic&packetID
szBuffer[1] = 0x0E;
*(unsigned short *)(szBuffer + 2) = PacketSize; // insert packet size (ushort) starting at buffer[2]
sprintf((char *)szBuffer + 3, szText); // copy the string onto the end of the buffer (just past the header)
if((send(sockfd, (char *)szBuffer, PacketSize+5, 0))==-1){cout<<"ERRRRRRRROOOOR\n\nasdfasdfasd";}

}

[/code]
June 10, 2004, 7:16 PM

Search