• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

Revision4f41d115925bb32d24b7624a5e1bc8a4fde66dfd (tree)
Time2020-12-06 17:57:36
AuthorDaigo Moriwaki <beatles@sgtp...>
CommiterDaigo Moriwaki

Log Message

[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)

Change Summary

Incremental Difference

--- a/changelog
+++ b/changelog
@@ -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+
19 2020-10-04 Daigo Moriwaki <daigo at debian dot org>
210
311 * [shogi-server] Improve timed-up detection.
--- a/shogi_server/command.rb
+++ b/shogi_server/command.rb
@@ -28,7 +28,7 @@ module ShogiServer
2828 def Command.factory(str, player, time=Time.now)
2929 cmd = nil
3030 case str
31- when "", /^%[^%]/, :timeout
31+ when "", " ", /^%[^%]/, :timeout
3232 cmd = SpecialCommand.new(str, player)
3333 when /^[\+\-][^%]/
3434 cmd = MoveCommand.new(str, player)
@@ -174,9 +174,15 @@ module ShogiServer
174174
175175 # Command like "%TORYO", :timeout, or keep alive
176176 #
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.
180186 #
181187 class SpecialCommand < Command
182188 def initialize(str, player)
@@ -186,9 +192,9 @@ module ShogiServer
186192 def call
187193 rc = :continue
188194
189- if @str == "" # keep alive
195+ if @str == "" || @str == " " # keep alive
190196 log_debug("received keep alive from #{@player.name}")
191- @player.write_safe("\n")
197+ @player.write_safe("\n") if @str == ""
192198 # Fall back to :timeout to check the game gets timed up
193199 @str = :timeout
194200 end
--- a/test/TC_command.rb
+++ b/test/TC_command.rb
@@ -93,6 +93,11 @@ class TestFactoryMethod < Test::Unit::TestCase
9393 assert_instance_of(ShogiServer::SpecialCommand, cmd)
9494 end
9595
96+ def test_keep_alive_command_space
97+ cmd = ShogiServer::Command.factory(" ", @p)
98+ assert_instance_of(ShogiServer::SpecialCommand, cmd)
99+ end
100+
96101 def test_move_command
97102 cmd = ShogiServer::Command.factory("+7776FU", @p)
98103 assert_instance_of(ShogiServer::MoveCommand, cmd)
@@ -409,6 +414,12 @@ class TestSpecialComand < Test::Unit::TestCase
409414 rc = cmd.call
410415 assert_equal(:continue, rc)
411416 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
412423 end
413424
414425 #