• Welcome to Valhalla Legends Archive.
 

Data Types and Sockets

Started by FrostWraith, March 23, 2008, 11:03 AM

Previous topic - Next topic

FrostWraith

OK.  Well I have created my first client written purely in C that can connect to servers and such.  I have decided that making it connect to BNET and BNLS are good practice servers for me.  The problem is I don't have anything like a packet buffer or ways to modify the data to be sent.  It's not that I can't write some crude code, I just don't know an efficient way to do it in C.  In my opinion, for each packet, I would construct a struct.

Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of.  It is just purely inexperience with the language.

Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits.  I want to know if their are any libraries to assist with this.

One last thing is whether or not I should be doing connect() or WSAConnect().  Which is more up to date?  Which is better and for what reasons?

Please post even if you don't have an all out explanation.  I just would like to learn this all piece by piece.
Thank you.

brew

Quote from: FrostWraith on March 23, 2008, 11:03 AM
OK.  Well I have created my first client written purely in C that can connect to servers and such.  I have decided that making it connect to BNET and BNLS are good practice servers for me.  The problem is I don't have anything like a packet buffer or ways to modify the data to be sent.  It's not that I can't write some crude code, I just don't know an efficient way to do it in C.  In my opinion, for each packet, I would construct a struct.
A struct? are you sure about that?
And what about variable length strings? :d

Quote
Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of.  It is just purely inexperience with the language.
If you'd like, I can PM you my packetbuffer.c.

Quote
Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits.  I want to know if their are any libraries to assist with this.
I'm not sure I can say that i know what you're talking about, but if you want to get rid of the high and low bits, then what's stopping you from NANDing them out? "dword &= ~(0x80000001);"

Quote
One last thing is whether or not I should be doing connect() or WSAConnect().  Which is more up to date?  Which is better and for what reasons?
I personally use connect(), since WSAConnect calls it down the road anyway. WSA* functions are just lame wrappers for the winsock api. They don't do anything too special.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

FrostWraith

I would definitely be interested in seeing how you formed your packet buffer.  Thanks for the reply.

I am used to programming in a lot of languages where much is handed to you so I am not used to having to do it all myself  :P.

NicoQwertyu

Quote from: FrostWraith on March 23, 2008, 11:03 AM
One last thing is whether or not I should be doing connect() or WSAConnect().  Which is more up to date?  Which is better and for what reasons?

AFAIK, WSAConnect() supports more options at connection time, such as a QoS request and some connect data used for legacy protocols such as DECNet and OSI TP4. For what you're doing, use connect(). If you want to read more, the link to the MSDN page is here.

FrostWraith

Thank you once again for your code brew, but I am trying not to copy, so here is my dilemma.

So far since the packet have been small, this has worked, but if I were to write larger packets, how would this do?

memset(sendbuffer, (unsigned short)(pbufferlen), 1);

I am trying to write a WORD typed variable into the first two bytes of the string to be sent.  Since I have only tested on REQUESTVERBYTE on bnls, the packer size has only been 7.  Will this work if we start getting into larger packets?

NicoQwertyu

#5
Quotevoid * memset ( void * ptr, int value, size_t num );   <cstring>


Fill block of memory

Sets the first num bytes of the block of memory pointed by ptr to the specified value (interpreted as an unsigned char).

The size of the packet shouldn't make a difference. Isn't a WORD two bytes though? Would you want:
memset(sendbuffer, pbufferlen, 2);?

l2k-Shadow

Quote from: FrostWraith on March 24, 2008, 10:05 PM
Thank you once again for your code brew, but I am trying not to copy, so here is my dilemma.

So far since the packet have been small, this has worked, but if I were to write larger packets, how would this do?

memset(sendbuffer, (unsigned short)(pbufferlen), 1);

I am trying to write a WORD typed variable into the first two bytes of the string to be sent.  Since I have only tested on REQUESTVERBYTE on bnls, the packer size has only been 7.  Will this work if we start getting into larger packets?

*(WORD*)(sendbuffer + 2) = pbufferlen
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

FrostWraith

Thanks, I got this ultimately to work with

*(unsigned short *)(sendbuffer) = (unsigned short)(pbufferlen);


I wrote some code that would need both bytes and it matched across other languages.
Thanks again.

UserLoser

#8
Quote from: FrostWraith on March 23, 2008, 11:03 AM
OK.  Well I have created my first client written purely in C that can connect to servers and such.  I have decided that making it connect to BNET and BNLS are good practice servers for me.  The problem is I don't have anything like a packet buffer or ways to modify the data to be sent.  It's not that I can't write some crude code, I just don't know an efficient way to do it in C.  In my opinion, for each packet, I would construct a struct.

Can anyone point me in the direction of an article or preparing data to be sent across a socket or post some source code to learn off of.  It is just purely inexperience with the language.

Another question of mine is a way to get a function like CreateWORD and CreateDWORD without sending low and high bits.  I want to know if their are any libraries to assist with this.

One last thing is whether or not I should be doing connect() or WSAConnect().  Which is more up to date?  Which is better and for what reasons?

Please post even if you don't have an all out explanation.  I just would like to learn this all piece by piece.
Thank you.

Not sure how picky you are on C vs C++ personally who cares:
http://www.valhallalegends.com/pub/BC4/Prerelease/BinaryChat4SDK.zip

See StoreBuffer.h and ParseBuffer.h.  I use a system that is almost exact to that