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

Fix PHP motd array/string issues #93

Merged
merged 3 commits into from
Sep 12, 2021
Merged
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
2 changes: 1 addition & 1 deletion PHP/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fragland/minestat",
"version": "2.2.0",
"version": "2.2.1",
"type": "library",
"description": "A Minecraft server status checker",
"keywords": ["Minecraft","status"],
Expand Down
18 changes: 10 additions & 8 deletions PHP/minestat.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class MineStat
{
const VERSION = "2.2.0"; // MineStat version
const VERSION = "2.2.1"; // MineStat version
const NUM_FIELDS = 6; // number of values expected from server
const NUM_FIELDS_BETA = 3; // number of values expected from a 1.8b/1.3 server
const MAX_VARINT_SIZE = 5; // maximum number of bytes a varint can be
Expand Down Expand Up @@ -118,22 +118,24 @@ public function get_latency() { return $this->latency; }
public function get_request_type() { return $this->request_type; }

/* Strips message of the day formatting characters */
private function strip_motd($is_json = false)
private function strip_motd()
{
if(!$is_json)
$this->stripped_motd = preg_replace("/§./", "", $this->motd);
if(isset($this->motd['text']))
$this->stripped_motd = $this->motd['text'];
else
$this->stripped_motd = $this->motd;
if(isset($this->motd['extra']))
{
$this->stripped_motd = $this->motd['text'];
$json_data = $this->motd['extra'];
if(!empty($json_data))
{
foreach($json_data as &$nested_hash)
$this->stripped_motd .= $nested_hash['text'];
}
$this->motd = json_encode($this->motd);
$this->stripped_motd = preg_replace("/§./", "", $this->stripped_motd);
}
if(is_array($this->motd))
$this->motd = json_encode($this->motd);
$this->stripped_motd = preg_replace("/§./", "", $this->stripped_motd);
}

/* Connects to remote server */
Expand Down Expand Up @@ -392,7 +394,7 @@ public function json_request()
$this->protocol = (int)@$json_data['version']['protocol'];
$this->version = @$json_data['version']['name'];
$this->motd = @$json_data['description'];
$this->strip_motd(true);
$this->strip_motd();
$this->current_players = (int)@$json_data['players']['online'];
$this->max_players = (int)@$json_data['players']['max'];
if(isset($this->version) && isset($this->motd) && isset($this->current_players) && isset($this->max_players))
Expand Down