improved handling network protocol version mismatch
[rocksndiamonds.git] / src / network.c
index 0b3c6a8f0b6c27be5385663fbb6311e4d3e5cd07..b0a6a0eee2fcc78096a6c25eae72a34cd4358b94 100644 (file)
@@ -48,6 +48,8 @@ static byte readbuffer[MAX_BUFFER_SIZE], writbuffer[MAX_BUFFER_SIZE];
 static byte *buffer = realbuffer + 4;
 static int nread = 0, nwrite = 0;
 static boolean stop_network_game = FALSE;
+static boolean stop_network_client = FALSE;
+static char stop_network_client_message[MAX_OUTPUT_LINESIZE + 1];
 
 static void DrawNetworkTextExt(char *message, int font_nr, boolean initialize)
 {
@@ -430,9 +432,15 @@ void SendToServer_MovePlayer(byte player_action)
 static void Handle_OP_BAD_PROTOCOL_VERSION()
 {
   Error(ERR_WARN, "protocol version mismatch");
-  Error(ERR_EXIT, "server expects %d.%d.x instead of %d.%d.%d",
+  Error(ERR_WARN, "server expects %d.%d.x instead of %d.%d.%d",
        buffer[2], buffer[3],
        PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3);
+
+  sprintf(stop_network_client_message, "Network protocol version mismatch! Server expects version %d.%d.x instead of %d.%d.%d!",
+         buffer[2], buffer[3],
+         PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3);
+
+  stop_network_client = TRUE;
 }
 
 static void Handle_OP_YOUR_NUMBER()
@@ -645,8 +653,11 @@ static void Handle_OP_PAUSE_PLAYING()
   printf("OP_PAUSE_PLAYING: %d\n", buffer[0]);
   Error(ERR_NETWORK_CLIENT, "client %d pauses game", buffer[0]);
 
-  tape.pausing = TRUE;
-  DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0);
+  if (game_status == GAME_MODE_PLAYING)
+  {
+    tape.pausing = TRUE;
+    DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0);
+  }
 }
 
 static void Handle_OP_CONTINUE_PLAYING()
@@ -654,8 +665,11 @@ static void Handle_OP_CONTINUE_PLAYING()
   printf("OP_CONTINUE_PLAYING: %d\n", buffer[0]);
   Error(ERR_NETWORK_CLIENT, "client %d continues game", buffer[0]);
 
-  tape.pausing = FALSE;
-  DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
+  if (game_status == GAME_MODE_PLAYING)
+  {
+    tape.pausing = FALSE;
+    DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
+  }
 }
 
 static void Handle_OP_STOP_PLAYING()
@@ -820,6 +834,9 @@ static char *HandleNetworkingPackets()
     nread += num_bytes;
 
     HandleNetworkingMessages();
+
+    if (stop_network_client)
+      return stop_network_client_message;
   }
 
   return NULL;