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

Fix PHP motd array/string issues #93

merged 3 commits into from
Sep 12, 2021

Conversation

ldilley
Copy link
Member

@ldilley ldilley commented Sep 11, 2021

Proposed Changes

  • Increment version to 2.2.1.
  • Fix PHP motd array/string issues.

@ldilley ldilley added the bug Something isn't working label Sep 11, 2021
@ldilley ldilley self-assigned this Sep 11, 2021
@ldilley ldilley added this to ToDo in MineStat via automation Sep 11, 2021
@AppVeyorBot
Copy link

Build minestat 1.0.0.80 completed (commit b26787ba3c by @ldilley)

@ldilley ldilley moved this from ToDo to In Progress in MineStat Sep 11, 2021
Copy link
Collaborator

@mindsolve mindsolve left a 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))

@AppVeyorBot
Copy link

Build minestat 1.0.0.81 completed (commit 7080b1e0bf by @ldilley)

@ldilley ldilley merged commit 7d4aefc into FragLand:master Sep 12, 2021
MineStat automation moved this from In Progress to Complete Sep 12, 2021
ldilley added a commit to ldilley/minestat that referenced this pull request Jan 23, 2022
Fix PHP motd array/string issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
MineStat
Complete
Development

Successfully merging this pull request may close these issues.

None yet

3 participants