Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Trurl

Network

Recommended Posts

Cleaned up the network code in client, now there's one function for sending each type of packet...

I don't know if you like it, because it involves a lot of code change only for sake of structure. :(

All network packet sending functions can be found in network.c...

 

network_cleanup.patch

Share this post


Link to post
Share on other sites

SDL_net doesn't know what type of data you are sending...

 

void send_TRADE_WITH(int actId) {

Uint8 msg[6];

msg[0]=TRADE_WITH;

*((int *)(msg+1))=actId; <- how should it know that there's an int in the Uint8 array

my_tcp_send(my_socket,msg,5);

}

 

exactly that line would generate an bus-error on sparc cpu's cuz the pointer isn't int aligned...

Share this post


Link to post
Share on other sites

np...but its a good idea to put it all in one file like u did...so there's only one place to look at if some1 wants to do the byteoder/alignment stuff...or some future protocol changes :(

Share this post


Link to post
Share on other sites

void send_TRADE_WITH(int actId) {

Uint8 msg[6];

msg[0]=TRADE_WITH;

memcpy(msg+1, &actId, sizeof (actId));

my_tcp_send(my_socket,msg,5);

}

 

or:

 

void send_TRADE_WITH(int actId) {

Uint8 msg[8];

msg[3]=TRADE_WITH;

*((int *)(msg+4))=actId; <- how should it know that there's an int in the Uint8 array

my_tcp_send(my_socket,msg+3,5);

}

Share this post


Link to post
Share on other sites

His point was that every place that had that kind of int casting would cause an error on archs that require alignment, not just in that one function :P

Share this post


Link to post
Share on other sites

In my Ant bot code I handle the sending of packets differently to make things easier. I use writePacket(packetType, dataLength, *dataPtr). And dataLength is the length of the data pointed to by dataPtr and writePacket handles the +1 so I never forget. Then writePacket is responsible for assembling the data to be sent to the server in the proper order.

 

I've found that method to be handy in keeping my code nice and simple.

Share this post


Link to post
Share on other sites
In my Ant bot code I handle the sending of packets differently to make things easier. I use writePacket(packetType, dataLength, *dataPtr). And dataLength is the length of the data pointed to by dataPtr and writePacket handles the +1 so I never forget. Then writePacket is responsible for assembling the data to be sent to the server in the proper order.

 

I've found that method to be handy in keeping my code nice and simple.

I use a similiar function in Gambler.

I think that using seperate functions for all packages send by the client is somewhat overkill. When that is said the current my_tcp_send is somewhat annoying and could be implemented in a smarter way (like the Ant's and Gambler handles these).

Share this post


Link to post
Share on other sites

As you like it, just meant as a suggestion ;)

In my opinion it is not a very structured way to encode each packet separately each time you want to send it. It is hard to read the code and it is hard to change or fix it in case something is wrong if you have several places to look at.

Share this post


Link to post
Share on other sites
As you like it, just meant as a suggestion ;)

In my opinion it is not a very structured way to encode each packet separately each time you want to send it. It is hard to read the code and it is hard to change or fix it in case something is wrong if you have several places to look at.

It's not a bad idea either - I'd just prefer having it all in my_tcp_send(TCPsocket socket, void *dataPtr, int type, int length) and then do a switch(type) :-) Having that many different functions that practically does the same just seems like a waste.

Share this post


Link to post
Share on other sites
btw. SDL_net does the byteordering if u use the SDL_Net_Write/Read functions (network byteorder)

Yes it would, except the byte order EL uses iw backwards to the standard network byte order.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×