Skip to content

Commit

Permalink
Merge pull request FragLand#93 from ldilley/master
Browse files Browse the repository at this point in the history
Fix PHP motd array/string issues
  • Loading branch information
ldilley committed Sep 12, 2021
2 parents 0eca1d8 + 17babd9 commit 30968f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit 30968f2

Please sign in to comment.