Don't accept room messages when not in room state. Not tested even if it builds.
authorunc0rr
Thu, 09 Aug 2012 15:32:49 +0400
changeset 7526 ff3a05e29ddd
parent 7523 0790527b4e00
child 7529 058fcb451b37
Don't accept room messages when not in room state. Not tested even if it builds.
QTfrontend/net/newnetclient.cpp
--- a/QTfrontend/net/newnetclient.cpp	Wed Aug 08 20:32:27 2012 -0400
+++ b/QTfrontend/net/newnetclient.cpp	Thu Aug 09 15:32:49 2012 +0400
@@ -384,38 +384,6 @@
         return;
     }
 
-    if (lst[0] == "ADD_TEAM")
-    {
-        if(lst.size() != 24)
-        {
-            qWarning("Net: Bad ADDTEAM message");
-            return;
-        }
-        QStringList tmp = lst;
-        tmp.removeFirst();
-        emit AddNetTeam(tmp);
-        return;
-    }
-
-    if (lst[0] == "REMOVE_TEAM")
-    {
-        if(lst.size() != 2)
-        {
-            qWarning("Net: Bad REMOVETEAM message");
-            return;
-        }
-        emit RemoveNetTeam(HWTeam(lst[1]));
-        return;
-    }
-
-    if(lst[0] == "ROOMABANDONED")
-    {
-        netClientState = InLobby;
-        askRoomsList();
-        emit LeftRoom(tr("Room destroyed"));
-        return;
-    }
-
     if(lst[0] == "KICKED")
     {
         netClientState = InLobby;
@@ -424,31 +392,6 @@
         return;
     }
 
-    if(lst[0] == "JOINED")
-    {
-        if(lst.size() < 2)
-        {
-            qWarning("Net: Bad JOINED message");
-            return;
-        }
-
-        for(int i = 1; i < lst.size(); ++i)
-        {
-            if (lst[i] == mynick)
-            {
-                netClientState = InRoom;
-                emit EnteredGame();
-                emit roomMaster(isChief);
-                if (isChief)
-                    emit configAsked();
-            }
-
-            emit nickAdded(lst[i], isChief && (lst[i] != mynick));
-            emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
-        }
-        return;
-    }
-
     if(lst[0] == "LOBBY:JOINED")
     {
         if(lst.size() < 2)
@@ -472,21 +415,6 @@
         return;
     }
 
-    if(lst[0] == "LEFT")
-    {
-        if(lst.size() < 2)
-        {
-            qWarning("Net: Bad LEFT message");
-            return;
-        }
-        emit nickRemoved(lst[1]);
-        if (lst.size() < 3)
-            emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
-        else
-            emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2]));
-        return;
-    }
-
     if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD")
     {
         QStringList tmp = lst;
@@ -529,13 +457,6 @@
         return;
     }
 
-    if (lst[0] == "RUN_GAME")
-    {
-        netClientState = InGame;
-        emit AskForRunGame();
-        return;
-    }
-
     if (lst[0] == "ASKPASSWORD")
     {
         emit AskForPassword(mynick);
@@ -563,76 +484,6 @@
         return;
     }
 
-    if (lst[0] == "TEAM_ACCEPTED")
-    {
-        if (lst.size() != 2)
-        {
-            qWarning("Net: Bad TEAM_ACCEPTED message");
-            return;
-        }
-        emit TeamAccepted(lst[1]);
-        return;
-    }
-
-
-    if (lst[0] == "CFG")
-    {
-        if(lst.size() < 3)
-        {
-            qWarning("Net: Bad CFG message");
-            return;
-        }
-        QStringList tmp = lst;
-        tmp.removeFirst();
-        tmp.removeFirst();
-        if (lst[1] == "SCHEME")
-            emit netSchemeConfig(tmp);
-        else
-            emit paramChanged(lst[1], tmp);
-        return;
-    }
-
-    if (lst[0] == "HH_NUM")
-    {
-        if (lst.size() != 3)
-        {
-            qWarning("Net: Bad TEAM_ACCEPTED message");
-            return;
-        }
-        HWTeam tmptm(lst[1]);
-        tmptm.setNumHedgehogs(lst[2].toUInt());
-        emit hhnumChanged(tmptm);
-        return;
-    }
-
-    if (lst[0] == "TEAM_COLOR")
-    {
-        if (lst.size() != 3)
-        {
-            qWarning("Net: Bad TEAM_COLOR message");
-            return;
-        }
-        HWTeam tmptm(lst[1]);
-        tmptm.setColor(lst[2].toInt());
-        emit teamColorChanged(tmptm);
-        return;
-    }
-
-    if (lst[0] == "EM")
-    {
-        if(lst.size() < 2)
-        {
-            qWarning("Net: Bad EM message");
-            return;
-        }
-        for(int i = 1; i < lst.size(); ++i)
-        {
-            QByteArray em = QByteArray::fromBase64(lst[i].toAscii());
-            emit FromNet(em);
-        }
-        return;
-    }
-
     if (lst[0] == "BYE")
     {
         if (lst.size() < 2)
@@ -650,26 +501,177 @@
         return;
     }
 
