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 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 "minecraft.tomheinan.com"
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:0x007ffe250099b8 @host="minecraft.tomheinan.com", @port=25565, @timeout=3, @socket=#<UDPSocket:fd 8>, @motd="Welcome to Arkenfall!", @gamemode="SMP", @version="1.2.5", @plugins=["CraftBukkit on Bukkit 1.2.5-R4.1-MCPC-SNAPSHOT: mod_MinecraftForge ForgeMod", "AdminCmd 6.0.1 (BUILD 01.06.2012 @ 10:41:06)", "WorldEdit 5.3", "ExtraBiomes XL ForgeMod", "WorldGuard 5.5.3", "PermissionsBukkit 1.6"], @map_name="arkenfall", @num_players=1, @max_players=16, @players=["tomheinan"]>
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
@@ -4,9 +4,11 @@ require "glowstone/packets"
4
4
 
5
5
  module Glowstone
6
6
 
7
- MAGIC_BYTES = [0xFE, 0xFD]
8
- REQUEST_BYTE = {:challenge => [0x09], :query => [0x00]}
9
- CLIENT_ID = [0x67, 0x6C, 0x6F, 0x77]
10
- SOCKET_TIMEOUT = 3 # seconds
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
@@ -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", port=25565)
12
- @host = host
13
- @port = port
14
- @timeout = SOCKET_TIMEOUT
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
- @plugins = status.plugins.to_s.split(/;\s*/)
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
@@ -1,3 +1,3 @@
1
1
  module Glowstone
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
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.2
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: 2012-08-05 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bindata