All pastes #42053 Raw Edit

Unnamed

public php v1 · immutable
#42053 ·published 2006-02-18 15:23 UTC
rendered paste body
<?php class ircd {    var $port = 6667;  var $listen;  var $client;  var $server_name = "PHP IRCD";  var $server_host = "irc.php.net";    var $client_nick;    function start($port = 6667) {    $this->port = $port;    $this->listen = socket_create_listen($port);	socket_listen($this->listen);	echo "*** Server started at ".$this->server_host.":$port\n";	while(1) {	  if(!$this->client && $this->client = socket_accept($this->listen)) { echo "*** Server got connection and accepted it\n"; }      elseif($this->client) {	    $line = trim(socket_read($this->client, 512));		if(ereg("\n", $line)) {		  $split = split("\n", $line);		  foreach($split as $value) { 		    echo "*** Incomming: $value\n";		    $this->parse($value); 		  }		}		else {		  echo "*** Incomming: $line\n";		  $this->parse($line);		}	  }	}  }  function send($str) {    socket_write($this->client, $str."\n", strlen($str."\n"));  }  function parse($str) {    $split = split(" ", $str);	if($split[0] == "NICK") { 	  $this->client_nick = $split[1];	  echo "*** Nickname is: ".$split[1]."\n";	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :Welcome to PHP IRCD! Enjoy");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :What works? Nearly nothing here is the list:");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/JOIN #CHAN");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/MODE #CHAN +modes NICK");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/msg #CHAN thetime");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/msg #CHAN show-urself");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/msg #CHAN hide-urself");	  $this->send(":". $this->server_host ." NOTICE ".$this->client_nick." :/msg #CHAN bots [number of bots]");	}	if($split[0] == "PRIVMSG") {	  if($split[2] == ":bots") {	    for($i=1;$i <= (is_numeric($split[3])?$split[3]:50);$i++) {		  $this->send(":BotNumber-$i JOIN ".$split[1]);		}	  }	  if($split[2] == ":thetime") {	    $this->send(":Mr-Invisible PRIVMSG ".$split[1]." :The time is ".date("d.m.Y - H:i:s")." mister!");	  }	  if($split[2] == ":show-urself") {	    $this->send(":Mr-Invisible JOIN ".$split[1]);	    $this->send(":Mr-Invisible PRIVMSG ".$split[1]." :I went visible on your command mister!!");	  }	  if($split[2] == ":hide-urself") {	    $this->send(":Mr-Invisible PART ".$split[1]." :Im still here watching you! Muahahhaha");	    $this->send(":Mr-Invisible PRIVMSG ".$split[1]." :I went invisible on your command mister!!");	  }	}	if($split[0] == "MODE") {	  $this->send(":".$this->server_host." MODE ".$split[1]." ".$split[2]." ".$split[3]);	}	if($split[0] == "JOIN") { 	  $this->send(":".$this->client_nick." JOIN ".$split[1]);	  $this->send(":".$this->server_host." 332 ".$this->client_nick." {$split[1]} :Velkommen til {$split[1]}");	  $this->send(":".$this->server_host." 333 ".$this->client_nick." = {$split[1]} :");	  $this->send(":".$this->server_host." 366 ".$this->client_nick." {$split[1]} :End of /NAMES list");	  $this->send(":".$this->server_host." 324 ".$this->client_nick." {$split[1]} +tnc");	  $this->send(":".$this->server_host." 329 ".$this->client_nick." {$split[1]} :1046582738");	  $this->send(":Q JOIN ".$split[1]);	  $this->send(":".$this->server_host." MODE ".$split[1]." +o Q");	}  }}$ircd = new ircd;$ircd->start(6667);?>