gameoverseer-client 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 +5 -5
- data/README.md +41 -41
- data/gameoverseer-client.gemspec +26 -26
- data/lib/gameoverseer/client.rb +95 -92
- data/lib/gameoverseer/client/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 780be3c8b42fed1d660f5a491339a458aec7003819159aa963461876631b8c7b
|
4
|
+
data.tar.gz: 31c23cced9b9829deb6eab1083e5b15a7c92106176f87a4cc78ef1f4fd9df71b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a57f73d641b355291ad5259709da0c05fed6b334b5f8adf12a04c3a04fdfc27e5e6e76f07ccc6cdd1a8b0443c32031596cbe49aecea3b719c96dc68d8b5709e7
|
7
|
+
data.tar.gz: c51eee05a00940b42c9e310b1e94491d92567f1f4a64fa9a59d5458db5a1172d852c62b35729ee3ed211d9876f3fe44c28c228ddef9a5ce1a2047997916336e8
|
data/README.md
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
[](https://codeclimate.com/github/cyberarm/gameoverseer-client)
|
2
|
-
[](http://inch-ci.org/github/cyberarm/gameoverseer-client)
|
3
|
-
|
4
|
-
# GameOverseer::Client
|
5
|
-
|
6
|
-
Client library for GameOverseer.
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
gem 'gameoverseer-client'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself as:
|
21
|
-
|
22
|
-
$ gem install gameoverseer-client
|
23
|
-
|
24
|
-
## Usage
|
25
|
-
|
26
|
-
Simple example
|
27
|
-
```ruby
|
28
|
-
require "gameoverseer/client"
|
29
|
-
|
30
|
-
client = GameOverseer::Client.new("localhost", 56789)
|
31
|
-
client.transmit('world', 'connect', {access_token: "f2a..."})
|
32
|
-
client.disconnect
|
33
|
-
```
|
34
|
-
|
35
|
-
## Contributing
|
36
|
-
|
37
|
-
1. Fork it ( https://github.com/cyberarm/gameoverseer-client/fork )
|
38
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
-
5. Create a new Pull Request
|
1
|
+
[](https://codeclimate.com/github/cyberarm/gameoverseer-client)
|
2
|
+
[](http://inch-ci.org/github/cyberarm/gameoverseer-client)
|
3
|
+
|
4
|
+
# GameOverseer::Client
|
5
|
+
|
6
|
+
Client library for GameOverseer.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'gameoverseer-client'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install gameoverseer-client
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Simple example
|
27
|
+
```ruby
|
28
|
+
require "gameoverseer/client"
|
29
|
+
|
30
|
+
client = GameOverseer::Client.new("localhost", 56789)
|
31
|
+
client.transmit('world', 'connect', {access_token: "f2a..."})
|
32
|
+
client.disconnect
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/cyberarm/gameoverseer-client/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/gameoverseer-client.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'gameoverseer/client/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "gameoverseer-client"
|
8
|
-
spec.version = GameOverseer::Client::VERSION
|
9
|
-
spec.authors = ["Cyberarm"]
|
10
|
-
spec.email = ["matthewlikesrobots@gmail.com"]
|
11
|
-
spec.summary = %q{Client library for GameOverseer.}
|
12
|
-
spec.description = %q{Library for easily communicating with a GameOverseer server.}
|
13
|
-
spec.homepage = "https://github.com/cyberarm/gameoverseer-client"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "renet", ">= 0.2.0"
|
22
|
-
spec.add_dependency "multi_json"
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gameoverseer/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gameoverseer-client"
|
8
|
+
spec.version = GameOverseer::Client::VERSION
|
9
|
+
spec.authors = ["Cyberarm"]
|
10
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
11
|
+
spec.summary = %q{Client library for GameOverseer.}
|
12
|
+
spec.description = %q{Library for easily communicating with a GameOverseer server.}
|
13
|
+
spec.homepage = "https://github.com/cyberarm/gameoverseer-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "renet", ">= 0.2.0"
|
22
|
+
spec.add_dependency "multi_json"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/gameoverseer/client.rb
CHANGED
@@ -1,92 +1,95 @@
|
|
1
|
-
require "renet"
|
2
|
-
require "multi_json"
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def self.instance
|
35
|
-
@instance
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
raise "
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
1
|
+
require "renet"
|
2
|
+
require "multi_json"
|
3
|
+
if defined?(Oj)
|
4
|
+
Oj.default_options = {mode: :strict}
|
5
|
+
end
|
6
|
+
|
7
|
+
require_relative "client/version"
|
8
|
+
require_relative "client/service_manager"
|
9
|
+
require_relative "client/service"
|
10
|
+
|
11
|
+
module GameOverseer
|
12
|
+
class Client
|
13
|
+
CHAT = 0 # channel int. used for in-game chat
|
14
|
+
WORLD= 1 # channel int. used for sending/receiving world state updates
|
15
|
+
HANDSHAKE = 2 # channel int. used for authentication or similar purposes
|
16
|
+
FAULT=3 # channel int. used to send/receive errors
|
17
|
+
attr_reader :socket
|
18
|
+
|
19
|
+
def initialize(host = "localhost", port = 56789, compression = true)
|
20
|
+
@host = host
|
21
|
+
@port = port
|
22
|
+
@compression = compression
|
23
|
+
|
24
|
+
GameOverseer::Client.instance = self
|
25
|
+
@service_manager = ServiceManager.new
|
26
|
+
|
27
|
+
@socket = ENet::Connection.new(host, port, 4, 0, 0)
|
28
|
+
@socket.use_compression(compression)
|
29
|
+
@socket.on_packet_receive(method(:handle_packet))
|
30
|
+
|
31
|
+
connect
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.instance
|
35
|
+
@instance
|
36
|
+
end
|
37
|
+
def self.instance=instance
|
38
|
+
@instance = instance
|
39
|
+
end
|
40
|
+
|
41
|
+
def connect(timeout = 1000) # default to 1 second
|
42
|
+
tries = 0
|
43
|
+
begin
|
44
|
+
@socket.connect(timeout)
|
45
|
+
rescue StandardError
|
46
|
+
tries+=1
|
47
|
+
retry unless tries > 3
|
48
|
+
raise if tries > 3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def online?
|
53
|
+
@socket.online?
|
54
|
+
end
|
55
|
+
|
56
|
+
def connected?
|
57
|
+
@socket.connected?
|
58
|
+
end
|
59
|
+
|
60
|
+
def handle_packet(data, channel)
|
61
|
+
_data= data.chomp.strip
|
62
|
+
data = MultiJson.load(_data)
|
63
|
+
ServiceManager.instance.handle_packet(data, channel)
|
64
|
+
end
|
65
|
+
|
66
|
+
def disconnect(timeout = 1000)
|
67
|
+
tries = 0
|
68
|
+
begin
|
69
|
+
@socket.disconnect(timeout)
|
70
|
+
rescue StandardError
|
71
|
+
tries+=1
|
72
|
+
retry unless tries > 3
|
73
|
+
raise if tries > 3
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def transmit(channel, mode, data = nil, channel_id = CHAT, reliable = false)
|
78
|
+
raise "channel must be a String" unless channel.is_a?(String)
|
79
|
+
raise "mode must be a String" unless mode.is_a?(String)
|
80
|
+
raise "data must be a Hash" unless data.is_a?(Hash) or data == nil
|
81
|
+
raise "reliable must be a Boolean" unless reliable.is_a?(TrueClass) or reliable.is_a?(FalseClass)
|
82
|
+
|
83
|
+
if data
|
84
|
+
message = MultiJson.dump({channel: channel, mode: mode, data: data})
|
85
|
+
else
|
86
|
+
message = MultiJson.dump({channel: channel, mode: mode})
|
87
|
+
end
|
88
|
+
@socket.send_packet(message, reliable, channel_id)
|
89
|
+
end
|
90
|
+
|
91
|
+
def update(timeout = 0)
|
92
|
+
@socket.update(timeout)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gameoverseer-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyberarm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: renet
|
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.6
|
106
|
+
rubygems_version: 2.7.6
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Client library for GameOverseer.
|
110
110
|
test_files: []
|
111
|
-
has_rdoc:
|