glowstone 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -3
- data/lib/glowstone.rb +6 -4
- data/lib/glowstone/server.rb +23 -5
- data/lib/glowstone/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -27,17 +27,26 @@ Or install it yourself as:
|
|
27
27
|
Glowstone's interface is super simple. Just instantiate yourself a new server object, like so:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
my_server = Glowstone::Server.new "
|
30
|
+
my_server = Glowstone::Server.new "tomheinan.com"
|
31
31
|
```
|
32
32
|
|
33
33
|
... and Glowstone will whip you up a server object full of all that delicious realtime data you've been craving:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
=> #<Glowstone::Server:
|
36
|
+
=> #<Glowstone::Server:0x007f9af2d17768 @host="minecraft.tomheinan.com", @port=25565, @timeout=10, @socket=#<UDPSocket:fd 7>, @motd="Welcome to Arkenfall!", @gamemode="SMP", @version="1.4.7", @plugins=["ThirdRail 1.0.0", "Vault 1.2.22-b277", "AdminCmd 7.2.0 (BUILD 22.01.2013 @ 22:13:34)", "WorldEdit 5.5.1", "TreeAssist 5.0", "WorldGuard 747-e3dfc6a", "PlayerMarkers 0.2.0", "PermissionsBukkit 2.0", "SimpleSpleef 3.4.2"], @map_name="arkenfall", @num_players=1, @max_players=16, @players=["tomheinan"]>
|
37
37
|
```
|
38
38
|
|
39
39
|
And that's all there is to it! No fancy bukkit plugins or server-side scripts required. If your server object is particularly long-lived and you find yourself wanting to refresh its data, just do `my_server.refresh` and it'll pull down the latest information for you.
|
40
40
|
|
41
|
+
### Options and Defaults
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Glowstone::Server.new("localhost",
|
45
|
+
:port => 25565,
|
46
|
+
:timeout => 5 # seconds before we give up on the socket connection
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
41
50
|
## Troubleshooting
|
42
51
|
|
43
52
|
**Help! I'm not receiving any data!**
|
@@ -45,7 +54,7 @@ And that's all there is to it! No fancy bukkit plugins or server-side scripts r
|
|
45
54
|
The first thing to do is make sure your server is set up to send it. Check your `server.properties` file and make sure the `enable-query` flag is set to `true`. Then, make sure your server's firewall allows connections on UDP port `25565`. If you've changed that value via the `query.port` flag, then you'll also need to specify it when instantiating Glowstone, like so:
|
46
55
|
|
47
56
|
```ruby
|
48
|
-
my_server = Glowstone::Server.new("myminecraftserver.com", 12345)
|
57
|
+
my_server = Glowstone::Server.new("myminecraftserver.com", :port => 12345)
|
49
58
|
```
|
50
59
|
|
51
60
|
## Contributing
|
data/lib/glowstone.rb
CHANGED
@@ -4,9 +4,11 @@ require "glowstone/packets"
|
|
4
4
|
|
5
5
|
module Glowstone
|
6
6
|
|
7
|
-
MAGIC_BYTES
|
8
|
-
REQUEST_BYTE
|
9
|
-
CLIENT_ID
|
10
|
-
|
7
|
+
MAGIC_BYTES = [0xFE, 0xFD]
|
8
|
+
REQUEST_BYTE = {:challenge => [0x09], :query => [0x00]}
|
9
|
+
CLIENT_ID = [0x67, 0x6C, 0x6F, 0x77]
|
10
|
+
|
11
|
+
DEFAULT_PORT = 25565
|
12
|
+
DEFAULT_SOCKET_TIMEOUT = 5 # seconds
|
11
13
|
|
12
14
|
end
|
data/lib/glowstone/server.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'resolv'
|
1
2
|
require 'socket'
|
2
3
|
|
3
4
|
module Glowstone
|
@@ -8,11 +9,27 @@ module Glowstone
|
|
8
9
|
attr_accessor :timeout
|
9
10
|
attr_reader :motd, :gamemode, :version, :plugins, :map_name, :num_players, :max_players, :players
|
10
11
|
|
11
|
-
def initialize(host="localhost",
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def initialize(host="localhost", options={})
|
13
|
+
|
14
|
+
# backwards compatibility for old style invocation
|
15
|
+
if options.is_a?(Numeric)
|
16
|
+
options = {:port => options.to_i}
|
17
|
+
end
|
18
|
+
|
19
|
+
# if the host is a srv record, get its info
|
20
|
+
begin
|
21
|
+
resource = Resolv::DNS.new.getresource("_minecraft._tcp.#{host}", Resolv::DNS::Resource::IN::SRV)
|
22
|
+
@host = resource.target.to_s
|
23
|
+
@port = resource.port.to_i
|
24
|
+
rescue
|
25
|
+
@host = host
|
26
|
+
@port = options[:port] ? options[:port].to_i : DEFAULT_PORT
|
27
|
+
end
|
28
|
+
|
29
|
+
# set request timeout
|
30
|
+
@timeout = options[:timeout] ? options[:timeout].to_i : DEFAULT_SOCKET_TIMEOUT
|
15
31
|
|
32
|
+
# create a reusable UDP socket
|
16
33
|
@socket = UDPSocket.new
|
17
34
|
@socket.connect(@host, @port)
|
18
35
|
refresh
|
@@ -27,7 +44,8 @@ module Glowstone
|
|
27
44
|
@motd = status.motd.to_s
|
28
45
|
@gamemode = status.gametype.to_s
|
29
46
|
@version = status.version.to_s
|
30
|
-
|
47
|
+
|
48
|
+
@plugins = status.plugins.to_s.gsub!(/^(craft)?bukkit[^:]*:\s*/i, "").split(/;\s*/)
|
31
49
|
@map_name = status.map_name.to_s
|
32
50
|
@num_players = status.num_players.to_i
|
33
51
|
@max_players = status.max_players.to_i
|
data/lib/glowstone/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glowstone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bindata
|