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.
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.
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.
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 (http://msdn2.microsoft.com/en-us/library/ms741559(VS.85).aspx).
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?
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);?
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
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.
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