Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some regulations... #222

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/protocol/AcknowledgePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@ protected function encodePayload(PacketSerializer $out) : void{
if($start === $last){
$payload .= chr(self::RECORD_TYPE_SINGLE);
$payload .= Binary::writeLTriad($start);
$start = $last = $current;
}else{
$payload .= chr(self::RECORD_TYPE_RANGE);
$payload .= Binary::writeLTriad($start);
$payload .= Binary::writeLTriad($last);
$start = $last = $current;
}
$start = $last = $current;
++$records;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/Datagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function encodePayload(PacketSerializer $out) : void{
/**
* @return int
*/
public function length(){
public function length(): int{
$length = self::HEADER_SIZE;
foreach($this->packets as $packet){
$length += $packet->getTotalLength();
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/OfflineMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ abstract class OfflineMessage extends Packet{
* @return void
* @throws BinaryDataException
*/
protected function readMagic(BinaryStream $in){
protected function readMagic(BinaryStream $in): void{
$this->magic = $in->get(16);
}

/**
* @return void
*/
protected function writeMagic(BinaryStream $out){
protected function writeMagic(BinaryStream $out): void{
$out->put($this->magic);
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/Packet.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

abstract class Packet{
/** @var int */
public static $ID = -1;
public static int $ID = -1;

public function encode(PacketSerializer $out) : void{
$this->encodeHeader($out);
Expand Down
2 changes: 1 addition & 1 deletion src/server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function openSession(ServerSession $session) : void{

private function checkSessions() : void{
if(count($this->sessions) > 4096){
foreach($this->sessions as $sessionId => $session){
foreach($this->sessions as $session){
if($session->isTemporary()){
$this->removeSessionInternal($session);
if(count($this->sessions) <= 4096){
Expand Down
5 changes: 3 additions & 2 deletions src/server/ServerSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public function disableBroadcast() : bool{
}

/**
* @param string $source reference parameter
* @param int $port reference parameter
* @param string|null $source reference parameter
* @param int|null $port reference parameter
*
* @return string|null
* @throws SocketException
*/
public function readPacket(?string &$source, ?int &$port) : ?string{
Expand Down
10 changes: 3 additions & 7 deletions src/utils/ExceptionTraceCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ public function getTrace(int $start = 0, ?array $trace = null) : array{
for($i = $start; isset($trace[$i]); ++$i, ++$j){
$params = "";
if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){
if(isset($trace[$i]["args"])){
$args = $trace[$i]["args"];
}else{
$args = $trace[$i]["params"];
}
foreach($args as $name => $value){
$args = $trace[$i]["args"] ?? $trace[$i]["params"];
foreach($args as $value){
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
}
}
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? $this->cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? $this->cleanPath($trace[$i]["file"]) : "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
}

return $messages;
Expand Down
Loading