faster packet decode using pure-PHP functions instead of core-PHP ones :P. WTF PHP

This commit is contained in:
Shoghi Cervantes 2014-03-05 02:49:40 +01:00
parent 9c38ead76d
commit b00da18f41
3 changed files with 19 additions and 12 deletions

View File

@ -108,6 +108,7 @@ foreach($inc as $s){
$sha1sum ^= sha1_file($s, true); $sha1sum ^= sha1_file($s, true);
} }
/***REM_END***/ /***REM_END***/
ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OPCache address errors
define("SOURCE_SHA1SUM", bin2hex($sha1sum)); define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/ /***REM_START***/

View File

@ -56,12 +56,15 @@ abstract class RakNetDataPacket extends stdClass{
if($len <= 0){ if($len <= 0){
$this->offset = strlen($this->buffer) - 1; $this->offset = strlen($this->buffer) - 1;
return ""; return "";
} }elseif($len === true){
if($len === true){
return substr($this->buffer, $this->offset); return substr($this->buffer, $this->offset);
} }
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len); $buffer = b"";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
} }
protected function put($str){ protected function put($str){
@ -118,7 +121,7 @@ abstract class RakNetDataPacket extends stdClass{
} }
protected function getByte(){ protected function getByte(){
return ord($this->get(1)); return ord($this->buffer{$this->offset++});
} }
protected function putByte($v){ protected function putByte($v){

View File

@ -31,17 +31,20 @@ class RakNetPacket extends Packet{
public function pid(){ public function pid(){
return $this->packetID; return $this->packetID;
} }
private function get($len){ protected function get($len){
if($len <= 0){ if($len <= 0){
$this->offset = strlen($this->buffer) - 1; $this->offset = strlen($this->buffer) - 1;
return ""; return "";
} }elseif($len === true){
if($len === true){
return substr($this->buffer, $this->offset); return substr($this->buffer, $this->offset);
} }
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len); $buffer = b"";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
} }
private function getLong($unsigned = false){ private function getLong($unsigned = false){
@ -61,7 +64,7 @@ class RakNetPacket extends Packet{
} }
private function getByte(){ private function getByte(){
return ord($this->get(1)); return ord($this->buffer{$this->offset++});
} }
private function feof(){ private function feof(){