McQuery 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 000551989c48261d1fca5b3a53fcc6d99a7afc92
4
- data.tar.gz: 2e9474e3e372a0de63196a07fd8399dc96d62d65
3
+ metadata.gz: 3adf613800f8950bd220d47f9ca6f0a918067274
4
+ data.tar.gz: 4848b0b86235e1db1a4a4b4454caa25f57da42b4
5
5
  SHA512:
6
- metadata.gz: bd0404690dd574e9f580c9fa8e54b22d95a5f7965c3202c250cff0cb38bd7a065e728dc011dacf879464caab7568b5725a2d067a2237d184a3040b6ef811b96f
7
- data.tar.gz: c338619909c618e7290be979f60f0fa354eff80ad97fa6d86260d03e232f441dfdd9119faf8ffbde8ab59c493079e4d74d783477a1d3bbf80a7e92bfa876010c
6
+ metadata.gz: b2872ff82a98dbc5dff056ab6d3e05baeb9932d49bce58342b024d7c06e1250f0e84693cfaad83684b5b7eadc90cf8346cbddb3ac50a19aacabc6a54548e2696
7
+ data.tar.gz: aeee63eccd8b19b5aacea281cde197710cf50a679ca66d9eba25ccaf4492a27a519500de39c13a93b76abcb0662988b11b4b035807501820b59cfe1d8666c1fc
@@ -0,0 +1,29 @@
1
+ require 'socket'
2
+
3
+ module McQuery
4
+ class Ping
5
+ attr_reader :protocol_version, :server_version, :motd, :players_online, :players_max
6
+ def initialize(hostname, port)
7
+ @hostname = hostname
8
+ @port = port
9
+ doPing
10
+ end
11
+
12
+ private
13
+ def doPing
14
+ s = TCPSocket.open(@hostname, @port)
15
+
16
+ s.puts "\xFE\x01"
17
+ repl = s.gets
18
+ s.close
19
+ qstring = repl[3,repl.length].force_encoding("utf-16be").encode("utf-8")
20
+ qarray = qstring.split("\0")
21
+ qdict = {}
22
+ @protocol_version = qarray[1]
23
+ @server_version = qarray[2]
24
+ @motd = qarray[3]
25
+ @players_online = qarray[4]
26
+ @players_max = qarray[5]
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module McQuery
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require_relative '../lib/McQuery.rb'
2
+ require 'test/unit'
3
+
4
+ class TestPing < Test::Unit::TestCase
5
+ def test_ping
6
+ retVal = McQuery::Ping.new('0', 25565)
7
+ assert_not_nil retVal.protocol_version
8
+ assert_not_nil retVal.server_version
9
+ assert_not_nil retVal.motd
10
+ assert_not_nil retVal.players_online
11
+ assert_not_nil retVal.players_max
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: McQuery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin James Harrison-Sims
@@ -52,7 +52,9 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/McQuery.rb
55
+ - lib/McQuery/ping.rb
55
56
  - lib/McQuery/version.rb
57
+ - test/testPing.rb
56
58
  homepage: http://github.com/TehRainbowGuy/McQuery
57
59
  licenses:
58
60
  - MIT
@@ -77,4 +79,5 @@ rubygems_version: 2.0.3
77
79
  signing_key:
78
80
  specification_version: 4
79
81
  summary: Server ping for Minecraft.
80
- test_files: []
82
+ test_files:
83
+ - test/testPing.rb