gameoverseer 0.1.7 → 0.1.8
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/.gitignore +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +30 -30
- data/README.md +53 -51
- data/Rakefile +2 -0
- data/gameoverseer.gemspec +22 -22
- data/lib/gameoverseer.rb +73 -73
- data/lib/gameoverseer/channels/channel_manager.rb +48 -48
- data/lib/gameoverseer/clients/client_manager.rb +68 -68
- data/lib/gameoverseer/console/console.rb +206 -206
- data/lib/gameoverseer/console/namespace_creator.rb +4 -4
- data/lib/gameoverseer/encryption_handler/encryption_handler.rb +40 -40
- data/lib/gameoverseer/input_handler/input_handler.rb +36 -36
- data/lib/gameoverseer/messages/message_manager.rb +40 -40
- data/lib/gameoverseer/packet_handler/json_packet_handler.rb +34 -31
- data/lib/gameoverseer/packet_handler/messagepack_packet_handler.rb +31 -31
- data/lib/gameoverseer/packet_handler/packet_handler.rb +29 -29
- data/lib/gameoverseer/server/renet_server.rb +126 -126
- data/lib/gameoverseer/services/service.rb +112 -111
- data/lib/gameoverseer/services/services.rb +38 -38
- data/lib/gameoverseer/version.rb +4 -4
- data/license.md +9 -9
- data/test-clients/test-client-gamma.rb +62 -62
- data/test/test_helper.rb +1 -1
- metadata +4 -4
@@ -1,111 +1,112 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
|
3
|
-
# Services are at the heart on GameOverseer
|
4
|
-
#
|
5
|
-
# Subclass this class to implement a service
|
6
|
-
class Service
|
7
|
-
attr_accessor :client_id
|
8
|
-
attr_reader :safe_methods
|
9
|
-
|
10
|
-
# Adds the class that subclassed this class to a list for activation later
|
11
|
-
# @param subclass [Service]
|
12
|
-
def self.inherited(subclass)
|
13
|
-
Services.register(subclass)
|
14
|
-
GameOverseer::Console.log "Service> added '#{subclass}' to Services::List."
|
15
|
-
end
|
16
|
-
|
17
|
-
# This method should not be overridden, you should instead implement {#setup} with no arguments
|
18
|
-
def initialize
|
19
|
-
if defined?(self.setup)
|
20
|
-
@client_id = 0
|
21
|
-
@safe_methods = []
|
22
|
-
setup
|
23
|
-
enable
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# Called before {#enable} there should be no active code here, only setup variables.
|
28
|
-
def setup
|
29
|
-
end
|
30
|
-
|
31
|
-
# Called when services are first initialized, put active code here, in a thread.
|
32
|
-
def enable
|
33
|
-
end
|
34
|
-
|
35
|
-
# Called when a message is recieved for this channel.
|
36
|
-
# @param data [Hash] The data from the packet
|
37
|
-
def process(data)
|
38
|
-
end
|
39
|
-
|
40
|
-
def version
|
41
|
-
# Please use the sematic versioning system,
|
42
|
-
# http://semver.org
|
43
|
-
#
|
44
|
-
# e.g.
|
45
|
-
# "1.5.9"
|
46
|
-
# (Major.Minor.Patch)
|
47
|
-
"0.0.0-default"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Sets methods that are safe for {#data_to_method} to call
|
51
|
-
# @param array [Array] Array of strings or symbols that match a method in the service class
|
52
|
-
def set_safe_methods(array)
|
53
|
-
raise "argument must be an array of strings or symbols" unless array.is_a?(Array)
|
54
|
-
@safe_methods = array
|
55
|
-
end
|
56
|
-
|
57
|
-
# @return [ChannelManager] Active instance of ChannelManager
|
58
|
-
def channel_manager
|
59
|
-
ChannelManager.instance
|
60
|
-
end
|
61
|
-
|
62
|
-
# @return [MessageManager] Instance of MessageManager
|
63
|
-
def message_manager
|
64
|
-
MessageManager.instance
|
65
|
-
end
|
66
|
-
|
67
|
-
# @return [ClientManager] Current instance of ClientManager
|
68
|
-
def client_manager
|
69
|
-
ClientManager.instance
|
70
|
-
end
|
71
|
-
|
72
|
-
# Uses the 'mode' from a packet to call the method of the same name
|
73
|
-
# @param data [Hash] data from packet
|
74
|
-
def data_to_method(data)
|
75
|
-
@safe_methods.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
# @param
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
# @param
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
#
|
106
|
-
# @param
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
|
3
|
+
# Services are at the heart on GameOverseer
|
4
|
+
#
|
5
|
+
# Subclass this class to implement a service
|
6
|
+
class Service
|
7
|
+
attr_accessor :client_id
|
8
|
+
attr_reader :safe_methods
|
9
|
+
|
10
|
+
# Adds the class that subclassed this class to a list for activation later
|
11
|
+
# @param subclass [Service]
|
12
|
+
def self.inherited(subclass)
|
13
|
+
Services.register(subclass)
|
14
|
+
GameOverseer::Console.log "Service> added '#{subclass}' to Services::List."
|
15
|
+
end
|
16
|
+
|
17
|
+
# This method should not be overridden, you should instead implement {#setup} with no arguments
|
18
|
+
def initialize
|
19
|
+
if defined?(self.setup)
|
20
|
+
@client_id = 0
|
21
|
+
@safe_methods = []
|
22
|
+
setup
|
23
|
+
enable
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Called before {#enable} there should be no active code here, only setup variables.
|
28
|
+
def setup
|
29
|
+
end
|
30
|
+
|
31
|
+
# Called when services are first initialized, put active code here, in a thread.
|
32
|
+
def enable
|
33
|
+
end
|
34
|
+
|
35
|
+
# Called when a message is recieved for this channel.
|
36
|
+
# @param data [Hash] The data from the packet
|
37
|
+
def process(data)
|
38
|
+
end
|
39
|
+
|
40
|
+
def version
|
41
|
+
# Please use the sematic versioning system,
|
42
|
+
# http://semver.org
|
43
|
+
#
|
44
|
+
# e.g.
|
45
|
+
# "1.5.9"
|
46
|
+
# (Major.Minor.Patch)
|
47
|
+
"0.0.0-default"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets methods that are safe for {#data_to_method} to call
|
51
|
+
# @param array [Array] Array of strings or symbols that match a method in the service class
|
52
|
+
def set_safe_methods(array)
|
53
|
+
raise "argument must be an array of strings or symbols" unless array.is_a?(Array)
|
54
|
+
@safe_methods = array
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [ChannelManager] Active instance of ChannelManager
|
58
|
+
def channel_manager
|
59
|
+
ChannelManager.instance
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [MessageManager] Instance of MessageManager
|
63
|
+
def message_manager
|
64
|
+
MessageManager.instance
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [ClientManager] Current instance of ClientManager
|
68
|
+
def client_manager
|
69
|
+
ClientManager.instance
|
70
|
+
end
|
71
|
+
|
72
|
+
# Uses the 'mode' from a packet to call the method of the same name
|
73
|
+
# @param data [Hash] data from packet
|
74
|
+
def data_to_method(data)
|
75
|
+
raise "No safe methods defined!" unless @safe_methods.size > 0
|
76
|
+
@safe_methods.each do |method|
|
77
|
+
if data['mode'] == method.to_s
|
78
|
+
self.send(data['mode'], data)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Calls Proc immediately then every milliseconds, async.
|
84
|
+
# @param milliseconds [Integer][Float] Time to wait before calling the block
|
85
|
+
# @param block [Proc]
|
86
|
+
def every(milliseconds, &block)
|
87
|
+
Thread.new do
|
88
|
+
loop do
|
89
|
+
block.call
|
90
|
+
sleep(milliseconds/1000.0)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Calls Proc after milliseconds have passed, async.
|
96
|
+
# @param milliseconds [Integer][Float] Time to wait before calling the block
|
97
|
+
# @param block [Proc]
|
98
|
+
def after(milliseconds, &block)
|
99
|
+
Thread.new do
|
100
|
+
sleep(milliseconds/1000.0)
|
101
|
+
block.call
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# String to be logged
|
106
|
+
# @param string [String] text to log
|
107
|
+
# @param color [Gosu::Color] color of text in console
|
108
|
+
def log(string, color = Gosu::Color::RED)
|
109
|
+
GameOverseer::Console.log_with_color(string, color)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
module Services
|
3
|
-
LIST = []
|
4
|
-
ACTIVE=[]
|
5
|
-
|
6
|
-
# Adds klass to list
|
7
|
-
# @param klass [Service] Service class to add to services list
|
8
|
-
def self.register(klass)
|
9
|
-
LIST << klass
|
10
|
-
end
|
11
|
-
|
12
|
-
# instantiates the Services in 'LIST' and adds them to the 'ACTIVE' list
|
13
|
-
def self.enable
|
14
|
-
LIST.each do |service|
|
15
|
-
_service = service.new
|
16
|
-
GameOverseer::Console.log "Services> #{_service.class} #{_service.version}"
|
17
|
-
ACTIVE << _service
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Tells all services that have 'client_connected' defined that 'client_id' has connected
|
22
|
-
# @param client_id [Integer] ID of client
|
23
|
-
# @param ip_address [String] ip address of client
|
24
|
-
def self.client_connected(client_id, ip_address)
|
25
|
-
ACTIVE.each do |service|
|
26
|
-
service.client_connected(client_id, ip_address) if defined?(service.client_connected)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Tells all services that have 'client_disconnected' defined that 'client_id' is now disconnected
|
31
|
-
# @param client_id [Integer] ID of client
|
32
|
-
def self.client_disconnected(client_id)
|
33
|
-
ACTIVE.each do |service|
|
34
|
-
service.client_disconnected(client_id) if defined?(service.client_disconnected)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
module Services
|
3
|
+
LIST = []
|
4
|
+
ACTIVE=[]
|
5
|
+
|
6
|
+
# Adds klass to list
|
7
|
+
# @param klass [Service] Service class to add to services list
|
8
|
+
def self.register(klass)
|
9
|
+
LIST << klass
|
10
|
+
end
|
11
|
+
|
12
|
+
# instantiates the Services in 'LIST' and adds them to the 'ACTIVE' list
|
13
|
+
def self.enable
|
14
|
+
LIST.each do |service|
|
15
|
+
_service = service.new
|
16
|
+
GameOverseer::Console.log "Services> #{_service.class} #{_service.version}"
|
17
|
+
ACTIVE << _service
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Tells all services that have 'client_connected' defined that 'client_id' has connected
|
22
|
+
# @param client_id [Integer] ID of client
|
23
|
+
# @param ip_address [String] ip address of client
|
24
|
+
def self.client_connected(client_id, ip_address)
|
25
|
+
ACTIVE.each do |service|
|
26
|
+
service.client_connected(client_id, ip_address) if defined?(service.client_connected)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Tells all services that have 'client_disconnected' defined that 'client_id' is now disconnected
|
31
|
+
# @param client_id [Integer] ID of client
|
32
|
+
def self.client_disconnected(client_id)
|
33
|
+
ACTIVE.each do |service|
|
34
|
+
service.client_disconnected(client_id) if defined?(service.client_disconnected)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/gameoverseer/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
VERSION = "0.1.
|
3
|
-
RELEASE_NAME = "Blank Slate" # 1.0 is to be "Ice Crystal"
|
4
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
VERSION = "0.1.8"
|
3
|
+
RELEASE_NAME = "Blank Slate" # 1.0 is to be "Ice Crystal"
|
4
|
+
end
|
data/license.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2014 cyberarm
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
-
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 cyberarm
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,62 +1,62 @@
|
|
1
|
-
require "multi_json"
|
2
|
-
require 'uri'
|
3
|
-
require "renet"
|
4
|
-
require_relative "protocol-lib"
|
5
|
-
|
6
|
-
class TestClientGamma
|
7
|
-
HANDSHAKE = 2
|
8
|
-
# include Celluloid
|
9
|
-
|
10
|
-
def initialize(host, port)
|
11
|
-
@client = ENet::Connection.new(host, port, 4, 0, 0)
|
12
|
-
|
13
|
-
@client.on_connection(method(:on_connect))
|
14
|
-
@client.on_packet_receive(method(:on_packet))
|
15
|
-
@client.on_disconnection(method(:on_disconnect))
|
16
|
-
|
17
|
-
@client.connect(2000)
|
18
|
-
@client.send_packet("#{PROTOCOLS[:handshake_extend_hand]}", true, HANDSHAKE)
|
19
|
-
|
20
|
-
puts "Running...."
|
21
|
-
run
|
22
|
-
end
|
23
|
-
|
24
|
-
def run
|
25
|
-
loop do
|
26
|
-
@client.update(0)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def on_packet(data, channel)
|
31
|
-
p "P: #{data}-#{channel}"
|
32
|
-
handle_connection(data, channel)
|
33
|
-
end
|
34
|
-
|
35
|
-
def on_connect(data = 0, channel = 0)
|
36
|
-
p "C: #{data}-#{channel}"
|
37
|
-
end
|
38
|
-
|
39
|
-
def on_disconnect(data = 0, channel = 0)
|
40
|
-
p "D: #{data}-#{channel}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def handle_connection(data, channel)
|
44
|
-
response = MultiJson.load(data)
|
45
|
-
case response['channel']
|
46
|
-
when 'handshake'
|
47
|
-
public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
|
48
|
-
public_key = OpenSSL::PKey::RSA.new public_key_pem
|
49
|
-
encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}".force_encoding("utf-8")}})
|
50
|
-
@client.send_packet(encrypted_auth_key_response, true, HANDSHAKE)
|
51
|
-
puts "PAST"
|
52
|
-
else
|
53
|
-
puts "hmm"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
start_time = Time.now
|
59
|
-
|
60
|
-
TestClientGamma.new("localhost", 56789)
|
61
|
-
|
62
|
-
puts "Time to complete: #{Time.now-start_time}"
|
1
|
+
require "multi_json"
|
2
|
+
require 'uri'
|
3
|
+
require "renet"
|
4
|
+
require_relative "protocol-lib"
|
5
|
+
|
6
|
+
class TestClientGamma
|
7
|
+
HANDSHAKE = 2
|
8
|
+
# include Celluloid
|
9
|
+
|
10
|
+
def initialize(host, port)
|
11
|
+
@client = ENet::Connection.new(host, port, 4, 0, 0)
|
12
|
+
|
13
|
+
@client.on_connection(method(:on_connect))
|
14
|
+
@client.on_packet_receive(method(:on_packet))
|
15
|
+
@client.on_disconnection(method(:on_disconnect))
|
16
|
+
|
17
|
+
@client.connect(2000)
|
18
|
+
@client.send_packet("#{PROTOCOLS[:handshake_extend_hand]}", true, HANDSHAKE)
|
19
|
+
|
20
|
+
puts "Running...."
|
21
|
+
run
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
loop do
|
26
|
+
@client.update(0)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def on_packet(data, channel)
|
31
|
+
p "P: #{data}-#{channel}"
|
32
|
+
handle_connection(data, channel)
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_connect(data = 0, channel = 0)
|
36
|
+
p "C: #{data}-#{channel}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_disconnect(data = 0, channel = 0)
|
40
|
+
p "D: #{data}-#{channel}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def handle_connection(data, channel)
|
44
|
+
response = MultiJson.load(data)
|
45
|
+
case response['channel']
|
46
|
+
when 'handshake'
|
47
|
+
public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
|
48
|
+
public_key = OpenSSL::PKey::RSA.new public_key_pem
|
49
|
+
encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}".force_encoding("utf-8")}})
|
50
|
+
@client.send_packet(encrypted_auth_key_response, true, HANDSHAKE)
|
51
|
+
puts "PAST"
|
52
|
+
else
|
53
|
+
puts "hmm"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
start_time = Time.now
|
59
|
+
|
60
|
+
TestClientGamma.new("localhost", 56789)
|
61
|
+
|
62
|
+
puts "Time to complete: #{Time.now-start_time}"
|