Trurl Report post Posted September 19, 2004 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
waldi Report post Posted September 19, 2004 nice work :-) how about adding support for big-endian byteorder and archs that need alignment ? Share this post Link to post Share on other sites
Trurl Report post Posted September 19, 2004 Isn't that already done in the SDL_net functions? Share this post Link to post Share on other sites
waldi Report post Posted September 19, 2004 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
Trurl Report post Posted September 19, 2004 Sorry, that's just the way I found it in interface.c... Share this post Link to post Share on other sites
waldi Report post Posted September 19, 2004 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
Trurl Report post Posted September 19, 2004 yep, exactly my thought... I would fix this (*int) thingy if I knew what to replace it with... Share this post Link to post Share on other sites
waldi Report post Posted September 19, 2004 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
Trurl Report post Posted September 19, 2004 Changed it and updated the patch. Share this post Link to post Share on other sites
waldi Report post Posted September 19, 2004 u should wait for some1 to accept ur patch first... Share this post Link to post Share on other sites
Cicero Report post Posted September 19, 2004 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 Share this post Link to post Share on other sites
Learner Report post Posted September 19, 2004 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
Wytter Report post Posted September 19, 2004 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
Trurl Report post Posted September 19, 2004 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
duran Report post Posted September 19, 2004 heh, didnt you talk about creaping featureitis the other day cicero? maybe this patch can help a bit? Share this post Link to post Share on other sites
Wytter Report post Posted September 19, 2004 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
frak Report post Posted September 20, 2004 btw. SDL_net does the byteordering if u use the SDL_Net_Write/Read functions (network byteorder) Share this post Link to post Share on other sites
Learner Report post Posted September 20, 2004 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