• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

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

shogi-server source


Commit MetaInfo

Révision2df2951afe960f85d98b7b68311d17d231a27251 (tree)
l'heure2015-01-17 18:23:00
AuteurDaigo Moriwaki <daigo@debi...>
CommiterDaigo Moriwaki

Message de Log

[shogi-server] shogi-server, shogi_server/{command,game_result,player}.rb: The change at 2014-10-13 was not worked as expected. Reworked.

A player, attempting to login with the current live player
stalling for more than a day, can forcibly override the current
player.

Change Summary

Modification

--- a/changelog
+++ b/changelog
@@ -1,3 +1,12 @@
1+2015-01-17 Daigo Moriwaki <daigo at debian dot org>
2+
3+ * [shogi-server]
4+ - shogi-server, shogi_server/{command,game_result,player}.rb:
5+ The change at 2014-10-13 was not worked as expected. Reworked.
6+ A player, attempting to login with the current live player
7+ stalling for more than a day, can forcibly override the current
8+ player.
9+
110 2015-01-12 Daigo Moriwaki <daigo at debian dot org>
211
312 * [shogi-server]
--- a/shogi-server
+++ b/shogi-server
@@ -356,8 +356,9 @@ def login_loop(client)
356356 # can override the current player.
357357 if (current_player.password == player.password &&
358358 (current_player.status != "game" ||
359- Time.now - current_player.modifiled_at > ONE_DAY))
360- log_message("user %s login forcely (previously modified at %s)" % [player.name, player.modified_at])
359+ Time.now - current_player.last_command_at > ONE_DAY))
360+ log_message("player %s login forcibly, nudging the former player" % [player.name])
361+ log_message(" the former player was in %s and received the last command at %s" % [current_player.status, current_player.last_command_at])
361362 current_player.kill
362363 else
363364 login.incorrect_duplicated_player(str)
--- a/shogi_server/command.rb
+++ b/shogi_server/command.rb
@@ -121,6 +121,7 @@ module ShogiServer
121121 end
122122
123123 cmd.time = time
124+ player.last_command_at = time
124125 return cmd
125126 end
126127
--- a/shogi_server/game_result.rb
+++ b/shogi_server/game_result.rb
@@ -94,7 +94,7 @@ class GameResult
9494 elsif !p1.sente && p2.sente
9595 @black, @white = p2, p1
9696 else
97- raise "Never reached!"
97+ raise "Never reached!: %s p1: %s p2: %s" % [game.game_id, p1.sente, p2.sente]
9898 end
9999 @players.each do |player|
100100 player.status = "connected"
--- a/shogi_server/player.rb
+++ b/shogi_server/player.rb
@@ -148,6 +148,7 @@ class Player < BasicPlayer
148148 @main_thread = Thread::current
149149 @write_queue = ShogiServer::TimeoutQueue.new(WRITE_THREAD_WATCH_INTERVAL)
150150 @player_logger = nil
151+ @last_command_at = Time.now
151152 start_write_thread
152153 end
153154
@@ -155,6 +156,8 @@ class Player < BasicPlayer
155156 attr_accessor :protocol, :eol, :game, :mytime
156157 attr_accessor :main_thread
157158 attr_reader :socket_buffer
159+ # It is updated whenever a player sends a new command
160+ attr_accessor :last_command_at
158161
159162 def setup_logger(dir)
160163 log_file = File.join(dir, "%s.log" % [simple_player_id])
--- a/test/TC_floodgate_history.rb
+++ b/test/TC_floodgate_history.rb
@@ -18,6 +18,7 @@ end
1818
1919 class MockPlayer < ShogiServer::BasicPlayer
2020 attr_accessor :status
21+ attr_accessor :last_command_at
2122 end
2223
2324 class TestHistory < Test::Unit::TestCase
--- a/test/mock_player.rb
+++ b/test/mock_player.rb
@@ -7,6 +7,7 @@ class MockPlayer < ShogiServer::BasicPlayer
77 attr_accessor :game_name
88 attr_reader :socket_buffer
99 attr_reader :rate
10+ attr_accessor :last_command_at
1011
1112 def initialize
1213 @name = "mock_player"