Add server version (which is separate from protocol version) and a check in frontend for a new enough server (currently only qWarning)
authorunc0rr
Mon, 28 Feb 2011 22:04:10 +0300
changeset 4973 53411a26df7e
parent 4972 2f9c8a12edce
child 4974 078cd026a7b1
Add server version (which is separate from protocol version) and a check in frontend for a new enough server (currently only qWarning)
QTfrontend/hwconsts.cpp.in
QTfrontend/hwconsts.h
QTfrontend/mapContainer.cpp
QTfrontend/newnetclient.cpp
gameServer/Actions.hs
gameServer/Consts.hs
gameServer/hedgewars-server.hs
--- a/QTfrontend/hwconsts.cpp.in	Sun Feb 27 18:55:34 2011 -0500
+++ b/QTfrontend/hwconsts.cpp.in	Mon Feb 28 22:04:10 2011 +0300
@@ -35,6 +35,7 @@
 bool custom_data = false;
 
 int cMaxTeams = 6;
+int cMinServerVersion = 0;
 
 QString * cDefaultAmmoStore = new QString(
         "93919294221991210322351110012010000002111101010111299"
--- a/QTfrontend/hwconsts.h	Sun Feb 27 18:55:34 2011 -0500
+++ b/QTfrontend/hwconsts.h	Mon Feb 28 22:04:10 2011 +0300
@@ -35,6 +35,7 @@
 extern bool custom_data;
 
 extern int cMaxTeams;
+extern int cMinServerVersion;
 
 extern QStringList * Themes;
 extern QStringList * mapList;
--- a/QTfrontend/mapContainer.cpp	Sun Feb 27 18:55:34 2011 -0500
+++ b/QTfrontend/mapContainer.cpp	Mon Feb 28 22:04:10 2011 +0300
@@ -616,7 +616,6 @@
 
 void HWMapContainer::updatePreview()
 {
-    qDebug("updating a preview");
     int curIndex = chooseMap->currentIndex();
 
     switch(curIndex)
--- a/QTfrontend/newnetclient.cpp	Sun Feb 27 18:55:34 2011 -0500
+++ b/QTfrontend/newnetclient.cpp	Mon Feb 28 22:04:10 2011 +0300
@@ -240,6 +240,12 @@
     }
 
     if (lst[0] == "CONNECTED") {
+        if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion)
+        {
+            // TODO: Warn user, disconnect
+            qWarning() << "Server too old";
+        }
+
         RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick));
         RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer));
         netClientState = 1;
--- a/gameServer/Actions.hs	Sun Feb 27 18:55:34 2011 -0500
+++ b/gameServer/Actions.hs	Mon Feb 28 22:04:10 2011 +0300
@@ -20,6 +20,7 @@
 import Utils
 import ClientIO
 import ServerState
+import Consts
 
 data Action =
     AnswerClients ![ClientChan] ![B.ByteString]
@@ -381,7 +382,7 @@
         return ci
 
     modify (\s -> s{clientIndex = Just newClId})
-    processAction $ AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"]
+    processAction $ AnswerClients [sendChan cl] ["CONNECTED", "Hedgewars server http://www.hedgewars.org/", serverVersion]
 
     let newLogins = takeWhile (\(_ , (time, _)) -> connectTime cl `diffUTCTime` time <= 0) $ lastLogins si
     let info = host cl `Prelude.lookup` newLogins
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer/Consts.hs	Mon Feb 28 22:04:10 2011 +0300
@@ -0,0 +1,7 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Consts where
+
+import qualified Data.ByteString.Char8 as B
+
+serverVersion :: B.ByteString
+serverVersion = "0"
--- a/gameServer/hedgewars-server.hs	Sun Feb 27 18:55:34 2011 -0500
+++ b/gameServer/hedgewars-server.hs	Mon Feb 28 22:04:10 2011 +0300
@@ -8,7 +8,9 @@
 import qualified Control.Exception as E
 import System.Log.Logger
 import System.Process
+#if defined(OFFICIAL_SERVER)
 import Control.Monad
+#endif
 -----------------------------------
 import Opts
 import CoreTypes