hedgewars/uIO.pas
changeset 154 5667e6f38704
parent 112 ca5f06017e99
child 155 401f4ea24715
equal deleted inserted replaced
153:dc10da2a73f9 154:5667e6f38704
    37 {$INCLUDE options.inc}
    37 {$INCLUDE options.inc}
    38 
    38 
    39 const ipcPort: Word = 0;
    39 const ipcPort: Word = 0;
    40 
    40 
    41 procedure SendIPC(s: shortstring);
    41 procedure SendIPC(s: shortstring);
       
    42 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    42 procedure SendIPCAndWaitReply(s: shortstring);
    43 procedure SendIPCAndWaitReply(s: shortstring);
    43 procedure IPCCheckSock;
    44 procedure IPCCheckSock;
    44 procedure InitIPC;
    45 procedure InitIPC;
    45 procedure CloseIPC;
    46 procedure CloseIPC;
    46 procedure NetGetNextCmd;
    47 procedure NetGetNextCmd;
    98                'N': GameType:= gmtNet;
    99                'N': GameType:= gmtNet;
    99                'S': GameType:= gmtSave;
   100                'S': GameType:= gmtSave;
   100                else OutError(errmsgIncorrectUse + ' IPC "T" :' + s[2], true) end;
   101                else OutError(errmsgIncorrectUse + ' IPC "T" :' + s[2], true) end;
   101      else
   102      else
   102      inc(cmdendpos);
   103      inc(cmdendpos);
   103      extcmd[cmdendpos].Time := PLongWord(@s[byte(s[0]) - 3])^;
   104      extcmd[cmdendpos].Time := SDLNet_Read32(@s[byte(s[0]) - 3]);
   104      extcmd[cmdendpos].str  := s;
   105      extcmd[cmdendpos].str  := s;
   105      {$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+inttostr(extcmd[cmdendpos].Time)+' at '+inttostr(cmdendpos));{$ENDIF}
   106      {$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+inttostr(extcmd[cmdendpos].Time)+' at '+inttostr(cmdendpos));{$ENDIF}
   106      dec(extcmd[cmdendpos].len, 4)
   107      dec(extcmd[cmdendpos].len, 4)
   107      end
   108      end
   108 end;
   109 end;
   135 procedure SendIPC(s: shortstring);
   136 procedure SendIPC(s: shortstring);
   136 begin
   137 begin
   137 if IPCSock <> nil then
   138 if IPCSock <> nil then
   138    begin
   139    begin
   139    if s[0]>#251 then s[0]:= #251;
   140    if s[0]>#251 then s[0]:= #251;
   140    PLongWord(@s[Succ(byte(s[0]))])^:= GameTicks;
   141    SDLNet_Write32(GameTicks, @s[Succ(byte(s[0]))]);
   141    {$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s);{$ENDIF}
   142    {$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s);{$ENDIF}
   142    inc(s[0],4);
   143    inc(s[0],4);
   143    SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
   144    SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
   144    end
   145    end
       
   146 end;
       
   147 
       
   148 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
       
   149 var s: shortstring;
       
   150 begin
       
   151 s[0]:= #5;
       
   152 s[1]:= cmd;
       
   153 SDLNet_Write16(X, @s[2]);
       
   154 SDLNet_Write16(Y, @s[4]);
       
   155 SendIPC(s)
   145 end;
   156 end;
   146 
   157 
   147 procedure SendIPCAndWaitReply(s: shortstring);
   158 procedure SendIPCAndWaitReply(s: shortstring);
   148 begin
   159 begin
   149 SendIPC(s);
   160 SendIPC(s);
   193         'N': begin
   204         'N': begin
   194              tmpflag:= false;
   205              tmpflag:= false;
   195              {$IFDEF DEBUGFILE}AddFileLog('got cmd "N": time '+inttostr(extcmd[cmdcurpos].Time)){$ENDIF}
   206              {$IFDEF DEBUGFILE}AddFileLog('got cmd "N": time '+inttostr(extcmd[cmdcurpos].Time)){$ENDIF}
   196              end;
   207              end;
   197         'p': begin
   208         'p': begin
   198              TargetPoint.X:= extcmd[cmdcurpos].X;
   209              TargetPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X);
   199              TargetPoint.Y:= extcmd[cmdcurpos].Y;
   210              TargetPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y);
   200              ParseCommand('put')
   211              ParseCommand('put')
   201              end;
   212              end;
   202         'P': begin
   213         'P': begin
   203              CursorPoint.X:= extcmd[cmdcurpos].X + WorldDx;
   214              CursorPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X) + WorldDx;
   204              CursorPoint.Y:= extcmd[cmdcurpos].Y + WorldDy;
   215              CursorPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y) + WorldDy;
   205              end;
   216              end;
   206         '1'..'5': ParseCommand('timer ' + extcmd[cmdcurpos].cmd);
   217         '1'..'5': ParseCommand('timer ' + extcmd[cmdcurpos].cmd);
   207         #128..char(128 + cMaxSlotIndex): ParseCommand('slot ' + char(byte(extcmd[cmdcurpos].cmd) - 79))
   218         #128..char(128 + cMaxSlotIndex): ParseCommand('slot ' + char(byte(extcmd[cmdcurpos].cmd) - 79))
   208         end;
   219         end;
   209    inc(cmdcurpos)
   220    inc(cmdcurpos)