minestat 2.2.0 → 2.2.2

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/minestat.rb +72 -38
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 289592d2813eb1246b9a3033ce10a219513bf0c9cb792951051bdf6f97b20598
4
- data.tar.gz: beee739e9c19250fb6663e9561e065dfbcbae817442afe07ca3a21911e5f975a
3
+ metadata.gz: affbc3d1ec0778e630ea341dbd8afcf5f79a907f2da08554703f4b52d6f7f553
4
+ data.tar.gz: c65a8af83bc4c81695892c3447480ccde9fc731bab00e28ac7700012b7203341
5
5
  SHA512:
6
- metadata.gz: ad094493fac2c5b788c7ed86bdcc1e5296715d410cfe435491101fa56aae2bda6cd81644a88ce8caf183e6ae13072e559a073a4a4b42f9a51b0dfe261a46b378
7
- data.tar.gz: a757852cab9404fe9937a9a4f9fb7bac2effccd3317173d2abf0bc200a87dea5a6576e382c878be9d15f31b2489298197fafa6f5c1b4eaa1aff75d90f6ab6c16
6
+ metadata.gz: 62da41df1030d258d4f72ac64c9d4e8f882372e43c2a342712e48b75e016634076ac4537a928e5631ed61448df1e35210e697e0c9dd1023032079e9b6bfb0d54
7
+ data.tar.gz: f442d1bbe7a625d5ae7eb665da4caf6612465abbb83e031a1ea010e6aa3f7aa0b41c8b74da15f2e06a987702ac440091dd3495701864c2682d0a5b72cf492281
data/lib/minestat.rb CHANGED
@@ -16,6 +16,7 @@
16
16
  # with this program; if not, write to the Free Software Foundation, Inc.,
17
17
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
18
 
19
+ require 'base64'
19
20
  require 'json'
20
21
  require 'socket'
21
22
  require 'timeout'
@@ -24,7 +25,7 @@ require 'timeout'
24
25
  # Provides a ruby interface for polling Minecraft server status.
25
26
  class MineStat
26
27
  # MineStat version
27
- VERSION = "2.2.0"
28
+ VERSION = "2.2.2"
28
29
  # Number of values expected from server
29
30
  NUM_FIELDS = 6
30
31
  # Number of values expected from a 1.8b/1.3 server
@@ -32,7 +33,7 @@ class MineStat
32
33
  # Maximum number of bytes a varint can be
33
34
  MAX_VARINT_SIZE = 5
34
35
  # Default TCP port
35
- DEFAULT_PORT = 25565
36
+ DEFAULT_TCP_PORT = 25565
36
37
  # Bedrock/Pocket Edition default UDP port
37
38
  DEFAULT_BEDROCK_PORT = 19132
38
39
  # Default TCP/UDP timeout in seconds
@@ -79,7 +80,7 @@ class MineStat
79
80
 
80
81
  ##
81
82
  # Instantiate an instance of MineStat and poll the specified server for information
82
- def initialize(address, port = DEFAULT_PORT, timeout = DEFAULT_TIMEOUT, request_type = Request::NONE)
83
+ def initialize(address, port = DEFAULT_TCP_PORT, timeout = DEFAULT_TIMEOUT, request_type = Request::NONE)
83
84
  @address = address # address of server
84
85
  @port = port # TCP/UDP port of server
85
86
  @online # online or offline?
@@ -91,10 +92,16 @@ class MineStat
91
92
  @max_players # maximum player capacity
92
93
  @protocol # protocol level
93
94
  @json_data # JSON data for 1.7 queries
95
+ @favicon_b64 # base64-encoded favicon possibly contained in JSON 1.7 responses
96
+ @favicon # decoded favicon data
94
97
  @latency # ping time to server in milliseconds
95
98
  @timeout = timeout # TCP/UDP timeout
96
99
  @server # server socket
97
- @request_type # Protocol version
100
+ @request_type # protocol version
101
+ @connection_status # status of connection ("Success", "Fail", "Timeout", or "Unknown")
102
+ @try_all = false # try all protocols?
103
+
104
+ @try_all = true if request_type == Request::NONE
98
105
 
99
106
  case request_type
100
107
  when Request::BETA
@@ -108,7 +115,7 @@ class MineStat
108
115
  when Request::BEDROCK
109
116
  retval = bedrock_request()
110
117
  else
111
- # Attempt various SLP ping requests in a particular order. If the
118
+ # Attempt various ping requests in a particular order. If the
112
119
  # connection fails, there is no reason to continue with subsequent
113
120
  # requests. Attempts should continue in the event of a timeout
114
121
  # however since it may be due to an issue during the handshake.
@@ -127,14 +134,23 @@ class MineStat
127
134
  unless retval == Retval::CONNFAIL
128
135
  retval = json_request()
129
136
  end
130
- # Bedrock
131
- unless retval == Retval::CONNFAIL
137
+ # Bedrock/Pocket Edition
138
+ unless retval == Retval::SUCCESS || retval == Retval::CONNFAIL
132
139
  retval = bedrock_request()
133
140
  end
134
141
  end
142
+ set_connection_status(retval)
135
143
  @online = false unless retval == Retval::SUCCESS
136
144
  end
137
145
 
146
+ # Sets connection status
147
+ def set_connection_status(retval)
148
+ @connection_status = "Success" if retval == Retval::SUCCESS
149
+ @connection_status = "Fail" if retval == Retval::CONNFAIL
150
+ @connection_status = "Timeout" if retval == Retval::TIMEOUT
151
+ @connection_status = "Unknown" if retval == Retval::UNKNOWN
152
+ end
153
+
138
154
  # Strips message of the day formatting characters
139
155
  def strip_motd()
140
156
  unless @motd['text'] == nil
@@ -159,7 +175,7 @@ class MineStat
159
175
  def connect()
160
176
  begin
161
177
  if @request_type == Request::BEDROCK || @request_type == "Bedrock/Pocket Edition"
162
- @port = DEFAULT_BEDROCK_PORT if @port == DEFAULT_PORT && @request_type == Request::NONE
178
+ @port = DEFAULT_BEDROCK_PORT if @port == DEFAULT_TCP_PORT && @try_all
163
179
  start_time = Time.now
164
180
  @server = UDPSocket.new
165
181
  @server.connect(@address, @port)
@@ -260,9 +276,9 @@ class MineStat
260
276
  # 2b. data length
261
277
  # 2c. 3 fields delimited by \u00A7 (section symbol)
262
278
  # The 3 fields, in order, are:
263
- # * message of the day
264
- # * current players
265
- # * max players
279
+ # * message of the day
280
+ # * current players
281
+ # * max players
266
282
  def beta_request()
267
283
  retval = nil
268
284
  begin
@@ -293,12 +309,12 @@ class MineStat
293
309
  # 2b. data length
294
310
  # 2c. 6 fields delimited by \x00 (null)
295
311
  # The 6 fields, in order, are:
296
- # * the section symbol and 1
297
- # * protocol version
298
- # * server version
299
- # * message of the day
300
- # * current players
301
- # * max players
312
+ # * the section symbol and 1
313
+ # * protocol version
314
+ # * server version
315
+ # * message of the day
316
+ # * current players
317
+ # * max players
302
318
  #
303
319
  # The protocol version corresponds with the server version and can be the
304
320
  # same for different server versions.
@@ -340,12 +356,12 @@ class MineStat
340
356
  # 2b. data length
341
357
  # 2c. 6 fields delimited by \x00 (null)
342
358
  # The 6 fields, in order, are:
343
- # * the section symbol and 1
344
- # * protocol version
345
- # * server version
346
- # * message of the day
347
- # * current players
348
- # * max players
359
+ # * the section symbol and 1
360
+ # * protocol version
361
+ # * server version
362
+ # * message of the day
363
+ # * current players
364
+ # * max players
349
365
  #
