-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
✅ Build minestat 1.0.0.80 completed (commit b26787ba3c by @ldilley) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, the changes look good to me. All previous tests are now working flawlessly 👍
Optionally, you could now completely remove the parameter is_json
as you are now checking for existence of all fields before accessing them. The following diff worked in my tests:
diff --git a/PHP/minestat.php b/PHP/minestat.php
index 58b0e0f..eb55208 100644
--- a/PHP/minestat.php
+++ b/PHP/minestat.php
@@ -118,29 +118,24 @@ class MineStat
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']))
{
- if(isset($this->motd['text']))
- $this->stripped_motd = $this->motd['text'];
- else
- $this->stripped_motd = $this->motd;
- if(isset($this->motd['extra']))
+ $json_data = $this->motd['extra'];
+ if(!empty($json_data))
{
- $json_data = $this->motd['extra'];
- if(!empty($json_data))
- {
- foreach($json_data as &$nested_hash)
- $this->stripped_motd .= $nested_hash['text'];
- }
+ foreach($json_data as &$nested_hash)
+ $this->stripped_motd .= $nested_hash['text'];
}
- if(is_array($this->motd))
- $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 */
@@ -399,7 +394,7 @@ class MineStat
$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))
✅ Build minestat 1.0.0.81 completed (commit 7080b1e0bf by @ldilley) |
Fix PHP motd array/string issues
Proposed Changes