Class: MineStat
- Inherits:
-
Object
- Object
- MineStat
- Defined in:
- lib/minestat.rb
Overview
Provides a Ruby interface for polling the status of Minecraft servers
Defined Under Namespace
Constant Summary collapse
- VERSION =
MineStat version
"3.0.5"- DEFAULT_TCP_PORT =
Default TCP port
25565- DEFAULT_BEDROCK_PORT =
Bedrock/Pocket Edition default UDP port
19132- DEFAULT_TIMEOUT =
Default TCP/UDP timeout in seconds
5
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Address (hostname or IP address) of the Minecraft server.
-
#connection_status ⇒ Object
readonly
Connection status.
-
#current_players ⇒ Object
readonly
Current player count.
-
#debug ⇒ Object
readonly
Whether or not debug mode is enabled.
-
#favicon ⇒ Object
readonly
Decoded favicon.
-
#favicon_b64 ⇒ Object
readonly
Base64-encoded favicon.
-
#json_data ⇒ Object
readonly
Complete JSON response data.
-
#latency ⇒ Object
readonly
Ping time to the server in milliseconds (ms).
-
#max_players ⇒ Object
readonly
Maximum player limit.
-
#mode ⇒ Object
readonly
Game mode.
-
#motd ⇒ Object
readonly
Full message of the day (MotD).
-
#online ⇒ Object
readonly
Whether or not the Minecraft server is online.
-
#player_list ⇒ Object
readonly
List of players.
-
#plugin_list ⇒ Object
readonly
List of plugins.
-
#port ⇒ Object
readonly
Port (TCP or UDP) of the Minecraft server.
-
#protocol ⇒ Object
readonly
Protocol level.
-
#request_type ⇒ Object
readonly
Protocol used to request data from a Minecraft server.
-
#srv_address ⇒ Object
readonly
Address of the Minecraft server from a DNS SRV record.
-
#srv_enabled ⇒ Object
readonly
Whether or not DNS SRV resolution is enabled.
-
#srv_port ⇒ Object
readonly
TCP port of the Minecraft server from a DNS SRV record.
-
#srv_succeeded ⇒ Object
readonly
Whether or not DNS SRV resolution was successful.
-
#stripped_motd ⇒ Object
readonly
Plain text contained within the message of the day (MotD).
-
#timeout ⇒ Object
TCP/UDP timeout in seconds.
-
#try_all ⇒ Object
readonly
Whether or not all protocols should be attempted.
-
#version ⇒ Object
readonly
Minecraft server version.
Instance Method Summary collapse
-
#initialize(address, port = DEFAULT_TCP_PORT, timeout = DEFAULT_TIMEOUT, request_type = Request::NONE, debug = false, srv_enabled = true) ⇒ MineStat
constructor
Instantiates a MineStat object and polls the specified server for information.
Constructor Details
#initialize(address, port = DEFAULT_TCP_PORT, timeout = DEFAULT_TIMEOUT, request_type = Request::NONE, debug = false, srv_enabled = true) ⇒ MineStat
Instantiates a MineStat object and polls the specified server for information
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/minestat.rb', line 144 def initialize(address, port = DEFAULT_TCP_PORT, timeout = DEFAULT_TIMEOUT, request_type = Request::NONE, debug = false, srv_enabled = true) @address = address # address of server @port = port # TCP/UDP port of server @srv_address # server address from DNS SRV record @srv_port # server TCP port from DNS SRV record @online # online or offline? @version # server version @mode # game mode (Bedrock/Pocket Edition only) @motd # message of the day @stripped_motd # message of the day without formatting @current_players # current number of players online @max_players # maximum player capacity @player_list # list of players (UT3/GS4 query only) @plugin_list # list of plugins (UT3/GS4 query only) @protocol # protocol level @json_data # JSON data for 1.7 queries @favicon_b64 # base64-encoded favicon possibly contained in JSON 1.7 responses @favicon # decoded favicon data @latency # ping time to server in milliseconds @timeout = timeout # TCP/UDP timeout @server # server socket @request_type # protocol version @connection_status # status of connection ("Success", "Fail", "Timeout", or "Unknown") @try_all = false # try all protocols? @debug = debug # debug mode @srv_enabled = srv_enabled # enable SRV resolution? @srv_succeeded = false # SRV resolution successful? @try_all = true if request_type == Request::NONE @srv_succeeded = resolve_srv() if @srv_enabled set_connection_status(attempt_protocols(request_type)) end |
Instance Attribute Details
#address ⇒ Object (readonly)
Address (hostname or IP address) of the Minecraft server
811 812 813 |
# File 'lib/minestat.rb', line 811 def address @address end |
#connection_status ⇒ Object (readonly)
Connection status
893 894 895 |
# File 'lib/minestat.rb', line 893 def connection_status @connection_status end |
#current_players ⇒ Object (readonly)
Current player count
846 847 848 |
# File 'lib/minestat.rb', line 846 def current_players @current_players end |
#debug ⇒ Object (readonly)
Whether or not debug mode is enabled
900 901 902 |
# File 'lib/minestat.rb', line 900 def debug @debug end |
#favicon ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Decoded favicon
878 879 880 |
# File 'lib/minestat.rb', line 878 def favicon @favicon end |
#favicon_b64 ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Base64-encoded favicon
873 874 875 |
# File 'lib/minestat.rb', line 873 def favicon_b64 @favicon_b64 end |
#json_data ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Complete JSON response data
868 869 870 |
# File 'lib/minestat.rb', line 868 def json_data @json_data end |
#latency ⇒ Object (readonly)
Ping time to the server in milliseconds (ms)
882 883 884 |
# File 'lib/minestat.rb', line 882 def latency @latency end |
#max_players ⇒ Object (readonly)
Maximum player limit
849 850 851 |
# File 'lib/minestat.rb', line 849 def max_players @max_players end |
#mode ⇒ Object (readonly)
Bedrock/Pocket Edition only
Game mode
833 834 835 |
# File 'lib/minestat.rb', line 833 def mode @mode end |
#motd ⇒ Object (readonly)
If only the plain text MotD is relevant, use #stripped_motd
Full message of the day (MotD)
838 839 840 |
# File 'lib/minestat.rb', line 838 def motd @motd end |
#online ⇒ Object (readonly)
Whether or not the Minecraft server is online
825 826 827 |
# File 'lib/minestat.rb', line 825 def online @online end |
#player_list ⇒ Object (readonly)
UT3/GS4 query only
List of players
854 855 856 |
# File 'lib/minestat.rb', line 854 def player_list @player_list end |
#plugin_list ⇒ Object (readonly)
UT3/GS4 query only
List of plugins
859 860 861 |
# File 'lib/minestat.rb', line 859 def plugin_list @plugin_list end |
#port ⇒ Object (readonly)
Port (TCP or UDP) of the Minecraft server
814 815 816 |
# File 'lib/minestat.rb', line 814 def port @port end |
#protocol ⇒ Object (readonly)
This is arbitrary and varies by Minecraft version (may also be shared by multiple Minecraft versions)
Protocol level
863 864 865 |
# File 'lib/minestat.rb', line 863 def protocol @protocol end |
#request_type ⇒ Object (readonly)
Protocol used to request data from a Minecraft server
889 890 891 |
# File 'lib/minestat.rb', line 889 def request_type @request_type end |
#srv_address ⇒ Object (readonly)
Address of the Minecraft server from a DNS SRV record
818 819 820 |
# File 'lib/minestat.rb', line 818 def srv_address @srv_address end |
#srv_enabled ⇒ Object (readonly)
Whether or not DNS SRV resolution is enabled
904 905 906 |
# File 'lib/minestat.rb', line 904 def srv_enabled @srv_enabled end |
#srv_port ⇒ Object (readonly)
TCP port of the Minecraft server from a DNS SRV record
822 823 824 |
# File 'lib/minestat.rb', line 822 def srv_port @srv_port end |
#srv_succeeded ⇒ Object (readonly)
Whether or not DNS SRV resolution was successful
908 909 910 |
# File 'lib/minestat.rb', line 908 def srv_succeeded @srv_succeeded end |
#stripped_motd ⇒ Object (readonly)
If the full MotD is desired, use #motd
Plain text contained within the message of the day (MotD)
843 844 845 |
# File 'lib/minestat.rb', line 843 def stripped_motd @stripped_motd end |
#timeout ⇒ Object
TCP/UDP timeout in seconds
886 887 888 |
# File 'lib/minestat.rb', line 886 def timeout @timeout end |
#try_all ⇒ Object (readonly)
Whether or not all protocols should be attempted
896 897 898 |
# File 'lib/minestat.rb', line 896 def try_all @try_all end |
#version ⇒ Object (readonly)
Minecraft server version
828 829 830 |
# File 'lib/minestat.rb', line 828 def version @version end |