hedgewars/uIO.pas
changeset 2382 bfd378dfc4e7
parent 2240 7ce9e6b7be3b
child 2396 e13a1117152b
equal deleted inserted replaced
2381:959da8402cac 2382:bfd378dfc4e7
    26 procedure SendIPC(s: shortstring);
    26 procedure SendIPC(s: shortstring);
    27 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    27 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    28 procedure SendIPCRaw(p: pointer; len: Longword);
    28 procedure SendIPCRaw(p: pointer; len: Longword);
    29 procedure SendIPCAndWaitReply(s: shortstring);
    29 procedure SendIPCAndWaitReply(s: shortstring);
    30 procedure SendIPCTimeInc;
    30 procedure SendIPCTimeInc;
       
    31 procedure SendKeepAliveMessage(Lag: Longword);
    31 procedure LoadRecordFromFile(fileName: shortstring);
    32 procedure LoadRecordFromFile(fileName: shortstring);
    32 procedure IPCWaitPongEvent;
    33 procedure IPCWaitPongEvent;
    33 procedure IPCCheckSock;
    34 procedure IPCCheckSock;
    34 procedure InitIPC;
    35 procedure InitIPC;
    35 procedure CloseIPC;
    36 procedure CloseIPC;
    50                 cmd: Char;
    51                 cmd: Char;
    51                 X, Y: SmallInt);
    52                 X, Y: SmallInt);
    52             2: (str: shortstring);
    53             2: (str: shortstring);
    53             end;
    54             end;
    54 
    55 
    55 var  IPCSock: PTCPSocket = nil;
    56 var
    56      fds: PSDLNet_SocketSet;
    57 	IPCSock: PTCPSocket = nil;
    57 
    58 	fds: PSDLNet_SocketSet;
    58      headcmd: PCmd = nil;
    59 
    59      lastcmd: PCmd = nil;
    60 	headcmd: PCmd = nil;
       
    61 	lastcmd: PCmd = nil;
       
    62 
       
    63 	SendEmptyPacketTicks: LongWord = 0;
       
    64 
    60 
    65 
    61 function AddCmd(Time: Longword; str: shortstring): PCmd;
    66 function AddCmd(Time: Longword; str: shortstring): PCmd;
    62 var Result: PCmd;
    67 var Result: PCmd;
    63 begin
    68 begin
    64 new(Result);
    69 new(Result);
   194 end;
   199 end;
   195 
   200 
   196 procedure SendIPC(s: shortstring);
   201 procedure SendIPC(s: shortstring);
   197 begin
   202 begin
   198 if IPCSock <> nil then
   203 if IPCSock <> nil then
   199    begin
   204 	begin
   200    if s[0]>#251 then s[0]:= #251;
   205 	SendEmptyPacketTicks:= 0;
   201    SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
   206 	if s[0]>#251 then s[0]:= #251;
   202    {$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s[1]);{$ENDIF}
   207 	SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
   203    inc(s[0], 2);
   208 	{$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s[1]);{$ENDIF}
   204    SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
   209 	inc(s[0], 2);
   205    end
   210 	SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
       
   211 	end
   206 end;
   212 end;
   207 
   213 
   208 procedure SendIPCRaw(p: pointer; len: Longword);
   214 procedure SendIPCRaw(p: pointer; len: Longword);
   209 begin
   215 begin
   210 if IPCSock <> nil then
   216 if IPCSock <> nil then
   241 procedure SendIPCAndWaitReply(s: shortstring);
   247 procedure SendIPCAndWaitReply(s: shortstring);
   242 begin
   248 begin
   243 SendIPC(s);
   249 SendIPC(s);
   244 SendIPC('?');
   250 SendIPC('?');
   245 IPCWaitPongEvent
   251 IPCWaitPongEvent
       
   252 end;
       
   253 
       
   254 procedure SendKeepAliveMessage(Lag: Longword);
       
   255 begin
       
   256 inc(SendEmptyPacketTicks, Lag);
       
   257 if (SendEmptyPacketTicks >= cSendEmptyPacketTime) then
       
   258 	SendIPC('+')
   246 end;
   259 end;
   247 
   260 
   248 procedure NetGetNextCmd;
   261 procedure NetGetNextCmd;
   249 var tmpflag: boolean;
   262 var tmpflag: boolean;
   250 	s: shortstring;
   263 	s: shortstring;