Updating version & protocol enforcement

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-30 15:35:33 +01:00
parent 9a8850cb9c
commit a75f8c2737
5 changed files with 29 additions and 21 deletions

View File

@ -55,7 +55,7 @@ class Player{
$this->CID = $this->server->clientID($ip, $port); $this->CID = $this->server->clientID($ip, $port);
$this->ip = $ip; $this->ip = $ip;
$this->port = $port; $this->port = $port;
$this->timeout = microtime(true) + 25; $this->timeout = microtime(true) + 20;
$this->inventory = array_fill(0, 36, array(0, 0, 0)); $this->inventory = array_fill(0, 36, array(0, 0, 0));
$this->evid[] = $this->server->event("server.tick", array($this, "onTick")); $this->evid[] = $this->server->event("server.tick", array($this, "onTick"));
$this->evid[] = $this->server->event("server.close", array($this, "close")); $this->evid[] = $this->server->event("server.close", array($this, "close"));
@ -297,7 +297,7 @@ class Player{
public function handle($pid, $data){ public function handle($pid, $data){
if($this->connected === true){ if($this->connected === true){
$this->timeout = microtime(true) + 25; $this->timeout = microtime(true) + 20;
switch($pid){ switch($pid){
case 0xa0: //NACK case 0xa0: //NACK
if(isset($this->buffer[$data[2]])){ if(isset($this->buffer[$data[2]])){
@ -368,6 +368,10 @@ class Player{
} }
$this->send(0xc0, array(1, true, $data[0])); $this->send(0xc0, array(1, true, $data[0]));
} }
if(!isset($data["id"])){
break;
}
switch($data["id"]){ switch($data["id"]){
case MC_KEEP_ALIVE: case MC_KEEP_ALIVE:
@ -399,6 +403,10 @@ class Player{
if($this->loggedIn === true){ if($this->loggedIn === true){
break; break;
} }
if($data["protocol1"] !== CURRENT_PROTOCOL){
$this->close("protocol", false);
break;
}
$this->loggedIn = true; $this->loggedIn = true;
$this->username = str_replace(array("\x00", "/", " ", "\r", "\n", '"', "'"), array("", "-", "_", "", "", "", ""), $data["username"]); $this->username = str_replace(array("\x00", "/", " ", "\r", "\n", '"', "'"), array("", "-", "_", "", "", "", ""), $data["username"]);
if($this->username == ""){ if($this->username == ""){

View File

@ -541,7 +541,7 @@ class PocketMinecraftServer{
} }
$version = $data[1]; $version = $data[1];
$size = strlen($data[2]); $size = strlen($data[2]);
if($version !== CURRENT_PROTOCOL){ if($version !== 5){
console("[DEBUG] Incorrect protocol #$version from ".$packet["ip"].":".$packet["port"], true, true, 2); console("[DEBUG] Incorrect protocol #$version from ".$packet["ip"].":".$packet["port"], true, true, 2);
$this->send(0x1a, array( $this->send(0x1a, array(
CURRENT_PROTOCOL, CURRENT_PROTOCOL,

View File

@ -91,7 +91,7 @@ class CustomPacketHandler{
$this->raw .= "\xcd"; $this->raw .= "\xcd";
$this->raw .= Utils::writeShort($this->data["port"]); $this->raw .= Utils::writeShort($this->data["port"]);
$this->raw .= Utils::writeDataArray(array( $this->raw .= Utils::writeDataArray(array(
"\xff\xff\xff\xff", "\xf5\xff\xff\xf5",
"\xff\xff\xff\xff", "\xff\xff\xff\xff",
"\xff\xff\xff\xff", "\xff\xff\xff\xff",
"\xff\xff\xff\xff", "\xff\xff\xff\xff",
@ -140,11 +140,11 @@ class CustomPacketHandler{
case MC_LOGIN: case MC_LOGIN:
if($this->c === false){ if($this->c === false){
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false)); $this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
$this->data["maxX"] = Utils::readInt($this->get(4)); $this->data["protocol1"] = Utils::readInt($this->get(4));
$this->data["maxY"] = Utils::readInt($this->get(4)); $this->data["protocol2"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"]; $this->raw .= Utils::writeShort(strlen($this->data["username"])).$this->data["username"];
$this->raw .= "\x00\x00\x00\x08\x00\x00\x00\x08"; $this->raw .= Utils::writeInt(CURRENT_PROTOCOL).Utils::writeInt(CURRENT_PROTOCOL);
} }
break; break;
case MC_LOGIN_STATUS: case MC_LOGIN_STATUS:

View File

@ -39,5 +39,5 @@ define("LOG", true);
define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78"); define("MAGIC", "\x00\xff\xff\x00\xfe\xfe\xfe\xfe\xfd\xfd\xfd\xfd\x12\x34\x56\x78");
define("TEST_MD5", "d0ca3786e53b615bb4fb9f5094d5c9a7"); define("TEST_MD5", "d0ca3786e53b615bb4fb9f5094d5c9a7");
define("MAJOR_VERSION", "Alpha_1.1dev"); define("MAJOR_VERSION", "Alpha_1.1dev");
define("CURRENT_PROTOCOL", 5); define("CURRENT_PROTOCOL", 9);
define("CURRENT_MINECRAFT_VERSION", "v0.6.0 alpha"); define("CURRENT_MINECRAFT_VERSION", "v0.6.0 alpha");

View File

@ -68,20 +68,20 @@ define("MC_CHUNK_DATA", 0x9e);
define("MC_PLAYER_EQUIPMENT", 0x9f); define("MC_PLAYER_EQUIPMENT", 0x9f);
define("MC_INTERACT", 0xa0); define("MC_INTERACT", 0xa1);
define("MC_USE_ITEM", 0xa1); define("MC_USE_ITEM", 0xa2);
define("MC_PLAYER_ACTION", 0xa2); define("MC_PLAYER_ACTION", 0xa3);
define("MC_SET_ENTITY_DATA", 0xa3); define("MC_SET_ENTITY_DATA", 0xa4);
define("MC_SET_ENTITY_MOTION", 0xa4); define("MC_SET_ENTITY_MOTION", 0xa5);
define("MC_SET_HEALTH", 0xa5); define("MC_SET_HEALTH", 0xa6);
define("MC_SET_SPAWN_POSITION", 0xa6); define("MC_SET_SPAWN_POSITION", 0xa7);
define("MC_ANIMATE", 0xa7); define("MC_ANIMATE", 0xa8);
define("MC_RESPAWN", 0xa8); define("MC_RESPAWN", 0xa9);
define("MC_DROP_ITEM", 0xaa); define("MC_DROP_ITEM", 0xab);
define("MC_CONTAINER_OPEN", 0xab); define("MC_CONTAINER_OPEN", 0xac);
define("MC_CONTAINER_CLOSE", 0xac); define("MC_CONTAINER_CLOSE", 0xad);
define("MC_CONTAINER_SET_SLOT", 0xad); define("MC_CONTAINER_SET_SLOT", 0xae);
define("MC_CLIENT_MESSAGE", 0xb1); define("MC_CLIENT_MESSAGE", 0xb1);
define("MC_SIGN_UPDATE", 0xb2); define("MC_SIGN_UPDATE", 0xb2);