foxygit / doom Log in
commit ca93f90c5522955b57f63430f2c728edf812331a
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Fri Apr 20 23:00:36 2018 -0400
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Fri Apr 20 23:00:36 2018 -0400

    net: Improve game mismatch error messages.

    If game mode/mission don't match then the client can't connect to the
    server. But give some details about the mismatch in the error message
    to aid in debugging.

    Thanks to AgitationSkeleton and GuyNamedErick for help with this.
---
 src/d_mode.c     | 17 +++++++++++++++++
 src/d_mode.h     |  1 +
 src/net_server.c | 10 +++++++++-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/d_mode.c b/src/d_mode.c
index b0685ff6..34d2c4cd 100644
--- a/src/d_mode.c
+++ b/src/d_mode.c
@@ -210,3 +210,20 @@ const char *D_GameMissionString(GameMission_t mission)
     }
 }

+const char *D_GameModeString(GameMode_t mode)
+{
+    switch (mode)
+    {
+        case shareware:
+            return "shareware";
+        case registered:
+            return "registered";
+        case commercial:
+            return "commercial";
+        case retail:
+            return "retail";
+        case indetermined:
+            return "indetermined";
+    }
+}
+
diff --git a/src/d_mode.h b/src/d_mode.h
index 420248f3..7822a44a 100644
--- a/src/d_mode.h
+++ b/src/d_mode.h
@@ -103,6 +103,7 @@ boolean D_ValidEpisodeMap(GameMission_t mission, GameMode_t mode,
 int D_GetNumEpisodes(GameMission_t mission, GameMode_t mode);
 boolean D_IsEpisodeMap(GameMission_t mission);
 const char *D_GameMissionString(GameMission_t mission);
+const char *D_GameModeString(GameMode_t mode);

 #endif /* #ifndef __D_MODE__ */

diff --git a/src/net_server.c b/src/net_server.c
index ab79b954..d86cab35 100644
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -688,7 +688,15 @@ static void NET_SV_ParseSYN(net_packet_t *packet, net_client_t *client,
     // the other clients
     if (data.gamemode != sv_gamemode || data.gamemission != sv_gamemission)
     {
-        NET_SV_SendReject(addr, "You are playing the wrong game!");
+        char msg[128];
+        M_snprintf(msg, sizeof(msg),
+                   "Game mismatch: server is %s (%s), client is %s (%s)",
+                   D_GameMissionString(sv_gamemission),
+                   D_GameModeString(sv_gamemode),
+                   D_GameMissionString(data.gamemission),
+                   D_GameModeString(data.gamemode));
+
+        NET_SV_SendReject(addr, msg);
         return;
     }