From f8c6921ac42bb75368076a8da97bac71c94b4b8e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 31 Mar 2013 00:12:19 +0100 Subject: [PATCH] Few protocol edits --- src/Player.php | 14 ++++++--- src/PocketMinecraftServer.php | 45 ----------------------------- src/constants/ProtocolInfo.php | 4 +++ src/network/CustomPacketHandler.php | 18 ++++++++++-- 4 files changed, 30 insertions(+), 51 deletions(-) diff --git a/src/Player.php b/src/Player.php index 8100e30b78..b5f2483c46 100644 --- a/src/Player.php +++ b/src/Player.php @@ -202,10 +202,10 @@ class Player{ } $reason = $reason == "" ? "server stop":$reason; $this->eventHandler(new Container("You have been kicked. Reason: ".$reason), "server.chat"); - $this->dataPacket(MC_LOGIN_STATUS, array( + $this->directDataPacket(MC_LOGIN_STATUS, array( "status" => 1, )); - $this->dataPacket(MC_DISCONNECT); + $this->directDataPacket(MC_DISCONNECT); $this->sendBuffer(); $this->buffer = null; unset($this->buffer); @@ -638,11 +638,15 @@ class Player{ if($this->loggedIn === true){ break; } + if(count($this->server->clients) >= $this->server->maxClients){ + $this->close("server is full!", false); + return; + } + if($data["protocol1"] !== CURRENT_PROTOCOL){ $this->close("protocol", false); break; } - $this->loggedIn = true; if(preg_match('#^[a-zA-Z0-9_]{2,16}$#', $data["username"])){ $this->username = $data["username"]; $this->iusername = strtolower($this->username); @@ -658,6 +662,8 @@ class Player{ $this->close("\"\x1b[33m".$this->username."\x1b[0m\" is banned!", false); return; } + $this->loggedIn = true; + $u = $this->server->api->player->get($this->iusername); if($u !== false){ $u->close("logged in from another location"); @@ -1045,7 +1051,7 @@ class Player{ $this->nextBuffer = microtime(true) + 0.1; } - public function directDataPacket($id, $data, $count = false){ + public function directDataPacket($id, $data = array(), $count = false){ $data["id"] = $id; $data["sendtime"] = microtime(true); if($count === false){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index e5800f7f72..0a465b339c 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -534,15 +534,6 @@ class PocketMinecraftServer{ ), false, $packet["ip"], $packet["port"]); break; } - if($this->api->ban->isIPBanned($packet["ip"])){ - $this->send(0x1c, array( - $data[0], - $this->serverID, - RAKNET_MAGIC, - $this->serverType. $this->name . " [You're banned]", - ), false, $packet["ip"], $packet["port"]); - break; - } if(!isset($this->custom["times_".$CID])){ $this->custom["times_".$CID] = 0; } @@ -561,24 +552,6 @@ class PocketMinecraftServer{ $this->custom["times_".$CID] = ($this->custom["times_".$CID] + 1) % strlen($this->description); break; case 0x05: - if($this->api->ban->isIPBanned($packet["ip"]) or count($this->clients) >= $this->maxClients){ - $this->send(0x80, array( - 0, - 0x00, - array( - "id" => MC_LOGIN_STATUS, - "status" => 1, - ), - ), false, $packet["ip"], $packet["port"]); - $this->send(0x80, array( - 1, - 0x00, - array( - "id" => MC_DISCONNECT, - ), - ), false, $packet["ip"], $packet["port"]); - break; - } $version = $data[1]; $size = strlen($data[2]); if($version !== CURRENT_STRUCTURE){ @@ -598,24 +571,6 @@ class PocketMinecraftServer{ } break; case 0x07: - if($this->api->ban->isIPBanned($packet["ip"]) or count($this->clients) >= $this->maxClients){ - $this->send(0x80, array( - 0, - 0x00, - array( - "id" => MC_LOGIN_STATUS, - "status" => 1, - ), - ), false, $packet["ip"], $packet["port"]); - $this->send(0x80, array( - 1, - 0x00, - array( - "id" => MC_DISCONNECT, - ), - ), false, $packet["ip"], $packet["port"]); - break; - } $port = $data[2]; $MTU = $data[3]; $clientID = $data[4]; diff --git a/src/constants/ProtocolInfo.php b/src/constants/ProtocolInfo.php index 92977403d3..2bd67cafdd 100644 --- a/src/constants/ProtocolInfo.php +++ b/src/constants/ProtocolInfo.php @@ -34,8 +34,11 @@ define("MC_SERVER_HANDSHAKE", 0x10); define("MC_CLIENT_HANDSHAKE", 0x13); +define("MC_SERVER_FULL", 0x14); define("MC_DISCONNECT", 0x15); +define("MC_BANNED", 0x17); + define("MC_LOGIN", 0x82); define("MC_LOGIN_STATUS", 0x83); define("MC_READY", 0x84); @@ -99,6 +102,7 @@ class Protocol{ MC_CLIENT_HANDSHAKE => "Client Handshake", + //MC_SERVER_FULL => "Server Full", MC_DISCONNECT => "Disconnect", 0x18 => "Unknown", diff --git a/src/network/CustomPacketHandler.php b/src/network/CustomPacketHandler.php index 14ef5c0339..13698e4a5c 100644 --- a/src/network/CustomPacketHandler.php +++ b/src/network/CustomPacketHandler.php @@ -87,7 +87,7 @@ class CustomPacketHandler{ $this->data["port"] = Utils::readShort($this->get(2), false); $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 10, $offset); $this->get($offset); - $this->data["unknown1"] = $this->get(2); + $this->data["timestamp"] = $this->get(2); $this->data["session"] = Utils::readLong($this->get(8)); $this->data["session2"] = Utils::readLong($this->get(8)); }else{ @@ -119,7 +119,7 @@ class CustomPacketHandler{ $this->data["dataArray0"] = $this->get(ord($this->get(1))); $this->data["dataArray"] = Utils::readDataArray($this->get(true, false), 9, $offset); $this->get($offset); - $this->data["unknown1"] = $this->get(2); + $this->data["timestamp"] = $this->get(2); $this->data["session2"] = Utils::readLong($this->get(8)); $this->data["session"] = Utils::readLong($this->get(8)); }else{ @@ -134,9 +134,23 @@ class CustomPacketHandler{ $this->raw .= Utils::writeLong($this->data["session"]); } break; + case MC_SERVER_FULL: + if($this->c === false){ + }else{ + $this->raw .= RAKNET_MAGIC; + $this->raw .= Utils::writeLong($this->data["serverID"]); + } + break; case MC_DISCONNECT: //null break; + case MC_BANNED: + if($this->c === false){ + }else{ + $this->raw .= RAKNET_MAGIC; + $this->raw .= Utils::writeLong($this->data["serverID"]); + } + break; case MC_LOGIN: if($this->c === false){ $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));