merge
authorStepan777 <stepik-777@mail.ru>
Fri, 10 Aug 2012 17:25:22 +0400
changeset 7536 e1b80da69991
parent 7534 ccb9c2906160 (current diff)
parent 7529 058fcb451b37 (diff)
child 7538 2d6e69b392cb
merge
--- a/QTfrontend/net/newnetclient.cpp	Thu Aug 09 19:52:21 2012 +0400
+++ b/QTfrontend/net/newnetclient.cpp	Fri Aug 10 17:25:22 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)
--- a/QTfrontend/ui/widget/teamselect.cpp	Thu Aug 09 19:52:21 2012 +0400
+++ b/QTfrontend/ui/widget/teamselect.cpp	Fri Aug 10 17:25:22 2012 +0400
@@ -135,6 +135,11 @@
             curPlayingTeams.erase(itPlay);
             break;
         }
+        else
+        {
+            qWarning() << QString("removeNetTeam: team '%1' was actually a local team!").arg(team.name());
+            break;
+        }
     }
     emit setEnabledGameStart(curPlayingTeams.size()>1);
 }
--- a/gameServer/ServerCore.hs	Thu Aug 09 19:52:21 2012 +0400
+++ b/gameServer/ServerCore.hs	Fri Aug 10 17:25:22 2012 +0400
@@ -43,7 +43,7 @@
 
         ClientMessage (ci, cmd) -> do
             liftIO $ debugM "Clients" $ show ci ++ ": " ++ show cmd
-            
+
             removed <- gets removedClients
             unless (ci `Set.member` removed) $ do
                 modify (\s -> s{clientIndex = Just ci})
@@ -75,8 +75,6 @@
             (fromJust $ serverSocket si)
             (coreChan si)
 
-    return ()
-
     _ <- forkIO $ timerLoop 0 $ coreChan si
 
     startDBConnection si
--- a/tools/pas2c.hs	Thu Aug 09 19:52:21 2012 +0400
+++ b/tools/pas2c.hs	Fri Aug 10 17:25:22 2012 +0400
@@ -809,14 +809,15 @@
     e2 <- expr2C e2'
     let inc = if up then "inc" else "dec"
     let add = if up then "+ 1" else "- 1"
+    let iEnd = i <> text "__end__"
     ph <- phrase2C . appendPhrase (BuiltInFunctionCall [Reference $ SimpleReference i'] (SimpleReference (Identifier inc BTUnknown))) $ wrapPhrase p
     return . braces $
         i <+> text "=" <+> e1 <> semi
         $$
-        iType <+> i <> text "__end__" <+> text "=" <+> e2 <+> text add <> semi
+        iType <+> iEnd <+> text "=" <+> e2 <> semi
         $$ 
-        text "do" <+> ph <+>
-        text "while" <> parens (i <+> text "!=" <+> i <> text "__end__") <> semi
+        text "if" <+> (parens $ i <+> text "<=" <+> iEnd) <+> text "do" <+> ph <+>
+        text "while" <> parens (i <+> text "!=" <+> iEnd <+> text add) <> semi
     where
         appendPhrase p (Phrases ps) = Phrases $ ps ++ [p]
 phrase2C (RepeatCycle e' p') = do