minestat 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +6 -0
  3. data/lib/minestat.rb +18 -20
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b6006984abccf0461b0cfaccbc5e40f875f833f9996eb99e4d0a1bd6c636359
4
- data.tar.gz: 49f04e6d471f3f4f0494d2c47da13e4562f9653a5cf98d9906508648dff3e562
3
+ metadata.gz: 91e281cebc7b0ed35188df906f0a93ffb216952b9f524f2aeb2a435120978273
4
+ data.tar.gz: 226896ef611cc2cc1d9bbc5122dddbf9a8a40b5089d5a956fd52af5bf13837a6
5
5
  SHA512:
6
- metadata.gz: 2a267e36c53d565b313742dc5e48b25bc46fb0e19dca0d26a3410a74f224c323590f1be51e88bd356d150cc5f2c1580fcb7984f9e1e5af2bcba0376e61c27e91
7
- data.tar.gz: 40c34e11de59a7c10cb018b32a216ea4dae9e3aad267168a82205dce541d634b544a452ec500b841c79a0c931bdbe47ad80b53e85bc1d3722f9c32c9ef47d480
6
+ metadata.gz: 9c61f0e76903e24e94c669bc6963212775de447b6c898b57898737ac486a0182bbf22d93447b72e399207bf167c746c5441e3091f5b24478f09e0a9600c9dee1
7
+ data.tar.gz: 5d34a0b1282e6097bebdd4099398a99eac414b9ad59ced7a538ec632da838ecae7386da71a2ea708b17e60a794e9c4c7294704b26187ed92010bff1472740336
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 3.0.5 (March 30, 2024)
2
+ - Fixed nested JSON MotD issue
3
+
4
+ ## 3.0.4 (March 25, 2024)
5
+ - Fixed typo
6
+
1
7
  ## 3.0.3 (November 2, 2023)
2
8
  - Fixed empty MotD issue
3
9
 
data/lib/minestat.rb CHANGED
@@ -27,7 +27,7 @@ require 'timeout'
27
27
  # Provides a Ruby interface for polling the status of Minecraft servers
28
28
  class MineStat
29
29
  # MineStat version
30
- VERSION = "3.0.3"
30
+ VERSION = "3.0.5"
31
31
 
32
32
  # Number of values expected from server
33
33
  NUM_FIELDS = 6
@@ -170,7 +170,7 @@ class MineStat
170
170
  @srv_succeeded = false # SRV resolution successful?
171
171
 
172
172
  @try_all = true if request_type == Request::NONE
173
- @srv_suceeded = resolve_srv() if @srv_enabled
173
+ @srv_succeeded = resolve_srv() if @srv_enabled
174
174
  set_connection_status(attempt_protocols(request_type))
175
175
  end
176
176
 
@@ -253,21 +253,19 @@ class MineStat
253
253
  private :set_connection_status
254
254
 
255
255
  # Strips message of the day formatting characters
256
- def strip_motd()
257
- unless @motd['text'] == nil
258
- @motd = @motd['text']
259
- @stripped_motd = @motd
260
- else
261
- @stripped_motd = @motd
262
- end
263
- unless @motd['extra'] == nil
264
- json_data = @motd['extra']
265
- unless json_data.nil? || json_data.empty?
266
- json_data.each do |nested_hash|
267
- @stripped_motd += nested_hash['text']
256
+ def strip_motd(raw_motd)
257
+ @stripped_motd = raw_motd if raw_motd.is_a?(String)
258
+
259
+ if raw_motd.is_a?(Hash)
260
+ @stripped_motd = raw_motd['text'] unless raw_motd['text'].nil?
261
+
262
+ unless raw_motd['extra'].nil?
263
+ raw_motd['extra'].each do |nested_hash|
264
+ @stripped_motd += strip_motd(nested_hash)
268
265
  end
269
266
  end
270
267
  end
268
+
271
269
  @stripped_motd = @stripped_motd.force_encoding('UTF-8')
272
270
  @stripped_motd = @stripped_motd.gsub(/§./, "")
273
271
  end
@@ -360,7 +358,7 @@ class MineStat
360
358
  if server_info != nil && server_info.length >= NUM_FIELDS_BETA
361
359
  @version = ">=1.8b/1.3" # since server does not return version, set it
362
360
  @motd = server_info[0]
363
- strip_motd()
361
+ strip_motd(@motd)
364
362
  @current_players = server_info[1].to_i
365
363
  @max_players = server_info[2].to_i
366
364
  @online = true
@@ -373,7 +371,7 @@ class MineStat
373
371
  @version = "#{server_info[3]} #{server_info[7]} (#{server_info[0]})"
374
372
  @mode = server_info[8]
375
373
  @motd = server_info[1]
376
- strip_motd()
374
+ strip_motd(@motd)
377
375
  @current_players = server_info[4].to_i
378
376
  @max_players = server_info[5].to_i
379
377
  @online = true
@@ -386,7 +384,7 @@ class MineStat
386
384
  server_info = Hash[*server_info[0].split(delimiter).flatten(1)]
387
385
  @version = server_info["version"]
388
386
  @motd = server_info["hostname"]
389
- strip_motd()
387
+ strip_motd(@motd)
390
388
  @current_players = server_info["numplayers"].to_i
391
389
  @max_players = server_info["maxplayers"].to_i
392
390
  unless server_info["plugins"].nil? || server_info["plugins"].empty?
@@ -405,7 +403,7 @@ class MineStat
405
403
  @protocol = server_info[1].to_i # contains the protocol version (51 for 1.9 or 78 for 1.6.4 for example)
406
404
  @version = server_info[2]
407
405
  @motd = server_info[3]
408
- strip_motd()
406
+ strip_motd(@motd)
409
407
  @current_players = server_info[4].to_i
410
408
  @max_players = server_info[5].to_i
411
409
  @online = true
@@ -612,7 +610,7 @@ class MineStat
612
610
  @protocol = json_data['version']['protocol'].to_i
613
611
  @version = json_data['version']['name']
614
612
  @motd = json_data['description']
615
- strip_motd()
613
+ strip_motd(@motd)
616
614
  @current_players = json_data['players']['online'].to_i
617
615
  @max_players = json_data['players']['max'].to_i
618
616
  @favicon_b64 = json_data['favicon']
@@ -785,7 +783,7 @@ class MineStat
785
783
  challenge_token = @server.recv(QUERY_HANDSHAKE_SIZE)[QUERY_HANDSHAKE_OFFSET..-1]
786
784
  payload = "\xFE\xFD\x00\x0B\x03\x03\x0F".force_encoding('ASCII-8BIT')
787
785
  # Use the full stat below by stripping the null terminator from the challenge token and padding the end
788
- # of the payload with "\x00\x00\x00\x00". The basic stat response does not include the server version.
786
+ # of the payload with "\x00\x00\x00\x00". The basic stat response does not include the server version.
789
787
  payload += [challenge_token.rstrip.to_i].pack('l>').force_encoding('ASCII-8BIT')
790
788
  payload += "\x00\x00\x00\x00".force_encoding('ASCII-8BIT')
791
789
  @server.write(payload)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minestat
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lloyd Dilley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-04 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MineStat polls Minecraft server data such as version, motd, current players,
14
14
  and max players.