Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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));
- }
- // Separate all data
- $this->ex = explode(' ', $data);
- // Send PONG back to the server
- 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');
- }
- $this->ex = explode(' ', $data);
- foreach($this->ex as $i => $v){
- $this->ex[$i] = trim($v);
- }
- if($this->ex[0] == 'PING'){
- $this->send('PONG', $this->ex[1]);
- continue;
- }elseif($this->ex[0] == 'ERROR'){
- $this->out("CONNECTION ERROR");
- $this->active = false;
- continue;
- }
- 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));
- }
- $this->checkACTION();
- $this->checkALL();
- $this->checkMSG();
- foreach($GLOBALS['MODULES'] as $m){
- call_user_func($m['run'],$this->args,$this->ex);
- }
- }
- }
- $this->out("Connection Ended");
- }
- function checkACTION(){
- if(isset($this->ex[1])){
- if($this->ex[1] == 'JOIN'){
- $this->channels[$this->channel(substr($this->args['chan'],1))]->addUser($this->args['nick']);
- }elseif($this->ex[1] == 'PART'){
- $this->channels[$this->channel($this->args['chan'])]->removeUser($this->args['nick']);
- }elseif($this->ex[1]=='KICK'){
- $this->channels[$this->channel($this->args['chan'])]->removeUser($this->ex[3]);
- }elseif($this->ex[1]=='QUIT'){
- foreach($this->channels as $i=>$c){
- $this->channels[$i]->removeUser($this->args['nick']);
- }
- }
- }
- }
- function checkALL(){
- 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->active = false;
- $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($this->ex[4]);
- }
- break;
- case '!part':
- if($u=&user($this->args['nick'])&&$u['rank']>=3){
- $this->part($this->ex[4]);
- }
- break;
- }
- }
- function checkMSG(){
- if(!$this->args['ischan']){
- switch($this->args['cmd']){
- case 'changepass':
- changePassword($this->args['nick'],$this->ex[4],$this->ex[5]);
- break;
- case 'adduser':
- if($u=&user($this->args['nick'])&&$u['rank']>=3){
- createUser($this->ex[4],$this->ex[5]);
- }
- break;
- case 'annouce':
- if($u=&user($this->args['nick'])&&$u['rank']>=3){
- $msg = '';
- foreach($this->ex as $i => $v){
- if($i>5){
- $msg = $msg.' '.$v;
- }elseif($i == 5){
- $msg = $v;
- }
- }
- $this->send('PRIVMSG',$this->ex[4].' :'.$msg);
- }
- 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'],$this->ex[4],$this->ex[5]);
- break;
- }
- }
- }
- 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($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);
- }
- 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]);
- }
- }
- }
- private $md5;
- public $socket;
- public $server;
- public $port;
- public $nick;
- public $active = true;
- public $channels;
- private $ex;
- private $args;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement