diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fac7d7b7..83af8a8d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,14 +5,14 @@ Before contributing to NostalgiaCore, please read this. ## I want to create an issue -* First, use the [Issue Search](https://github.com/oldminecraftcommunity/NostalgiaCore/search?ref=cmdform&type=Issues) to check if anyone has reported it. +* First, use the [Issue Search](https://github.com/kotyaralih/NostalgiaCore/search?ref=cmdform&type=Issues) to check if anyone has reported it. * Is your issue related to a Plugin? If so, please contact their original author instead of reporting it here. * And no, we won't update a Plugin because you need it. * When reporting, give as much info as you can, and if the Issue is a crash, give the Crash Dump. * Issues should be written in English. ## I want to contribute code -* Use the [Pull Request](https://github.com/oldminecraftcommunity/NostalgiaCore/pull/new) system, your request will be checked and discussed. +* Use the [Pull Request](https://github.com/kotyaralih/NostalgiaCore/pull/new) system, your request will be checked and discussed. * __Create a single branch for that pull request__ * If you want to be part of NostalgiaCore, we will ask you to. * Code using the syntax as in NostalgiaCore. See below for an example. diff --git a/src/Player.php b/src/Player.php index 626c7160..86bf3317 100755 --- a/src/Player.php +++ b/src/Player.php @@ -222,8 +222,8 @@ class Player{ $this->chatMessagesQueue = new RakNetPacket(RakNetInfo::DATA_PACKET_0); $this->chatMessagesQueue->data = []; - $this->server->schedule(20 * 60, [$this, "clearQueue"], [], true); - $this->server->interface->maxACKsAllowed["{$this->ip}:{$this->port}"] = 0; + //$this->server->schedule(20 * 60, [$this, "clearQueue"], [], true); + $this->evid[] = $this->server->event("server.close", [$this, "close"]); console("[DEBUG] New Session started with $ip:$port. MTU {$this->MTU}, Client ID {$this->clientID}", true, true, 2); } @@ -2021,10 +2021,6 @@ class Player{ //$this->entity->close(); } } - - public function __destruct(){ //pwease dont leak memory >_< - unset($this->server->interface->maxACKsAllowed["{$this->ip}:{$this->port}"]); - } public function save(){ if($this->entity instanceof Entity){ @@ -3275,27 +3271,23 @@ class Player{ $t->spawn($this); }else{ $nbt = new NBT(); - $d = $nbt->loadSignNBT($packet->namedtag); - if($d === false){ + $nbt->load($packet->namedtag); + $d = array_shift($nbt->tree); + if($d["id"] !== TILE_SIGN){ $t->spawn($this); }else{ + $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); } } } break; case ProtocolInfo::SET_ENTITY_LINK_PACKET: - if($this->spawned === false){ - break; - } if($this->entity->riding != 0){ $this->entity->setRiding(null); } break; case ProtocolInfo::PLAYER_INPUT_PACKET: - if($this->spawned === false){ - break; - } $this->isJumping = $packet->isJumping; $this->isSneaking = $packet->isSneaking; $this->entity->moveForward = $packet->moveForward; @@ -3574,10 +3566,8 @@ class Player{ foreach($packet->packets as $count){ if(isset($this->packetAlwaysRecoverQueue[$count])){ $this->resendQueue[$count] = $this->packetAlwaysRecoverQueue[$count]; - $this->resendQueue[$count]->incrementAllowedAck = false; }else if(isset($this->recoveryQueue[$count])){ $this->resendQueue[$count] =& $this->recoveryQueue[$count]; - $this->resendQueue[$count]->incrementAllowedAck = false; $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); }else{ //lost and wont be recovered @@ -3597,8 +3587,8 @@ class Player{ }else if(isset($this->recoveryQueue[$count])){ $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); + unset($this->resendQueue[$count]); } - unset($this->resendQueue[$count]); ++$this->packetStats[0]; } break; diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 71f52a35..150e3e90 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -5,8 +5,7 @@ class PocketMinecraftServer{ const TICK_F20TPS = 1; const TICK_NETWAIT = 2; public $tCnt, $ticks; - public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $eidCnt, $description, $motd, $port, $saveEnabled; - public $custom, $customLastTime = []; + public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled; /** * @var ServerAPI */ @@ -628,8 +627,7 @@ class PocketMinecraftServer{ $pk->ip = $packet->ip; $pk->port = $packet->port; $this->send($pk); - $this->custom["times_$CID"] = ($this->custom["times_$CID"] + 1) % strlen($this->description); - $this->customLastTime[$CID] = microtime(true); + $this->custom["times_" . $CID] = ($this->custom["times_" . $CID] + 1) % strlen($this->description); break; case RakNetInfo::OPEN_CONNECTION_REQUEST_1: if($packet->structure !== RakNetInfo::STRUCTURE){ @@ -679,14 +677,6 @@ class PocketMinecraftServer{ public function tick(){ $time = microtime(true); if($this->lastTick <= ($time - 0.05)){ - foreach($this->customLastTime as $CID => $lastTime){ - //server is removed from the list every 3 seconds(will also add a tiny 1 second delay so it will def not be updated incorrectly <3) - if(($time - $lastTime) > 4){ - unset($this->custom["times_$CID"]); - unset($this->customLastTime[$CID]); - } - } - $this->tickMeasure[] = $this->lastTick = $time; unset($this->tickMeasure[key($this->tickMeasure)]); ++$this->ticks; diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 087a0630..725d99ef 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -37,43 +37,18 @@ class MinecraftInterface{ return $this->parsePacket($buf, $source, $port); } - /** - * Stores max ACK packets that the server is allowed to handle. - * - * @var array - */ - public $maxACKsAllowed = []; - private function parsePacket($buffer, $source, $port){ $pid = ord($buffer[0]); if(RakNetInfo::isValid($pid)){ - $id = "$source:$port"; - $ackCnt = 0; - $acks = $this->maxACKsAllowed[$id] ?? 0; - - $packet = RakNetParser::parse($buffer, $acks, $ackCnt); + $packet = RakNetParser::parse($buffer); if($packet !== false){ - if($ackCnt != 0 && isset($this->maxACKsAllowed[$id]) && $packet->pid() != RakNetInfo::NACK){ - $this->maxACKsAllowed[$id] = $acks - $ackCnt; - } $packet->ip = $source; $packet->port = $port; if(EventHandler::callEvent(new PacketReceiveEvent($packet)) === BaseEvent::DENY){ return false; } return $packet; - }else if($ackCnt > 0){ - $CID = PocketMinecraftServer::clientID($source, $port); - $server = ServerAPI::request(); - $c = $server->clients[$CID] ?? false; - if($c !== false){ - $username = $c->iusername == "" ? $id : $c->iusername; - ConsoleAPI::warn("Player '$username' sent too many ACK packets (allowed: {$acks}, attempted {$ackCnt} or more)!"); - $c->close("too many ack packets"); - }else{ - //ConsoleAPI::warn("$id sent too many ACK packets (allowed: {$acks}, attempted {$ackCnt} or more)!"); - } } return false; }elseif($pid === 0xfe and $buffer[1] === "\xfd" and ServerAPI::request()->api->query instanceof QueryHandler){ @@ -100,14 +75,6 @@ class MinecraftInterface{ return 0; }elseif($packet instanceof RakNetPacket){ RakNetCodec::encode($packet); - if($packet->pid() >= RakNetInfo::DATA_PACKET_0 && $packet->pid() <= RakNetInfo::DATA_PACKET_F && $packet->incrementAllowedAck){ - $id = "{$packet->ip}:{$packet->port}"; - if(isset($this->maxACKsAllowed[$id])){ - ++$this->maxACKsAllowed[$id]; - }else{ - $this->maxACKsAllowed[$id] = 1; - } - } } $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); $this->bandwidth[1] += $write; diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index f53fc9a3..260a1d4b 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -2,10 +2,7 @@ class UDPSocket{ - public $connected; - public $sock; - public $server; - public $port; + public $connected, $sock, $server, $port; function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ $this->server = $server; $this->port = $port; diff --git a/src/network/raknet/RakNetPacket.php b/src/network/raknet/RakNetPacket.php index 81ab86d2..870a2733 100644 --- a/src/network/raknet/RakNetPacket.php +++ b/src/network/raknet/RakNetPacket.php @@ -5,7 +5,6 @@ class RakNetPacket extends Packet{ public $packetID; public $seqNumber; public $sendtime; - public $incrementAllowedAck = true; public function __construct($packetID){ $this->packetID = (int) $packetID; diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index 8ee4d362..74bc3708 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -1,7 +1,7 @@ packets = []; - $acks = 0; for($i = 0; $i < $count && isset($buffer[$offset]); ++$i){ ++$offset; if(ord(substr($buffer, $offset - 1, 1)) === 0){ @@ -68,29 +67,17 @@ class RakNetParser{ $start = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3))); $offset += 3; $end = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3))); - $acks += ($end - $start)+1; - if($acks <= 0 || $maxACKAllowed >= 0 && ($maxACKAllowed - $acks) < 0){ - $packet = false; - break; - } - /*if(($end - $start) > 4096){ //not really needed? + if(($end - $start) > 4096){ $end = $start + 4096; - }*/ + } for($c = $start; $c <= $end; ++$c){ $packet->packets[] = $c; } }else{ $offset += 3; - $acks += 1; - if($maxACKAllowed >= 0 && ($maxACKAllowed - $acks) < 0){ - $packet = false; - break; - } $packet->packets[] = Utils::readTriad(strrev(substr($buffer, $offset - 3, 3))); } } - - $ackCnt = $acks; break; default: $packet = false; diff --git a/src/utils/NBT.php b/src/utils/NBT.php index bbf92e5e..6d1084ac 100644 --- a/src/utils/NBT.php +++ b/src/utils/NBT.php @@ -22,62 +22,6 @@ class NBT{ $this->binary .= $bin; } - /** - * A function to safely load sign nbt - * @param string $str raw nbt data - * @return false|array array with sign data, false if failed - */ - public function loadSignNBT($str){ - $this->offset = 0; - $this->binary = (string) $str; - //sign nbt in vanilla is - /* - * [ - * "id": "Sign", - * "x": , - * "y": , - * "z": , - * "Text1": , //max 15 chars - * "Text2": , //^ - * "Text3": , //^ - * "Text4": //^ - * ] - */ - $tag = ord($this->read(1)); - if($tag == self::TAG_COMPOUND){ - $name = $this->readTAG_STRING_maxlen(2); - if($name != "") return false; - $value = []; - for($n = 0; $n < 8; ++$n){ - $tag = ord($this->read(1)); - if($tag == self::TAG_END){ - break; - }else if($tag == self::TAG_INT){ - $name = $this->readTAG_STRING_maxlen(1); - if($name != "x" && $name != "y" && $name != "z") return false; - $value[$name] = $this->readTAG_INT(); - }else if($tag == self::TAG_STRING){ - $name = $this->readTAG_STRING_maxlen(5); - if($name == "id"){ - $s = $this->readTAG_STRING_maxlen(4); - if($s != "Sign") return false; - $value[$name] = $s; - }else if($name == "Text1" || $name == "Text2" || $name == "Text3" || $name == "Text4"){ - $value[$name] = $this->readTAG_STRING_maxlen(15*4); //mcpe 0.8.1 supports unicode, so the max char size 4 bytes - }else{ - return false; - } - }else{ - return false; - } - } - if(count($value) != 8) return false; - return $value; - }else{ - return false; - } - } - public function load($str){ $this->offset = 0; $this->binary = (string) $str; @@ -122,7 +66,7 @@ class NBT{ break; default: echo bin2hex(substr($this->binary, $this->offset - 1)) . PHP_EOL . PHP_EOL; - throw new NBTException("Invalid NBT Tag $tag"); + die("Invalid NBT Tag $tag"); } $node[$name] = $value; } @@ -139,14 +83,7 @@ class NBT{ private function feof(){ return !isset($this->binary[$this->offset]); } - - //i guess i could have modified old method? - //*but it will make it slower read(2), false); - return $this->read($len <= $ml ? $len : $ml); - } + public function readTAG_STRING(){ return $this->read(Utils::readLShort($this->read(2), false)); } diff --git a/src/utils/NBTException.php b/src/utils/NBTException.php deleted file mode 100644 index 9af46728..00000000 --- a/src/utils/NBTException.php +++ /dev/null @@ -1,8 +0,0 @@ -