better custom packet handling

This commit is contained in:
Shoghi Cervantes Pueyo 2012-11-25 20:27:33 +01:00
parent 95b78a90ac
commit 0205880f99
8 changed files with 62 additions and 24 deletions

View File

@ -78,7 +78,24 @@ class CustomPacketHandler{
$this->data["time"] = Utils::readInt($this->get(4)); $this->data["time"] = Utils::readInt($this->get(4));
}else{ }else{
$this->raw .= Utils::writeInt($this->data["time"]); $this->raw .= Utils::writeInt($this->data["time"]);
} }
break;
case 0x87:
if($this->c === false){
$this->data["seed"] = $this->get(8);
$this->data["unknown1"] = $this->get(4);
$this->data["unknown2"] = $this->get(4);
$this->data["spawnX"] = Utils::readFloat($this->get(4));
$this->data["spawnY"] = Utils::readFloat($this->get(4));
$this->data["spawnZ"] = Utils::readFloat($this->get(4));
}else{
$this->raw .= $this->data["seed"];
$this->raw .= "\x00\x00\x00\x01\x00\x00\x00\x05";
$this->raw .= "\x43\x00\x80\x00\x42\x82\x00\x00\x43\x00\x80\x00";
/*$this->raw .= Utils::writeFloat($this->data["spawnX"]);
$this->raw .= Utils::writeFloat($this->data["spawnY"]);
$this->raw .= Utils::writeFloat($this->data["spawnZ"]);*/
}
break; break;
case 0x09: case 0x09:
if($this->c === false){ if($this->c === false){

View File

@ -71,11 +71,21 @@ class Packet{
} }
break; break;
case "customData": case "customData":
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true); switch($this->data[1]){
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3)); case 0x40:
$this->addRaw(Utils::writeTriad($this->data[$field]["count"])); $reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
$this->addRaw(chr($this->data[$field]["id"])); $this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
$this->addRaw($reply->raw); $this->addRaw(Utils::writeTriad($this->data[$field]["count"]));
$this->addRaw(chr($this->data[$field]["id"]));
$this->addRaw($reply->raw);
break;
case 0x00:
$reply = new CustomPacketHandler($this->data[$field]["id"], "", $this->data[$field], true);
$this->addRaw(Utils::writeShort((strlen($reply->raw) + 1) << 3));
$this->addRaw(chr($this->data[$field]["id"]));
$this->addRaw($reply->raw);
break;
}
break; break;
case "magic": case "magic":
$this->addRaw(MAGIC); $this->addRaw(MAGIC);

View File

