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.
@@ -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.each do |method|
76
- if data['mode'] == method.to_s
77
- self.send(data['mode'], data)
78
- end
79
- end
80
- end
81
-
82
- # Calls Proc immediately then every milliseconds, async.
83
- # @param milliseconds [Integer][Float] Time to wait before calling the block
84
- # @param block [Proc]
85
- def every(milliseconds, &block)
86
- Thread.new do
87
- loop do
88
- block.call
89
- sleep(milliseconds/1000.0)
90
- end
91
- end
92
- end
93
-
94
- # Calls Proc after milliseconds have passed, async.
95
- # @param milliseconds [Integer][Float] Time to wait before calling the block
96
- # @param block [Proc]
97
- def after(milliseconds, &block)
98
- Thread.new do
99
- sleep(milliseconds/1000.0)
100
- block.call
101
- end
102
- end
103
-
104
- # String to be logged
105
- # @param string [String] text to log
106
- # @param color [Gosu::Color] color of text in console
107
- def log(string, color = Gosu::Color::RED)
108
- GameOverseer::Console.log_with_color(string, color)
109
- end
110
- end
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
@@ -1,4 +1,4 @@
1
- module GameOverseer
2
- VERSION = "0.1.7"
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}"