Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-09-2010, 05:34 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Scripted IP Banning

Well editing the text file gets pretty tedious.

File Manager -> Navigate to Folder -> Edit as Text -> Add IP and Comment.

Ideally I'd prefer to see /openaccess ip:xxx.xxx.xxx.xxx but this will have to do until then.

The bare-bones of an IP Banning script:

PHP Code:
function onCreated() {
  
setTimer(1);
}

function 
onTimeout() {
  if (
this.timedipbans.size() > 0) {
    for (
temp.ipthis.timedipbans) {
      if (
timevar2 getIPReleaseTime(temp.ip)) {
        
ipUnBan(temp.ip);
      }
    }
    
setTimer(60);
  }
}

public function 
ipBan(ipcommentnoupdate) {
  if (!(
ip in this.ipbans)) {
    
this.ipbans.add(ip);
  }
  
this.comment.(@ip) = comment;
  
this.trigger("saveData""");
  if (!
noupdatesaveIPBanned();
}

public function 
ipBanTimed(ipcommentseconds) {
  if (!(
ip in this.ipbans)) {
    
this.ipbans.add(ip);
  }
  if (!(
ip in this.timedipbans)) {
    
this.timedipbans.add(ip);
  }
  
this.comment.(@ip) = comment;
  
this.release.(@ip) = timevar2 seconds;
  
this.trigger("saveData""");
  
saveIPBanned();
  
setTimer(1);
}

public function 
ipUnBan(ip) {
  if (
isIPBanned(ip)) {
    
this.ipbans.remove(ip);
    
this.timedipbans.remove(ip);
    
this.comment.(@ip) = "";
    
this.release.(@ip) = "";
    
this.trigger("saveData""");
    
saveIPBanned();
    return 
true;
  }
  return 
false;
}

public function 
getIPBans() {
  return 
this.ipbans;
}

public function 
getIPBanComment(ip) {
  return 
this.comment.(@ip);
}

public function 
getIPReleaseTime(ip) {
  return 
this.release.(@ip);
}

public function 
isIPBanned(ip) {
  return (
ip in this.ipbans);
}

function 
loadIPBanned() {
  
temp.lines.loadlines("levels/ipbanned.txt");
  for (
temp.linetemp.lines) {
    if (
temp.line.starts("#") || temp.line == "") continue;
    if (
temp.line.positions(".").size() == 3) {
      
ipBan(temp.line""true);
    }
  }
  
saveIPBanned(); 
}

function 
saveIPBanned() {
  
temp.lines = {
    
"###################################",
    
"# Automatically generated IP Bans #",
    
"###################################",
    
"",
  };
  for (
temp.ipgetIPBans()) {
    
temp.comment getIPBanComment(ip);
    if (
temp.comment) {
      if (
temp.lines[temp.lines.size()-1] != "") {
        
temp.lines.add("");
      }
      
temp.lines.add("#" SPC temp.comment);
      
temp.lines.add(temp.ip);
      
temp.lines.add("");
    } else {
      
temp.lines.add(temp.ip);
    }
  }
  
temp.lines.savelines("levels/ipbanned.txt"0);

I've provided a load/save function but they are fairly basic, you'll have to write your own to format it the way you like and take any comments into consideration.

I'd like to add 'time-length' features to it but that can be in V2 of it. The bans and comments could also be stored in SQL table. Anyway enjoy.
__________________
Quote:

Last edited by Tigairius; 08-11-2010 at 01:46 AM.. Reason: V2.2
Reply With Quote
  #2  
Old 08-09-2010, 05:37 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Nice.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 08-09-2010, 10:09 AM
Entrok Entrok is offline
Registered User
Join Date: Sep 2009
Location: Sweden
Posts: 51
Entrok is on a distinguished road
Send a message via MSN to Entrok
Should the script be a class joined to a player or in a DB?
Reply With Quote
  #4  
Old 08-09-2010, 12:26 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
* Scripts should only identify players uniquely via their account name, nickname or community name. Any other attempt to track a player such as through their IP address, PCID or by planting corrupt files in their system could constitute a criminal offence. Servers are strictly forbidden from using any sort of method to store or retrieve the player's IP address or PCID with script.

eh?
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #5  
Old 08-09-2010, 01:39 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Imperialistic View Post
* Scripts should only identify players uniquely via their account name, nickname or community name. Any other attempt to track a player such as through their IP address, PCID or by planting corrupt files in their system could constitute a criminal offence. Servers are strictly forbidden from using any sort of method to store or retrieve the player's IP address or PCID with script.

eh?
The code doesn't get or provide any IPs. IP bans exist, they are provided by the gserver. It's just that it's a real hassle to update the TXT file to manage these bans. This makes it easier.
__________________
Reply With Quote
  #6  
Old 08-09-2010, 03:13 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Entrok View Post
Should the script be a class joined to a player or in a DB?
Read the script, and the variables it uses then make a decision of which you think would be more effective.

Details like that were purposely left out because the one's using it should know enough to connect the missing dots. Servers uploading this should have their rights figured out and trust established so it's not used against them.
__________________
Quote:
Reply With Quote
  #7  
Old 08-09-2010, 03:33 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Imperialistic View Post
* Scripts should only identify players uniquely via their account name, nickname or community name. Any other attempt to track a player such as through their IP address, PCID or by planting corrupt files in their system could constitute a criminal offence. Servers are strictly forbidden from using any sort of method to store or retrieve the player's IP address or PCID with script.

eh?
This rule is broken on every server I've ever worked for, and for good reason.
__________________
Reply With Quote
  #8  
Old 08-09-2010, 03:37 PM
Fulg0reSama Fulg0reSama is offline
Extrinsical Anomaly
Fulg0reSama's Avatar
Join Date: Sep 2009
Location: Ohio
Posts: 3,049
Fulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant futureFulg0reSama has a brilliant future
Quote:
Originally Posted by Imperialistic View Post
* Scripts should only identify players uniquely via their account name, nickname or community name. Any other attempt to track a player such as through their IP address, PCID or by planting corrupt files in their system could constitute a criminal offence. Servers are strictly forbidden from using any sort of method to store or retrieve the player's IP address or PCID with script.

eh?
Point is made but... Graal is like 35% Developer Platformer 35% Copyrighted stuff that most likely does not belong to them and 30% rule breaking. That's what makes graal fun.
__________________

Careful, thoughts and opinions here scare people.
Reply With Quote
  #9  
Old 08-09-2010, 11:10 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
V2: Added basic time banning, there's some redundancy with the arrays. That'll be resolved when I switch it to SQL storage.
__________________
Quote:
Reply With Quote
  #10  
Old 08-10-2010, 03:06 PM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
Love the work Jerret, just amused how funny it is how Graal Admins don't keep up with their own rules.
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #11  
Old 08-12-2010, 07:16 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Had issues with the script Jerret put on Classic iPhone so made my own adaptation which provided some error checking. Depending on jerrets next version, will either improve this or implement changes to his next version.

This is based on what Jerret created but ended up starting from scratch using his as a reference point while scripting with style I am used to. Made my version as a backend, allowing for a simple frontend to be created. Provided example of NPC commands (RC) but can be adapted to be done anywhere.

Ultimately should move the hasright checking to DBNPC itself but that's for the next version =]

PHP Code:
function onCreated() {
  const 
ipbantick 60;
  
setTimer(1);
}

function 
onTimeout() {
  for (
ip this.ipban.getdynamicvarnames()) {
    
    if (
this.ipban.(@ip)[0] == "permanent")
      continue;
    
    
this.ipban.(@ip)[0] -= ipbantick;
    if (
this.ipban.(@ip)[0] <= 0)
      
unIPBan(ip,"Released by the system","system");  
  }
  
setTimer(ipbantick);
}

/* Add/Modify an IP ban */

public function IPBan(iptimecommentadminoverwrite) {
  
/* Work out ban time */
  
temp.ban banTime(time);
  if (
temp.ban[0] == 0)
    return 
"Invalid time specified: "@time;
  
  
/* Check IP given */
  
temp.check checkIP(ip);
  if (
temp.check[0] == 0)
    return 
temp.check[1];
  
  if (
comment "")
    return 
"Must provide a reason for the IP ban";

  
//Checks done: lets ban an IP!
  
temp.ipstring iptostring(ip);
  
  if (
this.ipban.(@ipstring).size() > 2)
  {
    if (!
overwrite)
    {
      
temp.ret format("%s has already been banned. Set overwrite as true to overwrite this entry",ip);
      return 
temp.ret;
    }
    else 
     
temp.modified true;
  }
  else
    
this.ipban.(@ipstring) = new[4];

  
/* set the ban */
  
this.ipban.(@ipstring) = {temp.ban[0], temp.commenttemp.admintemp.ban[0]};

  if (
temp.modified)
    
temp.ret format("%s modified the IP Ban for %s. Now banned for %s with reason: %s",
      
adminiptemp.ban[1], comment);
  else
    
temp.ret format("%s has IP banned %s for %s with reason: %s",
      
adminiptemp.ban[1], comment);
  
  
savelog2("ipbans.txt",temp.ret);
  
this.trigger("saveData","");
  
updateIPBans();  
  return 
temp.ret;
}

/* Remove an IP Ban */
public function unIPBan(ipcommentadmin) {
  if (
admin == "system")
    
temp.ipstring ip;
  else
    
temp.ipstring iptostring(ip);
    
  if (
this.ipban.(@ipstring).size() < 1)
    return 
"given IP address is not banned: "@ip;
  if (
comment == "")
    return 
"Must provide a reason to unban ip";
  
this.ipban.(@ipstring).clear();
  
this.trigger("saveData","");
  
updateIPBans();
  
temp.ret format("%s has unbanned the IP %s reason: %s",admin,ip,comment);
  
savelog2("ipbans.txt"temp.ret);
  return 
temp.ret;
}
  
public function 
updateIPBans() {
  
temp.lines = {
    
"###################################",
    
"#           Automatically generated IP Bans            #",
    
"###################################",
  };
  
  for (
ip this.ipban.getdynamicvarnames()) {
    if (
this.ipban.(@ip).size() < 1)
      continue;
    
temp.lines.add("# Ban Reason: "@this.ipban.(@ip)[1]);
    
temp.lines.add("# Banned for: "@this.ipban.(@ip)[3]);
    
temp.lines.add("# Banned by: "@this.ipban.(@ip)[2]);
    
temp.lines.add(stringtoip(ip));
    
temp.lines.add("");
  }
  
temp.lines.savelines("levels/ipbanned.txt"0);
  return 
1;
}
  
public function 
listBans() {
  for (
this.ipban.getdynamicvarnames()) {
    if (
this.ipban.(@t).size() < 1)
      continue;  
    
temp.list.add(stringtoip(t));
  }
  return 
temp.list;
}
  
  
/* Return with ban time*/

function banTime(time) {
  switch (
time) {
    case 
"minute":
      
temp.bantime 60;
      
temp.timereport "a minute (testing)";
      break;
    case 
"hour"
      
temp.bantime 3600
      
temp.timereport "an hour";
      break;
    case 
"day"
      
temp.bantime 3600 24
      
temp.timereport "a day";
      break;
    case 
"week"
      
temp.bantime 3600 24 7
      
temp.timereport "a week";
      break;
    case 
"month"
      
temp.bantime 3600 24 30
      
temp.timereport "a month";
      break;
    case 
"year"
      
temp.bantime 3600 24 365
      
temp.timereport "a year";
      break;
    case 
"permanent"
      
temp.bantime "permanent"
      
temp.timereport "a very long time";
      break;
    default:
      
temp.bantime int(time);      
      if (
temp.bantime 0)
        
temp.timereport "a custom time of " @time@" seconds";
      else
        
temp.bantime 0;
      break;
  }
  
temp.ret = {temp.bantimetemp.timereport};
  return 
temp.ret;
}

/* Verify whether given IP address can be banned */
function checkIP(ip) {
  
temp.tokens ip.tokenize(".");

  
// Check if IP address is private 
  
temp.private = {"10""127""172.16""192.168"};
  for (
temp.private) {
    if (
ip.starts(t)) {
      
temp.ret = {0format("IP Ban Error: %s is in a private address class"ip)};
      return 
temp.ret;
    }
  }
  
  
// Not enough octets: needs to be x.x.x.x
  
if (temp.tokens.size() != 4) {
    
temp.ret = {0format("IP Ban Error: Invalid IP address given: %s. 4 octets expected (x.x.x.x)",ip)};
    return 
temp.ret;
  }
  
  for (
i=0i<temp.tokens.size(); i++) {
    
    if (
temp.tokens[i] == "*")
      continue;
      
    if (
temp.tokens[i] != int(temp.tokens[i])) {
      
temp.ret = {0format("IP Ban Error: Invalid IP address given: %s. An IP address can only contain numbers!",ip)};
      return 
temp.ret;
    }
    
    
// An octet needs to be above 0 and less than 255
    
if (temp.tokens[i] > 255 || temp.tokens[i] < 0) {
      
temp.ret = {0format("IP Ban Error: Invalid IP address given: %s. An octet value must be between 0 and 255",ip)}; 
      return 
temp.ret;
    }
  }
  
  return 
1;
}

public function 
iptostring(ip) {
  
temp.toks ip.tokenize(".");
  
temp.ipstring toks[0] @"_"toks[1] @"_"toks[2] @"_"toks[3];
  return 
temp.ipstring;
}

public function 
stringtoip(ip) {
  
temp.toks ip.tokenize("_");
  
temp.ipstring toks[0] @"."toks[1] @"."toks[2] @"."toks[3];
  return 
temp.ipstring;


Example of my NC commands

PHP Code:
    case "ipban": {
      if (!
player.hasright("rw""levels/ipbanned.txt")) {
        
sendtorc("You do not have IP Ban rights, "@player.account);
        return;
      }
      
temp.ret IPBans.ipBan(params[1], params[2], params[3], player.accountparams[4]);
      
sendtorc(temp.ret);
      break;
    };
    
    case 
"listipbans": {
      if (!
player.hasright("rw""levels/ipbanned.txt")) {
        
sendtorc("You do not have IP Ban rights, "@player.account);
        return;
      }
      
temp.ret IPBans.listBans();
      
sendtorc(temp.ret);
      break;
    };
    
    case 
"unipban": {
      if (!
player.hasright("rw""levels/ipbanned.txt")) {
        
sendtorc("You do not have IP Ban rights, "@player.account);
        return;
      }
      
temp.ret IPBans.unIPBan(params[1],params[2],player.account);
      
sendtorc(temp.ret);
      break;
    };
   
   case 
"rebuildipbanlist": {
      if (!
player.hasright("rw""levels/ipbanned.txt")) {
        
sendtorc("You do not have IP Ban rights, "@player.account);
        return;
      }
      
temp.ret IPBans.updateIPBans();
      if (
temp.ret)
        
sendtorc("IP Bans list has been regenerated");
      else
        
sendtorc("Issues generating IP bans list");
      break;
   }; 

Last edited by Twinny; 08-12-2010 at 07:59 AM..
Reply With Quote
  #12  
Old 08-12-2010, 02:29 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Looks good.
__________________
Quote:
Reply With Quote
  #13  
Old 08-12-2010, 07:07 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
I will probably use one of these when I complete my newest project.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #14  
Old 08-12-2010, 07:41 PM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
Could add this as a feature of the Client RC.
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #15  
Old 08-12-2010, 08:07 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Rufus View Post
Could add this as a feature of the Client RC.
The problem is that it is a security issue to have the file writable with script, and that there's flaws with the file itself that would allow you to lock out an entire server with a single line / IP Ban.

I'd much rather see true openaccess support for IP bans due to how ineffective PC bans actually are.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:27 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.