hotline 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/bin/tracker_client +16 -0
- data/lib/hotline/version.rb +5 -0
- data/lib/hotline.rb +7 -0
- data/lib/tracker/client.rb +77 -0
- data/lib/tracker/exceptions.rb +4 -0
- data/lib/tracker/types.rb +31 -0
- metadata +109 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ddf955bd5b12ad0d8122b1e07de691b29f68705517fd6878247ff6063a3c857a
|
|
4
|
+
data.tar.gz: 14579f74347736e736ee01108552f4ab3da18a3e922284491601e3a25f14c0e8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bd6f30ba39f7d004f888be1ff62aee9d7e83e15ba10bd7ea97e793904cfeaf1292514ce8424d6fdc250ea7832546f65ce675cc6cec1173dd6f199265666d26c4
|
|
7
|
+
data.tar.gz: f0b368c0bd91a5eeb0ba29cfaf978fcb9f1ee7cc5c089fa31283a673d9b2511585c6d645b52d7838449e2431ac0cf033b398d900400bc75d471359ae32bd8685
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Bryce Mecum
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# hotline
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
An implementation of the Hotline protocols, currently just the tracker client.
|
|
6
|
+
|
|
7
|
+
Implementation status:
|
|
8
|
+
|
|
9
|
+
- [ ] Server
|
|
10
|
+
- [ ] Server
|
|
11
|
+
- [ ] Client
|
|
12
|
+
- [ ] Tracker
|
|
13
|
+
- [ ] Server
|
|
14
|
+
- [x] Client
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'hotline'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
$ bundle
|
|
27
|
+
|
|
28
|
+
Or install it yourself as:
|
|
29
|
+
|
|
30
|
+
$ gem install hotline
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
At this point, only the tracker client is written:
|
|
35
|
+
|
|
36
|
+
### Tracker Client
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require 'hotline/tracker/client'
|
|
40
|
+
|
|
41
|
+
client = Hotline::Tracker::Client.new("hltracker.com")
|
|
42
|
+
client.fetch
|
|
43
|
+
client.servers.each do |server|
|
|
44
|
+
puts server.name
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
51
|
+
|
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
53
|
+
|
|
54
|
+
## Contributing
|
|
55
|
+
|
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amoeba/hotline. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
61
|
+
|
|
62
|
+
## Code of Conduct
|
|
63
|
+
|
|
64
|
+
Everyone interacting in the Hotline project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/amoeba/hotline/blob/main/CODE_OF_CONDUCT.md).
|
data/bin/tracker_client
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'hotline'
|
|
4
|
+
|
|
5
|
+
host = ARGV[0]
|
|
6
|
+
|
|
7
|
+
if host.nil? || host.length <= 0
|
|
8
|
+
puts "Usage: tracker_client [tracker_url]"
|
|
9
|
+
exit(1)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
client = Hotline::Tracker::Client.new(host)
|
|
13
|
+
client.fetch
|
|
14
|
+
client.servers.each do |s|
|
|
15
|
+
puts s.name
|
|
16
|
+
end
|
data/lib/hotline.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "socket"
|
|
4
|
+
require "bindata"
|
|
5
|
+
require "hotline/version"
|
|
6
|
+
require_relative "types"
|
|
7
|
+
require_relative "exceptions"
|
|
8
|
+
|
|
9
|
+
module Hotline
|
|
10
|
+
module Tracker
|
|
11
|
+
class Client
|
|
12
|
+
DEFAULT_PORT = 5498
|
|
13
|
+
RECV_TIMEOUT = 20
|
|
14
|
+
|
|
15
|
+
attr_reader :version
|
|
16
|
+
|
|
17
|
+
def initialize(host = nil, port = DEFAULT_PORT, version = 1)
|
|
18
|
+
@host = host
|
|
19
|
+
@port = port
|
|
20
|
+
@version = version.to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_s
|
|
24
|
+
[
|
|
25
|
+
self.class.name,
|
|
26
|
+
"{host: #{@host}, port: #{@port}, version: #{@version}}"
|
|
27
|
+
].join("")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def socket
|
|
31
|
+
@socket ||= begin
|
|
32
|
+
s = TCPSocket.new(@host, @port)
|
|
33
|
+
s.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, [RECV_TIMEOUT, 0].pack("l_2"))
|
|
34
|
+
s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def servers
|
|
39
|
+
@servers ||= []
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def fetch
|
|
43
|
+
handshake
|
|
44
|
+
header = read_header
|
|
45
|
+
@servers = read_servers(header)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def handshake
|
|
51
|
+
request = Request.new(version: version.to_i)
|
|
52
|
+
request.write(socket)
|
|
53
|
+
|
|
54
|
+
response = Request.read(socket.read(request.num_bytes))
|
|
55
|
+
raise InvalidTrackerResponse if response != request
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def read_header
|
|
59
|
+
Response.read(socket.read(Response.new.num_bytes))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def read_servers(header)
|
|
63
|
+
data = socket.read(header.remaining)
|
|
64
|
+
servers = []
|
|
65
|
+
cursor = 0
|
|
66
|
+
|
|
67
|
+
header.n.times do
|
|
68
|
+
server = Server.read(data[cursor..])
|
|
69
|
+
servers << server
|
|
70
|
+
cursor += server.num_bytes
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
servers
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Request < BinData::Record
|
|
4
|
+
endian :big
|
|
5
|
+
string :protocol, read_length: 4, value: "HTRK"
|
|
6
|
+
uint16 :version
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Response < BinData::Record
|
|
10
|
+
endian :big
|
|
11
|
+
|
|
12
|
+
uint16 :kind
|
|
13
|
+
uint16 :remaining
|
|
14
|
+
uint16 :padding
|
|
15
|
+
uint16 :n
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class Server < BinData::Record
|
|
19
|
+
endian :big
|
|
20
|
+
|
|
21
|
+
uint32 :ip
|
|
22
|
+
uint16 :port
|
|
23
|
+
uint16 :n_users
|
|
24
|
+
uint16 :empty # Not used
|
|
25
|
+
|
|
26
|
+
uint8 :name_len
|
|
27
|
+
string :name, read_length: :name_len
|
|
28
|
+
|
|
29
|
+
uint8 :desc_len
|
|
30
|
+
string :description, read_length: :desc_len
|
|
31
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hotline
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bryce Mecum
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rake
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '13.0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '13.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.14'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.14'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: standard
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: bindata
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '2.0'
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '2.0'
|
|
68
|
+
description: An implementation of the Hotline protocols, currently just the tracker
|
|
69
|
+
client.
|
|
70
|
+
email:
|
|
71
|
+
- petridish@gmail.com
|
|
72
|
+
executables:
|
|
73
|
+
- tracker_client
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- LICENSE.txt
|
|
78
|
+
- README.md
|
|
79
|
+
- bin/tracker_client
|
|
80
|
+
- lib/hotline.rb
|
|
81
|
+
- lib/hotline/version.rb
|
|
82
|
+
- lib/tracker/client.rb
|
|
83
|
+
- lib/tracker/exceptions.rb
|
|
84
|
+
- lib/tracker/types.rb
|
|
85
|
+
homepage: https://github.com/amoeba/hotline
|
|
86
|
+
licenses:
|
|
87
|
+
- MIT
|
|
88
|
+
metadata:
|
|
89
|
+
homepage_uri: https://github.com/amoeba/hotline
|
|
90
|
+
source_code_uri: https://github.com/amoeba/hotline
|
|
91
|
+
changelog_uri: https://github.com/amoeba/hotline/releases
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: 3.3.0
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubygems_version: 4.0.3
|
|
107
|
+
specification_version: 4
|
|
108
|
+
summary: Ruby gem for the Hotline protocol
|
|
109
|
+
test_files: []
|