(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
authortruelight
Wed, 08 Dec 2004 18:16:43 +0000
changeset 571 530e8e994d55
parent 570 7bf6ec3045c9
child 572 39524c0f9c3f
(svn r982) -Fix: [Network] Because dparams are misused as a char, we had some
endian-problems. To fix this, we are sending dparams byte by byte
(instead of an uint32). Because of this dparam is sent
not-uint32-endian-safe, but char-endian-safe. Too bad dparam can no
longer be used for normal stuff (which is currently not the case) (tnx
to Tron and Bjarni)
network_client.c
network_server.c
--- a/network_client.c	Wed Dec 08 17:14:36 2004 +0000
+++ b/network_client.c	Wed Dec 08 18:16:43 2004 +0000
@@ -146,6 +146,7 @@
 	//
 
 	int i;
+	char *dparam_char;
 	Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND);
 
 	NetworkSend_uint8(p, cp->player);
@@ -153,8 +154,13 @@
 	NetworkSend_uint32(p, cp->p1);
 	NetworkSend_uint32(p, cp->p2);
 	NetworkSend_uint32(p, (uint32)cp->tile);
-	for (i = 0; i < lengthof(cp->dp); i++) {
-		NetworkSend_uint32(p, cp->dp[i]);
+	/* We are going to send them byte by byte, because dparam is misused
+	    for chars (if it is used), and else we have a BigEndian / LittleEndian
+	    problem.. we should fix the misuse of dparam... -- TrueLight */
+	dparam_char = (char *)&cp->dp[0];
+	for (i = 0; i < lengthof(cp->dp) * 4; i++) {
+		NetworkSend_uint8(p, *dparam_char);
+		dparam_char++;
 	}
 	NetworkSend_uint8(p, cp->callback);
 
@@ -548,14 +554,21 @@
 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
 {
 	int i;
+	char *dparam_char;
 	CommandPacket *cp = malloc(sizeof(CommandPacket));
 	cp->player = NetworkRecv_uint8(p);
 	cp->cmd = NetworkRecv_uint32(p);
 	cp->p1 = NetworkRecv_uint32(p);
 	cp->p2 = NetworkRecv_uint32(p);
 	cp->tile = NetworkRecv_uint32(p);
-	for (i = 0; i < lengthof(cp->dp); i++)
-		cp->dp[i] = NetworkRecv_uint32(p);
+	/* We are going to send them byte by byte, because dparam is misused
+	    for chars (if it is used), and else we have a BigEndian / LittleEndian
+	    problem.. we should fix the misuse of dparam... -- TrueLight */
+	dparam_char = (char *)&cp->dp[0];
+	for (i = 0; i < lengthof(cp->dp) * 4; i++) {
+		*dparam_char = NetworkRecv_uint8(p);
+		dparam_char++;
+	}
 	cp->callback = NetworkRecv_uint8(p);
 	cp->frame = NetworkRecv_uint32(p);
 	cp->next = NULL;
--- a/network_server.c	Wed Dec 08 17:14:36 2004 +0000
+++ b/network_server.c	Wed Dec 08 18:16:43 2004 +0000
@@ -445,6 +445,7 @@
 	//
 
 	int i;
+	char *dparam_char;
 	Packet *p = NetworkSend_Init(PACKET_SERVER_COMMAND);
 
 	NetworkSend_uint8(p, cp->player);
@@ -452,8 +453,13 @@
 	NetworkSend_uint32(p, cp->p1);
 	NetworkSend_uint32(p, cp->p2);
 	NetworkSend_uint32(p, cp->tile);
-	for (i = 0; i < lengthof(cp->dp); i++) {
-		NetworkSend_uint32(p, cp->dp[i]);
+	/* We are going to send them byte by byte, because dparam is misused
+	    for chars (if it is used), and else we have a BigEndian / LittleEndian
+	    problem.. we should fix the misuse of dparam... -- TrueLight */
+	dparam_char = (char *)&cp->dp[0];
+	for (i = 0; i < lengthof(cp->dp) * 4; i++) {
+		NetworkSend_uint8(p, *dparam_char);
+		dparam_char++;
 	}
 	NetworkSend_uint8(p, cp->callback);
 	NetworkSend_uint32(p, cp->frame);
@@ -732,6 +738,7 @@
 	byte callback;
 	ClientState *new_cs;
 	NetworkClientInfo *ci;
+	char *dparam_char;
 
 	CommandPacket *cp = malloc(sizeof(CommandPacket));
 
@@ -747,8 +754,14 @@
 	cp->p1 = NetworkRecv_uint32(p);
 	cp->p2 = NetworkRecv_uint32(p);
 	cp->tile = NetworkRecv_uint32(p);
-	for (i = 0; i < lengthof(cp->dp); i++)
-		cp->dp[i] = NetworkRecv_uint32(p);
+	/* We are going to send them byte by byte, because dparam is misused
+	    for chars (if it is used), and else we have a BigEndian / LittleEndian
+	    problem.. we should fix the misuse of dparam... -- TrueLight */
+	dparam_char = (char *)&cp->dp[0];
+	for (i = 0; i < lengthof(cp->dp) * 4; i++) {
+		*dparam_char = NetworkRecv_uint8(p);
+		dparam_char++;
+	}
 
 	callback = NetworkRecv_uint8(p);