New packets and fields

This commit is contained in:
Shoghi Cervantes Pueyo 2012-10-20 16:30:52 +02:00
parent 0dc53c2bc1
commit 9c4abf49f5
4 changed files with 57 additions and 44 deletions

View File

@ -26,7 +26,7 @@ the Free Software Foundation, either version 3 of the License, or
*/
class MinecraftInterface{
var $pstruct, $name, $server, $protocol;
var $pstruct, $name, $server, $protocol, $client;
function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){
$this->server = new Socket($server, $port, (bool) $listen);
@ -35,6 +35,7 @@ class MinecraftInterface{
require("pstruct/packetName.php");
$this->pstruct = $pstruct;
$this->name = $packetName;
$this->client = (bool) $client;
}
public function close(){
@ -50,11 +51,11 @@ class MinecraftInterface{
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
if(LOG === true and DEBUG >= 2){
$p = "[".microtime(true)."] [".((($origin === "client" and $client === true) or ($origin === "server" and $client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL;
$p = "[".microtime(true)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL;
$p .= hexdump($raw, false, false, true);
if(is_array($data)){
foreach($data as $i => $d){
$p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special") ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL;
$p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL;
}
}
$p .= PHP_EOL;

View File

@ -81,24 +81,34 @@ class PocketMinecraftServer{
case 0x05:
$version = $data[1];
$size = strlen($data[2]);
console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." handshake (".$size.")", true, true, 2);
$this->send(0x06, array(
MAGIC,
$this->serverID,
0,
strlen($packet["raw"]),
), false, $packet["ip"], $packet["port"]);
console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." MTU Sizing ".$size, true, true, 2);
if($version != 5){
$this->send(0x1a, array(
5,
MAGIC,
$this->serverID,
), false, $packet["ip"], $packet["port"]);
}else{
$this->send(0x06, array(
MAGIC,
$this->serverID,
0,
strlen($packet["raw"]),
), false, $packet["ip"], $packet["port"]);
}
break;
case 0x07:
$port = $data[2];
$MTU = $data[3];
$clientID = $data[4];
//console("[DEBUG] ".$packet["ip"].":".$packet["port"]." v".$version." response (".$size.")", true, true, 2);
$sess2 = Utils::readInt(substr(Utils::generateKey(), 0, 4));
//$sess2 = Utils::readInt(substr(Utils::generateKey(), 0, 4));
$this->send(0x08, array(
MAGIC,
$this->serverID,
$data[1],
$packet["port"],
$MTU,
0,
), false, $packet["ip"], $packet["port"]);
break;
case 0x84:

View File

@ -27,55 +27,57 @@ the Free Software Foundation, either version 3 of the License, or
$pstruct = array(
0x02 => array(
"double",
"double", //Ping ID
"magic",
),
0x05 => array(
"magic",
"byte",
"special1",
"byte", //Protocol Version
"special1", //MTU Size Null Lenght
),
0x06 => array(
"magic",
8,
"byte",
"short",
8, //Server GUID
"byte", //Server Security
"short", //MTU Size
),
0x07 => array(
"magic",
5,
"short",
"short",
8,
5, //Security Cookie (idk why it's sent here)
"short", //Server UDP Port
"short", //MTU Size
8, //Client GUID
),
0x08 => array(
"magic",
8,
5,
8, //Server GUID
"short", //Client UDP Port
"short", //MTU Size
"byte", //Security
),
0x09 => array(
8,
"double",
"byte",
0x1a => array(
"byte", //Server Version
"magic",
8, //Server GUID
),
0x1c => array(
"double",
8,
"double", //Ping ID
8, //Server ID
"magic",
"string",
"string", //Data
),
0x1d => array(
"double",
8,
"double", //Ping ID
8, //Server ID
"magic",
"string",
"string", //Data
),
0x84 => array(

View File

@ -26,14 +26,14 @@ the Free Software Foundation, either version 3 of the License, or
*/
$packetName = array(
0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS",
0x05 => "ID_OPEN_CONNECTION_REQUEST_1",
0x06 => "ID_OPEN_CONNECTION_REPLY_1",
0x07 => "ID_OPEN_CONNECTION_REQUEST_2",
0x08 => "ID_OPEN_CONNECTION_REPLY_2",
0x09 => "ID_CONNECTION_REQUEST",
0x1c => "ID_UNCONNECTED_PONG",
0x1d => "ID_ADVERTISE_SYSTEM",
0x84 => "Unknown",
0xc0 => "Unknown",
0x02 => "ID_UNCONNECTED_PING_OPEN_CONNECTIONS", //RakNet
0x05 => "ID_OPEN_CONNECTION_REQUEST_1", //RakNet
0x06 => "ID_OPEN_CONNECTION_REPLY_1", //RakNet
0x07 => "ID_OPEN_CONNECTION_REQUEST_2", //RakNet
0x08 => "ID_OPEN_CONNECTION_REPLY_2", //RakNet
0x1a => "ID_INCOMPATIBLE_PROTOCOL_VERSION", //RakNet
0x1c => "ID_UNCONNECTED_PONG", //RakNet
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
0x84 => "ID_RESERVED_7", //Minecraft Implementation
0xc0 => "Unknown", //Minecraft Implementation
);