+2010-03-07 Daigo Moriwaki <daigo at debian dot org>
+
+ * [shogi-server]
+ - If two sequential moves from a player are identical, the last
+ one will be ignored and a game is in play. This situation might
+ happen with human players, especially on slow network,
+ impatiently sending a move twice.
+
2010-02-27 Daigo Moriwaki <daigo at debian dot org>
* [shogi-server]
if (@player.status == "game")
array_str = @str.split(",")
move = array_str.shift
+ if @player.game.last_move &&
+ @player.game.last_move.split(",").first == move
+ log_warning("Received two sequencial identical moves [#{move}] from #{@player.name}. The last one was ignored.")
+ return :continue
+ end
additional = array_str.shift
comment = nil
if /^'(.*)/ =~ additional
assert("", str)
end
end
+
+class TestTwoSameMoves < CSABaseClient
+ def test_two_same_moves
+ result, result2 = handshake do
+ cmd "+7776FU"
+ cmd2 "-3334FU"
+ cmd2 "-3334FU"
+ cmd "+2726FU"
+ sleep 1
+ end
+ assert(/#ILLEGAL_MOVE/ !~ result)
+ assert(/#ILLEGAL_MOVE/ !~ result2)
+ end
+end
handshake(csa)
cmd2 "%KACHI"
sleep 1
- result1 = read_nonblock(@socket1)
- result2 = read_nonblock(@socket2)
+ result1 = cmd ""
+ result2 = cmd2 ""
+ result1 += read_nonblock(@socket1)
+ result2 += read_nonblock(@socket2)
logout12
assert_match(/#JISHOGI.#LOSE/m, result1)
assert_match(/#JISHOGI.#WIN/m, result2)
handshake(csa)
#cmd2 "%KACHI"
sleep 1
- result1 = read_nonblock(@socket1)
- result2 = read_nonblock(@socket2)
+ result1 = cmd ""
+ result2 = cmd2 ""
+ result1 += read_nonblock(@socket1)
+ result2 += read_nonblock(@socket2)
logout12
assert_match(/#OUTE_SENNICHITE.#LOSE/m, result1)
assert_match(/#OUTE_SENNICHITE.#WIN/m, result2)
handshake(csa)
#cmd2 "%KACHI"
sleep 1
- result1 = read_nonblock(@socket1)
- result2 = read_nonblock(@socket2)
+ result1 = cmd ""
+ result2 = cmd2 ""
+ result1 += read_nonblock(@socket1)
+ result2 += read_nonblock(@socket2)
logout12
assert_match(/#OUTE_SENNICHITE.#WIN/m, result1)
assert_match(/#OUTE_SENNICHITE.#LOSE/m, result2)
handshake(csa)
#cmd2 "%KACHI"
sleep 1
- result1 = read_nonblock(@socket1)
- result2 = read_nonblock(@socket2)
+ result1 = cmd ""
+ result2 = cmd2 ""
+ result1 += read_nonblock(@socket1)
+ result2 += read_nonblock(@socket2)
logout12
assert_match(/#OUTE_SENNICHITE.#LOSE/m, result1)
assert_match(/#OUTE_SENNICHITE.#WIN/m, result2)
result2 = cmd2 "-0064FU"
result1 = cmd "%TORYO"
sleep 1
+ result1 = cmd ""
+ result2 = cmd2 ""
result1 += read_nonblock(@socket1)
result2 += read_nonblock(@socket2)
logout12
cmd2 "-0092FU"
cmd "%TORYO"
sleep 1
- result1 = read_nonblock(@socket1)
- result2 = read_nonblock(@socket2)
+ result1 = cmd ""
+ result2 = cmd2 ""
+ result1 += read_nonblock(@socket1)
+ result2 += read_nonblock(@socket2)
logout12
assert_match(/#LOSE/m, result1)
assert_match(/#WIN/m, result2)
port = 4000
params = {"Host" => "localhost", "Port" => port, "Prompt" => //}
@socket1 = TCPSocket.open("localhost", port)
+ @socket1.sync = true
@socket2 = TCPSocket.open("localhost", port)
+ @socket2.sync = true
end
def teardown
while line = csa_io.gets do
case line
when /^\+\d{4}\w{2}/
+ cmd ""
cmd $&
when /^\-\d{4}\w{2}/
+ cmd2 ""
cmd2 $&
end
end
attr_accessor :started
attr_accessor :game_id
attr_accessor :game_name
+ attr_accessor :last_move
def initialize
@finish_flag = false