-
     if (lst[0] == "ADMIN_ACCESS")
     {
         emit adminAccess(true);
         return;
     }
 
-    if (lst[0] == "ROOM_CONTROL_ACCESS")
+
+    if(netClientState == InRoom)
     {
-        if (lst.size() < 2)
+        if (lst[0] == "EM")
+        {
+            if(lst.size() < 2)
+            {
+                qWarning("Net: Bad EM message");
+                return;
+            }
+            for(int i = 1; i < lst.size(); ++i)
+            {
+                QByteArray em = QByteArray::fromBase64(lst[i].toAscii());
+                emit FromNet(em);
+            }
+            return;
+        }
+
+        if (lst[0] == "ADD_TEAM")
+        {
+            if(lst.size() != 24)
+            {
+                qWarning("Net: Bad ADDTEAM message");
+                return;
+            }
+            QStringList tmp = lst;
+            tmp.removeFirst();
+            emit AddNetTeam(tmp);
+            return;
+        }
+
+        if (lst[0] == "REMOVE_TEAM")
         {
-            qWarning("Net: Bad ROOM_CONTROL_ACCESS message");
+            if(lst.size() != 2)
+            {
+                qWarning("Net: Bad REMOVETEAM message");
+                return;
+            }
+            emit RemoveNetTeam(HWTeam(lst[1]));
+            return;
+        }
+
+        if(lst[0] == "ROOMABANDONED")
+        {
+            netClientState = InLobby;
+            askRoomsList();
+            emit LeftRoom(tr("Room destroyed"));
+            return;
+        }
+
+        if (lst[0] == "RUN_GAME")
+        {
+            netClientState = InGame;
+            emit AskForRunGame();
+            return;
+        }
+
+        if (lst[0] == "TEAM_ACCEPTED")
+        {
+            if (lst.size() != 2)
+            {
+                qWarning("Net: Bad TEAM_ACCEPTED message");
+                return;
+            }
+            emit TeamAccepted(lst[1]);
             return;
         }
-        isChief = (lst[1] != "0");
-        emit roomMaster(isChief);
-        return;
+
+        if (lst[0] == "CFG")
+        {
+            if(lst.size() < 3)
+            {
+                qWarning("Net: Bad CFG message");
+                return;
+            }
+            QStringList tmp = lst;
+            tmp.removeFirst();
+            tmp.removeFirst();
+            if (lst[1] == "SCHEME")
+                emit netSchemeConfig(tmp);
+            else
+                emit paramChanged(lst[1], tmp);
+            return;
+        }
+
+        if (lst[0] == "HH_NUM")
+        {
+            if (lst.size() != 3)
+            {
+                qWarning("Net: Bad TEAM_ACCEPTED message");
+                return;
+            }
+            HWTeam tmptm(lst[1]);
+            tmptm.setNumHedgehogs(lst[2].toUInt());
+            emit hhnumChanged(tmptm);
+            return;
+        }
+
+        if (lst[0] == "TEAM_COLOR")
+        {
+            if (lst.size() != 3)
+            {
+                qWarning("Net: Bad TEAM_COLOR message");
+                return;
+            }
+            HWTeam tmptm(lst[1]);
+            tmptm.setColor(lst[2].toInt());
+            emit teamColorChanged(tmptm);
+            return;
+        }
+
+        if(lst[0] == "JOINED")
+        {
+            if(lst.size() < 2)
+            {
+                qWarning("Net: Bad JOINED message");
+                return;
+            }
+
+            for(int i = 1; i < lst.size(); ++i)
+            {
+                if (lst[i] == mynick)
+                {
+                    netClientState = InRoom;
+                    emit EnteredGame();
+                    emit roomMaster(isChief);
+                    if (isChief)
+                        emit configAsked();
+                }
+
+                emit nickAdded(lst[i], isChief && (lst[i] != mynick));
+                emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
+            }
+            return;
+        }
+
+        if(lst[0] == "LEFT")
+        {
+            if(lst.size() < 2)
+            {
+                qWarning("Net: Bad LEFT message");
+                return;
+            }
+            emit nickRemoved(lst[1]);
+            if (lst.size() < 3)
+                emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
+            else
+                emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2]));
+            return;
+        }
+
+        if (lst[0] == "ROOM_CONTROL_ACCESS")
+        {
+            if (lst.size() < 2)
+            {
+                qWarning("Net: Bad ROOM_CONTROL_ACCESS message");
+                return;
+            }
+            isChief = (lst[1] != "0");
+            emit roomMaster(isChief);
+            return;
+        }
     }
 
-    qWarning() << "Net: Unknown message:" << lst;
+    qWarning() << "Net: Unknown message or wrong state:" << lst;
 }
 
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)