hedgewars/uIO.pas
changeset 351 29bc9c36ad5f
parent 208 a049157d673a
child 367 bc3c3edc5ce1
equal deleted inserted replaced
350:c3ccec3834e8 351:29bc9c36ad5f
    75 procedure ParseIPCCommand(s: shortstring);
    75 procedure ParseIPCCommand(s: shortstring);
    76 begin
    76 begin
    77 case s[1] of
    77 case s[1] of
    78      '!': begin {$IFDEF DEBUGFILE}AddFileLog('Ping? Pong!');{$ENDIF}isPonged:= true; end;
    78      '!': begin {$IFDEF DEBUGFILE}AddFileLog('Ping? Pong!');{$ENDIF}isPonged:= true; end;
    79      '?': SendIPC('!');
    79      '?': SendIPC('!');
    80      'e': ParseCommand(copy(s, 2, Length(s) - 1));
    80      'e': ParseCommand(copy(s, 2, Length(s) - 1), true);
    81      'E': OutError(copy(s, 2, Length(s) - 1), true);
    81      'E': OutError(copy(s, 2, Length(s) - 1), true);
    82      'W': OutError(copy(s, 2, Length(s) - 1), false);
    82      'W': OutError(copy(s, 2, Length(s) - 1), false);
    83      'T': case s[2] of
    83      'T': case s[2] of
    84                'L': GameType:= gmtLocal;
    84                'L': GameType:= gmtLocal;
    85                'D': GameType:= gmtDemo;
    85                'D': GameType:= gmtDemo;
    99 const ss: string = '';
    99 const ss: string = '';
   100 var i: integer;
   100 var i: integer;
   101     buf: array[0..255] of byte;
   101     buf: array[0..255] of byte;
   102     s: shortstring absolute buf;
   102     s: shortstring absolute buf;
   103 begin
   103 begin
   104 fds.numsockets:= 0;
   104 fds^.numsockets:= 0;
   105 SDLNet_AddSocket(fds, IPCSock);
   105 SDLNet_AddSocket(fds, IPCSock);
   106 
   106 
   107 while SDLNet_CheckSockets(fds, 0) > 0 do
   107 while SDLNet_CheckSockets(fds, 0) > 0 do
   108       begin
   108       begin
   109       i:= SDLNet_TCP_Recv(IPCSock, @buf[1], 255);
   109       i:= SDLNet_TCP_Recv(IPCSock, @buf[1], 255 - Length(ss));
   110       if i > 0 then
   110       if i > 0 then
   111          begin
   111          begin
   112          buf[0]:= i;
   112          buf[0]:= i;
   113          ss:= ss + s;
   113          ss:= ss + s;
   114          while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
   114          while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
   173       begin
   173       begin
   174       WriteLnToConsole('> ' + copy(extcmd[cmdcurpos].str, 2, Pred(extcmd[cmdcurpos].len)));
   174       WriteLnToConsole('> ' + copy(extcmd[cmdcurpos].str, 2, Pred(extcmd[cmdcurpos].len)));
   175       AddCaption('> ' + copy(extcmd[cmdcurpos].str, 2, Pred(extcmd[cmdcurpos].len)), $FFFFFF, capgrpNetSay);
   175       AddCaption('> ' + copy(extcmd[cmdcurpos].str, 2, Pred(extcmd[cmdcurpos].len)), $FFFFFF, capgrpNetSay);
   176       inc(cmdcurpos)
   176       inc(cmdcurpos)
   177       end;
   177       end;
   178          
   178 
   179 if cmdcurpos <= cmdendpos then
   179 if cmdcurpos <= cmdendpos then
   180    TryDo(GameTicks <= extcmd[cmdcurpos].Time,
   180    TryDo(GameTicks <= extcmd[cmdcurpos].Time,
   181          'oops, queue error. in buffer: ' + extcmd[cmdcurpos].cmd +
   181          'oops, queue error. in buffer: ' + extcmd[cmdcurpos].cmd +
   182          ' (' + inttostr(GameTicks) + ' > ' +
   182          ' (' + inttostr(GameTicks) + ' > ' +
   183          inttostr(extcmd[cmdcurpos].Time) + ')',
   183          inttostr(extcmd[cmdcurpos].Time) + ')',
   185 
   185 
   186 tmpflag:= true;
   186 tmpflag:= true;
   187 while (cmdcurpos <= cmdendpos)and(GameTicks = extcmd[cmdcurpos].Time) do
   187 while (cmdcurpos <= cmdendpos)and(GameTicks = extcmd[cmdcurpos].Time) do
   188    begin
   188    begin
   189    case extcmd[cmdcurpos].cmd of
   189    case extcmd[cmdcurpos].cmd of
   190         'L': ParseCommand('+left');
   190         'L': ParseCommand('+left', true);
   191         'l': ParseCommand('-left');
   191         'l': ParseCommand('-left', true);
   192         'R': ParseCommand('+right');
   192         'R': ParseCommand('+right', true);
   193         'r': ParseCommand('-right');
   193         'r': ParseCommand('-right', true);
   194         'U': ParseCommand('+up');
   194         'U': ParseCommand('+up', true);
   195         'u': ParseCommand('-up');
   195         'u': ParseCommand('-up', true);
   196         'D': ParseCommand('+down');
   196         'D': ParseCommand('+down', true);
   197         'd': ParseCommand('-down');
   197         'd': ParseCommand('-down', true);
   198         'A': ParseCommand('+attack');
   198         'A': ParseCommand('+attack', true);
   199         'a': ParseCommand('-attack');
   199         'a': ParseCommand('-attack', true);
   200         'S': ParseCommand('switch');
   200         'S': ParseCommand('switch', true);
   201         'j': ParseCommand('ljump');
   201         'j': ParseCommand('ljump', true);
   202         'J': ParseCommand('hjump');
   202         'J': ParseCommand('hjump', true);
   203         ',': ParseCommand('skip');
   203         ',': ParseCommand('skip', true);
   204         'N': begin
   204         'N': begin
   205              tmpflag:= false;
   205              tmpflag:= false;
   206              {$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}
   207              end;
   207              end;
   208         'p': begin
   208         'p': begin
   209              TargetPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X);
   209              TargetPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X);
   210              TargetPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y);
   210              TargetPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y);
   211              ParseCommand('put')
   211              ParseCommand('put', true)
   212              end;
   212              end;
   213         'P': begin
   213         'P': begin
   214              CursorPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X) + WorldDx;
   214              CursorPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X) + WorldDx;
   215              CursorPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y) + WorldDy;
   215              CursorPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y) + WorldDy;
   216              end;
   216              end;
   217         '1'..'5': ParseCommand('timer ' + extcmd[cmdcurpos].cmd);
   217         '1'..'5': ParseCommand('timer ' + extcmd[cmdcurpos].cmd, true);
   218         #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), true)
   219         end;
   219         end;
   220    inc(cmdcurpos)
   220    inc(cmdcurpos)
   221    end;
   221    end;
   222 isInLag:= (cmdcurpos > cmdendpos) and tmpflag
   222 isInLag:= (cmdcurpos > cmdendpos) and tmpflag
   223 end;
   223 end;