@players.each do |name, player|
if ((player.status == status) &&
(player.game_name == game_name) &&
- ((player.sente == nil) || (player.sente == sente)) &&
+ ((sente == nil) || (player.sente == nil) || (player.sente == sente)) &&
((searcher == nil) || (player != searcher)))
return player
end
write_safe(sprintf("##[LOGIN] +OK %s\n", @protocol))
else
log_message(sprintf("user %s run in CSA mode", @name))
- csa_1st_str = "%%GAME #{Default_Game_Name} *"
+ if (good_game_name?(@password))
+ csa_1st_str = "%%GAME #{@password} *"
+ else
+ csa_1st_str = "%%GAME #{Default_Game_Name} *"
+ end
end
while (csa_1st_str || (str = @socket.gets_safe(Default_Timeout)))
end
str.chomp! if (str.class == String)
case str
- when /^[\+\-%][^%]/, :timeout
+ when /^[\+\-][^%]/
+ if (@status == "game")
+ array_str = str.split(",")
+ move = array_str.shift
+ additional = array_str.shift
+ if /^'(.*)/ =~ additional
+ comment = array_str.unshift("'*#{$1}")
+ end
+ s = @game.handle_one_move(move, self)
+ @game.fh.print("#{comment}\n") if comment
+ return if (s && @protocol == "CSA")
+ end
+ when /^%[^%]/, :timeout
if (@status == "game")
s = @game.handle_one_move(str, self)
return if (s && @protocol == "CSA")
when /^%%HELP/
write_help
when /^%%GAME\s*$/
- @status = "connected"
- @game_name = ""
+ if ((@status == "connected") || (@status == "game_waiting"))
+ @status = "connected"
+ @game_name = ""
+ else
+ write_safe(sprintf("##[ERROR] you are in %s status. GAME is valid in connected or game_waiting status\n", @status))
+ end
when /^%%(GAME|CHALLENGE)\s+(\S+)\s+([\+\-\*])\s*$/
command_name = $1
game_name = $2
message = $1
LEAGUE.players.each do |name, player|
if (player.protocol != "CSA")
- s = player.write_safe(sprintf("##[CHAT][%s] %s\n", @name, message))
- player.status = "zombie" if (! s)
+ player.write_safe(sprintf("##[CHAT][%s] %s\n", @name, message))
end
end
when /^%%LIST/
t = Least_Time_Per_Move if (t < Least_Time_Per_Move)
move_status = nil
- if ((@current_player.mytime - t <= 0) && (@total_time > 0))
+ if ((@current_player.mytime - t <= -@byoyomi) && ((@total_time > 0) || (@byoyomi > 0)))
status = :timeout
elsif (str == :timeout)
return false # time isn't expired. players aren't swapped. continue game
else
+ @current_player.mytime = @current_player.mytime - t
+ if (@current_player.mytime < 0)
+ @current_player.mytime = 0
+ end
+
# begin
move_status = @board.handle_one_move(str)
# rescue
# log_error("handle_one_move raise exception for #{str}")
# move_status = :illegal
# end
+
if ((move_status == :illegal) || (move_status == :uchifuzme) || (move_status == :oute_kaihimore))
@fh.printf("'ILLEGAL_MOVE(%s)\n", str)
else
@last_move = sprintf("%s,T%d", str, t)
@current_turn = @current_turn + 1
end
+
@monitors.each do |monitor|
monitor.write_safe(show.gsub(/^/, "##[MONITOR][#{@id}] "))
monitor.write_safe(sprintf("##[MONITOR][%s] +OK\n", @id))
end
end
- if (@current_player.mytime - t < @byoyomi)
- @current_player.mytime = @byoyomi
- else
- @current_player.mytime = @current_player.mytime - t
- end
-
if (@next_player.status != "game") # rival is logout or disconnected
abnormal_win()
elsif (status == :timeout)