@ -114,7 +114,7 @@ class PocketMinecraftClient{
$serverID = $data[1]; $serverID = $data[1];
$this->send(0x84, array( $this->send(0x84, array(
$this->counter[0], $this->counter[0],
0x40, 0x00,
array( array(
"id" => 0x09, "id" => 0x09,
"clientID" => $this->clientID, "clientID" => $this->clientID,
@ -132,7 +132,7 @@ class PocketMinecraftClient{
case 0x00: case 0x00:
$this->send(0x84, array( $this->send(0x84, array(
$this->counter[0], $this->counter[0],
0x40, 0x00,
array( array(
"id" => 0x00, "id" => 0x00,
"payload" => $data["payload"], "payload" => $data["payload"],
@ -143,7 +143,7 @@ class PocketMinecraftClient{
case 0x10: case 0x10:
$this->send(0x84, array( $this->send(0x84, array(
$this->counter[0], $this->counter[0],
0x40, 0x00,
array( array(
"id" => 0x13, "id" => 0x13,
"port" => 19132, "port" => 19132,
@ -154,7 +154,7 @@ class PocketMinecraftClient{
++$this->counter[0]; ++$this->counter[0];
$this->send(0x84, array( $this->send(0x84, array(
$this->counter[0], $this->counter[0],
0x40, 0x00,
array( array(
"id" => 0x82, "id" => 0x82,
"username" => $this->username, "username" => $this->username,

View File

@ -28,13 +28,15 @@ the Free Software Foundation, either version 3 of the License, or
require_once("classes/Session.class.php"); require_once("classes/Session.class.php");
class PocketMinecraftServer{ class PocketMinecraftServer{
protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clients, $serverType; var $seed, $protocol;
protected $interface, $entities, $player, $cnt, $events, $username, $version, $clients, $serverType;
function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){ function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){
//$this->player = new Player($username); //$this->player = new Player($username);
$this->version = (int) $version; $this->version = (int) $version;
$this->username = $username; $this->username = $username;
$this->cnt = 1; $this->cnt = 1;
$this->serverID = substr(Utils::generateKey(), 0, 8); $this->serverID = substr(Utils::generateKey(), 0, 8);
$this->seed = "\x4f\xf0\x2d\x84\x00\x00\x00\x00";
$this->events = array("disabled" => array()); $this->events = array("disabled" => array());
$this->actions = array(); $this->actions = array();
$this->clients = array(); $this->clients = array();

View File

@ -77,12 +77,6 @@ class SerializedPacketHandler{
} }
$pk->data["packetName"] = $pk->name; $pk->data["packetName"] = $pk->name;
$this->data["packets"][] = array($pid, $pk->data, $raw); $this->data["packets"][] = array($pid, $pk->data, $raw);
/*if($pid === 0x60 and $i === 0){
$l = $this->get(3);
if(strlen($l) === 3){
$this->data["unknown2"] = $this->get(Utils::readTriad($l));
}
}*/
++$i; ++$i;
} }
} }

View File

@ -86,9 +86,9 @@ class Session{
$this->close("client disconnect"); $this->close("client disconnect");
break; break;
case 0x09: case 0x09:
$this->send(0x84, array( $this->send(0x88, array(
$this->counter[0], $this->counter[0],
0x40, 0x00,
array( array(
"id" => 0x10, "id" => 0x10,
"count" => 0, "count" => 0,
@ -98,10 +98,24 @@ class Session{
)); ));
++$this->counter[0]; ++$this->counter[0];
break; break;
case 0x82: case 0x82:
$this->username = $data["username"]; $this->username = $data["username"];
console("[INFO] User ".$this->username." connected from ".$this->ip.":".$this->port); console("[INFO] User ".$this->username." connected from ".$this->ip.":".$this->port);
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => 0x87,
"seed" => $this->server->seed,
"spawnX" => 0,
"spawnY" => 100,
"spawnZ" => 0,
),
));
++$this->counter[0];
break; break;
} }
break; break;
case 0x8c: case 0x8c:

View File

@ -35,7 +35,8 @@ $dataName = array(
0x83 => "LoginStatus", 0x83 => "LoginStatus",
0x84 => "Ready", 0x84 => "Ready",
0x85 => "Message", 0x85 => "Message",
0x66 => "SetTime", 0x86 => "SetTime",
0x87 => "StartGame",
0x93 => "MoveEntity_PosRot", 0x93 => "MoveEntity_PosRot",

View File

@ -34,10 +34,10 @@ $packetName = array(
0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet 0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet
0x1c => "ID_UNCONNECTED_PONG", //RakNet 0x1c => "ID_UNCONNECTED_PONG", //RakNet
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
0x80 => "Unknown", //Minecraft Implementation 0x80 => "Custom Packet", //Minecraft Implementation
0x84 => "Data Packet", //Minecraft Implementation 0x84 => "Custom Packet", //Minecraft Implementation
0x88 => "Unknown", //Minecraft Implementation 0x88 => "Custom Packet", //Minecraft Implementation
0x8c => "Unknown", //Minecraft Implementation 0x8c => "Custom Packet", //Minecraft Implementation
0xa0 => "Unknown", //Minecraft Implementation 0xa0 => "Unknown", //Minecraft Implementation
0xc0 => "ACK", //Minecraft Implementation 0xc0 => "ACK", //Minecraft Implementation
); );