hedgewars/uIO.pas
branchwebgl
changeset 8026 4a4f21070479
parent 8003 7d8bce524daf
child 8096 453917e94e55
equal deleted inserted replaced
8023:7de85783b823 8026:4a4f21070479
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uIO;
    21 unit uIO;
    22 interface
    22 interface
    23 uses SDLh, uTypes;
    23 uses SDLh, uTypes, uMisc;
    24 
    24 
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 procedure InitIPC;
    28 procedure InitIPC;
   112 end;
   112 end;
   113 
   113 
   114 procedure ParseIPCCommand(s: shortstring);
   114 procedure ParseIPCCommand(s: shortstring);
   115 var loTicks: Word;
   115 var loTicks: Word;
   116 begin
   116 begin
       
   117 
   117 case s[1] of
   118 case s[1] of
   118      '!': begin AddFileLog('Ping? Pong!'); isPonged:= true; end;
   119      '!': begin AddFileLog('Ping? Pong!'); isPonged:= true; end;
   119      '?': SendIPC(_S'!');
   120      '?': SendIPC(_S'!');
   120      'e': ParseCommand(copy(s, 2, Length(s) - 1), true);
   121      'e': ParseCommand(copy(s, 2, Length(s) - 1), true);
   121      'E': OutError(copy(s, 2, Length(s) - 1), true);
   122      'E': OutError(copy(s, 2, Length(s) - 1), true);
   166         OutError('IPC connection lost', true)
   167         OutError('IPC connection lost', true)
   167     end;
   168     end;
   168 end;
   169 end;
   169 
   170 
   170 procedure LoadRecordFromFile(fileName: shortstring);
   171 procedure LoadRecordFromFile(fileName: shortstring);
   171 var f: file;
   172 var f  : File;
   172     ss: shortstring = '';
   173     ss : shortstring = '';
   173     i: LongInt;
   174     i  : LongInt;
   174     s: shortstring;
   175     s  : shortstring;
       
   176    t, tt   : string;
   175 begin
   177 begin
   176 
   178 
   177 // set RDNLY on file open
   179 // set RDNLY on file open
   178 filemode:= 0;
   180 filemode:= 0;
   179 {$I-}
   181 {$I-}
   180 assign(f, fileName);
   182 assign(f, fileName);
   181 reset(f, 1);
   183 reset(f, 1);
   182 
       
   183 tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
   184 tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
   184 
   185 
   185 i:= 0; // avoid compiler hints
   186 i:= 0; // avoid compiler hints
   186 s[0]:= #0;
   187 s[0]:= #0;
   187 repeat
   188 repeat
   188     BlockRead(f, s[1], 255 - Length(ss), i);
   189     BlockRead(f, s[1], 255 - Length(ss), i);
   189     if i > 0 then
   190     if i > 0 then
   190         begin
   191     begin
   191         s[0]:= char(i);
   192         s[0]:= char(i);
   192         ss:= ss + s;
   193         ss:= ss + s;
   193         while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
   194         while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
   194             begin
   195             begin
   195             ParseIPCCommand(copy(ss, 2, byte(ss[1])));
   196             ParseIPCCommand(copy(ss, 2, byte(ss[1])));
   196             Delete(ss, 1, Succ(byte(ss[1])))
   197 	       Delete(ss, 1, Succ(byte(ss[1])));
   197             end
   198             end
   198         end
   199         end
   199 until i = 0;
   200 until i = 0;
   200 
   201 
   201 close(f)
   202 close(f)
   220         s[0]:= #251;
   221         s[0]:= #251;
   221         
   222         
   222     SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
   223     SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
   223     AddFileLog('[IPC out] '+ s[1]);
   224     AddFileLog('[IPC out] '+ s[1]);
   224     inc(s[0], 2);
   225     inc(s[0], 2);
   225     SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
   226        SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])));
       
   227        //log('SendIPC');
   226     end
   228     end
   227 end;
   229 end;
   228 
   230 
   229 procedure SendIPCRaw(p: pointer; len: Longword);
   231 procedure SendIPCRaw(p: pointer; len: Longword);
   230 begin
   232 begin
   374 procedure doPut(putX, putY: LongInt; fromAI: boolean);
   376 procedure doPut(putX, putY: LongInt; fromAI: boolean);
   375 begin
   377 begin
   376 if CheckNoTeamOrHH or isPaused then
   378 if CheckNoTeamOrHH or isPaused then
   377     exit;
   379     exit;
   378 bShowFinger:= false;
   380 bShowFinger:= false;
   379 if not CurrentTeam^.ExtDriven and bShowAmmoMenu then
   381 if (not CurrentTeam^.ExtDriven) and bShowAmmoMenu then
   380     begin
   382     begin
   381     bSelected:= true;
   383     bSelected:= true;
   382     exit
   384     exit
   383     end;
   385     end;
   384 
   386 
   427     isPonged:= false;
   429     isPonged:= false;
   428     SocketString:= '';
   430     SocketString:= '';
   429     
   431     
   430     hiTicks:= 0;
   432     hiTicks:= 0;
   431     SendEmptyPacketTicks:= 0;
   433     SendEmptyPacketTicks:= 0;
       
   434 
   432 end;
   435 end;
   433 
   436 
   434 procedure freeModule;
   437 procedure freeModule;
   435 begin
   438 begin
   436     while headcmd <> nil do RemoveCmd;
   439     while headcmd <> nil do RemoveCmd;
   437     SDLNet_FreeSocketSet(fds);
   440     SDLNet_FreeSocketSet(fds);
   438     SDLNet_TCP_Close(IPCSock);
   441     SDLNet_TCP_Close(IPCSock);
   439     SDLNet_Quit();
   442     SDLNet_Quit();
       
   443 
   440 end;
   444 end;
   441 
   445 
   442 end.
   446 end.