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

Nested extra in MOTD is not parsed correctly on stripped_motd #224

Closed
ryush00 opened this issue Mar 27, 2024 · 6 comments
Closed

Nested extra in MOTD is not parsed correctly on stripped_motd #224

ryush00 opened this issue Mar 27, 2024 · 6 comments
Assignees
Labels
bug Something isn't working lang: Ruby Affects the Ruby version of minestat

Comments

@ryush00
Copy link
Contributor

ryush00 commented Mar 27, 2024

Expected Behavior

  • It should be parsed correctly.

Actual Behavior/Symptoms

  • Nested extra MOTD is not parsed.

How to Reproduce Behavior/Symptoms

ms = MineStat.new("mineplanet.kr")
ms.stripped_motd

But this server may not reached oversea from Korea, I also attach its data.

"description"=>
    {"extra"=>
      [{"extra"=>
         [{"color"=>"#4482B7",
           "extra"=>
            [{"bold"=>true,
              "extra"=>
               [{"color"=>"#4482B7", "text"=>"M"},
                {"color"=>"#4787BD", "text"=>"I"},
                {"color"=>"#4A8CC3", "text"=>"N"},
                {"color"=>"#4D90C8", "text"=>"E"},
                {"color"=>"#5095CE", "text"=>" "},
                {"color"=>"#549AD4", "text"=>"P"},
                {"color"=>"#579FDA", "text"=>"L"},
                {"color"=>"#5AA4E0", "text"=>"A"},
                {"color"=>"#5DA8E5", "text"=>"N"},
                {"color"=>"#60ADEB", "text"=>"E"},
                {"color"=>"#63B2F1", "text"=>"T"}],
              "text"=>""},
             {"color"=>"#63B2F1", "text"=>" ₪"}],
           "text"=>"₪ "}],
        "text"=>"                   "},
       "\n",
       {"extra"=>
         [{"color"=>"#63F1D5", "text"=>"당"},
          {"color"=>"#67F2D6", "text"=>"신"},
          {"color"=>"#6BF2D8", "text"=>"의"},
          {"color"=>"#6FF3D9", "text"=>" "},
          {"color"=>"#74F4DB", "text"=>"모"},
          {"color"=>"#78F4DC", "text"=>"험"},
          {"color"=>"#7CF5DD", "text"=>"을"},
          {"color"=>"#80F6DF", "text"=>" "},
          {"color"=>"#84F7E0", "text"=>"시"},
          {"color"=>"#88F7E1", "text"=>"작"},
          {"color"=>"#8DF8E3", "text"=>"하"},
          {"color"=>"#91F9E4", "text"=>"세"},
          {"color"=>"#95F9E6", "text"=>"요"},
          {"color"=>"#99FAE7", "text"=>"!"}],
        "text"=>"                   "}],
     "text"=>""}

MineStat Version

  • 3.0.4

Programming Language and Compiler/Interpreter Version

  • Ruby 3.2.2

Operating System

  • Ubuntu

Output/Screenshot(s)

image

image

Related

def strip_motd()
unless @motd['text'] == nil
@motd = @motd['text']
@stripped_motd = @motd
else
@stripped_motd = @motd
end
unless @motd['extra'] == nil
json_data = @motd['extra']
unless json_data.nil? || json_data.empty?
json_data.each do |nested_hash|
@stripped_motd += nested_hash['text']
end
end
end
@stripped_motd = @stripped_motd.force_encoding('UTF-8')
@stripped_motd = @stripped_motd.gsub(/§./, "")
end
private :strip_motd

@ryush00 ryush00 added the bug Something isn't working label Mar 27, 2024
@mindsolve mindsolve added the lang: Ruby Affects the Ruby version of minestat label Mar 30, 2024
@mindsolve
Copy link
Collaborator

Hey @ldilley, would you mind taking a look at this?

In the Python version, the stripped MOTD looks more reasonable:

                   ₪ MINE PLANET ₪
                   당신의 모험을 시작하세요!
