takumi-server_list_ping 0.0.1 → 0.0.2

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: be23f0c948e352c9f29c6be8f86207bb06436dcb
4
- data.tar.gz: d3e993d3005f535d995d4fe32adba22fe87aab7b
3
+ metadata.gz: 19ae0f8d983d9ecc2fe163cd40f0349abcdf87b9
4
+ data.tar.gz: 48a6c148c62731f592a224a4600d323a569cb3be
5
5
  SHA512:
6
- metadata.gz: 7b86359cef79dbf1a9f763290d8625189c28bb37d2e5059a098324f7c9a53aeb83e2002575fd079ee3a9c2327b708664d724893b43cccb6b43aa5a41cd9b9c91
7
- data.tar.gz: 2f9a0e76401af75cc3fcce6716f87c41e63934a24be65759e79cd60ed2e8f2038c87197f68fe99efe8ede8beec371f052c13eafb32678463239ac9f4446ff943
6
+ metadata.gz: a5f99a0ef880a7a6fa40fe52d96a10d0eb8a9af3e55e4f6389c778facb5ee3ca850f6f80911396b8ab247669e74e83fd4a49924b8cb51994bbb962873f85b145
7
+ data.tar.gz: a0afb26ba787ddf6d3a57579571a7ca095a9e50a407601d9b0b11ff639be64fe63f07026b92233c86f7b31f15cac54a75681a4dad51cf5da49a315642e7f2887
data/README.md CHANGED
@@ -22,9 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ ### Command
26
+
25
27
  $ bundle exec takumi-server_list_ping YOUR_SERVER_IP_ADDRESS_OR_HOSTNAME
26
28
  {"description":"A Minecraft Server","players":{"max":20,"online":0},"version":{"name":"1.8","protocol":47}}
27
29
 
30
+ ### Get server list ping
31
+
32
+ Takumi::ServerListPing.ping(MINECRAFT_SERVER_ADDRESS, PORT)
33
+
28
34
  ## Contributing
29
35
 
30
36
  1. Fork it ( https://github.com/blockgiven/takumi-server_list_ping/fork )
@@ -8,16 +8,9 @@ if ARGV[0]
8
8
  server_address, port = ARGV[0].split(':')
9
9
  end
10
10
 
11
- handshake = Takumi::ServerListPing::Handshake.create({
12
- server_address: server_address || 'localhost',
13
- port: (port && port.to_i) || ::Takumi::ServerListPing::PORT
14
- })
15
- status_request = Takumi::ServerListPing::StatusRequest.create
11
+ status_response = Takumi::ServerListPing.ping(
12
+ server_address || 'localhost',
13
+ (port && port.to_i) || ::Takumi::ServerListPing::PORT
14
+ )
16
15
 
17
- socket = TCPSocket.open(handshake.server_address, handshake.port)
18
- socket.write(handshake.to_s)
19
- socket.write(status_request.to_s)
20
-
21
- packets = socket.read
22
- status_response = Takumi::ServerListPing::StatusResponse.decode(packets)
23
16
  puts status_response.json
@@ -3,8 +3,27 @@ module Takumi
3
3
  NEXT_STATUS = 1
4
4
  PROTOCOL_VERSION = 4
5
5
  PORT = 25565
6
+
7
+ module_function
8
+
9
+ def ping(server_address = 'localhost', port = PORT)
10
+ handshake = Takumi::ServerListPing::Handshake.create({
11
+ server_address: server_address,
12
+ port: port
13
+ })
14
+ status_request = Takumi::ServerListPing::StatusRequest.create
15
+
16
+ socket = TCPSocket.open(handshake.server_address, handshake.port)
17
+ socket.write(handshake.to_s)
18
+ socket.write(status_request.to_s)
19
+
20
+ Takumi::ServerListPing::StatusResponse.decode(socket.read)
21
+ ensure
22
+ socket.close if socket
23
+ end
6
24
  end
7
25
  end
26
+
8
27
  require "takumi/packet"
9
28
  require "takumi/server_list_ping/version"
10
29
  require "takumi/server_list_ping/base"
@@ -1,5 +1,5 @@
1
1
  module Takumi
2
2
  module ServerListPing
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takumi-server_list_ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - block_given?