gameoverseer 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/gameoverseer/channels/channel_manager.rb +1 -5
- data/lib/gameoverseer/clients/client_manager.rb +12 -2
- data/lib/gameoverseer/console/console.rb +1 -1
- data/lib/gameoverseer/messages/message_manager.rb +1 -1
- data/lib/gameoverseer/server/encryption.rb +31 -0
- data/lib/gameoverseer/server/renet_server.rb +4 -4
- data/lib/gameoverseer/services/service.rb +35 -8
- data/lib/gameoverseer/version.rb +1 -1
- data/lib/gameoverseer.rb +1 -2
- metadata +3 -8
- data/lib/gameoverseer/server/handshake.rb +0 -19
- data/lib/gameoverseer/services/internal/broadcast.rb +0 -13
- data/lib/gameoverseer/services/internal/chat.rb +0 -9
- data/lib/gameoverseer/services/internal/environment.rb +0 -9
- data/lib/gameoverseer/services/internal/handshake.rb +0 -25
- data/lib/gameoverseer/services/internal/services.rb +0 -3
data/README.md
CHANGED
@@ -6,11 +6,7 @@ module GameOverseer
|
|
6
6
|
FAULT=3
|
7
7
|
def initialize
|
8
8
|
@channels = {}
|
9
|
-
ChannelManager.instance = self
|
10
|
-
# 'chat' => GameOverseer::InternalService::Chat,
|
11
|
-
# 'handshake' => GameOverseer::InternalService::Handshake,
|
12
|
-
# 'broadcast' => GameOverseer::InternalService::Broadcast,
|
13
|
-
# 'environment' => GameOverseer::InternalService::Environment
|
9
|
+
ChannelManager.instance = self
|
14
10
|
end
|
15
11
|
|
16
12
|
def register_channel(channel, service)
|
@@ -13,15 +13,25 @@ module GameOverseer
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def update(client_id, key, value)
|
16
|
-
@clients.
|
16
|
+
@clients.each do |hash|
|
17
17
|
if hash[:client_id] == client_id
|
18
18
|
hash[key] = value
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def get(client_id)
|
24
|
+
_hash = @clients.detect do |hash|
|
25
|
+
if hash[:client_id] == client_id
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
return _hash
|
31
|
+
end
|
32
|
+
|
23
33
|
def remove(client_id)
|
24
|
-
@clients.
|
34
|
+
@clients.each do |hash|
|
25
35
|
if hash[:client_id] == client_id
|
26
36
|
@clients.delete(hash)
|
27
37
|
GameOverseer::Services.client_disconnected(client_id)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GameOverseer
|
2
2
|
class Console < Gosu::Window
|
3
3
|
include Celluloid
|
4
|
-
# TODO: Use Gosu::Window.record to lower number of objects that need to be
|
4
|
+
# TODO: Use Gosu::Window.record to lower number of objects that need to be drawn
|
5
5
|
|
6
6
|
PENDING_LOG = []
|
7
7
|
def initialize
|
@@ -8,7 +8,7 @@ module GameOverseer
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def message(client_id, string, reliable = false, channel = ChannelManager::CHAT)
|
11
|
-
GameOverseer::ENetServer.instance.
|
11
|
+
GameOverseer::ENetServer.instance.transmit(client_id, string, reliable, channel)
|
12
12
|
GameOverseer::Console.log("MessageManager> #{string}-#{client_id}")
|
13
13
|
end
|
14
14
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GameOverseer
|
2
|
+
module Encryption
|
3
|
+
|
4
|
+
# OpenSSL Public/Private Key Encryption For Initial Handshaking And Authentication Masking.
|
5
|
+
def generate(size = 512)
|
6
|
+
@openssl_keys = OpenSSL::PKey::RSA.new(size)
|
7
|
+
end
|
8
|
+
|
9
|
+
def public_key
|
10
|
+
generate unless defined?(@openssl_keys)
|
11
|
+
@openssl_keys.public_key.to_pem
|
12
|
+
end
|
13
|
+
|
14
|
+
def openssl_keys
|
15
|
+
generate unless defined?(@openssl_keys)
|
16
|
+
@openssl_keys
|
17
|
+
end
|
18
|
+
|
19
|
+
# return encrypted string
|
20
|
+
def encrypt(string)
|
21
|
+
generate unless defined?(@openssl_keys)
|
22
|
+
@openssl_keys.private_encrypt(string)
|
23
|
+
end
|
24
|
+
|
25
|
+
# return decrypted string
|
26
|
+
def decrypt(string)
|
27
|
+
generate unless defined?(@openssl_keys)
|
28
|
+
@openssl_keys.public_decrypt(string)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -42,12 +42,12 @@ module GameOverseer
|
|
42
42
|
@client_manager.remove(client_id)
|
43
43
|
end
|
44
44
|
|
45
|
-
# send
|
46
|
-
def
|
45
|
+
# send message to a specific client
|
46
|
+
def transmit(client_id, message, reliable = false, channel = ChannelManager::CHAT)
|
47
47
|
@server.send_packet(client_id, message, reliable, channel)
|
48
48
|
end
|
49
49
|
|
50
|
-
#
|
50
|
+
# send message to all connected clients
|
51
51
|
def broadcast(message, reliable = false, channel = ChannelManager::CHAT)
|
52
52
|
@server.broadcast_packet(message, reliable, channel)
|
53
53
|
end
|
@@ -61,7 +61,7 @@ module GameOverseer
|
|
61
61
|
data = MultiJson.load(data)
|
62
62
|
process_data(data, client_id)
|
63
63
|
rescue MultiJson::ParseError => e
|
64
|
-
|
64
|
+
transmit(client_id, " \"channel\": \"__UNDEFINED__\", \"mode\": \"__UNDEFINED__\", \"data\": {\"code\": 400, \"message\": \"Invalid JSON received.\"}}", true, ChannelManager::FAULT)
|
65
65
|
GameOverseer::Console.log("Server> Parse error: '#{e.to_s}'. Bad data: '#{data}' received from client.")
|
66
66
|
end
|
67
67
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module GameOverseer
|
2
2
|
class Service
|
3
3
|
attr_accessor :client_id
|
4
|
+
attr_reader :safe_methods
|
4
5
|
|
5
6
|
def self.inherited(subclass)
|
6
|
-
GameOverseer::Console.log "Service> added '#{subclass}' to Services::List."
|
7
7
|
Services.register(subclass)
|
8
|
+
GameOverseer::Console.log "Service> added '#{subclass}' to Services::List."
|
8
9
|
end
|
9
10
|
|
10
11
|
def initialize
|
11
12
|
if defined?(self.setup)
|
12
13
|
@client_id = 0
|
14
|
+
@safe_methods = []
|
13
15
|
setup
|
14
16
|
end
|
15
17
|
end
|
@@ -27,35 +29,60 @@ module GameOverseer
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def version
|
30
|
-
raise "Method 'version' on class '#{self}' not defined, see '#{__FILE__}#version' in GameOverseer source."
|
31
32
|
# Please use the sematic versioning system,
|
32
33
|
# http://semver.org
|
33
34
|
#
|
34
35
|
# e.g.
|
35
36
|
# "1.5.9"
|
36
37
|
# (Major.Minor.Patch)
|
38
|
+
"0.0.0-default"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sets methods that are safe for `data_to_method` to call
|
42
|
+
def set_safe_methods(array)
|
43
|
+
raise "argument must be an array or strings or symbols" unless array.is_a?(Array)
|
44
|
+
@safe_methods = array
|
37
45
|
end
|
38
46
|
|
39
47
|
protected
|
40
48
|
def channel_manager
|
41
|
-
|
42
|
-
@channel_manager
|
49
|
+
ChannelManager.instance
|
43
50
|
end
|
44
51
|
|
45
52
|
def message_manager
|
46
|
-
|
47
|
-
|
53
|
+
MessageManager.instance
|
54
|
+
end
|
55
|
+
|
56
|
+
def client_manager
|
57
|
+
ClientManager.instance
|
48
58
|
end
|
49
59
|
|
50
60
|
def data_to_method(data)
|
51
|
-
|
52
|
-
[self.methods - Class.methods].each do |method|
|
61
|
+
@safe_methods.each do |method|
|
53
62
|
if data['mode'] == method.to_s
|
54
63
|
self.send(data['mode'], data)
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
68
|
+
# Calls Proc immediately then every milliseconds, async.
|
69
|
+
def every(milliseconds, &block)
|
70
|
+
Thread.new do
|
71
|
+
loop do
|
72
|
+
block.call
|
73
|
+
sleep(milliseconds/1000.0)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Calls Proc after milliseconds have passed, async.
|
79
|
+
def after(milliseconds, &block)
|
80
|
+
Thread.new do
|
81
|
+
sleep(milliseconds/1000.0)
|
82
|
+
block.call
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
59
86
|
def log(string, color = Gosu::Color::RED)
|
60
87
|
GameOverseer::Console.log_with_color(string, color)
|
61
88
|
end
|
data/lib/gameoverseer/version.rb
CHANGED
data/lib/gameoverseer.rb
CHANGED
@@ -17,12 +17,11 @@ require_relative "gameoverseer/clients/client_manager"
|
|
17
17
|
|
18
18
|
require_relative "gameoverseer/services/service"
|
19
19
|
require_relative "gameoverseer/services/services"
|
20
|
-
require_relative "gameoverseer/services/internal/services"
|
21
20
|
|
22
21
|
require_relative "gameoverseer/input_handler/input_handler"
|
23
22
|
|
24
23
|
require_relative "gameoverseer/server/renet_server"
|
25
|
-
require_relative "gameoverseer/server/
|
24
|
+
require_relative "gameoverseer/server/encryption"
|
26
25
|
|
27
26
|
# TEMP
|
28
27
|
Thread.abort_on_exception = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gameoverseer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gosu
|
@@ -94,13 +94,8 @@ files:
|
|
94
94
|
- lib/gameoverseer/console/console.rb
|
95
95
|
- lib/gameoverseer/input_handler/input_handler.rb
|
96
96
|
- lib/gameoverseer/messages/message_manager.rb
|
97
|
-
- lib/gameoverseer/server/
|
97
|
+
- lib/gameoverseer/server/encryption.rb
|
98
98
|
- lib/gameoverseer/server/renet_server.rb
|
99
|
-
- lib/gameoverseer/services/internal/broadcast.rb
|
100
|
-
- lib/gameoverseer/services/internal/chat.rb
|
101
|
-
- lib/gameoverseer/services/internal/environment.rb
|
102
|
-
- lib/gameoverseer/services/internal/handshake.rb
|
103
|
-
- lib/gameoverseer/services/internal/services.rb
|
104
99
|
- lib/gameoverseer/services/service.rb
|
105
100
|
- lib/gameoverseer/services/services.rb
|
106
101
|
- lib/gameoverseer/version.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class HandShake
|
3
|
-
|
4
|
-
# OpenSSL Public/Private Key Encryption For Initial Handshaking And Authentication Masking.
|
5
|
-
def self.generate
|
6
|
-
@keys = OpenSSL::PKey::RSA.new 512
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.public_key
|
10
|
-
generate unless defined?(@keys)
|
11
|
-
@keys.public_key.to_pem
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.keys
|
15
|
-
generate unless defined?(@keys)
|
16
|
-
@keys
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class InternalService
|
3
|
-
class Handshake < GameOverseer::Service
|
4
|
-
def setup
|
5
|
-
channel_manager.register_channel('handshake', self)
|
6
|
-
end
|
7
|
-
|
8
|
-
def process(data)
|
9
|
-
data_to_method(data)
|
10
|
-
end
|
11
|
-
|
12
|
-
def extend_hand(data)
|
13
|
-
message = MultiJson.dump({channel: 'handshake', mode: 'public_key', data: {public_key: GameOverseer::HandShake.public_key}})
|
14
|
-
message_manager.message("#{message}", client_id, true, ChannelManager::HANDSHAKE)
|
15
|
-
log("#{self.class}> #{message}.", Gosu::Color::RED)
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def version
|
21
|
-
"0.1.0"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|