0 Members and 2 Guests are viewing this topic.
{ server must be run without safe mode : ./soldatserver -safe 0}function JoinServer(ID : Byte; TargetIP : String; TargetPort : Integer): boolean;var SrcIP, ShellCmds, StPort, ServerPath : String; SrcPort : Integer;begin ServerPath := '~/soldatserver263'; {You have to adjust this depending on your server path} SrcPort := 23073; {will be changed by lastport.txt if linux and there is no errors with the shell command} SrcIP := IDToIP(ID); if GetSystem() = 'linux' then begin ShellCmds := '/bin/bash | grep '+SrcIP+' '+ServerPath+'/logs/ConsoleLog* | grep "joining game" | tail -n 1 | grep -o "[0-9]\{4,5\}" > '+ServerPath+'/scripts/'+ScriptName+'/lastport.txt | exit'; shell_exec(ShellCmds); StPort := GetPiece(ReadFile('scripts/'+ScriptName+'/lastport.txt'),chr(13),0); if (Length(StPort)<4) or (Length(StPort)>5) then writeln ('[JoinServer] Error while trying to retrieve the port, trying with default port 23073...') else SrcPort := StrToInt(StPort); {the good case, we retrieved the port through shell command} end; if GetSystem() = 'windows' then begin SayToPlayer(ID,'[JoinServer] Can t retrieve port with windows servers yet, trying with default port 23073...'); end; ForwardClient(SrcIP, SrcPort, TargetIP, TargetPort); Result := false;end;{For testing - Just an example on how to use the JoinServer Function}function OnCommand(ID : Byte; Text: string): boolean;begin if Text = '/test' then JoinServer(ID, '88.191.25.12', 25011); Result := false; // Return true if you want to ignore the command typed.end;
shell_exec returns after the command finished executing? Just a doubt I have.