Fix some string/translation inconsistencies in strings related to leaving
authorWuzzy <Wuzzy2@mail.ru>
Tue, 21 Aug 2018 02:14:15 +0200
changeset 13678 1aa5e884326a
parent 13676 7a31a292fa84
child 13679 3f6fae745f84
Fix some string/translation inconsistencies in strings related to leaving
QTfrontend/hwform.cpp
QTfrontend/net/newnetclient.cpp
QTfrontend/ui/widget/chatwidget.cpp
gameServer/Actions.hs
gameServer/ClientIO.hs
gameServer/HWProtoCore.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoNEState.hs
gameServer/Utils.hs
--- a/QTfrontend/hwform.cpp	Sun Aug 19 09:54:46 2018 -0400
+++ b/QTfrontend/hwform.cpp	Tue Aug 21 02:14:15 2018 +0200
@@ -1672,7 +1672,8 @@
     }
     if (pnetserver)
         return; // we have server - let it care of all things
-    if (hwnet) {
+    if (hwnet && (reason != "bye") && (!reason.startsWith("User quit: ")))
+    {
         QString errorStr = QMessageBox::tr("The connection to the server is lost.") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Reason:") + "\n" + reason));
         MessageDialog::ShowErrorMessage(errorStr, this);
     }
--- a/QTfrontend/net/newnetclient.cpp	Sun Aug 19 09:54:46 2018 -0400
+++ b/QTfrontend/net/newnetclient.cpp	Tue Aug 21 02:14:15 2018 +0200
@@ -74,7 +74,7 @@
 {
     if (m_game_connected)
     {
-        RawSendNet(QString("QUIT%1%2").arg(delimiter).arg("User quit"));
+        RawSendNet(QString("QUIT%1").arg(delimiter));
         emit disconnected(tr("User quit"));
     }
     NetSocket.flush();
@@ -91,7 +91,7 @@
 void HWNewNet::Disconnect()
 {
     if (m_game_connected)
-        RawSendNet(QString("QUIT%1%2").arg(delimiter).arg("User quit"));
+        RawSendNet(QString("QUIT%1").arg(delimiter));
     m_game_connected = false;
 
     NetSocket.disconnectFromHost();
@@ -870,7 +870,21 @@
             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]));
+            {
+                QString leaveMsg = QString(lst[2]);
+                if (leaveMsg.startsWith("User quit: "))
+                {
+                    leaveMsg.remove(0, 11);
+                    emit chatStringFromNet(tr("%1 *** %2 has left (message: \"%3\")").arg('\x03').arg(lst[1]).arg(leaveMsg));
+                }
+                else if (leaveMsg.startsWith("part: "))
+                {
+                    leaveMsg.remove(0, 6);
+                    emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1]).arg(leaveMsg));
+                }
+                else
+                    emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1]).arg(HWApplication::translate("server", leaveMsg.toLatin1().constData())));
+            }
             m_playersModel->playerLeftRoom(lst[1]);
             return;
         }
--- a/QTfrontend/ui/widget/chatwidget.cpp	Sun Aug 19 09:54:46 2018 -0400
+++ b/QTfrontend/ui/widget/chatwidget.cpp	Tue Aug 21 02:14:15 2018 +0200
@@ -539,10 +539,28 @@
 
     emit nickCountUpdate(chatNicks->model()->rowCount());
 
-    if (message.isEmpty())
+    // Normal quit
+    if (message.isEmpty() || message == "bye")
         printChatString(nick, QString("*** ") + tr("%1 has left").arg(linkedNick(nick)), "Leave", false);
+    // Quit with custom player message
+    else if (message.startsWith("User quit: ") && message.length() > 11)
+    {
+        QString playerMessage = QString(message);
+        playerMessage.remove(0, 11);
+        printChatString(nick, QString("*** ") + tr("%1 has left (message: \"%2\")").arg(linkedNick(nick)).arg(playerMessage.toHtmlEscaped()), "Leave", false);
+    }
+    // Quit with special PART message
+    else if (message.startsWith("part: ") && message.length() > 6)
+    {
+        QString playerMessage = QString(message);
+        playerMessage.remove(0, 6);
+        printChatString(nick, QString("*** ") + tr("%1 has left (%2)").arg(linkedNick(nick).arg(playerMessage.toHtmlEscaped())), "Leave", false);
+    }
+    // Quit with additional server message (i.e. ping timeout)
     else
