shogi-server source
Revisão | 2df2951afe960f85d98b7b68311d17d231a27251 (tree) |
---|---|
Hora | 2015-01-17 18:23:00 |
Autor | Daigo Moriwaki <daigo@debi...> |
Commiter | Daigo Moriwaki |
[shogi-server] shogi-server, shogi_server/{command,game_result,player}.rb: The change at 2014-10-13 was not worked as expected. Reworked.
@@ -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 | + | |
1 | 10 | 2015-01-12 Daigo Moriwaki <daigo at debian dot org> |
2 | 11 | |
3 | 12 | * [shogi-server] |
@@ -356,8 +356,9 @@ def login_loop(client) | ||
356 | 356 | # can override the current player. |
357 | 357 | if (current_player.password == player.password && |
358 | 358 | (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]) | |
361 | 362 | current_player.kill |
362 | 363 | else |
363 | 364 | login.incorrect_duplicated_player(str) |
@@ -121,6 +121,7 @@ module ShogiServer | ||
121 | 121 | end |
122 | 122 | |
123 | 123 | cmd.time = time |
124 | + player.last_command_at = time | |
124 | 125 | return cmd |
125 | 126 | end |
126 | 127 |
@@ -94,7 +94,7 @@ class GameResult | ||
94 | 94 | elsif !p1.sente && p2.sente |
95 | 95 | @black, @white = p2, p1 |
96 | 96 | else |
97 | - raise "Never reached!" | |
97 | + raise "Never reached!: %s p1: %s p2: %s" % [game.game_id, p1.sente, p2.sente] | |
98 | 98 | end |
99 | 99 | @players.each do |player| |
100 | 100 | player.status = "connected" |
@@ -148,6 +148,7 @@ class Player < BasicPlayer | ||
148 | 148 | @main_thread = Thread::current |
149 | 149 | @write_queue = ShogiServer::TimeoutQueue.new(WRITE_THREAD_WATCH_INTERVAL) |
150 | 150 | @player_logger = nil |
151 | + @last_command_at = Time.now | |
151 | 152 | start_write_thread |
152 | 153 | end |
153 | 154 |
@@ -155,6 +156,8 @@ class Player < BasicPlayer | ||
155 | 156 | attr_accessor :protocol, :eol, :game, :mytime |
156 | 157 | attr_accessor :main_thread |
157 | 158 | attr_reader :socket_buffer |
159 | + # It is updated whenever a player sends a new command | |
160 | + attr_accessor :last_command_at | |
158 | 161 | |
159 | 162 | def setup_logger(dir) |
160 | 163 | log_file = File.join(dir, "%s.log" % [simple_player_id]) |
@@ -18,6 +18,7 @@ end | ||
18 | 18 | |
19 | 19 | class MockPlayer < ShogiServer::BasicPlayer |
20 | 20 | attr_accessor :status |
21 | + attr_accessor :last_command_at | |
21 | 22 | end |
22 | 23 | |
23 | 24 | class TestHistory < Test::Unit::TestCase |
@@ -7,6 +7,7 @@ class MockPlayer < ShogiServer::BasicPlayer | ||
7 | 7 | attr_accessor :game_name |
8 | 8 | attr_reader :socket_buffer |
9 | 9 | attr_reader :rate |
10 | + attr_accessor :last_command_at | |
10 | 11 | |
11 | 12 | def initialize |
12 | 13 | @name = "mock_player" |