gameoverseer 0.1.2 → 0.1.3

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,31 +1,38 @@
1
- module GameOverseer
2
- module Services
3
- LIST = []
4
- ACTIVE=[]
5
-
6
- def self.register(klass)
7
- LIST << klass
8
- end
9
-
10
- def self.enable
11
- LIST.each do |service|
12
- _service = service.new
13
- _service.enable
14
- GameOverseer::Console.log "Services> #{_service.class} #{_service.version}"
15
- ACTIVE << _service
16
- end
17
- end
18
-
19
- def self.client_connected(client_id, ip_address)
20
- ACTIVE.each do |service|
21
- service.client_connected(client_id, ip_address) if defined?(service.client_connected)
22
- end
23
- end
24
-
25
- def self.client_disconnected(client_id)
26
- ACTIVE.each do |service|
27
- service.client_disconnected(client_id) if defined?(service.client_disconnected)
28
- end
29
- end
30
- end
31
- 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.2"
3
- RELEASE_NAME = "Blank Slate" # 1.0.0 is to be "Ice Crystal"
4
- end
1
+ module GameOverseer
2
+ VERSION = "0.1.3"
3
+ RELEASE_NAME = "Blank Slate" # 1.0 is to be "Ice Crystal"
4
+ end
data/lib/gameoverseer.rb CHANGED
@@ -1,57 +1,59 @@
1
- require "set"
2
-
3
- require "gosu"
4
- require "celluloid"
5
- require "renet"
6
- require "multi_json"
7
-
8
- require_relative "gameoverseer/version"
9
-
10
- require_relative "gameoverseer/console/console"
11
-
12
- require_relative "gameoverseer/channels/channel_manager"
13
-
14
- require_relative "gameoverseer/messages/message_manager"
15
-
16
- require_relative "gameoverseer/clients/client_manager"
17
-
18
- require_relative "gameoverseer/services/service"
19
- require_relative "gameoverseer/services/services"
20
-
21
- require_relative "gameoverseer/input_handler/input_handler"
22
-
23
- require_relative "gameoverseer/server/renet_server"
24
- require_relative "gameoverseer/server/encryption"
25
-
26
- # TEMP
27
- Thread.abort_on_exception = true
28
-
29
- # TODO: Move to own file
30
- module GameOverseer
31
- def self.activate(host, port)
32
- GameOverseer::ChannelManager.new
33
- GameOverseer::MessageManager.new
34
- GameOverseer::ClientManager.new
35
-
36
- # @console = GameOverseer::Console.new
37
- @server = GameOverseer::ENetServerRunner.new
38
-
39
- # Thread.new {@console.show}
40
- Thread.new {@server.start(host, port)}
41
- sleep
42
-
43
- at_exit do
44
- # GameOverseer::Console.instance.close
45
- @server.supervisor.terminate if defined?(@server.supervisor.terminate)
46
- puts "Server Shutdown"
47
- end
48
- end
49
-
50
- def self.deactivate
51
- puts "ALERT \"CONSOLE CLOSED. LOST CONTROL OF SERVER.\""
52
- @server.supervisor.terminate
53
- end
54
- end
55
-
56
- # Activate self, remove this before a release.
57
- # GameOverseer.activate("localhost", 56789)
1
+ require "set"
2
+ require "openssl"
3
+
4
+ require "gosu"
5
+ require "concurrent"
6
+ require "renet"
7
+ require "multi_json"
8
+
9
+ require_relative "gameoverseer/version"
10
+
11
+ require_relative "gameoverseer/console/console"
12
+
13
+ require_relative "gameoverseer/channels/channel_manager"
14
+
15
+ require_relative "gameoverseer/messages/message_manager"
16
+
17
+ require_relative "gameoverseer/clients/client_manager"
18
+
19
+ require_relative "gameoverseer/services/service"
20
+ require_relative "gameoverseer/services/services"
21
+
22
+ require_relative "gameoverseer/input_handler/input_handler"
23
+
24
+ require_relative "gameoverseer/packet_handler/packet_handler"
25
+ require_relative "gameoverseer/encryption_handler/encryption_handler"
26
+
27
+ require_relative "gameoverseer/server/renet_server"
28
+
29
+
30
+ Thread.abort_on_exception = true
31
+ # General purpose game server that uses services (plugins) for logic.
32
+ module GameOverseer
33
+
34
+ # Start server
35
+ def self.activate(host, port, packet_handler = PacketHandler, encryption_handler = nil)
36
+ GameOverseer::ChannelManager.new
37
+ GameOverseer::MessageManager.new
38
+ GameOverseer::ClientManager.new
39
+
40
+ @console = GameOverseer::Console.new
41
+ @server = GameOverseer::ENetServerRunner.new
42
+
43
+ Thread.new {@server.start(host, port, packet_handler, encryption_handler)}
44
+ @console.show
45
+ sleep
46
+
47
+ at_exit do
48
+ GameOverseer::Console.instance.close
49
+ @server.supervisor.terminate if defined?(@server.supervisor.terminate)
50
+ puts "Server Shutdown"
51
+ end
52
+ end
53
+
54
+ # Stop server
55
+ def self.deactivate
56
+ puts "ALERT \"CONSOLE CLOSED. LOST CONTROL OF SERVER.\""
57
+ @server.supervisor.terminate
58
+ end
59
+ end
@@ -0,0 +1 @@
1
+ require "minitest"
@@ -1,13 +1,13 @@
1
- require "multi_json"
2
-
3
- PROTOCOLS = {
4
- # Client
5
- handshake_extend_hand: MultiJson.dump({'channel' => 'handshake', 'mode' => 'extend_hand'}),
6
- handshake_authenticate: "{'channel'=> 'handshake', \"mode\": \"authenticate\", \"data\": {\"auth_key\": \"public_key_encrypted_auth_key\"}}",
7
-
8
-
9
- # Server
10
- handshake_public_key: "{\"channel\": \"handshake\", \"mode\": \"public_key\", \"data\": {\"public_key\": \"really_long_string\"}}",
11
- handshake_authenticated: "{\"channel\": \"handshake\", \"mode\": \"authenticated\", \"data\": {\"code\": 200, \"message\": \"Successfully authenticated.\"}}",
12
- handshake_bad_authentication: "{\"channel\": \"handshake\", \"mode\": \"bad_authentication\", \"data\": {\"code\": 401, \"message\": \"Could not authenticate.\"}}"
13
- }
1
+ require "multi_json"
2
+
3
+ PROTOCOLS = {
4
+ # Client
5
+ handshake_extend_hand: MultiJson.dump({'channel' => 'handshake', 'mode' => 'extend_hand'}),
6
+ handshake_authenticate: "{'channel'=> 'handshake', \"mode\": \"authenticate\", \"data\": {\"auth_key\": \"public_key_encrypted_auth_key\"}}",
7
+
8
+
9
+ # Server
10
+ handshake_public_key: "{\"channel\": \"handshake\", \"mode\": \"public_key\", \"data\": {\"public_key\": \"really_long_string\"}}",
11
+ handshake_authenticated: "{\"channel\": \"handshake\", \"mode\": \"authenticated\", \"data\": {\"code\": 200, \"message\": \"Successfully authenticated.\"}}",
12
+ handshake_bad_authentication: "{\"channel\": \"handshake\", \"mode\": \"bad_authentication\", \"data\": {\"code\": 401, \"message\": \"Could not authenticate.\"}}"
13
+ }
@@ -1,36 +1,36 @@
1
- require "celluloid/io"
2
- require "multi_json"
3
- require "net/ssh"
4
- require_relative "protocol-lib"
5
-
6
- class TestClientAlpha
7
- include Celluloid::IO
8
- finalizer :finish
9
-
10
- def initialize(host, port)
11
- @client = UDPSocket.new
12
- @client.connect(host, port)
13
- run
14
- end
15
-
16
- def run
17
- @client.send("#{PROTOCOLS[:handshake_extend_hand]}", 0)
18
- socket = @client.recvfrom(1024)
19
- response = MultiJson.load(socket[0])
20
- public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
21
- public_key = OpenSSL::PKey::RSA.new public_key_pem
22
- encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}"}})
23
- p encrypted_auth_key_response
24
- @client.send("#{encrypted_auth_key_response}", 0)
25
- end
26
-
27
- def finish
28
- @client.close if @client
29
- end
30
- end
31
-
32
- start_time = Time.now
33
-
34
- TestClientAlpha.supervise('localhost', 56789)
35
-
36
- puts "Time to complete: #{Time.now-start_time}"
1
+ require "celluloid/io"
2
+ require "multi_json"
3
+ require "net/ssh"
4
+ require_relative "protocol-lib"
5
+
6
+ class TestClientAlpha
7
+ include Celluloid::IO
8
+ finalizer :finish
9
+
10
+ def initialize(host, port)
11
+ @client = UDPSocket.new
12
+ @client.connect(host, port)
13
+ run
14
+ end
15
+
16
+ def run
17
+ @client.send("#{PROTOCOLS[:handshake_extend_hand]}", 0)
18
+ socket = @client.recvfrom(1024)
19
+ response = MultiJson.load(socket[0])
20
+ public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
21
+ public_key = OpenSSL::PKey::RSA.new public_key_pem
22
+ encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}"}})
23
+ p encrypted_auth_key_response
24
+ @client.send("#{encrypted_auth_key_response}", 0)
25
+ end
26
+
27
+ def finish
28
+ @client.close if @client
29
+ end
30
+ end
31
+
32
+ start_time = Time.now
33
+
34
+ TestClientAlpha.supervise('localhost', 56789)
35
+
36
+ puts "Time to complete: #{Time.now-start_time}"
@@ -1,37 +1,37 @@
1
- require "celluloid/io"
2
- require "multi_json"
3
- require "net/ssh"
4
- require 'uri'
5
- require_relative "protocol-lib"
6
-
7
- class TestClientBeta
8
- include Celluloid::IO
9
- finalizer :finish
10
-
11
- def initialize(host, port)
12
- @client = Celluloid::IO::TCPSocket.new(host, port)
13
- run
14
- end
15
-
16
- def run
17
- @client.puts("#{PROTOCOLS[:handshake_extend_hand]}")
18
- line = @client.gets
19
- p line
20
- response = MultiJson.load(line)
21
- public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
22
- public_key = OpenSSL::PKey::RSA.new public_key_pem
23
- encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}".force_encoding("utf-8")}})
24
- p encrypted_auth_key_response
25
- @client.puts("#{encrypted_auth_key_response.inspect}")
26
- end
27
-
28
- def finish
29
- @client.close if @client
30
- end
31
- end
32
-
33
- start_time = Time.now
34
-
35
- TestClientBeta.supervise("127.0.0.1", 56789)
36
-
37
- puts "Time to complete: #{Time.now-start_time}"
1
+ require "celluloid/io"
2
+ require "multi_json"
3
+ require "net/ssh"
4
+ require 'uri'
5
+ require_relative "protocol-lib"
6
+
7
+ class TestClientBeta
8
+ include Celluloid::IO
9
+ finalizer :finish
10
+
11
+ def initialize(host, port)
12
+ @client = Celluloid::IO::TCPSocket.new(host, port)
13
+ run
14
+ end
15
+
16
+ def run
17
+ @client.puts("#{PROTOCOLS[:handshake_extend_hand]}")
18
+ line = @client.gets
19
+ p line
20
+ response = MultiJson.load(line)
21
+ public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
22
+ public_key = OpenSSL::PKey::RSA.new public_key_pem
23
+ encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}".force_encoding("utf-8")}})
24
+ p encrypted_auth_key_response
25
+ @client.puts("#{encrypted_auth_key_response.inspect}")
26
+ end
27
+
28
+ def finish
29
+ @client.close if @client
30
+ end
31
+ end
32
+
33
+ start_time = Time.now
34
+
35
+ TestClientBeta.supervise("127.0.0.1", 56789)
36
+
37
+ puts "Time to complete: #{Time.now-start_time}"
@@ -1,59 +1,62 @@
1
- require "multi_json"
2
- require "net/ssh"
3
- require 'uri'
4
- require "renet"
5
- require_relative "protocol-lib"
6
-
7
- class TestClientGamma
8
- HANDSHAKE = 2
9
- # include Celluloid
10
-
11
- def initialize(host, port)
12
- @client = ENet::Connection.new(host, port, 4, 0, 0)
13
-
14
- @client.on_connection(method(:on_connect))
15
- @client.on_packet_receive(method(:on_packet))
16
- @client.on_disconnection(method(:on_disconnect))
17
-
18
- @client.connect(2000)
19
- @client.send_packet("#{PROTOCOLS[:handshake_extend_hand]}", true, HANDSHAKE)
20
- run
21
- end
22
-
23
- def run
24
- loop do
25
- @client.update(0)
26
- end
27
- end
28
-
29
- def on_packet(data, channel)
30
- p "P: #{data}-#{channel}"
31
- handle_connection(data, channel)
32
- end
33
-
34
- def on_connect(data = 0, channel = 0)
35
- p "C: #{data}-#{channel}"
36
- end
37
-
38
- def on_disconnect(data = 0, channel = 0)
39
- p "D: #{data}-#{channel}"
40
- end
41
-
42
- def handle_connection(data, channel)
43
- response = MultiJson.load(data)
44
- case response['channel']
45
- when 'handshake'
46
- public_key_pem = response['data']['public_key'] if response['mode'] == 'public_key'
47
- public_key = OpenSSL::PKey::RSA.new public_key_pem
48
- encrypted_auth_key_response = MultiJson.dump({'channel'=> 'handshake', 'mode' => 'authenticate', 'data' => {'auth_key' => "#{public_key.public_encrypt('HELLO_WORLD')}".force_encoding("utf-8")}})
49
- @client.send_packet(encrypted_auth_key_response, true, HANDSHAKE)
50
- puts "PAST"
51
- end
52
- end
53
- end
54
-
55
- start_time = Time.now
56
-
57
- TestClientGamma.new("localhost", 56789)
58
-
59
- 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}"