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.3"- 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
813 814 815 |
# File 'lib/minestat.rb', line 813 def address @address end |
#connection_status ⇒ Object (readonly)
Connection status
895 896 897 |
# File 'lib/minestat.rb', line 895 def connection_status @connection_status end |
#current_players ⇒ Object (readonly)
Current player count
848 849 850 |
# File 'lib/minestat.rb', line 848 def current_players @current_players end |
#debug ⇒ Object (readonly)
Whether or not debug mode is enabled
902 903 904 |
# File 'lib/minestat.rb', line 902 def debug @debug end |
#favicon ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Decoded favicon
880 881 882 |
# File 'lib/minestat.rb', line 880 def favicon @favicon end |
#favicon_b64 ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Base64-encoded favicon
875 876 877 |
# File 'lib/minestat.rb', line 875 def favicon_b64 @favicon_b64 end |
#json_data ⇒ Object (readonly)
Received using SLP 1.7 (JSON) queries
Complete JSON response data
870 871 872 |
# File 'lib/minestat.rb', line 870 def json_data @json_data end |
#latency ⇒ Object (readonly)
Ping time to the server in milliseconds (ms)
884 885 886 |
# File 'lib/minestat.rb', line 884 def latency @latency end |
#max_players ⇒ Object (readonly)
Maximum player limit
851 852 853 |
# File 'lib/minestat.rb', line 851 def max_players @max_players end |
#mode ⇒ Object (readonly)
Bedrock/Pocket Edition only
Game mode
835 836 837 |
# File 'lib/minestat.rb', line 835 def mode @mode end |
#motd ⇒ Object (readonly)
If only the plain text MotD is relevant, use #stripped_motd
Full message of the day (MotD)
840 841 842 |
# File 'lib/minestat.rb', line 840 def motd @motd end |
#online ⇒ Object (readonly)
Whether or not the Minecraft server is online
827 828 829 |
# File 'lib/minestat.rb', line 827 def online @online end |
#player_list ⇒ Object (readonly)
UT3/GS4 query only
List of players
856 857 858 |
# File 'lib/minestat.rb', line 856 def player_list @player_list end |
#plugin_list ⇒ Object (readonly)
UT3/GS4 query only
List of plugins
861 862 863 |
# File 'lib/minestat.rb', line 861 def plugin_list @plugin_list end |
#port ⇒ Object (readonly)
Port (TCP or UDP) of the Minecraft server
816 817 818 |
# File 'lib/minestat.rb', line 816 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
865 866 867 |
# File 'lib/minestat.rb', line 865 def protocol @protocol end |
#request_type ⇒ Object (readonly)
Protocol used to request data from a Minecraft server
891 892 893 |
# File 'lib/minestat.rb', line 891 def request_type @request_type end |
#srv_address ⇒ Object (readonly)
Address of the Minecraft server from a DNS SRV record
820 821 822 |
# File 'lib/minestat.rb', line 820 def srv_address @srv_address end |
#srv_enabled ⇒ Object (readonly)
Whether or not DNS SRV resolution is enabled
906 907 908 |
# File 'lib/minestat.rb', line 906 def srv_enabled @srv_enabled end |
#srv_port ⇒ Object (readonly)
TCP port of the Minecraft server from a DNS SRV record
824 825 826 |
# File 'lib/minestat.rb', line 824 def srv_port @srv_port end |
#srv_succeeded ⇒ Object (readonly)
Whether or not DNS SRV resolution was successful
910 911 912 |
# File 'lib/minestat.rb', line 910 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)
845 846 847 |
# File 'lib/minestat.rb', line 845 def stripped_motd @stripped_motd end |
#timeout ⇒ Object
TCP/UDP timeout in seconds
888 889 890 |
# File 'lib/minestat.rb', line 888 def timeout @timeout end |
#try_all ⇒ Object (readonly)
Whether or not all protocols should be attempted
898 899 900 |
# File 'lib/minestat.rb', line 898 def try_all @try_all end |
#version ⇒ Object (readonly)
Minecraft server version
830 831 832 |
# File 'lib/minestat.rb', line 830 def version @version end |