Some hedgewars coding a week keeps doctor away qmlfrontend
authorunc0rr
Sat, 25 Apr 2015 23:46:09 +0300
branchqmlfrontend
changeset 10900 6a805e822074
parent 10898 f373838129c2
child 10902 29519fe63fdd
Some hedgewars coding a week keeps doctor away
hedgewars/uFLNet.pas
tools/protocolParser.hs
--- a/hedgewars/uFLNet.pas	Wed Apr 22 23:33:16 2015 +0300
+++ b/hedgewars/uFLNet.pas	Sat Apr 25 23:46:09 2015 +0300
@@ -11,7 +11,32 @@
 
 var sock: PTCPSocket;
     fds: PSDLNet_SocketSet;
-    buf: shortstring;
+    netReaderThread: PSDL_Thread;
+    sockbuf: shortstring;
+    sockbufpos: byte;
+
+function getNextChar: char;
+var r: byte;
+begin
+    if sockbufpos < byte(sockbuf[0]) then
+    begin
+        inc(sockbufpos);
+        getNextChar:= sockbuf[sockbufpos];
+    end else
+    begin
+        r:= SDLNet_TCP_Recv(sock, @sockbuf[1], 255);
+        if r > 0 then
+        begin
+            sockbufpos:= 1;
+            sockbuf[0]:= char(i);
+            getNextChar:= sockbuf[1];
+        end else
+        begin
+            sockbufpos:= 0;
+            sockbuf[0]:= #0;
+            getNextChar:= #0
+        end;
+end;
 
 function netReader(data: pointer): LongInt; cdecl; export;
 begin
@@ -26,7 +51,9 @@
     if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
         sock:= SDLNet_TCP_Open(ipaddr);
 
-    callbackListenerThread:= SDL_CreateThread(@listener{$IFDEF SDL2}, 'ipcListener'{$ENDIF}, nil);
+    sockbufpos:= 0;
+    sockbuf:= '';
+    netReaderThread:= SDL_CreateThread(@netReader{$IFDEF SDL2}, 'netReader'{$ENDIF}, nil);
 end;
 
 procedure initModule;
--- a/tools/protocolParser.hs	Wed Apr 22 23:33:16 2015 +0300
+++ b/tools/protocolParser.hs	Sat Apr 25 23:46:09 2015 +0300
@@ -1,6 +1,7 @@
 module Main where
 
 import Text.PrettyPrint.HughesPJ
+import Data.Tree
 
 data HWProtocol = Command String [CmdParam]
 data CmdParam = Skip
@@ -26,4 +27,6 @@
         , cmd1 "LOBBY:JOINED" $ Many [SS]
     ]
 
-main = undefined
+pas = 
+    
+main = putStrLn $ render pas