• 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

Revision36b41e7cb23be85e2c766bc3ee2b27bce2c870c3 (tree)
Time2020-12-06 18:48:46
AuthorDaigo Moriwaki <beatles@sgtp...>
CommiterDaigo Moriwaki

Log Message

Merge branch 'master' into wdoor-stable

Change Summary

Incremental Difference

--- a/changelog
+++ b/changelog
@@ -1,3 +1,20 @@
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+ * [shogi-server] Support listening on IPv6 addresses
9+ Thanks to mizar for a patch.
10+ (Closes #40822)
11+ * [shogi-server] Make invalid comments illegal
12+ Some client sent moves with comments in an invalid format like
13+ "+7776FU '* 30 -3334FU +2726FU". Such messages are now deemed
14+ illegal.
15+ Thanks to mizar for a report.
16+ * [shogi-server] Bump up the revision to 20201206
17+
118 2020-10-04 Daigo Moriwaki <daigo at debian dot org>
219
320 * [shogi-server] Improve timed-up detection.
--- a/shogi-server
+++ b/shogi-server
@@ -440,7 +440,7 @@ def main
440440 $players = Set.new
441441
442442 config = {}
443- config[:BindAddress] = "0.0.0.0"
443+ config[:BindAddress] = nil # both IPv4 and IPv6
444444 config[:Port] = port
445445 config[:ServerType] = WEBrick::Daemon if $options["daemon"]
446446 config[:Logger] = $logger
--- a/shogi_server.rb
+++ b/shogi_server.rb
@@ -53,7 +53,7 @@ Default_Max_Moves = 256
5353 Default_Least_Time_Per_Move = 0
5454 One_Time = 10
5555 Login_Time = 300 # time for LOGIN
56-Revision = "20201004"
56+Revision = "20201206"
5757
5858 RELOAD_FILES = ["shogi_server/league/floodgate.rb",
5959 "shogi_server/league/persistent.rb",
--- a/shogi_server/board.rb
+++ b/shogi_server/board.rb
@@ -642,7 +642,7 @@ EOF
642642 # - :max_moves
643643 #
644644 def handle_one_move(str, sente=nil)
645- if (str =~ /^([\+\-])(\d)(\d)(\d)(\d)([A-Z]{2})/)
645+ if (str =~ /^([\+\-])(\d)(\d)(\d)(\d)([A-Z]{2})$/)
646646 sg = $1
647647 x0 = $2.to_i
648648 y0 = $3.to_i
--- 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_board.rb
+++ b/test/TC_board.rb
@@ -998,3 +998,23 @@ class TestSplitMoves < Test::Unit::TestCase
998998 end
999999 end
10001000 end
1001+
1002+
1003+class Test_illegal < Test::Unit::TestCase
1004+ def test_invaild_comment
1005+ b = ShogiServer::Board.new
1006+ b.set_from_str(<<EOM)
1007+P1-KY-KE-GI-KI-OU-KI-GI-KE-KY
1008+P2 * -HI * * * * * -KA *
1009+P3-FU-FU-FU-FU-FU-FU-FU-FU-FU
1010+P4 * * * * * * * * *
1011+P5 * * * * * * * * *
1012+P6 * * * * * * * * *
1013+P7+FU+FU+FU+FU+FU+FU+FU+FU+FU
1014+P8 * +KA * * * * * +HI *
1015+P9+KY+KE+GI+KI+OU+KI+GI+KE+KY
1016+EOM
1017+
1018+ assert_equal(:illegal, b.handle_one_move("+7776FU '* 30 -3334FU +2726FU"))
1019+ end
1020+end
--- a/test/TC_command.rb
+++ b/test/TC_command.rb
@@ -90,7 +90,12 @@ class TestFactoryMethod < Test::Unit::TestCase
9090
9191 def test_keep_alive_command
9292 cmd = ShogiServer::Command.factory("", @p)
93- assert_instance_of(ShogiServer::KeepAliveCommand, cmd)
93+ assert_instance_of(ShogiServer::SpecialCommand, cmd)
94+ end
95+
96+ def test_keep_alive_command_space
97+ cmd = ShogiServer::Command.factory(" ", @p)
98+ assert_instance_of(ShogiServer::SpecialCommand, cmd)
9499 end
95100
96101 def test_move_command
@@ -214,7 +219,7 @@ class TestFactoryMethod < Test::Unit::TestCase
214219 end
215220
216221 def test_space_command
217- cmd = ShogiServer::Command.factory(" ", @p)
222+ cmd = ShogiServer::Command.factory(" ", @p)
218223 assert_instance_of(ShogiServer::SpaceCommand, cmd)
219224 end
220225
@@ -315,20 +320,6 @@ end
315320
316321 #
317322 #
318-class TestKeepAliveCommand < Test::Unit::TestCase
319- def setup
320- @p = MockPlayer.new
321- end
322-
323- def test_call
324- cmd = ShogiServer::KeepAliveCommand.new("", @p)
325- rc = cmd.call
326- assert_equal(:continue, rc)
327- end
328-end
329-
330-#
331-#
332323 class TestMoveCommand < Test::Unit::TestCase
333324 def setup
334325 @p = MockPlayer.new
@@ -350,6 +341,13 @@ class TestMoveCommand < Test::Unit::TestCase
350341 assert_equal("'*comment", @game.log.first)
351342 end
352343
344+ def test_comment_illegal
345+ cmd = ShogiServer::MoveCommand.new("+7776FU 'comment", @p)
346+ rc = cmd.call
347+ assert_equal(:continue, rc)
348+ assert_nil(@game.log.first)
349+ end
350+
353351 def test_x1_return
354352 @game.finish_flag = true
355353 @p.protocol = ShogiServer::LoginCSA::PROTOCOL
@@ -417,6 +415,18 @@ class TestSpecialComand < Test::Unit::TestCase
417415 rc = cmd.call
418416 assert_equal(:continue, rc)
419417 end
418+
419+ def test_keep_alive
420+ cmd = ShogiServer::SpecialCommand.new("", @p)
421+ rc = cmd.call
422+ assert_equal(:continue, rc)
423+ end
424+
425+ def test_keep_alive_space
426+ cmd = ShogiServer::SpecialCommand.new(" ", @p)
427+ rc = cmd.call
428+ assert_equal(:continue, rc)
429+ end
420430 end
421431
422432 #
@@ -822,7 +832,7 @@ class TestSpaceCommand < Test::Unit::TestCase
822832 end
823833
824834 def test_call
825- cmd = ShogiServer::SpaceCommand.new("", @p)
835+ cmd = ShogiServer::SpaceCommand.new(" ", @p)
826836 rc = cmd.call
827837
828838 assert_equal(:continue, rc)
--- a/test/mock_log_message.rb
+++ b/test/mock_log_message.rb
@@ -30,3 +30,7 @@ def log_info(msg)
3030 $logger.info(msg)
3131 end
3232
33+def log_debug(msg)
34+ $logger.info(msg)
35+end
36+