gameoverseer-client 0.0.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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/gameoverseer-client.gemspec +26 -0
- data/lib/gameoverseer/client.rb +92 -0
- data/lib/gameoverseer/client/service.rb +26 -0
- data/lib/gameoverseer/client/service_manager.rb +49 -0
- data/lib/gameoverseer/client/version.rb +5 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad6101c2e2b10272e30528dc1a2e1e9bb3f79338
|
4
|
+
data.tar.gz: 4f2530092e030a77732253b52037e12b19c27bb1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94a0513d719bd42096ebe42c3c2df16ebe7f5b67901b1fd0b90edd922a84c92b01cf08e2560231810e38dbfd14a004e4792b58af0aeb4f5c34a67e85b4945588
|
7
|
+
data.tar.gz: 5d5b7ddf98357a84674195dd2cbd32866305540bb109ccf2fe6bd9b99e5910be98df14da2ad23666d999988e9501fc612971e49b92821be3c341cd477b544dba
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Cyberarm
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +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
|
data/Rakefile
ADDED
@@ -0,0 +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
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "renet"
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
require_relative "client/version"
|
5
|
+
require_relative "client/service_manager"
|
6
|
+
require_relative "client/service"
|
7
|
+
|
8
|
+
module GameOverseer
|
9
|
+
class Client
|
10
|
+
CHAT = 0 # channel int. used for in-game chat
|
11
|
+
WORLD= 1 # channel int. used for sending/receiving world state updates
|
12
|
+
HANDSHAKE = 2 # channel int. used for authentication or similar purposes
|
13
|
+
FAULT=3 # channel int. used to send/receive errors
|
14
|
+
attr_reader :socket
|
15
|
+
|
16
|
+
def initialize(host = "localhost", port = 56789, compression = true)
|
17
|
+
@host = host
|
18
|
+
@port = port
|
19
|
+
@compression = compression
|
20
|
+
|
21
|
+
GameOverseer::Client.instance = self
|
22
|
+
@service_manager = ServiceManager.new
|
23
|
+
|
24
|
+
@socket = ENet::Connection.new(host, port, 4, 0, 0)
|
25
|
+
@socket.use_compression(compression)
|
26
|
+
@socket.on_packet_receive(method(:handle_packet))
|
27
|
+
|
28
|
+
connect
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.instance
|
32
|
+
@instance
|
33
|
+
end
|
34
|
+
def self.instance=instance
|
35
|
+
@instance = instance
|
36
|
+
end
|
37
|
+
|
38
|
+
def connect(timeout = 1000) # default to 1 second
|
39
|
+
tries = 0
|
40
|
+
begin
|
41
|
+
@socket.connect(timeout)
|
42
|
+
rescue StandardError
|
43
|
+
tries+=1
|
44
|
+
retry unless tries > 3
|
45
|
+
raise if tries > 3
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def online?
|
50
|
+
@socket.online?
|
51
|
+
end
|
52
|
+
|
53
|
+
def connected?
|
54
|
+
@socket.connected?
|
55
|
+
end
|
56
|
+
|
57
|
+
def handle_packet(data, channel)
|
58
|
+
_data= data.chomp.strip
|
59
|
+
data = MultiJson.load(_data)
|
60
|
+
ServiceManager.instance.handle_packet(data, channel)
|
61
|
+
end
|
62
|
+
|
63
|
+
def disconnect(timeout = 1000)
|
64
|
+
tries = 0
|
65
|
+
begin
|
66
|
+
@socket.disconnect(timeout)
|
67
|
+
rescue StandardError
|
68
|
+
tries+=1
|
69
|
+
retry unless tries > 3
|
70
|
+
raise if tries > 3
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def transmit(channel, mode, data = nil, channel_id = CHAT, reliable = false)
|
75
|
+
raise "channel must be a String" unless channel.is_a?(String)
|
76
|
+
raise "mode must be a String" unless mode.is_a?(String)
|
77
|
+
raise "data must be a Hash" unless data.is_a?(Hash) or data == nil
|
78
|
+
raise "reliable must be a Boolean" unless reliable.is_a?(TrueClass) or reliable.is_a?(FalseClass)
|
79
|
+
|
80
|
+
if data
|
81
|
+
message = MultiJson.dump({channel: channel, mode: mode, data: data})
|
82
|
+
else
|
83
|
+
message = MultiJson.dump({channel: channel, mode: mode})
|
84
|
+
end
|
85
|
+
@socket.send_packet(message, reliable, channel_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def update(timeout = 0)
|
89
|
+
@socket.update(timeout)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GameOverseer
|
2
|
+
class Client
|
3
|
+
class Service
|
4
|
+
def self.inherited(klass)
|
5
|
+
ServiceManager::SERVICES.push(klass)
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
setup if defined?(setup)
|
10
|
+
end
|
11
|
+
|
12
|
+
def register_channel(string)
|
13
|
+
if ServiceManager.instance.register_channel(self, string)
|
14
|
+
true
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def transmit(channel, mode, data, channel_id = GameOverseer::Client::CHAT, reliable = false)
|
21
|
+
raise "data must be a Hash when sent from a Service" unless data.is_a?(Hash)
|
22
|
+
Client.instance.transmit(channel, mode, data, channel_id, reliable)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module GameOverseer
|
2
|
+
class Client
|
3
|
+
class ServiceManager
|
4
|
+
SERVICES = []
|
5
|
+
CHANNELS = []
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
GameOverseer::Client::ServiceManager.instance = self
|
9
|
+
SERVICES.each_with_index do |s, index|
|
10
|
+
if s.class == Class
|
11
|
+
SERVICES[index] = s.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.instance
|
17
|
+
@instance
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.instance=instance
|
21
|
+
@instance = instance
|
22
|
+
end
|
23
|
+
|
24
|
+
def register_channel(instance, string)
|
25
|
+
service = CHANNELS.detect do |_service|
|
26
|
+
if _service[:channel] == string
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
raise "channel '#{string}' in use by '#{service[:instance]}'" if service
|
32
|
+
|
33
|
+
CHANNELS.push({instance: instance, channel: string})
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle_packet(data, channel)
|
38
|
+
service_channel = data["channel"]
|
39
|
+
# service_method = data["mode"]
|
40
|
+
|
41
|
+
CHANNELS.each do |service|
|
42
|
+
if service[:channel] == service_channel
|
43
|
+
service[:instance].process_data(data, channel)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gameoverseer-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cyberarm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: renet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Library for easily communicating with a GameOverseer server.
|
70
|
+
email:
|
71
|
+
- matthewlikesrobots@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- gameoverseer-client.gemspec
|
82
|
+
- lib/gameoverseer/client.rb
|
83
|
+
- lib/gameoverseer/client/service.rb
|
84
|
+
- lib/gameoverseer/client/service_manager.rb
|
85
|
+
- lib/gameoverseer/client/version.rb
|
86
|
+
homepage: https://github.com/cyberarm/gameoverseer-client
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Client library for GameOverseer.
|
110
|
+
test_files: []
|
111
|
+
has_rdoc:
|