• R/O
  • HTTP
  • SSH
  • HTTPS

shogi-server: Commit

shogi-server source


Commit MetaInfo

Revision1ed93aa30496c3bac6b4f5bb810d13f3ead07fd3 (tree)
Time2020-10-09 22:04:18
AuthorDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Log Message

Merge branch 'master' into wdoor-stable

Change Summary

Incremental Difference

--- a/changelog
+++ b/changelog
@@ -1,3 +1,14 @@
1+2020-10-04 Daigo Moriwaki <daigo at debian dot org>
2+
3+ * [shogi-server] Improve timed-up detection.
4+ Previously, the server checked if a game got timed up when a player
5+ in turn sent no message for a certain amount of time mainly defined
6+ by Default_Timeout. If the player sent keep alive frequently, the
7+ timed-up detection could be quite delayed.
8+ This issue has been addressed. The server now checks timed up with
9+ keep alive received as well. Players are notified with TIME_UP not
10+ long before games gets timed up.
11+
112 2018-08-25 Daigo Moriwaki <daigo at debian dot org>
213
314 * [shogi-server] Support a graceful shutdown.
--- 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 = "20180825"
56+Revision = "20201004"
5757
5858 RELOAD_FILES = ["shogi_server/league/floodgate.rb",
5959 "shogi_server/league/persistent.rb",
--- a/shogi_server/command.rb
+++ b/shogi_server/command.rb
@@ -27,13 +27,11 @@ module ShogiServer
2727 #
2828 def Command.factory(str, player, time=Time.now)
2929 cmd = nil
30- case str
31- when ""
32- cmd = KeepAliveCommand.new(str, player)
30+ case str
31+ when "", /^%[^%]/, :timeout
32+ cmd = SpecialCommand.new(str, player)
3333 when /^[\+\-][^%]/
3434 cmd = MoveCommand.new(str, player)
35- when /^%[^%]/, :timeout
36- cmd = SpecialCommand.new(str, player)
3735 when :exception
3836 cmd = ExceptionCommand.new(str, player)
3937 when /^REJECT/
@@ -145,22 +143,6 @@ module ShogiServer
145143 end
146144 end
147145
148- # Application-level protocol for Keep-Alive.
149- # If the server receives an LF, it sends back an LF. Note that the 30 sec
150- # rule (client may not send LF again within 30 sec) is not implemented
151- # yet.
152- #
153- class KeepAliveCommand < Command
154- def initialize(str, player)
155- super
156- end
157-
158- def call
159- @player.write_safe("\n")
160- return :continue
161- end
162- end
163-
164146 # Command of moving a piece.
165147 #
166148 class MoveCommand < Command
@@ -190,7 +172,11 @@ module ShogiServer
190172 end
191173 end
192174
193- # Command like "%TORYO" or :timeout
175+ # Command like "%TORYO", :timeout, or keep alive
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.
194180 #
195181 class SpecialCommand < Command
196182 def initialize(str, player)
@@ -199,6 +185,14 @@ module ShogiServer
199185
200186 def call
201187 rc = :continue
188+
189+ if @str == "" # keep alive
190+ log_debug("received keep alive from #{@player.name}")
191+ @player.write_safe("\n")
192+ # Fall back to :timeout to check the game gets timed up
193+ @str = :timeout
194+ end
195+
202196 if (@player.status == "game")
203197 rc = in_game_status()
204198 elsif ["agree_waiting", "start_waiting"].include?(@player.status)
--- a/shogi_server/player.rb
+++ b/shogi_server/player.rb
@@ -301,7 +301,8 @@ class Player < BasicPlayer
301301 @socket_buffer << str
302302 str = @socket_buffer.shift
303303 end
304- log_debug("%s (%s)" % [str, @socket_buffer.map {|a| String === a ? a.strip : a }.join(",")])
304+ log_debug("dump socket buffer: '%s' (%s)" % [String === str ? str.strip : str,
305+ @socket_buffer.map {|a| String === a ? a.strip : a }.join(",")])
305306
306307 if (csa_1st_str)
307308 str = csa_1st_str
Show on old repository browser