shogi-server source
Revision | 4f41d115925bb32d24b7624a5e1bc8a4fde66dfd (tree) |
---|---|
Time | 2020-12-06 17:57:36 |
Author | Daigo Moriwaki <beatles@sgtp...> |
Commiter | Daigo Moriwaki |
[shogi-server] Improve timed-up detection (continued)
The server now checks timed up when it receives a-single-space keep
alive messages as well.
(Closes #40821)
@@ -1,3 +1,11 @@ | ||
1 | +2020-12-06 Daigo Moriwaki <daigo at debian dot org> | |
2 | + | |
3 | + * [shogi-server] Improve timed-up detection (continued). | |
4 | + The server now checks timed up when it receives a-single-space keep | |
5 | + alive messages as well. | |
6 | + Thanks to mizar for reports and patches. | |
7 | + (Closes #40821) | |
8 | + | |
1 | 9 | 2020-10-04 Daigo Moriwaki <daigo at debian dot org> |
2 | 10 | |
3 | 11 | * [shogi-server] Improve timed-up detection. |
@@ -28,7 +28,7 @@ module ShogiServer | ||
28 | 28 | def Command.factory(str, player, time=Time.now) |
29 | 29 | cmd = nil |
30 | 30 | case str |
31 | - when "", /^%[^%]/, :timeout | |
31 | + when "", " ", /^%[^%]/, :timeout | |
32 | 32 | cmd = SpecialCommand.new(str, player) |
33 | 33 | when /^[\+\-][^%]/ |
34 | 34 | cmd = MoveCommand.new(str, player) |
@@ -174,9 +174,15 @@ module ShogiServer | ||
174 | 174 | |
175 | 175 | # Command like "%TORYO", :timeout, or keep alive |
176 | 176 | # |
177 | - # Keep Alive is an application-level protocol. Whenever the server receives | |
178 | - # an LF, it sends back an LF. Note that the 30 sec rule (client may not send | |
179 | - # LF again within 30 sec) is not implemented yet. | |
177 | + # Keep Alive is an application-level protocol here. There are two representations: | |
178 | + # 1) LF (empty string) | |
179 | + # The server sends back an LF (empty string). | |
180 | + # Note that the 30 sec rule (client may not send LF again within 30 sec) | |
181 | + # is not implemented yet. | |
182 | + # This is compliant with CSA's protocol in certain situations. | |
183 | + # 2) Space + LF (a single space) | |
184 | + # The sever replies nothing. | |
185 | + # This is an enhancement to CSA's protocol. | |
180 | 186 | # |
181 | 187 | class SpecialCommand < Command |
182 | 188 | def initialize(str, player) |
@@ -186,9 +192,9 @@ module ShogiServer | ||
186 | 192 | def call |
187 | 193 | rc = :continue |
188 | 194 | |
189 | - if @str == "" # keep alive | |
195 | + if @str == "" || @str == " " # keep alive | |
190 | 196 | log_debug("received keep alive from #{@player.name}") |
191 | - @player.write_safe("\n") | |
197 | + @player.write_safe("\n") if @str == "" | |
192 | 198 | # Fall back to :timeout to check the game gets timed up |
193 | 199 | @str = :timeout |
194 | 200 | end |
@@ -93,6 +93,11 @@ class TestFactoryMethod < Test::Unit::TestCase | ||
93 | 93 | assert_instance_of(ShogiServer::SpecialCommand, cmd) |
94 | 94 | end |
95 | 95 | |
96 | + def test_keep_alive_command_space | |
97 | + cmd = ShogiServer::Command.factory(" ", @p) | |
98 | + assert_instance_of(ShogiServer::SpecialCommand, cmd) | |
99 | + end | |
100 | + | |
96 | 101 | def test_move_command |
97 | 102 | cmd = ShogiServer::Command.factory("+7776FU", @p) |
98 | 103 | assert_instance_of(ShogiServer::MoveCommand, cmd) |
@@ -409,6 +414,12 @@ class TestSpecialComand < Test::Unit::TestCase | ||
409 | 414 | rc = cmd.call |
410 | 415 | assert_equal(:continue, rc) |
411 | 416 | end |
417 | + | |
418 | + def test_keep_alive_space | |
419 | + cmd = ShogiServer::SpecialCommand.new(" ", @p) | |
420 | + rc = cmd.call | |
421 | + assert_equal(:continue, rc) | |
422 | + end | |
412 | 423 | end |
413 | 424 | |
414 | 425 | # |