예제 #1
0
 public function getByEID($eid)
 {
     $eid = (int) $eid;
     $CID = $this->server->query("SELECT ip,port FROM players WHERE EID = '" . $eid . "';", true);
     $CID = PocketMinecraftServer::clientID($CID["ip"], $CID["port"]);
     if (isset($this->server->clients[$CID])) {
         return $this->server->clients[$CID];
     }
     return false;
 }
 public function packetHandler(Packet $packet)
 {
     $data =& $packet;
     $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port);
     if (isset($this->clients[$CID])) {
         $this->clients[$CID]->handlePacket($packet);
     } else {
         if ($this->handle("server.noauthpacket." . $packet->pid(), $packet) === false) {
             return;
         }
         switch ($packet->pid()) {
             case RakNetInfo::UNCONNECTED_PING:
             case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
                 if ($this->invisible === true) {
                     $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                     $pk->pingID = $packet->pingID;
                     $pk->serverID = $this->serverID;
                     $pk->serverType = $this->serverType;
                     $pk->ip = $packet->ip;
                     $pk->port = $packet->port;
                     $this->send($pk);
                     break;
                 }
                 if (!isset($this->custom["times_" . $CID])) {
                     $this->custom["times_" . $CID] = 0;
                 }
                 $ln = 15;
                 if ($this->description == "" or substr($this->description, -1) != " ") {
                     $this->description .= " ";
                 }
                 $txt = substr($this->description, $this->custom["times_" . $CID], $ln);
                 $txt .= substr($this->description, 0, $ln - strlen($txt));
                 $pk = new RakNetPacket(RakNetInfo::UNCONNECTED_PONG);
                 $pk->pingID = $packet->pingID;
                 $pk->serverID = $this->serverID;
                 $pk->serverType = $this->serverType . $this->name . " [" . count($this->clients) . "/" . $this->maxClients . "] " . $txt;
                 $pk->ip = $packet->ip;
                 $pk->port = $packet->port;
                 $this->send($pk);
                 $this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description);
                 break;
             case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
                 if ($packet->structure !== RakNetInfo::STRUCTURE) {
                     console("[DEBUG] Incorrect structure #" . $packet->structure . " from " . $packet->ip . ":" . $packet->port, true, true, 2);
                     $pk = new RakNetPacket(RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION);
                     $pk->serverID = $this->serverID;
                     $pk->ip = $packet->ip;
                     $pk->port = $packet->port;
                     $this->send($pk);
                 } else {
                     $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_1);
                     $pk->serverID = $this->serverID;
                     $pk->mtuSize = strlen($packet->buffer);
                     $pk->ip = $packet->ip;
                     $pk->port = $packet->port;
                     $this->send($pk);
                 }
                 break;
             case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
                 if ($this->invisible === true) {
                     break;
                 }
                 $this->clients[$CID] = new Player($packet->clientID, $packet->ip, $packet->port, $packet->mtuSize);
                 //New Session!
                 $pk = new RakNetPacket(RakNetInfo::OPEN_CONNECTION_REPLY_2);
                 $pk->serverID = $this->serverID;
                 $pk->port = $this->port;
                 $pk->mtuSize = $packet->mtuSize;
                 $pk->ip = $packet->ip;
                 $pk->port = $packet->port;
                 $this->send($pk);
                 break;
         }
     }
 }