mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 00:25:04 +00:00
Updated to allow multiple protocol versions
This commit is contained in:
@ -49,14 +49,14 @@ class CustomPacketHandler{
|
||||
$this->offset = 0;
|
||||
$this->c = (bool) $create;
|
||||
switch($pid){
|
||||
case 0x00:
|
||||
case MC_KEEP_ALIVE:
|
||||
if($this->c === false){
|
||||
$this->data["payload"] = Utils::readLong($this->get(8));
|
||||
}else{
|
||||
$this->raw .= Utils::writeLong($this->data["payload"]);
|
||||
}
|
||||
break;
|
||||
case 0x09:
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
if($this->c === false){
|
||||
$this->data["clientID"] = Utils::readLong($this->get(8));
|
||||
$this->data["session"] = Utils::readLong($this->get(8));
|
||||
@ -67,7 +67,7 @@ class CustomPacketHandler{
|
||||
$this->raw .= "\x00";
|
||||
}
|
||||
break;
|
||||
case 0x10:
|
||||
case MC_SERVER_HANDSHAKE:
|
||||
if($this->c === false){
|
||||
$this->data["cookie"] = $this->get(4); // 043f57fe
|
||||
$this->data["security"] = $this->get(1);
|
||||
@ -98,7 +98,7 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeLong($this->data["session2"]);
|
||||
}
|
||||
break;
|
||||
case 0x13:
|
||||
case MC_CLIENT_CONNECT:
|
||||
if($this->c === false){
|
||||
$this->data["cookie"] = $this->get(4); // 043f57fe
|
||||
$this->data["security"] = $this->get(1);
|
||||
@ -121,13 +121,13 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeLong($this->data["session"]);
|
||||
}
|
||||
break;
|
||||
case 0x15:
|
||||
case MC_CLIENT_DISCONNECT:
|
||||
//null
|
||||
break;
|
||||
case 0x18:
|
||||
//null
|
||||
break;
|
||||
case 0x82:
|
||||
case MC_LOGIN:
|
||||
if($this->c === false){
|
||||
$this->data["username"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
$this->data["unknown1"] = Utils::readInt($this->get(4));
|
||||
@ -137,21 +137,21 @@ class CustomPacketHandler{
|
||||
$this->raw .= "\x00\x00\x00\x07\x00\x00\x00\x07";
|
||||
}
|
||||
break;
|
||||
case 0x83:
|
||||
case MC_LOGIN_STATUS:
|
||||
if($this->c === false){
|
||||
$this->data["status"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeInt($this->data["status"]);
|
||||
}
|
||||
break;
|
||||
case 0x84:
|
||||
case MC_READY:
|
||||
if($this->c === false){
|
||||
$this->data["status"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["status"]);
|
||||
}
|
||||
break;
|
||||
case 0x85:
|
||||
case MC_CHAT:
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
}else{
|
||||
|
@ -33,6 +33,7 @@ class MinecraftInterface{
|
||||
$this->protocol = (int) $protocol;
|
||||
require("pstruct/RakNet.php");
|
||||
require("pstruct/packetName.php");
|
||||
require("pstruct/".$this->protocol.".php");
|
||||
require("pstruct/dataName.php");
|
||||
$this->pstruct = $pstruct;
|
||||
$this->name = $packetName;
|
||||
|
@ -30,7 +30,7 @@ require_once("classes/Session.class.php");
|
||||
class PocketMinecraftServer{
|
||||
var $seed, $protocol, $gamemode, $name, $maxClients, $clients;
|
||||
protected $interface, $entities, $player, $cnt, $events, $version, $serverType;
|
||||
function __construct($name, $gamemode = 1, $seed = false, $port = 19132, $protocol = CURRENT_PROTOCOL, $serverID = false, $version = CURRENT_VERSION){
|
||||
function __construct($name, $gamemode = 1, $seed = false, $protocol = CURRENT_PROTOCOL, $port = 19132, $serverID = false, $version = CURRENT_VERSION){
|
||||
$this->gamemode = (int) $gamemode;
|
||||
$this->port = (int) $port;
|
||||
$this->version = (int) $version;
|
||||
@ -55,6 +55,7 @@ class PocketMinecraftServer{
|
||||
$this->action(1000000 * 5 * 60, '$this->chat(false, "Check it at http://bit.ly/RE7uaW");');
|
||||
console("[INFO] Server Name: ".$this->name);
|
||||
console("[INFO] Server GUID: ".$this->serverID);
|
||||
console("[INFO] Protocol Version: ".$this->protocol);
|
||||
console("[INFO] Seed: ".$this->seed);
|
||||
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
|
||||
console("[INFO] Max Clients: ".$this->maxClients);
|
||||
@ -143,7 +144,7 @@ class PocketMinecraftServer{
|
||||
case 0x05:
|
||||
$version = $data[1];
|
||||
$size = strlen($data[2]);
|
||||
if($version != 5){
|
||||
if($version !== $this->protocol){
|
||||
$this->send(0x1a, array(
|
||||
5,
|
||||
MAGIC,
|
||||
|
@ -55,16 +55,6 @@ class Session{
|
||||
foreach($this->evid as $ev){
|
||||
$this->server->deleteEvent($ev[0], $ev[1]);
|
||||
}
|
||||
if($this->reason === "server stop"){
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x15,
|
||||
),
|
||||
));
|
||||
++$this->counter[0];
|
||||
}
|
||||
$this->connected = false;
|
||||
$this->server->trigger("onChat", $this->username." left the game");
|
||||
console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to ".$reason, true, true, 2);
|
||||
@ -78,7 +68,7 @@ class Session{
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x86,
|
||||
"id" => MC_SET_TIME,
|
||||
"time" => $data,
|
||||
),
|
||||
));
|
||||
@ -89,7 +79,7 @@ class Session{
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x85,
|
||||
"id" => MC_CHAT,
|
||||
"message" => $data,
|
||||
),
|
||||
));
|
||||
@ -110,22 +100,25 @@ class Session{
|
||||
$data[3],
|
||||
0,
|
||||
));
|
||||
break;
|
||||
break;
|
||||
case 0x80:
|
||||
case 0x84:
|
||||
case 0x88:
|
||||
case 0x8c:
|
||||
if(isset($data[0])){
|
||||
$this->counter[1] = $data[0];
|
||||
$this->send(0xc0, array(1, true, $data[0]));
|
||||
}
|
||||
switch($data["id"]){
|
||||
case 0x15:
|
||||
case MC_CLIENT_DISCONNECT:
|
||||
$this->close("client disconnect");
|
||||
break;
|
||||
case 0x09:
|
||||
case MC_CLIENT_HANDSHAKE:
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x10,
|
||||
"id" => MC_SERVER_HANDSHAKE,
|
||||
"port" => $this->port,
|
||||
"session" => $data["session"],
|
||||
"session2" => Utils::readLong("\x00\x00\x00\x00\x04\x44\x0b\xa9"),
|
||||
@ -134,7 +127,7 @@ class Session{
|
||||
++$this->counter[0];
|
||||
break;
|
||||
|
||||
case 0x82:
|
||||
case MC_LOGIN:
|
||||
$this->username = $data["username"];
|
||||
console("[INFO] ".$this->username." connected from ".$this->ip.":".$this->port);
|
||||
$this->evid[] = array("onTimeChange", $this->server->event("onTimeChange", array($this, "eventHandler")));
|
||||
@ -143,7 +136,7 @@ class Session{
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x83,
|
||||
"id" => MC_LOGIN_STATUS,
|
||||
"status" => 0,
|
||||
),
|
||||
));
|
||||
@ -152,7 +145,7 @@ class Session{
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => 0x87,
|
||||
"id" => MC_START_GAME,
|
||||
"seed" => $this->server->seed,
|
||||
"x" => 128,
|
||||
"y" => 100,
|
||||
@ -172,9 +165,6 @@ class Session{
|
||||
|
||||
}
|
||||
break;
|
||||
case 0x8c:
|
||||
$counter = $data[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user