Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 11:31 PM.


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