server = $server; $this->clientID = $clientID; $this->ip = $ip; $this->port = $port; $this->serverID =& $this->server->serverID; $this->eventID = $this->server->event("onTick", array($this, "checkTimeout")); console("[DEBUG] New Session started with ".$ip.":".$port, true, true, 2); $this->connected = true; $this->counter = array(0, 0); } public function checkTimeout($time){ if($time > $this->timeout){ $this->close(); } } public function close(){ $this->server->deleteEvent("onTick", $this->eventID); $this->connected = false; console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to timeout", true, true, 2); } public function handle($pid, &$data){ if($this->connected === true){ $this->timeout = microtime(true) + 25; switch($pid){ case 0x07: $this->send(0x08, array( MAGIC, $this->serverID, $this->port, $data[3], 0, )); break; case 0x84: $this->counter[1] = $data[0]; $this->send(0xc0, array(1, true, $data[0])); switch($data[2]["packetName"]){ case "clientHandshake": $this->send(0x84, array( $this->counter[0], 0x600300, array( "port" => $this->port, ), )); ++$this->counter[0]; break; } break; case 0x8c: $counter = $data[0]; break; } } } public function send($pid, $data = array(), $raw = false){ $this->server->send($pid, $data, $raw, $this->ip, $this->port); } }