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: