Advertisement
Eeems

Untitled

May 19th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.69 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php # config$config[0]['server'] = 'withg.us.to';$config[0]['port'] = 6667;$config[0]['nick'] = 'EeeZor';$config[0]['name'] = 'EeeZorBot';$config[0]['channels'] = array("#IRP");# definesglobal $MODULES;global $USERS;$MODULES = array();$USERS = array();# settingsset_time_limit(0);ini_set('display_errors', 'on');# includes function out($msg){echo $msg."\n";}function user($user){foreach($GLOBALS['USERS'] as $u => $v){if($u==$user){return $v;}}return false;}function setUser($user){foreach($GLOBALS['USERS'] as $u => $v){if($v['name'] == $user['name']){$GLOBALS['USERS'][$u] = $user;return true;}}return false;}function createUser($n,$p){if(!user($n)){$GLOBALS['USERS'][$n]['rank'] = "1";$GLOBALS['USERS'][$n]['name'] = $n;$GLOBALS['USERS'][$n]['password'] = md5($p);save();return true;}return false;}function changeRank($op,$u,$r){if($op=& user($op)&&$u=& user($u)&&$op['rank']>=3&&$op['rank']>=(int)$r){$u['rank'] = $r;setUser($u);save();}}function changePassword($u,$o,$n){if($u=& user($u)&&$u['password']==md5($o)){$u['password'] = md5($n);setUser($u);save();return true;}return false;}function save(){write_ini_file($GLOBALS['USERS'],'users.ini',true);}function flushActive(){foreach($GLOBALS['USERS'] as $u => $v){unset($GLOBALS['USERS'][$u]['active']);}}function loaddir($p){$d = scandir($p);foreach($d as $f){if(is_file($p.'/'.$f)){loadfile($p.'/'.$f);}elseif($f!='.'&&$f!='..'){loaddir($p.'/'.$f);}}}function loadfile($path){out('Loading File: '.$path);eval(file_get_contents($path));}function regModule($name,$var){out('Registering Module: '.$name);$a['name'] = $name;$a['run'] =$var;$GLOBALS['MODULES'][] = $a;}function write_ini_file($assoc_arr, $path, $has_sections=FALSE) { $content = ""; if ($has_sections) { foreach ($assoc_arr as $key=>$elem) { $content .= "[".$key."]\n"; foreach ($elem as $key2=>$elem2) { if(is_array($elem2)) { for($i=0;$i<count($elem2);$i++) { $content .= $key2."[] = \"".$elem2[$i]."\"\n"; } } elseif($elem2=="")$content .= $key2." = \n"; else$content .= $key2." = \"".$elem2."\"\n"; } } } else { foreach ($assoc_arr as $key=>$elem) { if(is_array($elem)) { for($i=0;$i<count($elem);$i++) { $content .= $key2."[] = \"".$elem[$i]."\"\n"; } } elseif($elem=="")$content .= $key2." = \n"; else$content .= $key2." = \"".$elem."\"\n"; } } if (!$handle = fopen($path, 'w')) { return false; } if (!fwrite($handle, $content)) { return false; } fclose($handle); return true; }function set_ini_array($ini,$var){foreach($ini as $key => $val){$GLOBALS[$var][$key] = $val;}}ons.php'); class user{function __construct($user){$r = array('+','%','@','&','~');if(in_array(substr($user,0,1),$r)){$this->nick = substr($user,1);$this->prefix = substr($user,0,1);$this->rank = array_search(substr($user,0,1),$r)+1;}else{$this->nick = $user;}}public $nick;public $rank = 0;public $prefix = '';}ass.php'); class channel{function __construct($chan){$this->name = $chan;$this->users = array();}public function addUser($user){$this->users[] = new user($user);}public function removeUser($user){$r = array('+','%','@','&','~');if(in_array(substr($user,0,1),$r)){$user = array_search(substr($user,0,1),$r)+1;}foreach($this->users as $k => $u){if($u->nick==$user){unset($this->users[$k]);return true;}}return false;}public $name;public $users;}ass.php'); class server{function __construct($se,$po,$ni,$na,$cha = array()){$this->md5 = md5_file('users.ini');$this->server = $se;$this->port = $po;$this->nick = $ni;$this->name = $na;$this->socket = fsockopen($se,$po);if(!$this->socket){$this->out('Could not connect to '.$se.':'.$po);return false;}$this->send('USER',$this->nick.' eeezor.ec3club.tk '.$this->nick.' :'.$this->name);$this->send('NICK', $this->nick);$l = 0;while($l < 10) {$l++;$data = fgets($this->socket, 128);if(trim($data)!=''){$this->out(trim($data));}$this->ex = explode(' ', $data);if($this->ex[0] == "PING"){$this->send("PONG ".$this->ex[1]);}} sleep(1);foreach($cha as $c){$this->join($c);}}public function recieve(){while($this->active){$data = fgets($this->socket, 128);if(trim($data)!=''){if(md5_file('users.ini')!=$this->md5){$this->out("-----Reloading User Database----");set_ini_array(parse_ini_file('users.ini',true),'USERS');print_r($GLOBALS['USERS']);}$this->ex = explode(' ', $data);if(isset($this->ex[0])){if($this->ex[0] == 'PING'){$this->send('PONG', $this->ex[1]);}if(isset($this->ex[3])){$this->args['cmd'] = str_replace(array(chr(10), chr(13)), '', $this->ex[3]);if(substr($this->args['cmd'],0,1)==':'){$this->args['cmd'] = substr($this->args['cmd'],1);}}else{$this->args['cmd'] = '';}$this->args['chan'] = str_replace(array(chr(10), chr(13)), '', $this->ex[2]);$this->args['nick'] = explode(':',$this->ex[0]);$this->args['nick'] = explode('!',$this->args['nick'][1]);$this->args['nick'] = $this->args['nick'][0];$this->args['ischan'] = true;$this->args['server'] = $this;if(!substr_count($this->args['chan'],"#")){$this->args['ischan'] = false;$this->args['chan'] = $this->args['nick'];}else{$this->out(trim($data));}if(isset($this->ex[1])){if(trim($this->ex[1]) == 'JOIN'){$this->channels[$this->channel(substr($this->args['chan'],1))]->addUser($this->args['nick']);}elseif(trim($this->ex[1]) == 'PART'){$this->channels[$this->channel($this->args['chan'])]->removeUser($this->args['nick']);}elseif(trim($this->ex[1])=='KICK'){$this->channels[$this->channel($this->args['chan'])]->removeUser(trim($this->ex[3]));}elseif(trim($this->ex[1])=='QUIT'){foreach($this->channels as $i=>$c){$this->channels[$i]->removeUser($this->args['nick']);}}}switch($this->args['cmd']){case '!exit':if($u=& user($this->args['nick'])&&$u['rank']>=6){foreach($this->channels as $c){$this->part($c->name);}$this->send('QUIT', '*NOMS*');$this->socket = false;}break;case '!debug':if($u=&user($this->args['nick'])&&$u['rank']>=6){print_r($this->ex);$this->out('channel: '.$this->args['chan']);$this->out('nick: '.$this->args['nick']);if($this->args['ischan']){$this->out('ischan: true');}else{$this->out('ischan: false');}print_r($this->channels);}break;case '!join':if($u=&user($this->args['nick'])&&$u['rank']>=3){$this->join(trim($this->ex[4]));}break;case '!part':if($u=&user($this->args['nick'])&&$u['rank']>=3){$this->part(trim($this->ex[4]));}break;}if(!$this->args['ischan']){switch($this->args['cmd']){case 'changepass':changePassword($this->args['nick'],trim($this->ex[4]),trim($this->ex[5]));break;case 'adduser':if($u=&user($this->args['nick'])&&$u['rank']>=3){createUser(trim($this->ex[4]),trim($this->ex[5]));}break;case 'listusers':if($u=&user($this->args['nick'])&&$u['rank']>=4){foreach($GLOBALS['USERS'] as $k=>$v){$this->reply($k.': '.$v['rank']);sleep(1);}}break;case 'changerank':changeRank($this->args['nick'],trim($this->ex[4]),trim($this->ex[5]));break;}}foreach($GLOBALS['MODULES'] as $m){call_user_func($m['run'],$this->args,$this->ex);}}}}}function join($chan){$this->send('JOIN',$chan);$this->channels[] =  new channel($chan);$matches = array();$data = '';do{$data = trim(fgets($this->socket, 128));preg_match_all('/:([\S]+) (353) [\S]+ (?:=|@) #([\S]+) :(.+)/',$data,$matches);$this->out($data);if(count($matches)>0&&isset($matches[4][0])&&$matches[4][0]!=''){$t = explode(" ",$matches[4][0]);foreach($t as $u){$this->channels[count($this->channels)-1]->addUser(trim($u));}}else{$matches = array();}}while(count($matches)<1);}public function reply($msg){$this->send('PRIVMSG',$this->args['chan'].' :'.$msg);}public function send($cmd, $msg = null){ if($msg == null){fputs($this->socket, $cmd."\r\n");$this->out($cmd);}else{fputs($this->socket, $cmd.' '.$msg."\r\n");$this->out($cmd.' '.$msg);}}private function out($msg){out('['.$this->server.':'.$this->port.'] '.$msg);}public function sendTo($chan,$msg){ fputs($this->socket, 'PRIVMSG '.$chan.' :'.$msg."\r\n");$this->out('PRIVMSG '.$chan.' '.$msg);}function channel($chan){foreach($this->channels as $c=>$n){if($chan==$n->name){return $c;}}return false;}function part($chan){foreach($this->channels as $k =>$c){if($c->name==$chan){$this->send('PART',$chan);unset($this->channels[$k]);}}$this->active = false;}private $md5;public $socket;public $server;public $port;public $nick;public $active = true;public $channels;private $ex;private $args;}ass.php'); class irc{function __construct($se = array()){foreach($se as $s){if(!isset($s['channels'])){$s['channels'] = array();}$this->addServer($s['server'],$s['port'],$s['nick'],$s['name'],$s['channels']);}$this->wait();}function wait(){foreach($this->servers as $pid){pcntl_waitpid($pid,$status);}}function addServer($se,$po,$ni,$na,$cha = array()){if(!$this->child){$pid = pcntl_fork();$this->servers[]  = $pid;if ($pid == -1) {die('could not fork');} else if ($pid) {} else {$this->child = true;$s = new server($se,$po,$ni,$na,$cha);$s->recieve();}}}private $servers;private $child = false;}ass.php');# codeset_ini_array(parse_ini_file('users.ini',true),'USERS');loaddir('modules');flushActive();new irc($config);flushActive();?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement