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.
- checksums.yaml +7 -0
- data/.gitignore +4 -3
- data/Gemfile +3 -10
- data/Gemfile.lock +30 -34
- data/README.md +51 -48
- data/gameoverseer.gemspec +2 -2
- data/lib/gameoverseer/channels/channel_manager.rb +49 -36
- data/lib/gameoverseer/clients/client_manager.rb +66 -50
- data/lib/gameoverseer/console/console.rb +206 -207
- data/lib/gameoverseer/encryption_handler/encryption_handler.rb +40 -0
- data/lib/gameoverseer/input_handler/input_handler.rb +36 -30
- data/lib/gameoverseer/messages/message_manager.rb +42 -36
- data/lib/gameoverseer/packet_handler/packet_handler.rb +35 -0
- data/lib/gameoverseer/server/renet_server.rb +126 -84
- data/lib/gameoverseer/services/service.rb +111 -90
- data/lib/gameoverseer/services/services.rb +38 -31
- data/lib/gameoverseer/version.rb +4 -4
- data/lib/gameoverseer.rb +59 -57
- data/test/test_helper.rb +1 -0
- data/test-clients/protocol-lib.rb +13 -13
- data/test-clients/test-client-alpha.rb +36 -36
- data/test-clients/test-client-beta.rb +37 -37
- data/test-clients/test-client-gamma.rb +62 -59
- metadata +23 -30
- data/lib/gameoverseer/server/encryption.rb +0 -31
@@ -1,31 +1,38 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
module Services
|
3
|
-
LIST = []
|
4
|
-
ACTIVE=[]
|
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
|
-
|
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
|
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
|
-
|
4
|
-
require "
|
5
|
-
require "
|
6
|
-
require "
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
require_relative "gameoverseer/services/
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
require_relative "gameoverseer/
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
data/test/test_helper.rb
ADDED
@@ -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
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@client.
|
15
|
-
@client.
|
16
|
-
|
17
|
-
|
18
|
-
@client.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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}"
|