New packet

This commit is contained in:
Shoghi Cervantes Pueyo 2012-10-25 19:08:36 +02:00
parent 60c80110d3
commit 14e6fcb24e
5 changed files with 47 additions and 23 deletions

View File

@ -79,7 +79,8 @@ class MinecraftInterface{
}*/ }*/
$struct = $this->getStruct($pid); $struct = $this->getStruct($pid);
if($struct === false){ if($struct === false){
$p = "[".microtime(true)."] [SERVER->CLIENT]: Error, bad packet id 0x".Utils::strToHex(chr($pid)).PHP_EOL; console("[ERROR] Bad packet id 0x".Utils::strTohex(chr($pid)), true, true, 0);
$p = "[".microtime(true)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: Error, bad packet id 0x".Utils::strTohex(chr($pid))." [lenght ".strlen($raw)."]".PHP_EOL;
$p .= Utils::hexdump($data[0]); $p .= Utils::hexdump($data[0]);
$p .= PHP_EOL; $p .= PHP_EOL;
logg($p, "packets", true, 2); logg($p, "packets", true, 2);

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class Session{ class Session{
protected $server, $serverID; protected $server, $serverID, $timeout, $eventID, $connected;
var $clientID, $ip, $port; var $clientID, $ip, $port;
function __construct($server, $clientID, $ip, $port){ function __construct($server, $clientID, $ip, $port){
$this->server = $server; $this->server = $server;
@ -35,10 +35,26 @@ class Session{
$this->ip = $ip; $this->ip = $ip;
$this->port = $port; $this->port = $port;
$this->serverID =& $this->server->serverID; $this->serverID =& $this->server->serverID;
$this->eventID = $this->server->event("onTick", array($this, "checkTimeout"));
console("[DEBUG] New Session started with ".$ip.":".$port, true, true, 2); console("[DEBUG] New Session started with ".$ip.":".$port, true, true, 2);
$this->connected = true;
}
public function checkTimeout($time){
if($time > $this->timeout){
$this->close();
}
}
public function close(){
$this->server->deleteEvent("onTick", $this->eventID);
$this->connected = false;
console("[DEBUG] Session with ".$this->ip.":".$this->port." closed due to timeout", true, true, 2);
} }
public function handle($pid, &$data){ public function handle($pid, &$data){
if($this->connected === true){
$this->timeout = microtime(true) + 25;
switch($pid){ switch($pid){
case 0x07: case 0x07:
$this->send(0x08, array( $this->send(0x08, array(
@ -51,10 +67,14 @@ class Session{
break; break;
case 0x84: case 0x84:
$counter = $data[0]; $counter = $data[0];
$this->send(0xc0, array( /*$this->send(0xc0, array(
"\x00\x01\x01\x00\x00\x00", "\x00\x01\x01\x00\x00\x00",
)); ));*/
break; break;
case 0x8c:
$counter = $data[0];
break;
}
} }
} }

View File

@ -94,7 +94,7 @@ class Utils{
$c = (string) $c; $c = (string) $c;
for($i = 0; $i < 4; ++$i){ for($i = 0; $i < 4; ++$i){
$value ^= md5($i . $c . microtime(true), true); $value ^= md5($i . $c . microtime(true), true);
$value ^= substr(sha1($i . $c . microtime(true), true),$i,16); $value ^= substr(sha1($i . $c . microtime(true), true), $i,16);
} }
} }
return $value; return $value;

View File

@ -81,19 +81,21 @@ $pstruct = array(
), ),
0x84 => array( 0x84 => array(
"ubyte",
"ubyte", "ubyte",
"special1", "special1",
/*10,
8,
"double",
"byte", */
), ),
0x8c => array( 0x8c => array(
"ubyte",
"ubyte", "ubyte",
"special1", "special1",
), ),
0xa0 => array(
6,
),
0xc0 => array( 0xc0 => array(
6, 6,
), ),

View File

@ -36,5 +36,6 @@ $packetName = array(
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet 0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
0x84 => "ID_RESERVED_7", //Minecraft Implementation 0x84 => "ID_RESERVED_7", //Minecraft Implementation
0x8c => "Unknown", //Minecraft Implementation 0x8c => "Unknown", //Minecraft Implementation
0xa0 => "Unknown", //Minecraft Implementation
0xc0 => "Unknown", //Minecraft Implementation 0xc0 => "Unknown", //Minecraft Implementation
); );