gameoverseer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +30 -30
- data/README.md +51 -51
- data/gameoverseer.gemspec +23 -23
- data/lib/gameoverseer/channels/channel_manager.rb +49 -49
- data/lib/gameoverseer/clients/client_manager.rb +66 -66
- data/lib/gameoverseer/console/console.rb +206 -206
- 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 +42 -42
- data/lib/gameoverseer/packet_handler/packet_handler.rb +35 -35
- data/lib/gameoverseer/server/renet_server.rb +126 -126
- data/lib/gameoverseer/services/service.rb +111 -111
- data/lib/gameoverseer/services/services.rb +38 -38
- data/lib/gameoverseer/version.rb +4 -4
- data/lib/gameoverseer.rb +59 -59
- data/license.md +9 -9
- data/test/test_helper.rb +1 -1
- data/test-clients/test-client-gamma.rb +62 -62
- metadata +17 -6
@@ -1,206 +1,206 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class Console < Gosu::Window
|
3
|
-
# TODO: Use Gosu::Window.record to lower number of objects that need to be drawn
|
4
|
-
|
5
|
-
PENDING_LOG = []
|
6
|
-
def initialize
|
7
|
-
GameOverseer::Console.instance = self
|
8
|
-
super(720, 480, false)
|
9
|
-
$window = self
|
10
|
-
$window.caption = "GameOverseer Console"
|
11
|
-
$window.text_input = Gosu::TextInput.new
|
12
|
-
|
13
|
-
@default_text_instance = Gosu::Font.new($window, 'Consolas', 18)
|
14
|
-
@messages = []
|
15
|
-
setup_ui
|
16
|
-
end
|
17
|
-
|
18
|
-
def needs_cursor?
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
def draw
|
23
|
-
@ui_image.draw(0,0,0) if defined?(@ui_image)
|
24
|
-
end
|
25
|
-
|
26
|
-
def update
|
27
|
-
update_ui
|
28
|
-
@ui_image = $window.record(720, 480) {draw_ui}
|
29
|
-
end
|
30
|
-
|
31
|
-
def setup_ui
|
32
|
-
@current_text = text_instance
|
33
|
-
@current_text_x = 4
|
34
|
-
|
35
|
-
# Required first message
|
36
|
-
@messages << {
|
37
|
-
text: '',
|
38
|
-
instance: text_instance,
|
39
|
-
color: Gosu::Color::WHITE,
|
40
|
-
x: 4,
|
41
|
-
y: 480-26-18,
|
42
|
-
z: 1
|
43
|
-
}
|
44
|
-
|
45
|
-
submit_text("#{Time.now.strftime('%c')}", false)
|
46
|
-
end
|
47
|
-
|
48
|
-
def draw_ui
|
49
|
-
draw_rect(0,0, 720, 26, Gosu::Color.rgb(200, 75, 25))
|
50
|
-
draw_rect(0,454, 720, 480, Gosu::Color::WHITE)
|
51
|
-
text_instance.draw("GameOverSeer Console. GameOverseer version #{GameOverseer::VERSION} #{GameOverseer::RELEASE_NAME} #{@messages.count}", 4, 4, 3)
|
52
|
-
@current_text.draw("#{$window.text_input.text}", @current_text_x, 458, 3, 1, 1, Gosu::Color::BLACK)
|
53
|
-
draw_rect(@caret+@current_text_x, 456, 2.0+@caret+@current_text_x, 474, Gosu::Color::BLUE, 4) if defined?(@caret) && @render_caret
|
54
|
-
|
55
|
-
@messages.each do |message|
|
56
|
-
message[:instance].draw(message[:text],message[:x],message[:y],message[:z], 1, 1, message[:color])
|
57
|
-
p message[:color] unless message[:color] == Gosu::Color::WHITE
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def update_ui
|
62
|
-
PENDING_LOG.each do |log_message|
|
63
|
-
submit_text(log_message, false) if log_message.strip.length > 0
|
64
|
-
PENDING_LOG.delete(log_message)
|
65
|
-
end
|
66
|
-
|
67
|
-
@caret = @current_text.text_width($window.text_input.text[0...$window.text_input.caret_pos])
|
68
|
-
|
69
|
-
@caret_tick = 0 unless defined?(@caret_tick)
|
70
|
-
@render_caret = true if @caret_tick < 15
|
71
|
-
@render_caret = false if @caret_tick > 30
|
72
|
-
|
73
|
-
@caret_tick = 0 unless @caret_tick < 45
|
74
|
-
@caret_tick+=1
|
75
|
-
|
76
|
-
value = @current_text.text_width($window.text_input.text)+@current_text_x
|
77
|
-
if value >= 720
|
78
|
-
@current_text_x-=4
|
79
|
-
elsif value <= 715
|
80
|
-
@current_text_x+=4 unless @current_text_x >= 4
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def text_instance
|
85
|
-
@default_text_instance
|
86
|
-
end
|
87
|
-
|
88
|
-
def draw_rect(x1,y1, x2,y2, color = Gosu::Color::GRAY, z = 2)
|
89
|
-
$window.draw_quad(x1, y1, color, x2, y1, color, x1, y2, color, x2, y2, color, z)
|
90
|
-
end
|
91
|
-
|
92
|
-
def scroll(direction)
|
93
|
-
case direction
|
94
|
-
when :down
|
95
|
-
if @messages.last[:y] >= 480 - 26 - 18
|
96
|
-
@messages.each do |message|
|
97
|
-
message[:y]-=18
|
98
|
-
end
|
99
|
-
end
|
100
|
-
when :up
|
101
|
-
if @messages.first[:y] <= 26#<= 480 - 26 - 32
|
102
|
-
@messages.each do |message|
|
103
|
-
message[:y]+=18
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def clean_messages(count)
|
110
|
-
if @messages.count >= count
|
111
|
-
@messages.delete(@messages.first)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def button_up(id)
|
116
|
-
case id
|
117
|
-
when 41 # Escape
|
118
|
-
# Quit?
|
119
|
-
when 40 # Enter
|
120
|
-
submit_text($window.text_input.text)
|
121
|
-
when 88 # Numpad Enter
|
122
|
-
submit_text($window.text_input.text)
|
123
|
-
when 259 # Mouse wheel
|
124
|
-
scroll(:up)
|
125
|
-
when 260 # Mouse wheel
|
126
|
-
scroll(:down)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.instance
|
131
|
-
@instance
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.instance=_instance
|
135
|
-
@instance = _instance
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.log(string)
|
139
|
-
self.log_it(string) if string.strip.length > 0
|
140
|
-
begin
|
141
|
-
GameOverseer::Console.instance.submit_text(string, false)
|
142
|
-
rescue NoMethodError
|
143
|
-
self.defer_log(string)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def self.log_with_color(string, color = Gosu::Color::WHITE)
|
148
|
-
self.log_it(string) if string.strip.length > 0
|
149
|
-
GameOverseer::Console.instance.submit_text(string, false, color)
|
150
|
-
end
|
151
|
-
|
152
|
-
def self.defer_log(string)
|
153
|
-
PENDING_LOG << string
|
154
|
-
end
|
155
|
-
|
156
|
-
def self.log_it(string)
|
157
|
-
puts string
|
158
|
-
retry_limit = 0
|
159
|
-
begin
|
160
|
-
@log_file = File.open("#{Dir.pwd}/logs/log-#{Time.now.strftime('%B-%d-%Y')}.txt", 'a+') unless defined? @log_file
|
161
|
-
@log_file.write "[#{Time.now.strftime('%c')}] #{string}\n"
|
162
|
-
rescue Errno::ENOENT
|
163
|
-
Dir.mkdir("#{Dir.pwd}/logs") unless File.exist?("#{Dir.pwd}/logs") && File.directory?("#{Dir.pwd}/logs")
|
164
|
-
retry_limit+=1
|
165
|
-
retry unless retry_limit >= 2
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
protected
|
170
|
-
def submit_text(text, from_console = true, color = Gosu::Color::WHITE)
|
171
|
-
if text.strip.length > 0
|
172
|
-
clean_messages(300)
|
173
|
-
text = "Console> #{text}" if from_console
|
174
|
-
GameOverseer::Console.log_it(text)
|
175
|
-
if text.length > 83
|
176
|
-
temp_text = text[0..83]
|
177
|
-
@messages.each do |message|
|
178
|
-
message[:y]-=18
|
179
|
-
end
|
180
|
-
@messages << {
|
181
|
-
text: temp_text,
|
182
|
-
instance: text_instance,
|
183
|
-
color: color,
|
184
|
-
x: 4,
|
185
|
-
y: @messages.last[:y] + 18,
|
186
|
-
z: 1
|
187
|
-
}
|
188
|
-
submit_text(text[83..text.length], false)
|
189
|
-
else
|
190
|
-
@messages.each do |message|
|
191
|
-
message[:y]-=18
|
192
|
-
end
|
193
|
-
@messages << {
|
194
|
-
text: text,
|
195
|
-
instance: text_instance,
|
196
|
-
color: color,
|
197
|
-
x: 4,
|
198
|
-
y: @messages.last[:y] + 18,
|
199
|
-
z: 1
|
200
|
-
}
|
201
|
-
end
|
202
|
-
$window.text_input = Gosu::TextInput.new if from_console
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
class Console < Gosu::Window
|
3
|
+
# TODO: Use Gosu::Window.record to lower number of objects that need to be drawn
|
4
|
+
|
5
|
+
PENDING_LOG = []
|
6
|
+
def initialize
|
7
|
+
GameOverseer::Console.instance = self
|
8
|
+
super(720, 480, false)
|
9
|
+
$window = self
|
10
|
+
$window.caption = "GameOverseer Console"
|
11
|
+
$window.text_input = Gosu::TextInput.new
|
12
|
+
|
13
|
+
@default_text_instance = Gosu::Font.new($window, 'Consolas', 18)
|
14
|
+
@messages = []
|
15
|
+
setup_ui
|
16
|
+
end
|
17
|
+
|
18
|
+
def needs_cursor?
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def draw
|
23
|
+
@ui_image.draw(0,0,0) if defined?(@ui_image)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
update_ui
|
28
|
+
@ui_image = $window.record(720, 480) {draw_ui}
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup_ui
|
32
|
+
@current_text = text_instance
|
33
|
+
@current_text_x = 4
|
34
|
+
|
35
|
+
# Required first message
|
36
|
+
@messages << {
|
37
|
+
text: '',
|
38
|
+
instance: text_instance,
|
39
|
+
color: Gosu::Color::WHITE,
|
40
|
+
x: 4,
|
41
|
+
y: 480-26-18,
|
42
|
+
z: 1
|
43
|
+
}
|
44
|
+
|
45
|
+
submit_text("#{Time.now.strftime('%c')}", false)
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw_ui
|
49
|
+
draw_rect(0,0, 720, 26, Gosu::Color.rgb(200, 75, 25))
|
50
|
+
draw_rect(0,454, 720, 480, Gosu::Color::WHITE)
|
51
|
+
text_instance.draw("GameOverSeer Console. GameOverseer version #{GameOverseer::VERSION} #{GameOverseer::RELEASE_NAME} #{@messages.count}", 4, 4, 3)
|
52
|
+
@current_text.draw("#{$window.text_input.text}", @current_text_x, 458, 3, 1, 1, Gosu::Color::BLACK)
|
53
|
+
draw_rect(@caret+@current_text_x, 456, 2.0+@caret+@current_text_x, 474, Gosu::Color::BLUE, 4) if defined?(@caret) && @render_caret
|
54
|
+
|
55
|
+
@messages.each do |message|
|
56
|
+
message[:instance].draw(message[:text],message[:x],message[:y],message[:z], 1, 1, message[:color])
|
57
|
+
p message[:color] unless message[:color] == Gosu::Color::WHITE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def update_ui
|
62
|
+
PENDING_LOG.each do |log_message|
|
63
|
+
submit_text(log_message, false) if log_message.strip.length > 0
|
64
|
+
PENDING_LOG.delete(log_message)
|
65
|
+
end
|
66
|
+
|
67
|
+
@caret = @current_text.text_width($window.text_input.text[0...$window.text_input.caret_pos])
|
68
|
+
|
69
|
+
@caret_tick = 0 unless defined?(@caret_tick)
|
70
|
+
@render_caret = true if @caret_tick < 15
|
71
|
+
@render_caret = false if @caret_tick > 30
|
72
|
+
|
73
|
+
@caret_tick = 0 unless @caret_tick < 45
|
74
|
+
@caret_tick+=1
|
75
|
+
|
76
|
+
value = @current_text.text_width($window.text_input.text)+@current_text_x
|
77
|
+
if value >= 720
|
78
|
+
@current_text_x-=4
|
79
|
+
elsif value <= 715
|
80
|
+
@current_text_x+=4 unless @current_text_x >= 4
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def text_instance
|
85
|
+
@default_text_instance
|
86
|
+
end
|
87
|
+
|
88
|
+
def draw_rect(x1,y1, x2,y2, color = Gosu::Color::GRAY, z = 2)
|
89
|
+
$window.draw_quad(x1, y1, color, x2, y1, color, x1, y2, color, x2, y2, color, z)
|
90
|
+
end
|
91
|
+
|
92
|
+
def scroll(direction)
|
93
|
+
case direction
|
94
|
+
when :down
|
95
|
+
if @messages.last[:y] >= 480 - 26 - 18
|
96
|
+
@messages.each do |message|
|
97
|
+
message[:y]-=18
|
98
|
+
end
|
99
|
+
end
|
100
|
+
when :up
|
101
|
+
if @messages.first[:y] <= 26#<= 480 - 26 - 32
|
102
|
+
@messages.each do |message|
|
103
|
+
message[:y]+=18
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def clean_messages(count)
|
110
|
+
if @messages.count >= count
|
111
|
+
@messages.delete(@messages.first)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def button_up(id)
|
116
|
+
case id
|
117
|
+
when 41 # Escape
|
118
|
+
# Quit?
|
119
|
+
when 40 # Enter
|
120
|
+
submit_text($window.text_input.text)
|
121
|
+
when 88 # Numpad Enter
|
122
|
+
submit_text($window.text_input.text)
|
123
|
+
when 259 # Mouse wheel
|
124
|
+
scroll(:up)
|
125
|
+
when 260 # Mouse wheel
|
126
|
+
scroll(:down)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.instance
|
131
|
+
@instance
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.instance=_instance
|
135
|
+
@instance = _instance
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.log(string)
|
139
|
+
self.log_it(string) if string.strip.length > 0
|
140
|
+
begin
|
141
|
+
GameOverseer::Console.instance.submit_text(string, false)
|
142
|
+
rescue NoMethodError
|
143
|
+
self.defer_log(string)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.log_with_color(string, color = Gosu::Color::WHITE)
|
148
|
+
self.log_it(string) if string.strip.length > 0
|
149
|
+
GameOverseer::Console.instance.submit_text(string, false, color)
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.defer_log(string)
|
153
|
+
PENDING_LOG << string
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.log_it(string)
|
157
|
+
puts string
|
158
|
+
retry_limit = 0
|
159
|
+
begin
|
160
|
+
@log_file = File.open("#{Dir.pwd}/logs/log-#{Time.now.strftime('%B-%d-%Y')}.txt", 'a+') unless defined? @log_file
|
161
|
+
@log_file.write "[#{Time.now.strftime('%c')}] #{string}\n"
|
162
|
+
rescue Errno::ENOENT
|
163
|
+
Dir.mkdir("#{Dir.pwd}/logs") unless File.exist?("#{Dir.pwd}/logs") && File.directory?("#{Dir.pwd}/logs")
|
164
|
+
retry_limit+=1
|
165
|
+
retry unless retry_limit >= 2
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
protected
|
170
|
+
def submit_text(text, from_console = true, color = Gosu::Color::WHITE)
|
171
|
+
if text.strip.length > 0
|
172
|
+
clean_messages(300)
|
173
|
+
text = "Console> #{text}" if from_console
|
174
|
+
GameOverseer::Console.log_it(text)
|
175
|
+
if text.length > 83
|
176
|
+
temp_text = text[0..83]
|
177
|
+
@messages.each do |message|
|
178
|
+
message[:y]-=18
|
179
|
+
end
|
180
|
+
@messages << {
|
181
|
+
text: temp_text,
|
182
|
+
instance: text_instance,
|
183
|
+
color: color,
|
184
|
+
x: 4,
|
185
|
+
y: @messages.last[:y] + 18,
|
186
|
+
z: 1
|
187
|
+
}
|
188
|
+
submit_text(text[83..text.length], false)
|
189
|
+
else
|
190
|
+
@messages.each do |message|
|
191
|
+
message[:y]-=18
|
192
|
+
end
|
193
|
+
@messages << {
|
194
|
+
text: text,
|
195
|
+
instance: text_instance,
|
196
|
+
color: color,
|
197
|
+
x: 4,
|
198
|
+
y: @messages.last[:y] + 18,
|
199
|
+
z: 1
|
200
|
+
}
|
201
|
+
end
|
202
|
+
$window.text_input = Gosu::TextInput.new if from_console
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class EncryptionHandler
|
3
|
-
|
4
|
-
def initialize(key_size: 128, keypair_size: 2048)
|
5
|
-
EncryptionHandler.instance = self
|
6
|
-
generate_server_keypair(keypair_size)
|
7
|
-
end
|
8
|
-
|
9
|
-
def generate_server_keypair(keypair_size)
|
10
|
-
@server_keypair = OpenSSL::PKey::RSA.generate(keypair_size)
|
11
|
-
end
|
12
|
-
|
13
|
-
def encrypt_keypair(client_id, string)
|
14
|
-
end
|
15
|
-
|
16
|
-
def decrypt_keypair(string)
|
17
|
-
end
|
18
|
-
|
19
|
-
def encrypt(client_id, string)
|
20
|
-
end
|
21
|
-
|
22
|
-
def decrypt(client_id, string)
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_client_keypair(client_id, public_key_pem)
|
26
|
-
end
|
27
|
-
|
28
|
-
def set_client_key(client_id)
|
29
|
-
ClientManager.instance.update(client_id, '_aes_key', 'In progress, not ready.')
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.instance
|
33
|
-
@instance
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.instance=(_instance)
|
37
|
-
@instance = _instance
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
class EncryptionHandler
|
3
|
+
|
4
|
+
def initialize(key_size: 128, keypair_size: 2048)
|
5
|
+
EncryptionHandler.instance = self
|
6
|
+
generate_server_keypair(keypair_size)
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_server_keypair(keypair_size)
|
10
|
+
@server_keypair = OpenSSL::PKey::RSA.generate(keypair_size)
|
11
|
+
end
|
12
|
+
|
13
|
+
def encrypt_keypair(client_id, string)
|
14
|
+
end
|
15
|
+
|
16
|
+
def decrypt_keypair(string)
|
17
|
+
end
|
18
|
+
|
19
|
+
def encrypt(client_id, string)
|
20
|
+
end
|
21
|
+
|
22
|
+
def decrypt(client_id, string)
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_client_keypair(client_id, public_key_pem)
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_client_key(client_id)
|
29
|
+
ClientManager.instance.update(client_id, '_aes_key', 'In progress, not ready.')
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.instance
|
33
|
+
@instance
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.instance=(_instance)
|
37
|
+
@instance = _instance
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
class InputHandler
|
3
|
-
|
4
|
-
# @param client_id [Integer]
|
5
|
-
# @param data [Hash]
|
6
|
-
def self.process_data(client_id, data)
|
7
|
-
@data = data
|
8
|
-
@client_id = client_id
|
9
|
-
forward_to_channel_manager if data_valid?
|
10
|
-
end
|
11
|
-
|
12
|
-
# Checks if hash contains 'channel' and 'mode'
|
13
|
-
# @return [Boolean]
|
14
|
-
def self.data_valid?
|
15
|
-
if @data["channel"]
|
16
|
-
if @data["mode"]
|
17
|
-
true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Sends data and client_id to {ChannelManager}
|
23
|
-
def self.forward_to_channel_manager
|
24
|
-
count = 0
|
25
|
-
begin
|
26
|
-
channel_manager = GameOverseer::ChannelManager.instance
|
27
|
-
channel_manager.send_to_service(@client_id, @data)
|
28
|
-
rescue NoMethodError => e
|
29
|
-
GameOverseer::Console.log("InputHandler> #{e.to_s}")
|
30
|
-
raise if count >=2
|
31
|
-
count+=1
|
32
|
-
retry unless count >= 2
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
class InputHandler
|
3
|
+
|
4
|
+
# @param client_id [Integer]
|
5
|
+
# @param data [Hash]
|
6
|
+
def self.process_data(client_id, data)
|
7
|
+
@data = data
|
8
|
+
@client_id = client_id
|
9
|
+
forward_to_channel_manager if data_valid?
|
10
|
+
end
|
11
|
+
|
12
|
+
# Checks if hash contains 'channel' and 'mode'
|
13
|
+
# @return [Boolean]
|
14
|
+
def self.data_valid?
|
15
|
+
if @data["channel"]
|
16
|
+
if @data["mode"]
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Sends data and client_id to {ChannelManager}
|
23
|
+
def self.forward_to_channel_manager
|
24
|
+
count = 0
|
25
|
+
begin
|
26
|
+
channel_manager = GameOverseer::ChannelManager.instance
|
27
|
+
channel_manager.send_to_service(@client_id, @data)
|
28
|
+
rescue NoMethodError => e
|
29
|
+
GameOverseer::Console.log("InputHandler> #{e.to_s}")
|
30
|
+
raise if count >=2
|
31
|
+
count+=1
|
32
|
+
retry unless count >= 2
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
module GameOverseer
|
2
|
-
|
3
|
-
# Handles sending messages to clients on behalf of services
|
4
|
-
class MessageManager
|
5
|
-
MESSAGES = []
|
6
|
-
BROADCASTS = []
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
MessageManager.instance = self
|
10
|
-
end
|
11
|
-
|
12
|
-
# Send a message to a specific client
|
13
|
-
# @param client_id [Integer] ID of client
|
14
|
-
# @param string [String] message to send
|
15
|
-
# @param reliable [Boolean] whether or not packet delivery is reliable
|
16
|
-
# @param channel [Integer] What channel to send on
|
17
|
-
def message(client_id, string, reliable = false, channel = ChannelManager::CHAT)
|
18
|
-
GameOverseer::ENetServer.instance.transmit(client_id, string, reliable, channel)
|
19
|
-
GameOverseer::Console.log("MessageManager> #{string}-#{client_id}")
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
# Send a message to all connected clients
|
24
|
-
# @param string [String] message to send
|
25
|
-
# @param reliable [Boolean] whether or not packet delivery is reliable
|
26
|
-
# @param channel [Integer] What channel to send on
|
27
|
-
def broadcast(string, reliable = false, channel = ChannelManager::CHAT)
|
28
|
-
GameOverseer::ENetServer.instance.broadcast(string, reliable, channel)
|
29
|
-
GameOverseer::Console.log("MessageManager> #{string}-#{channel}")
|
30
|
-
end
|
31
|
-
|
32
|
-
# @return [MessageManager]
|
33
|
-
def self.instance
|
34
|
-
@instance
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param _instance [MessageManager]
|
38
|
-
def self.instance=_instance
|
39
|
-
@instance = _instance
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
module GameOverseer
|
2
|
+
|
3
|
+
# Handles sending messages to clients on behalf of services
|
4
|
+
class MessageManager
|
5
|
+
MESSAGES = []
|
6
|
+
BROADCASTS = []
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
MessageManager.instance = self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Send a message to a specific client
|
13
|
+
# @param client_id [Integer] ID of client
|
14
|
+
# @param string [String] message to send
|
15
|
+
# @param reliable [Boolean] whether or not packet delivery is reliable
|
16
|
+
# @param channel [Integer] What channel to send on
|
17
|
+
def message(client_id, string, reliable = false, channel = ChannelManager::CHAT)
|
18
|
+
GameOverseer::ENetServer.instance.transmit(client_id, string, reliable, channel)
|
19
|
+
GameOverseer::Console.log("MessageManager> #{string}-#{client_id}")
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Send a message to all connected clients
|
24
|
+
# @param string [String] message to send
|
25
|
+
# @param reliable [Boolean] whether or not packet delivery is reliable
|
26
|
+
# @param channel [Integer] What channel to send on
|
27
|
+
def broadcast(string, reliable = false, channel = ChannelManager::CHAT)
|
28
|
+
GameOverseer::ENetServer.instance.broadcast(string, reliable, channel)
|
29
|
+
GameOverseer::Console.log("MessageManager> #{string}-#{channel}")
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [MessageManager]
|
33
|
+
def self.instance
|
34
|
+
@instance
|
35
|
+
end
|
36
|
+
|
37
|
+
# @param _instance [MessageManager]
|
38
|
+
def self.instance=_instance
|
39
|
+
@instance = _instance
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|