All pastes #337368 Raw Edit

Someone

public text v1 · immutable
·published 2007-02-02 19:00 UTC
rendered paste body
#!/usr/local/bin/php
<?php
class pcwd 
{

	function pcwd() 
	{

		$file=file("pcw.txt");

		foreach ($file as $line) 
		{
			preg_match("/^#PC (.*)/i",$line,$x);
			$this->pcw=$x[1];
		}

		$this->config=array();
		$this->config['server']='phoenix.swiftirc.net';
		$this->config['nick']='World'; $this->cnick=$this->config['nick'];
		$this->config['port']=6667;
		$this->config['channel']="#pc"; $this->cchannel=$this->config['channel'];
		$this->config['name']='World Bot by Hamish'; $this->cname=$this->config['name'];
		$this->config['ip']=gethostbyname($this->config['server']);
		$this->socket=@fsockopen($this->config['ip'],$this->config['port']);
		set_time_limit(0);

		if ($this->socket) {
	    		$this->cmd_send("USER $this->cnick $this->cnick $this->cnick :$this->cname");
	    		$this->cmd_send("NICK $this->cnick");
		}

		while (!feof($this->socket)) 
		{

			$buffer=trim(fgets($this->socket,4096));


    			if (preg_match("/376 (.*) :End of \/MOTD command./",$buffer)) 
				{
       		 		$this->cmd_send("JOIN $this->cchannel");
    			}

	    		if(substr($buffer,0,6)=="PING :") 
				{
      	 	 		$reply=substr($buffer,6);
      	 		 	$this->cmd_send("PONG :".$reply);
    			}

    			if(preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG #PC :!(pcw|world|pcworld|pc)/",$buffer,$x)) 
				{
      		 	 	$this->cmd_send("NOTICE ".$x[1]." :".chr(3)."5[".chr(2)."PCW".chr(2)."]".chr(3)."14 ".chr(2)."T".chr(2)."he ".chr(2)."C".chr(2)."urrent ".chr(2)."P".chr(2)."est ".chr(2)."C".chr(2)."ontrol ".chr(2)."W".chr(2)."orld ".chr(2)."I".chr(2)."s: ".chr(3)."5,00[".chr(2)."".$this->pcw."".chr(2)."]");
    			}

    			if(preg_match("/^:(.*?)!(.*?)@(.*?) PRIVMSG #PC :!(change|setpcw|setworld|setpcworld) (.*)/",$buffer,$x)) 
				{
      	 		 	$this->setworld=$x[5];
					$this->checkreg($x[1]);
    			}

    			if(preg_match("/^:NickServ!services@swiftirc.net NOTICE (.*) :This nickname is registered and protected/i",$buffer,$x)) {
					$this->cmd_send("PRIVMSG NickServ :identify thisisthepass");
    			}

    			if (preg_match("/^ERROR :Closing Link:/",$buffer)) 
				{
    				$this->socket=@fsockopen($this->config['ip'],$this->config['port']);
    				$this->cmd_send("USER $this->cnick $this->cnick $this->cnick :$this->cname");
    				$this->cmd_send("NICK $this->cnick");
    			}

				if (preg_match("/^:(.*?) 353 $this->cnick = #PC :(.*)/i",$buffer,$x) && isset($this->setnick)) 
				{
					$names=explode(" ",$x[2]);
					$a=array("+", "%", "@");
					$b=array("", "", "");

					foreach ($names as $name) 
					{

						if (str_replace($a, $b, $name) == $this->setnick) 
						{

							$nick=$name;

							if (strpos($name,"+") !== FALSE) 
							{
								$this->isreg[$nick]="YEAH";
							}

							if (strpos($name,"%") !== FALSE) 
							{
								$this->isreg[$nick]="YEAH";
							}

							if (strpos($name,"@") !== FALSE) 
							{
								$this->isreg[$nick]="YEAH";
							}

							if ($this->isreg[$nick]=="YEAH") 
							{
								$file = "pcw.txt";
								$id = fopen($file, 'w');
								$data = "#PC ".$this->setworld;	
								fwrite($id, $data);
								fclose($id);
			        				$this->cmd_send("NOTICE $nick :".chr(3)."5[".chr(2)."PCW".chr(2)."]".chr(3)."14 ".chr(2)."T".chr(2)."he ".chr(2)."W".chr(2)."orld ".chr(2)."H".chr(2)."as ".chr(2)."B".chr(2)."een ".chr(2)."S".chr(2)."et ".chr(2)."T".chr(2)."o: ".chr(3)."5,00[".chr(2)."".$this->setworld."".chr(2)."]");
								$this->cmd_send("PRIVMSG #PC :".chr(3)."5[".chr(2)."PCW".chr(2)."]".chr(3)."14 ".chr(2)."T".chr(2)."he ".chr(2)."W".chr(2)."orld ".chr(2)."H".chr(2)."as ".chr(2)."B".chr(2)."een ".chr(2)."S".chr(2)."et ".chr(2)."T".chr(2)."o: ".chr(3)."5,00[".chr(2)."".$this->setworld."".chr(2)."]");
								$this->pcw=$this->setworld;
							}
						}	
					}
				}
			}	

		}

	function cmd_send($command) 
	{
     		fwrite($this->socket, $command."\r\n");
	}

	function checkreg($nick) 
	{
		$this->setnick=$nick;
		$this->cmd_send("NAMES #PC");
	}

	function daemon() 
	{
		$child = pcntl_fork();
   		if($child) 
		{
       		exit;
   		}
   		posix_setsid();
   		chdir("/");
   		umask(0);
   		return posix_getpid();
	}

}

$pcwd=new pcwd;
$pcwd->daemon();
$pcwd->pcwd();

?>