Teach engine to properly display clan message received from the net
authorWuzzy <Wuzzy2@mail.ru>
Thu, 04 Oct 2018 17:07:17 +0200
changeset 13828 76a1d6275cd3
parent 13827 28a86816dc01
child 13829 266a25b79374
Teach engine to properly display clan message received from the net This fixes a bug that the word “Clan” was not translated when you received a clan message from the net.
gameServer/HWProtoInRoomState.hs
hedgewars/uIO.pas
--- a/gameServer/HWProtoInRoomState.hs	Thu Oct 04 14:54:57 2018 +0200
+++ b/gameServer/HWProtoInRoomState.hs	Thu Oct 04 17:07:17 2018 +0200
@@ -382,9 +382,9 @@
     chans <- roomSameClanChans
     return [AnswerClients chans ["EM", engineMsg cl]]
     where
-        -- FIXME: Use different method to send team message, without hardcoding the format.
-        -- The formatting should be decided by the engine, not the sever. This one cannot be localized.
-        engineMsg cl = toEngineMsg $ B.concat ["b", "[Clan] ", nick cl, ": ", msg, "\x20\x20"]
+        -- This is formatted in a way so it can parsed by engine to make it translatable
+        -- Format: b<PLAYER NAME>]<MESSAGE>
+        engineMsg cl = toEngineMsg $ B.concat ["b", nick cl, "]", msg, "\x20\x20"]
 
 
 handleCmd_inRoom ["BAN", banNick] = do
--- a/hedgewars/uIO.pas	Thu Oct 04 14:54:57 2018 +0200
+++ b/hedgewars/uIO.pas	Thu Oct 04 17:07:17 2018 +0200
@@ -39,7 +39,7 @@
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
 
 implementation
-uses uConsole, uConsts, uVariables, uCommands, uUtils, uDebug;
+uses uConsole, uConsts, uVariables, uCommands, uUtils, uDebug, uLocale;
 
 const
     cSendEmptyPacketTime = 1000;
@@ -147,6 +147,8 @@
 procedure ParseIPCCommand(s: shortstring);
 var loTicks: Word;
     isProcessed: boolean;
+    nick, msg: shortstring;
+    i: LongInt;
 begin
 isProcessed := true;
 
@@ -175,7 +177,30 @@
           else
              isProcessed:= false;
      'b': if gameType = gmtNet then
-             ParseChatCommand('chatmsg ' + #4, s, 2)
+             // parse team message from net
+             // expected format: <PLAYER NAME>]<MESSAGE>
+             begin
+             i:= 2;
+             nick:= '';
+             while (i <= length(s)) and (s[i] <> ']') do
+                begin
+                nick:= nick + s[i];
+                inc(i)
+                end;
+
+             inc(i);
+             msg:= '';
+             while (i <= length(s)) do
+                begin
+                msg:= msg + s[i];
+                inc(i)
+                end;
+             s:= 'b' + Format(trmsg[sidChatTeam], [nick, msg]);
+             if (nick = '') or (msg = '') then
+                 isProcessed:= false
+             else
+                 ParseChatCommand('chatmsg ' + #4, s, 2);
+             end
           else
              isProcessed:= false;
      else