tVersion mismatch code revamped; now everything is done by the server, which only warns if the client does not understand any abilities (i.e. version 1.4.8 or earlier) or understands only a subset. - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 49346fcd6c535d76e66a422bb13c758c0ee04738
 (DIR) parent d26be250238f23b3a04c71649df95e344b76f37a
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Mon,  6 May 2002 12:56:33 +0000
       
       Version mismatch code revamped; now everything is done by the server,
       which only warns if the client does not understand any abilities
       (i.e. version 1.4.8 or earlier) or understands only a subset.
       
       
       Diffstat:
         M ChangeLog                           |       4 ++++
         M src/dopewars.h                      |       1 +
         M src/message.c                       |      24 +++++++++++-------------
         M src/message.h                       |       2 +-
         M src/serverside.c                    |      30 ++++++++++++++++++++++++++++++
       
       5 files changed, 47 insertions(+), 14 deletions(-)
       ---
 (DIR) diff --git a/ChangeLog b/ChangeLog
       t@@ -1,5 +1,9 @@
        cvs
            - Basic sound support
       +    - Version mismatches between client and server are now treated more
       +      sensibly (it's all done server-side, and spurious warnings are now
       +      removed - only an old client connecting to a new server will
       +      trigger them)
        
        1.5.6   29-04-2002
            - Bug fix: the server will only let you pay back loans or deal with the
 (DIR) diff --git a/src/dopewars.h b/src/dopewars.h
       t@@ -75,6 +75,7 @@ typedef struct ABILITIES {
                                         * connection has */
          gboolean Shared[A_NUM];       /* Abilites shared by us and the
                                         * remote host */
       +  gint RemoteNum;               /* The remote host's idea of what A_NUM is */
        } Abilities;
        
        struct NAMES {
 (DIR) diff --git a/src/message.c b/src/message.c
       t@@ -237,6 +237,7 @@ void InitAbilities(Player *Play)
            Play->Abil.Remote[i] = FALSE;
            Play->Abil.Shared[i] = FALSE;
          }
       +  Play->Abil.RemoteNum = 0;
        
          /* Set local abilities; abilities that are client-dependent (e.g.
           * A_NEWFIGHT) can be overridden by individual clients if required, by
       t@@ -247,10 +248,12 @@ void InitAbilities(Player *Play)
          Play->Abil.Local[A_TSTRING] = TRUE;
          Play->Abil.Local[A_DONEFIGHT] = TRUE;
        
       -  if (!Network)
       +  if (!Network) {
            for (i = 0; i < A_NUM; i++) {
              Play->Abil.Remote[i] = Play->Abil.Shared[i] = Play->Abil.Local[i];
            }
       +    Play->Abil.RemoteNum = A_NUM;
       +  }
        }
        
        /* 
       t@@ -264,13 +267,15 @@ void SendAbilities(Player *Play)
        
          if (!Network)
            return;
       -  for (i = 0; i < A_NUM; i++)
       +  for (i = 0; i < A_NUM; i++) {
            Data[i] = (Play->Abil.Local[i] ? '1' : '0');
       +  }
          Data[A_NUM] = '\0';
       -  if (Server)
       +  if (Server) {
            SendServerMessage(NULL, C_NONE, C_ABILITIES, Play, Data);
       -  else
       +  } else {
            SendClientMessage(Play, C_NONE, C_ABILITIES, NULL, Data);
       +  }
        }
        
        /* 
       t@@ -285,7 +290,8 @@ void ReceiveAbilities(Player *Play, gchar *Data)
          InitAbilities(Play);
          if (!Network)
            return;
       -  Length = MIN(strlen(Data), A_NUM);
       +  Play->Abil.RemoteNum = strlen(Data);
       +  Length = MIN(Play->Abil.RemoteNum, A_NUM);
          for (i = 0; i < Length; i++) {
            Play->Abil.Remote[i] = (Data[i] == '1' ? TRUE : FALSE);
          }
       t@@ -722,14 +728,6 @@ void ReceiveInitialData(Player *Play, char *Data)
            Currency.Prefix = (curr[0] == '1');
            AssignName(&Currency.Symbol, &curr[1]);
          }
       -
       -  if (strcmp(VERSION, ServerVersion) != 0) {
       -    g_message(_("This server is version %s, while your client is "
       -                "version %s.\nBe warned that different versions may not "
       -                "be fully compatible!\nRefer to the website at "
       -                "http://dopewars.sourceforge.net/\nfor the latest version."),
       -              ServerVersion, VERSION);
       -  }
        }
        
        void SendMiscData(Player *To)
 (DIR) diff --git a/src/message.h b/src/message.h
       t@@ -49,7 +49,7 @@ typedef enum {
          C_NONE = 'A',
          C_ASKLOAN, C_COPSMESG, C_ASKBITCH, C_ASKGUN, C_ASKGUNSHOP,
          C_ASKPUB, C_ASKBANK, C_ASKRUN, C_ASKRUNFIGHT, C_ASKSEW,
       -  C_MEETPLAYER, C_FIGHT, C_FIGHTDONE, C_MOTD
       +  C_MEETPLAYER, C_FIGHT, C_FIGHTDONE, C_MOTD, C_VERSIONCHECK
        } AICode;
        
        #define DT_LOCATION    'A'
 (DIR) diff --git a/src/serverside.c b/src/serverside.c
       t@@ -348,6 +348,35 @@ void SendPlayerDetails(Player *Play, Player *To, MsgCode Code)
          g_string_free(text, TRUE);
        }
        
       +/*
       + * Checks the version of the client that has connected, and sends a
       + * warning message if it's old.
       + */
       +void RemoteVersionCheck(Player *Play)
       +{
       +  /* Client didn't send a C_ABILITIES message at all, so is either broken
       +   * or is version 1.4.8 or earlier. */
       +  if (Play->Abil.RemoteNum == 0) {
       +    SendPrintMessage(NULL, C_VERSIONCHECK, Play,
       +        _("You appear to be using an extremely old (version 1.4.x) client.^"
       +          "While this will probably work, many of the newer features^"
       +          "will be unsupported. Get the latest version from the^"
       +          "dopewars website, http://dopewars.sourceforge.net/."));
       +
       +  /* The client has a smaller value of A_NUM; this means that not only does
       +   * it not support some features, it doesn't even know they might exist. */
       +  } else if (Play->Abil.RemoteNum < A_NUM) {
       +    SendPrintMessage(NULL, C_VERSIONCHECK, Play,
       +        _("Warning: your client is too old to support all of this^"
       +          "server's features. For the full \"experience\", get^"
       +          "the latest version of dopewars from the^"
       +          "website, http://dopewars.sourceforge.net/."));
       +  }
       +
       +  /* Otherwise, the client is either the same version as the server, or
       +   * it's newer. Both should be OK, so do nothing. */
       +}
       +
        /* 
         * Given a message "buf", from player "Play", performs processing and
         * sends suitable replies.
       t@@ -389,6 +418,7 @@ void HandleServerMessage(gchar *buf, Player *Play)
              SendServerMessage(NULL, C_NONE, C_NEWNAME, Play, NULL);
            } else if (strlen(GetPlayerName(Play)) == 0 && Data[0]) {
              if (CountPlayers(FirstServer) < MaxClients || !Network) {
       +        RemoteVersionCheck(Play);
                SendAbilities(Play);
                CombineAbilities(Play);
                SendInitialData(Play);