rendered paste body<?
include("commands.php");
error_reporting(E_ALL);
class mainSock {
var $sock;
var $newsock;
var $objectMainSock;
var $objectCommands;
var $objectClients;
function sockCreate($address, $port) {
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($this->sock, $address, $port);
socket_listen($this->sock, 3);
socket_set_block($this->sock);
}
function output($output) {
print_r($output);
}
function __destruct() {
@socket_close($this->sock);
@socket_close($this->newsock);
$data = null;
$newdata = null;
$test = null;
$nick = null;
}
}
class Clients {
public $ident;
public $ipaddr;
public $user;
public $nick;
public $curNick;
public $quitReason;
public $exData;
public $data;
public $sAddr;
function read($mainSock) {
$commands = new commands();
$commands->setObjects(array('mainSock' => $mainSock,'clients' => $this));
if ($mainSock->newsock = socket_accept($mainSock->sock)) {
$conn = socket_select($r = array($mainSock->newsock), $w = null, $e = null, 20, 0);
if ($conn == 1) {
socket_getpeername($mainSock->newsock, $this->ipaddr, $p);
echo "[New Connection] New connection (IP: $this->ipaddr)\n";
while ($mainSock->newsock !== false) {
$this->data = socket_read($mainSock->newsock, 4000);
$newdata = $this->data."\n";
echo $this->data;
$this->exData = explode(" ", $newdata);
if ($this->exData[0] == "PING") {
socket_write($mainSock->newsock, "PONG {$this->exData[1]}\n\r");
}
if ($this->exData[0] == "USER") {
$this->user = $this->exData[1];
$this->sAddr = str_replace("\"", "", $this->exData[3]);
$this->ident = $this->curNick."!~".$this->user."@".$this->ipaddr;
echo $this->ident."\n";
$commands->sendNoticeAuths();
$commands->sendRaws();
}
if ($this->exData[0] == "NICK") {
$this->nick = $this->exData[1];
if (preg_match("/^:/", $this->nick))
{
$this->nick = str_replace(":", "", $this->nick);
$commands->nickChange($this->curNick, $this->nick, $mainSock->newsock, $user, $address);
$this->curNick = $this->nick;
} else {
$this->curNick = $this->nick;
}
$mainSock->output($this->nick);
}
$mainSock->output($this->exData);
if ($this->exData[0] == "QUIT") {
$this->quitReason = explode(":", $newdata);
$commands->quit($this->quitReason[1], $this->ident, $mainSock->newsock);
unset($mainSock);
die();
}
}
}
}
}
}
$mainSock = new mainSock();
$mainSock->sockCreate('38.100.235.137','3913');
$clientsClass = new Clients();
$clientsClass->read($mainSock);
?>