-        printChatString(nick, QString("*** ") + tr("%1 has left (%2)").arg(linkedNick(nick)).arg(messageToHTML(message)), "Leave", false);
+    {
+        printChatString(nick, QString("*** ") + tr("%1 has left (%2)").arg(linkedNick(nick)).arg(HWApplication::translate("server", message.toLatin1().constData()).toHtmlEscaped()), "Leave", false);
+    }
 }
 
 void HWChatWidget::clear()
--- a/gameServer/Actions.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/Actions.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -117,7 +117,7 @@
     loggedIn <- client's isVisible
 
     when (ri /= lobbyId) $ do
-        processAction $ MoveToLobby ("quit: " `B.append` msg)
+        processAction $ (MoveToLobby msg)
         return ()
 
     clientsChans <- liftM (Prelude.map sendChan . Prelude.filter isVisible) $! allClientsS
--- a/gameServer/ClientIO.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/ClientIO.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -96,6 +96,7 @@
 
     where
         killReciever = Exception.throwTo tId . ShutdownThreadException
+        -- intentionally not localized
         quitMessage ["BYE"] = "bye"
         quitMessage ("BYE":msg:_) = msg
         quitMessage _ = error "quitMessage"
--- a/gameServer/HWProtoCore.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/HWProtoCore.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -40,7 +40,10 @@
 
 handleCmd ("QUIT" : xs) = return [ByeClient msg]
     where
-        msg = if not $ null xs then "User quit: " `B.append` (head xs) else loc "bye"
+        -- "User quit: " is a special string parsed by frontend, do not localize.
+        -- It denotes when the /quit command has been used with message parameter.
+        -- "bye" is also a special string.
+        msg = if not $ null xs then "User quit: " `B.append` (head xs) else "bye"
 
 
 handleCmd ["PONG"] = do
--- a/gameServer/HWProtoInRoomState.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/HWProtoInRoomState.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -74,7 +74,10 @@
     s <- roomOthersChans
     return [AnswerClients s ["CHAT", n, msg]]
 
-handleCmd_inRoom ["PART"] = return [MoveToLobby "part"]
+-- Leave room normally
+handleCmd_inRoom ["PART"] = return [MoveToLobby ""]
+-- Leave room with custom quit message by player
+-- "part: " is a special marker string to be detected by the frontend. Not translated for obvious reasons
 handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg]
 
 
--- a/gameServer/HWProtoNEState.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/HWProtoNEState.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -65,6 +65,7 @@
     if clientProto cl < 48 && passwd == webPassword cl then
         return $ JoinLobby : [AnswerClients [sendChan cl] ["ADMIN_ACCESS"] | isAdministrator cl]
         else
+        -- String is parsed by frontend, do not localize!
         return [ByeClient "Authentication failed"]
 
 
@@ -81,6 +82,7 @@
             , JoinLobby
             ]
         else
+        -- String is parsed by frontend, do not localize!
         return [ByeClient "Authentication failed"]
     where
         h = B.pack . showDigest . sha1 . BL.fromChunks
--- a/gameServer/Utils.hs	Sun Aug 19 09:54:46 2018 -0400
+++ b/gameServer/Utils.hs	Tue Aug 21 02:14:15 2018 +0200
@@ -233,6 +233,9 @@
             AnswerClients [clChan] ["HH_NUM", teamname team, showB $ hhnum team]]
 
 
+-- Locale function to localize strings.
+-- loc is just the identity functions, but it will be collected by scripts
+-- for localization. Use loc to mark a string for translation.
 loc :: B.ByteString -> B.ByteString
 loc = id