Author Topic: Maskcheck...  (Read 682 times)

0 Members and 1 Guest are viewing this topic.

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Maskcheck...
« on: February 22, 2009, 01:14:26 pm »
Code: [Select]
function Admin(ID: byte): boolean;
var txt,ip: string;
begin
  txt := ReadFile('remote.txt');
  ip := GetPlayerStat(ID,'ip');
  Result := Maskcheck(txt,ip);
  Case result of
    True: Writeconsole(0,'True',$000000);
    False: Writeconsole(0,'False',$000000);
  end;
end;

procedure OnJoinGame(ID, Team: byte);
begin
  If Admin(ID) = true then begin
WriteConsole(0,'Admin, Your ip is ' + getplayerstat(id,'ip'),$00FFFF);
  end else begin
WriteConsole(0,'Ip is ' + getplayerstat(id,'ip'),$00FFFF);
  end;
end;

func Admin checks if ID's IP is on remotelist or not, somewhy it always results False, help?
Also Known As REIMA


Lol Happles (happy apples)

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: Maskcheck...
« Reply #1 on: February 22, 2009, 02:04:54 pm »
Quote
function MaskCheck(CheckString, Mask: string):Boolean

Parameter Info:
  CheckString (String): String to be checked.
  Mask (String): Mask to be used to check (CheckString).

Description:
This function will return TRUE or FALSE if (CheckString) matches (Mask).

Mask Example:
* = Full Wildcard
? = Single character Wildcard

Syntax Example:   
var
MyString: string;
begin
    MyString := '127.94.45.244';
    MaskCheck(MyString,'127.*.*.*'); // True
    MaskCheck(MyString,'127.?.?.?'); // False
    MaskCheck(MyString,'127.9?.*.*'); // True
    MaskCheck(MyString,'12?.?4.4?.2*4'); // True
    MaskCheck(MyString,'127.94.45.244'); // True
    MaskCheck(MyString,'123.94.45.244'); // False
end;

You are using the function incorrectly.

Consider using ContainsString:

Quote
function ContainsString(haystack, needle: string): Boolean

Parameter Info:
  haystack (String): String to search in.
  needle (String): String to search for.

Description:
This function will return TRUE or FALSE if (needle) is found in (haystack)

Syntax Example:   
var
MyString: string;
begin
    MyString := 'Catch me if you can!';
    ContainsString(MyString,'find me'); // False
    ContainsString(MyString,'Catch'); // True
    ContainsString(MyString,'you'); // True
end;
« Last Edit: February 22, 2009, 02:06:44 pm by chrisgbk »

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Maskcheck...
« Reply #2 on: February 22, 2009, 02:11:09 pm »
1. Use ContainsString
2. function Admin() can be written in 2 lines:
Code: [Select]
Result:= ContainsString(ReadFile('remote.txt'), GetPlayerStat(ID,'ip'));
WriteConsole(ID,iif(Result, 'True', 'False'), $000000);

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Maskcheck...
« Reply #3 on: February 22, 2009, 03:33:44 pm »
Tyvm for both,

also that true false thing in Admin() was just to make testing easier

Thanks!
Also Known As REIMA


Lol Happles (happy apples)