350
366
  # The protocol version corresponds with the server version and can be the
351
367
  # same for different server versions.
@@ -425,6 +441,11 @@ class MineStat
425
441
  strip_motd
426
442
  @current_players = json_data['players']['online'].to_i
427
443
  @max_players = json_data['players']['max'].to_i
444
+ @favicon_b64 = json_data['favicon']
445
+ if !@favicon_b64.nil? && !@favicon_b64.empty?
446
+ @favicon_b64 = favicon_b64.split("base64,")[1]
447
+ @favicon = Base64.decode64(favicon_b64)
448
+ end
428
449
  if !@version.empty? && !@motd.empty? && !@current_players.nil? && !@max_players.nil?
429
450
  @online = true
430
451
  else
@@ -486,20 +507,21 @@ class MineStat
486
507
  # 2b. current time as a long
487
508
  # 2c. server GUID as a long
488
509
  # 2d. 16-bit magic number
489
- # 2e. server ID as a string
510
+ # 2e. server ID string length
511
+ # 2f. server ID as a string
490
512
  # The fields from the pong response, in order, are:
491
- # * edition
492
- # * MotD line 1
493
- # * protocol version
494
- # * version name
495
- # * current player count
496
- # * maximum player count
497
- # * unique server ID
498
- # * MotD line 2
499
- # * game mode as a string
500
- # * game mode as a numeric
501
- # * IPv4 port number
502
- # * IPv6 port number
513
+ # * edition
514
+ # * MotD line 1
515
+ # * protocol version
516
+ # * version name
517
+ # * current player count
518
+ # * maximum player count
519
+ # * unique server ID
520
+ # * MotD line 2
521
+ # * game mode as a string
522
+ # * game mode as a numeric
523
+ # * IPv4 port number
524
+ # * IPv6 port number
503
525
  def bedrock_request()
504
526
  retval = nil
505
527
  begin
@@ -554,7 +576,7 @@ class MineStat
554
576
  # Returns the maximum player count
555
577
  attr_reader :max_players
556
578
 
557
- # Returns the SLP (Server List Ping) protocol level
579
+ # Returns the protocol level
558
580
  #
559
581
  # This is arbitrary and varies by Minecraft version.
560
582
  # However, multiple Minecraft versions can share the same
@@ -565,9 +587,21 @@ class MineStat
565
587
  # servers with a version greater than or equal to 1.7
566
588
  attr_reader :json_data
567
589
 
590
+ # Returns the base64-encoded favicon from JSON 1.7 queries
591
+ attr_reader :favicon_b64
592
+
593
+ # Returns the decoded favicon from JSON 1.7 queries
594
+ attr_reader :favicon
595
+
568
596
  # Returns the ping time to the server in ms
569
597
  attr_reader :latency
570
598
 
571
- # Returns the SLP (Server List Ping) protocol version
599
+ # Returns the protocol version
572
600
  attr_reader :request_type
601
+
602
+ # Returns the connection status
603
+ attr_reader :connection_status
604
+
605
+ # Returns whether or not all ping protocols should be attempted
606
+ attr_reader :try_all
573
607
  end
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: 2.2.0
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lloyd Dilley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-01 00:00:00.000000000 Z
11
+ date: 2022-11-12 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.
@@ -23,7 +23,7 @@ homepage: https://github.com/FragLand/minestat
23
23
  licenses:
24
24
  - GPL-3.0
25
25
  metadata: {}
26
- post_install_message:
26
+ post_install_message:
27
27
  rdoc_options: []
28
28
  require_paths:
29
29
  - lib
@@ -38,8 +38,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  requirements: []
41
- rubygems_version: 3.3.7
42
- signing_key:
41
+ rubygems_version: 3.2.5
42
+ signing_key:
43
43
  specification_version: 4
44
44
  summary: Minecraft server status checker
45
45
  test_files: []