Author Topic: [Script request] Clear remote.txt file  (Read 1010 times)

0 Members and 1 Guest are viewing this topic.

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
[Script request] Clear remote.txt file
« on: June 05, 2013, 11:53:01 am »
Basing on this http://bugs.soldat.pl/view.php?id=319 I'd be glad if someone could provide me with a script which ereases remote.txt file if number of line equals 99. Thanks in advance
« Last Edit: June 05, 2013, 11:54:55 am by Bonecrusher »

Im chill like that

DarkCrusade

  • Guest
Re: [Script request] Clear remote.txt file
« Reply #1 on: June 05, 2013, 12:36:36 pm »
I'll send you a PM later ;)

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
Re: [Script request] Clear remote.txt file
« Reply #2 on: June 05, 2013, 12:43:29 pm »
Post it here so others can use it too.

Im chill like that

DarkCrusade

  • Guest
Re: [Script request] Clear remote.txt file
« Reply #3 on: June 05, 2013, 01:20:27 pm »
Code: (pascal) [Select]
const
 br=#13#10;

var
 last_check:byte;

function explode(source:string; const delimiter:string):array of string;
var position,dellength,reslength:integer;
begin
 dellength:=length(delimiter);
 source:=source+delimiter;
 repeat
  position:=pos(delimiter,source);
  setarraylength(result,reslength+1);
  result[reslength]:=copy(source,1,position-1);
  reslength:=reslength+1;
  delete(source,1,position+dellength-1);
 until (position=0);
 setarraylength(result,reslength-1);
end;

function check_file_length(name:string):integer;
var tmp:array of string;
begin
 if not fileexists(name)
 then begin
  writeln('File does not exist.');
  result:=0;
  exit;
 end else begin
  tmp    := explode(readfile(name),br);
  result := getarraylength(tmp);
 end;
end;

procedure do_check();
begin
 if check_file_length('remote.txt') > 98 then begin
  writefile('remote.txt','127.0.0.1');
  writeln('RemoteDebug -> cleaned Remote.txt');
 end;
end;

procedure apponidle(ticks:integer);
var today:byte;
begin
 if ticks mod (60 * 60 * 60 * 24) = 0 then begin
  today := strtoint(formatdate('d'));
  if (last_check = 0)
  or (today > last_check) 
  or ((today = 1) and (last_check > 27)) then begin
   last_check := today;
   do_check();
  end;
 end;
end;

procedure activateserver();
begin
 last_check := strtoint(formatdate('d'));
 do_check();
end;

The script will check 'remote.txt' every day and overwrite it with '127.0.0.1' if the file surpasses a length of 98 lines.
« Last Edit: June 05, 2013, 02:09:35 pm by DarkCrusade »

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
Re: [Script request] Clear remote.txt file
« Reply #4 on: June 05, 2013, 01:35:24 pm »
Thanks it recompiles we'll see if it works. Also checking remote.txt every 5 mins seems a bit overprotective, once every few days would do it.

Im chill like that

DarkCrusade

  • Guest
Re: [Script request] Clear remote.txt file
« Reply #5 on: June 05, 2013, 02:11:56 pm »
The above version will work better for you then. It will check the file once a day. Restarting the server will not hurt it, as it will always perform a check whenever the server is activated.

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
Re: [Script request] Clear remote.txt file
« Reply #6 on: June 05, 2013, 03:14:19 pm »
I dont think it works actually ;p
edit1:Okay i think what caused it my remote file had 100 lines and script states it must equal 98 to work. e
edit2: i was right
« Last Edit: June 05, 2013, 03:20:23 pm by Bonecrusher »

Im chill like that

DarkCrusade

  • Guest
Re: [Script request] Clear remote.txt file
« Reply #7 on: June 05, 2013, 03:47:14 pm »
It works. The first log shows that do_check() works, while the second shows that the time check works as well.

Code: [Select]
13-06-05 22:29:47 Filling 'Remote.txt' with unnecessary lines. (100)
13-06-05 22:29:47 Checking length of 'Remote.txt'
13-06-05 22:29:47 Length: 101
13-06-05 22:29:47 Starting do_check();
13-06-05 22:29:47 RemoteDebug -> cleaned Remote.txt

Code: [Select]
13-06-05 22:46:17 Time check.
13-06-05 22:46:17 Filling file with unnecessary lines.
13-06-05 22:46:17 Today: 5
13-06-05 22:46:17 Last check: 0
13-06-05 22:46:17 Is Today later than last check?
13-06-05 22:46:17 Yes. New last check = today
13-06-05 22:46:17 Starting do_check();
13-06-05 22:46:17 RemoteDebug -> cleaned Remote.txt

Edit: The script checks whether the length of the file is higher than 98, not equal. That's why there is a 'length > 98' and not 'length = 98' ;)
« Last Edit: June 05, 2013, 03:53:37 pm by DarkCrusade »

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
Re: [Script request] Clear remote.txt file
« Reply #8 on: June 06, 2013, 09:19:16 am »
13-06-06 05:44:07 RemoteDebug -> cleaned Remote.txt
13-06-06 09:04:07 RemoteDebug -> cleaned Remote.txt
13-06-06 10:10:47 RemoteDebug -> cleaned Remote.txt
13-06-06 11:17:27 RemoteDebug -> cleaned Remote.txt

etc on dm server

Im chill like that