Author Topic: Banlist with easy unban  (Read 3146 times)

0 Members and 1 Guest are viewing this topic.

Offline Hydro

  • Major(1)
  • Posts: 31
Banlist with easy unban
« on: October 06, 2007, 05:29:05 am »
Script Name: Banlist with easy unban
Script Description: This shows banlist and we can remove ban by ban-id
Original Author(s): oRdyH vel Hydro
Core Version: v2.6.2 (windows)
Code:
XSplit:
Code: [Select]
function xsplit(const source: string; const delimiter: string):TStringArray;
var
i,x,d:integer;
s:string;
begin
d:=length(delimiter);
x:=0;
i:=1;
SetArrayLength(Result,1);
while(i<=length(source)) do begin
s:=Copy(source,i,d);   
    if(s=delimiter) then begin
    inc(i,d);
    inc(x,1);
    SetArrayLength(result,x+1);
    end else begin       
    result[x]:= result[x]+Copy(s,1,1);
    inc(i,1);
  end;
end;
end;

banlist.pas:
Code: [Select]
var
    line : array[0..255] of record
          whole: string;
          parts: array[0..2] of string;
    end;
 
procedure AppOnIdle(Ticks: integer);
var
lines: TStringArray;
i: byte;
j: byte;
begin
if Ticks mod (60 * 5) = 0 then begin
    lines := XSplit(ReadFile('banned.txt'),chr(13) + chr(10));
    if ContainsString(lines[0],'.') then
    begin
      for i:=0 to GetArrayLength(lines) - 2 do
      line[i].whole:=trim(lines[i]);
     
      for j:=0 to GetArrayLength(lines) - 2 do
      begin
        line[j].parts[0]:=GetPiece(line[j].whole,':',0);
        line[j].parts[1]:=GetPiece(line[j].whole,':',1);
        line[j].parts[2]:=GetPiece(line[j].whole,':',2);
      end;
      end;
   
end;
end;

function OnCommand(ID: Byte; Text: string): boolean;
var
i: byte;
bantime: integer;
lines: TStringArray;
begin
if Text = '/banlist' then
begin
  lines := XSplit(ReadFile('banned.txt'),chr(13) + chr(10));
  if ContainsString(lines[0],'.') then
  begin
    WriteConsole(ID,'*** BAN LIST ***',$FFFF0000);
    for i:=0 to getarraylength(lines) - 2 do
    begin
      bantime:=strtoint(line[i].parts[1]);
      bantime:=bantime/3600;
      WriteConsole(ID,inttostr(i)+'. IP: '+line[i].parts[0]+' Time: '+inttostr(bantime)+' minutes. Info: '+line[i].parts[2],$FFff7e00);
    end;
  end;
end;
if GetPiece(Text,' ',0) = '/ub' then
begin
i:=strtoint(GetPiece(Text,' ',1));
Command('/unban '+line[i].parts[0]);
end;
Result := false; // Return true if you want to ignore the command typed.
end;


Commands:
- /banlist
- /ub X

13.10.2007
- repaired "Out Of Range" every 5 seconds
« Last Edit: October 13, 2007, 09:24:54 am by Hydro »

Offline Kitty

  • Major
  • *
  • Posts: 60
Re: Banlist with easy unban
« Reply #1 on: October 06, 2007, 06:46:38 am »
This one is very usefull ^^

Only problem is i get
*] [Error] banlist -> (AppOnIdle): Out Of Range

All the time
« Last Edit: October 06, 2007, 06:48:39 am by Kitty »
-A female soldat player.


Offline Hydro

  • Major(1)
  • Posts: 31
Re: Banlist with easy unban
« Reply #2 on: October 06, 2007, 07:11:45 am »
Ye, I have this 'error' when banned.txt is empty

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Banlist with easy unban
« Reply #3 on: October 06, 2007, 07:20:31 am »
Shouldn't the for loops go from 0 to for i:=0 to GetArrayLength(lines) - 1? That might be the apponidle bug sense the array length will be 1 and 1 - 2 = -1 and it'll try for i := 0 to -1... maybe..

Offline Hydro

  • Major(1)
  • Posts: 31
Re: Banlist with easy unban
« Reply #4 on: October 06, 2007, 07:24:48 am »
I tried -1 but it shows sometimes 1 line more than there are in banned.txt and there is in console a lot of "access violation"
« Last Edit: October 06, 2007, 07:26:30 am by Hydro »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Banlist with easy unban
« Reply #5 on: October 06, 2007, 07:46:23 am »
I dunno but a guess would be because the last line is always blank? (i don't know..) if thats the case, before the for loop, do a check on the array length and see if it returns "1" (if u subtract 2 from it, it will return -1) if so, don't do the for loop.. try that maybe.

Offline deguix

  • Major
  • *
  • Posts: 79
Re: Banlist with easy unban
« Reply #6 on: October 07, 2007, 09:04:52 pm »
"For" can only go from 0 to -1 if you use "downto" instead of "to", otherwise it won't be called. But, the case shown is an exception, because he's using the data type "byte", and it can't be negative. So 'for i:=0 to GetArrayLength(lines)-2' (when lines = 1) => 'while True ...' (it will go on forever...).

So, use an integer type, or add an extra if to take care of the value of GetArrayLength(lines).

That bug of having a "blank line" at the end of the file happens to me too, even though there's none... is the End Of File (or EOF) 'chr(13) + chr(10) +  chr(0)'?
« Last Edit: October 07, 2007, 09:08:49 pm by deguix »

Offline addict

  • Major(1)
  • Posts: 19
Re: Banlist with easy unban
« Reply #7 on: October 12, 2007, 01:11:03 pm »
 
  • ScriptCore v2.2 loaded! Found 6 scripts...
  • Compiling banlist -> xsplit.pas...
  • Compiling banlist -> banlist.pas...
  • banlist -> [Error] (65:87): String error
  • banlist -> [Error] (65:87): Syntax error

Offline SkyBoy

  • Major(1)
  • Posts: 4
  • To be or not to be... that is the question.
Re: Banlist with easy unban
« Reply #8 on: October 13, 2007, 04:40:09 am »
People! please, give me ScriptCore v2.2
I don't may find him(

Offline Hydro

  • Major(1)
  • Posts: 31
Re: Banlist with easy unban
« Reply #9 on: October 13, 2007, 09:09:34 am »
:O? http://www.soldat.pl/downloads/soldatserver263.zip
addict: Is there this error on linux server? It works on 263 on Windows.

UPDATE: repaired "Out Of Range"
Download in 1st post.
« Last Edit: October 13, 2007, 09:25:56 am by Hydro »