hedgewars/uIO.pas
branchqmlfrontend
changeset 10412 9a8d4efcf3fa
parent 10410 669bfa55cd70
child 10420 02c573d19224
--- a/hedgewars/uIO.pas	Thu Sep 18 00:19:05 2014 +0400
+++ b/hedgewars/uIO.pas	Thu Sep 18 23:02:05 2014 +0400
@@ -55,11 +55,9 @@
             2: (str: shortstring);
             end;
 
-var IPCSock: PTCPSocket;
-    fds: PSDLNet_SocketSet;
+var
     isPonged: boolean;
-    SocketString: shortstring;
-
+    
     headcmd: PCmd;
     lastcmd: PCmd;
 
@@ -102,20 +100,8 @@
 end;
 
 procedure InitIPC;
-var ipaddr: TIPAddress;
 begin
-    WriteToConsole('Init SDL_Net... ');
-    SDLTry(SDLNet_Init = 0, true);
-    fds:= SDLNet_AllocSocketSet(1);
-    SDLTry(fds <> nil, true);
-    WriteLnToConsole(msgOK);
-    WriteToConsole('Establishing IPC connection to tcp 127.0.0.1:' + IntToStr(ipcPort) + ' ');
-    {$HINTS OFF}
-    SDLTry(SDLNet_ResolveHost(ipaddr, PChar('127.0.0.1'), ipcPort) = 0, true);
-    {$HINTS ON}
-    IPCSock:= SDLNet_TCP_Open(ipaddr);
-    SDLTry(IPCSock <> nil, true);
-    WriteLnToConsole(msgOK)
+    // do nothing, flib initialized everything for us
 end;
 
 procedure ParseChatCommand(command: shortstring; message: shortstring;
@@ -176,31 +162,9 @@
 end;
 
 procedure IPCCheckSock;
-var i: LongInt;
-    s: shortstring;
 begin
-    if IPCSock = nil then
-        exit;
-
-    fds^.numsockets:= 0;
-    SDLNet_AddSocket(fds, IPCSock);
-
-    while SDLNet_CheckSockets(fds, 0) > 0 do
-    begin
-        i:= SDLNet_TCP_Recv(IPCSock, @s[1], 255 - Length(SocketString));
-        if i > 0 then
-        begin
-            s[0]:= char(i);
-            SocketString:= SocketString + s;
-            while (Length(SocketString) > 1) and (Length(SocketString) > byte(SocketString[1])) do
-            begin
-                ParseIPCCommand(copy(SocketString, 2, byte(SocketString[1])));
-                Delete(SocketString, 1, Succ(byte(SocketString[1])))
-            end
-        end
-    else
-        OutError('IPC connection lost', true)
-    end;
+    while ipcCheckFromFrontend() do
+        ParseIPCCommand(ipcReadFromFrontend())
 end;
 
 procedure LoadRecordFromFile(fileName: shortstring);
@@ -260,18 +224,11 @@
 
 procedure flushBuffer();
 begin
-    if IPCSock <> nil then
-        begin
-        SDLNet_TCP_Send(IPCSock, @sendBuffer.buf, sendBuffer.count);
-        flushDelayTicks:= 0;
-        sendBuffer.count:= 0
-        end
+
 end;
 
 procedure SendIPC(s: shortstring);
 begin
-if IPCSock <> nil then
-    begin
     if s[0] > #251 then
         s[0]:= #251;
 
@@ -280,37 +237,25 @@
     AddFileLog('[IPC out] '+ sanitizeCharForLog(s[1]));
     inc(s[0], 2);
 
-    if isSyncedCommand(s[1]) then
-        begin
-        if sendBuffer.count + byte(s[0]) >= cSendBufferSize then
-            flushBuffer();
-
-        Move(s, sendBuffer.buf[sendBuffer.count], byte(s[0]) + 1);
-        inc(sendBuffer.count, byte(s[0]) + 1);
-
-        if (s[1] = 'N') or (s[1] = '#') then
-            flushBuffer();
-        end else
-        SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
-    end
+    ipcToFrontend(s)
 end;
 
 procedure SendIPCRaw(p: pointer; len: Longword);
 begin
-if IPCSock <> nil then
+{    if IPCSock <> nil then
     begin
     SDLNet_TCP_Send(IPCSock, p, len)
-    end
+    end}
 end;
 
 procedure SendIPCXY(cmd: char; X, Y: LongInt);
 var s: shortstring;
 begin
-s[0]:= #9;
-s[1]:= cmd;
-SDLNet_Write32(X, @s[2]);
-SDLNet_Write32(Y, @s[6]);
-SendIPC(s)
+    s[0]:= #9;
+    s[1]:= cmd;
+    SDLNet_Write32(X, @s[2]);
+    SDLNet_Write32(Y, @s[6]);
+    SendIPC(s)
 end;
 
 procedure IPCWaitPongEvent;
@@ -440,13 +385,13 @@
 procedure chFatalError(var s: shortstring);
 begin
     SendIPC('E' + s);
-    // TODO: should we try to clean more stuff here?
+{    // TODO: should we try to clean more stuff here?
     SDL_Quit;
 
     if IPCSock <> nil then
         halt(HaltFatalError)
     else
-        halt(HaltFatalErrorNoIPC);
+        halt(HaltFatalErrorNoIPC);}
 end;
 
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
@@ -498,12 +443,9 @@
 begin
     RegisterVariable('fatal', @chFatalError, true );
 
-    IPCSock:= nil;
-
     headcmd:= nil;
     lastcmd:= nil;
     isPonged:= false;
-    SocketString:= '';
 
     hiTicks:= 0;
     flushDelayTicks:= 0;
@@ -513,10 +455,6 @@
 procedure freeModule;
 begin
     while headcmd <> nil do RemoveCmd;
-    SDLNet_FreeSocketSet(fds);
-    SDLNet_TCP_Close(IPCSock);
-    SDLNet_Quit();
-
 end;
 
 end.