Author Topic: How To use Follow CLient on Linux to join another server  (Read 3496 times)

0 Members and 1 Guest are viewing this topic.

Offline poutch

  • Major(1)
  • Posts: 34
How To use Follow CLient on Linux to join another server
« on: December 06, 2007, 12:43:26 am »
Script Name: joinserv
Script Description: Transfer a player from a server to another. Made for Linux servers
Original Author(s): Poutch
Core Version: 2.6.3
Code:
Code: [Select]
{ 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;

Updated on 12 december 2007
« Last Edit: December 12, 2007, 11:36:29 am by poutch »
www.pleez.fr .... coming soon

Offline BombSki

  • Flagrunner
  • ****
  • Posts: 927
    • Climbing-soldiers.net
Re: How To use Follow CLient on Linux to join another server
« Reply #1 on: December 06, 2007, 01:37:34 am »
hey thats awesome. im using a forwarder script right now but i didnt know how to get the clients' join port. ive used default port for this so far and told everyone to set their joinport to default :S
thanks, i hope i can integrate this :)

edit: you should follow the release-guidelines though.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How To use Follow CLient on Linux to join another server
« Reply #2 on: December 06, 2007, 06:24:11 am »
:) No more worries on getting the port; gj
EnEsCe is going to yell at you for ur post though.. not following the template :P lol

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: How To use Follow CLient on Linux to join another server
« Reply #3 on: December 06, 2007, 06:37:13 am »
OMGF UZ THE TEMPLARTE.... But seriously, use the template.

Good script though, its nice to see scripting being used in such a creative way.

Offline poutch

  • Major(1)
  • Posts: 34
Re: How To use Follow CLient on Linux to join another server
« Reply #4 on: December 06, 2007, 09:33:35 am »
*edited to follow the template*

You can do something like that with windows servers too but i ve never scripted anything on windows. You just have to use shell_exec(urscript) that will read at the ConsoleLog files, find in those logs the last port used by the IP, and write it in a file.

« Last Edit: December 06, 2007, 11:58:38 am by poutch »
www.pleez.fr .... coming soon

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: How To use Follow CLient on Linux to join another server
« Reply #5 on: December 10, 2007, 10:37:47 am »
Doesn't work, nothing happens and lastpost.txt is always empty and chmod at 777.
p.s Ok, this is what happens:

07-12-10 18:26:47 /join_inf
07-12-10 18:26:47 
  • [Error] joinserv -> (OnCommand): '' is not a valid integer value

« Last Edit: December 10, 2007, 10:58:57 am by Leo »

Offline FliesLikeABrick

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 6144
    • Ultimate 13 Soldat
Re: How To use Follow CLient on Linux to join another server
« Reply #6 on: December 10, 2007, 12:25:08 pm »
I'm guessing that you can get this script working on Windows with a bit of creativity in combination with either cygwin or a port of grep and other utilities for Windows.  I believe there's a package that contains "normal" UNIX command-line utilities for Windows, I forget the name of it though.

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: How To use Follow CLient on Linux to join another server
« Reply #7 on: December 11, 2007, 05:26:58 am »
Come on guys, anyone has an idea on why I can't make this work ?

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: How To use Follow CLient on Linux to join another server
« Reply #8 on: December 11, 2007, 11:45:55 am »
shell_exec returns after the command finished executing? Just a doubt I have.
urraka

Offline poutch

  • Major(1)
  • Posts: 34
Re: How To use Follow CLient on Linux to join another server
« Reply #9 on: December 11, 2007, 09:57:06 pm »
Sorry, i was away some days.

Leo, if your lastport.txt file is empty that means that the shell commands didn't work or didn't match any IP in your log files. The problem have to be checked around that point i think.

After, as the lastport.txt file is empty, GetPiece(ReadFile('scripts/'+ScriptName+'/lastport.txt'),chr(13),0) will be a null string, and i guess that StrToInt from a null string is the reason why you get an error.

I suggest you to try the shell command alone and see progressively where it doesn t work and must be adjusted :
From a script folder : (that is why there is ../../logs/ )

grep IP ../../logs/ConsoleLog* | tail -n 1 | grep -o "[0-9]{4,5}" > lastport.txt
should create the file lastport.txt with the port number in it.

If it doesn t work, check it progressively :

grep IP pathtologs -> should give you all the lines in your logs with the matching IP
|tail -n 1 take only the last line from the result of the first grep
|grep -o "[0-9]{4,5}" take only the part matching 4 or 5 consecutive digits from the last result
> lastport.txt write the result in the lastport.txt file (erase the old one if it existed).


also be sure that /bin/bash is the path to your bash shell. I added this /bin/bash | ...| exit just to be sure that the commands are executed by a bash shell because if you use another shell (like sh for example) the regexps can be a little be different (have to change some " in ' and stuff like that)
If you have bash by default you can remove /bin/bash and |exit at the end


Date Posted: December 11, 2007, 09:46:28 pm
shell_exec returns after the command finished executing? Just a doubt I have.
What do you mean, if it returns in the script code after execution of commands ? yes
www.pleez.fr .... coming soon

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: How To use Follow CLient on Linux to join another server
« Reply #10 on: December 11, 2007, 10:43:23 pm »
Yep, i meant that, thanks.
urraka

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: How To use Follow CLient on Linux to join another server
« Reply #11 on: December 12, 2007, 01:28:26 am »
poutch, can't make it work. If you could come to #lrs it would be great. Just PM me there :)

Offline poutch

  • Major(1)
  • Posts: 34
Re: How To use Follow CLient on Linux to join another server
« Reply #12 on: December 12, 2007, 10:00:51 am »
Ok, works for Leo now, but for all, depending on from where you start the script and your linux environment variables, you may have to adjust some path to get it to work. I ll try to find a way to make it work more globally later
www.pleez.fr .... coming soon

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: How To use Follow CLient on Linux to join another server
« Reply #13 on: December 12, 2007, 10:37:50 am »
Yes, many thanks to poutch for his help on this :)

Offline poutch

  • Major(1)
  • Posts: 34
Re: How To use Follow CLient on Linux to join another server
« Reply #14 on: December 12, 2007, 10:42:46 am »
Updated the script to work more globally but :
- ServerPath have to be adjusted depending on your system (Enesce, a ServerPath global variable would be interesting in that case)

some other little changes :
- more checks and the script will try the default port if server is on windows or the shell commands failed
- when there is errors, it will be written in the logs
www.pleez.fr .... coming soon

Offline HEX

  • Major
  • *
  • Posts: 77
  • =tNt=
    • SoldatX Brazilian Community
Re: How To use Follow CLient on Linux to join another server
« Reply #15 on: December 13, 2007, 04:46:20 pm »
Just wondering... how about someone having fun like this:
1. you join his server;
2. he redirects you to other server;
3. in the new server, redirects you back to the first server;
4. at the first server, redirects you to the second server, and so on...

after like 8 hours being transfered, you press ctrl+alt+del to finish Soldat process because the redirection is so fast that you can't press esc/quit or neither /shutdown.

And no, I haven't tryed the script, so be a gentleman for me. :)
« Last Edit: December 13, 2007, 04:52:23 pm by HEX »



Offline BombSki

  • Flagrunner
  • ****
  • Posts: 927
    • Climbing-soldiers.net
Re: How To use Follow CLient on Linux to join another server
« Reply #16 on: December 13, 2007, 05:19:29 pm »
u have to press OK every redirect.

if u keep pressing OK you will get flood banned

(ive tried it)