Based on the following JSON MOTD
{
   "extra":[
      {
         "extra":[
            {
               "color":"#4482B7",
               "extra":[
                  {
                     "bold":true,
                     "extra":[
                        {
                           "color":"#4482B7",
                           "text":"M"
                        },
                        {
                           "color":"#4787BD",
                           "text":"I"
                        },
                        {
                           "color":"#4A8CC3",
                           "text":"N"
                        },
                        {
                           "color":"#4D90C8",
                           "text":"E"
                        },
                        {
                           "color":"#5095CE",
                           "text":" "
                        },
                        {
                           "color":"#549AD4",
                           "text":"P"
                        },
                        {
                           "color":"#579FDA",
                           "text":"L"
                        },
                        {
                           "color":"#5AA4E0",
                           "text":"A"
                        },
                        {
                           "color":"#5DA8E5",
                           "text":"N"
                        },
                        {
                           "color":"#60ADEB",
                           "text":"E"
                        },
                        {
                           "color":"#63B2F1",
                           "text":"T"
                        }
                     ],
                     "text":""
                  },
                  {
                     "color":"#63B2F1",
                     "text":" \\u20aa"
                  }
               ],
               "text":"\\u20aa "
            }
         ],
         "text":"                   "
      },
      "\\n",
      {
         "extra":[
            {
               "color":"#63F1D5",
               "text":"\\ub2f9"
            },
            {
               "color":"#67F2D6",
               "text":"\\uc2e0"
            },
            {
               "color":"#6BF2D8",
               "text":"\\uc758"
            },
            {
               "color":"#6FF3D9",
               "text":" "
            },
            {
               "color":"#74F4DB",
               "text":"\\ubaa8"
            },
            {
               "color":"#78F4DC",
               "text":"\\ud5d8"
            },
            {
               "color":"#7CF5DD",
               "text":"\\uc744"
            },
            {
               "color":"#80F6DF",
               "text":" "
            },
            {
               "color":"#84F7E0",
               "text":"\\uc2dc"
            },
            {
               "color":"#88F7E1",
               "text":"\\uc791"
            },
            {
               "color":"#8DF8E3",
               "text":"\\ud558"
            },
            {
               "color":"#91F9E4",
               "text":"\\uc138"
            },
            {
               "color":"#95F9E6",
               "text":"\\uc694"
            },
            {
               "color":"#99FAE7",
               "text":"!"
            }
         ],
         "text":"                   "
      }
   ],
   "text":""
}

@ldilley
Copy link
Member

ldilley commented Mar 30, 2024

I am not able to fully connect to the address and port returned by the SRV query for "mineplanet.kr". I tried from 2 different US locations. I also attempted to use https://motd.gg/ to get a copy of the MotD for testing purposes using a local server. This utility succeeds in connecting. However, it is generating the entire message as a single string value for the description key (output below). Since I am unable to connect remotely, I need a sample MotD string containing nested extra fields that I can set in server.properties to test against locally. I am not doing anything fancy with the MotD on the Minecraft server that I host. So, if this cannot be done using the basic motd option in server.properties, I'll need the name of a plugin to use instead.

Minecraft server status of localhost on port 25565:
Server is online running version 1.8 with 0 out of 20 players.
Message of the day: §r                   §3₪ §lMINE P§7§lLANET§7 ₪§r
§7                   당신의 모험을 시작하세요!
Message of the day without formatting:                    ₪ MINE PLANET ₪
                   당신의 모험을 시작하세요!
JSON data: {"description"=>"§r                   §3₪ §lMINE P§7§lLANET§7 ₪§r\n§7                   당신의 모험을 시작하 세요!", "players"=>{"max"=>20, "online"=>0}, "version"=>{"name"=>"1.8", "protocol"=>47}}
Latency: 0ms
Connected using protocol: SLP 1.7 (JSON)

@ryush00
Copy link
Contributor Author

ryush00 commented Mar 30, 2024

ldilley added a commit to ldilley/minestat that referenced this issue Mar 31, 2024
@ldilley
Copy link
Member

ldilley commented Mar 31, 2024

Do the changes in PR #226 work for you, @ryush00? I ended up essentially unit testing strip_motd() using the JSON input that you and MindSolve provided. I've remodeled the Ruby method after the equivalent Python method (motd_strip_formatting()). It should now be appending nested extra JSON data using recursion.

@ryush00
Copy link
Contributor Author

ryush00 commented Apr 1, 2024

Thank you Idilley! Looks good! 👍

@ldilley
Copy link
Member

ldilley commented Apr 1, 2024

Thank you Idilley! Looks good! 👍

Excellent! I've merged PR #226 and just updated the Ruby gem as well. Thank you for finding and reporting this issue, @ryush00.

@ldilley ldilley closed this as completed Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang: Ruby Affects the Ruby version of minestat
Projects
None yet
Development

No branches or pull requests

3 participants