- Fix passing of ansistrings via ipc qmlfrontend
authorunc0rr
Sat, 26 Dec 2015 22:29:57 +0300
branchqmlfrontend
changeset 11462 33a0e3a14ddc
parent 11460 9f2fb0031ef0
child 11480 b0c34402038c
- Fix passing of ansistrings via ipc - Some work on getting drawn maps from network (missing zlib unpack)
hedgewars/CMakeLists.txt
hedgewars/uFLDrawnMap.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLNetTypes.pas
hedgewars/uFLTypes.pas
--- a/hedgewars/CMakeLists.txt	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/CMakeLists.txt	Sat Dec 26 22:29:57 2015 +0300
@@ -107,6 +107,7 @@
     uTeams.pas
 
     uFLAmmo.pas
+    uFLDrawnMap.pas
     uFLGameConfig.pas
     uFLIPC.pas
     uFLNet.pas
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uFLDrawnMap.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -0,0 +1,13 @@
+unit uFLDrawnMap;
+interface
+
+function decodeDrawnMap(data: ansistring): ansistring;
+
+implementation
+uses uUtils;
+
+function decodeDrawnMap(data: ansistring): ansistring;
+begin
+end;
+
+end.
--- a/hedgewars/uFLGameConfig.pas	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -33,6 +33,7 @@
 procedure netSetTeamColor(team: shortstring; color: Longword);
 procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
 procedure netRemoveTeam(teamName: shortstring);
+procedure netDrawnData(data: ansistring);
 procedure netResetTeams();
 procedure updatePreviewIfNeeded;
 
@@ -40,7 +41,8 @@
 procedure runNetGame();
 
 implementation
-uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue, uFLNet;
+uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo
+    , uFLUICallback, uFLRunQueue, uFLNet, uUtils;
 
 var
     currentConfig: TGameConfig;
@@ -51,6 +53,24 @@
     getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
 end;
 
+procedure sendDrawnMap(config: PGameConfig);
+var i: Longword;
+    s: shortstring;
+begin
+    i:= 1;
+
+    while i < config^.drawnDataSize do
+    begin
+        if config^.drawnDataSize - i > 240 then
+            s:= copy(config^.drawnData, i, 240)
+        else
+            s:= copy(config^.drawnData, i, config^.drawnDataSize - i);
+        system.writeln('[DRAWN MAP] ', s);
+        ipcToEngine('edraw ' + DecodeBase64(s));
+        inc(i, 240)
+    end;
+end;
+
 procedure sendConfig(config: PGameConfig);
 var i: Longword;
 begin
@@ -67,6 +87,8 @@
             else
                 ipcToEngine('e$template_filter ' + intToStr(template));
             ipcToEngine('e$feature_size ' + intToStr(featureSize));
+            if mapgen = 3 then
+                sendDrawnMap(config);
         end;
 gtLocal, gtNet: begin
             if gameType = gtNet then
@@ -81,6 +103,8 @@
                 ipcToEngine('e$template_filter ' + intToStr(template));
             ipcToEngine('e$feature_size ' + intToStr(featureSize));
             ipcToEngine('e$theme ' + theme);
+            if mapgen = 3 then
+                sendDrawnMap(config);
 
             sendSchemeConfig(scheme);
 
@@ -640,4 +664,12 @@
     end;
 end;
 
+procedure netDrawnData(data: ansistring);
+begin
+    currentConfig.drawnDataSize:= length(data);
+    currentConfig.drawnData:= data;
+
+    getPreview
+end;
+
 end.
--- a/hedgewars/uFLNet.pas	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/uFLNet.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -41,10 +41,13 @@
 
 procedure handler_L;
 var cmd: TCmdParamL;
+    s: ansistring;
 begin
     cmd.cmd:= state.cmd;
-    cmd.str1:= getLongString;
-    if length(cmd.str1) = 0 then exit;
+    s:= getLongString;
+    cmd.str1len:= length(s);
+    if cmd.str1len = 0 then exit;
+    cmd.str1:= s;
     sendUI(mtNetData, @cmd, sizeof(cmd));
     handleTail()
 end;
@@ -52,15 +55,21 @@
 procedure handler_ML;
 var cmd: TCmdParamL;
     f: boolean;
+    s: ansistring;
 begin
     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
     cmd.cmd:= Succ(state.cmd);
 
     repeat
-        cmd.str1:= getLongString;
-        f:= cmd.str1[0] <> #0;
+        s:= getLongString;
+        cmd.str1len:= length(s);
+        f:= cmd.str1len <> 0;
+
         if f then
+            begin
+            cmd.str1:= s;
             sendUI(mtNetData, @cmd, sizeof(cmd));
+            end
     until not f;
     state.l:= 0
 end;
--- a/hedgewars/uFLNetProtocol.pas	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -97,6 +97,7 @@
 
 procedure handler_CFG_DRAWNMAP(var p: TCmdParamL);
 begin
+    netDrawnData(copy(ansistring(p.str1), 1, p.str1len))
 end;
 
 procedure handler_CFG_FEATURE_SIZE(var p: TCmdParami);
@@ -262,7 +263,7 @@
 procedure handler_CHAT(var p: TCmdParamSL);
 var s: string;
 begin
-    s:= p.str1 + #10 + p.str2;
+    s:= p.str1 + #10 + copy(p.str2, 0, p.str2len);
     if isInRoom then
         sendUI(mtRoomChatLine, @s[1], length(s))
     else
@@ -375,9 +376,10 @@
 end;
 
 procedure handler_LEFT(var p: TCmdParamSL);
+var s: string;
 begin
-    p.str2:= p.str1 + #10 + p.str2;
-    sendUI(mtRemoveRoomClient, @p.str2[1], length(p.str2));
+    s:= p.str1 + #10 + copy(p.str2, 0, p.str2len);
+    sendUI(mtRemoveRoomClient, @s[1], length(s));
 end;
 
 procedure handler_LOBBY_JOINED(var p: TCmdParam);
@@ -396,9 +398,10 @@
 end;
 
 procedure handler_LOBBY_LEFT(var p: TCmdParamSL);
+var s: string;
 begin
-    p.str2:= p.str1 + #10 + p.str2;
-    sendUI(mtRemoveLobbyClient, @p.str2[1], length(p.str2));
+    s:= p.str1 + #10 + copy(p.str2, 0, p.str2len);
+    sendUI(mtRemoveLobbyClient, @s[1], length(s));
 end;
 
 procedure handler_NICK(var p: TCmdParamS);
--- a/hedgewars/uFLNetTypes.pas	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/uFLNetTypes.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -20,7 +20,8 @@
         end;
     type TCmdParamL = packed record
         cmd: TCmdType;
-        str1: string;
+        str1len: Longword;
+        str1: array[word] of char;
         end;
     type TCmdParamS = packed record
         cmd: TCmdType;
@@ -29,7 +30,8 @@
     type TCmdParamSL = packed record
         cmd: TCmdType;
         str1: shortstring;
-        str2: string;
+        str2len: Longword;
+        str2: array[word] of char;
         end;
     type TCmdParamSS = packed record
         cmd: TCmdType;
--- a/hedgewars/uFLTypes.pas	Sun Dec 20 12:45:49 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Sat Dec 26 22:29:57 2015 +0300
@@ -119,6 +119,8 @@
             theme: shortstring;
             script: shortstring;
             map: shortstring;
+            drawnData: array[word] of char;
+            drawnDataSize: LongWord;
             scheme: TScheme;
             ammo: TAmmo;
             mapgen: LongInt;