OSDN Git Service

[shogi-server] Write more game results in record files
[shogi-server/shogi-server.git] / shogi_server / game_result.rb
index 81a438a..27902b9 100644 (file)
@@ -1,7 +1,7 @@
 ## $Id$
 
 ## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
-## Copyright (C) 2007-2008 Daigo Moriwaki (daigo at debian dot org)
+## Copyright (C) 2007-2012 Daigo Moriwaki (daigo at debian dot org)
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -26,8 +26,8 @@ module ShogiServer # for a namespace
 #
 class MonitorObserver
   def update(game_result)
-    game_result.game.each_monitor do |monitor|
-      monitor.write_safe("##[MONITOR][%s] %s\n" % [game_result.game.game_id, game_result.result_type])
+    game_result.game.each_monitor do |monitor_handler|
+      monitor_handler.write_safe(game_result.game.game_id, game_result.result_type)
     end
   end
 end
@@ -94,7 +94,7 @@ class GameResult
     elsif !p1.sente && p2.sente
       @black, @white = p2, p1
     else
-      raise "Never reached!"
+      raise "Never reached!: %s p1: %s p2: %s" % [game.game_id, p1.sente, p2.sente]
     end
     @players.each do |player|
       player.status = "connected"
@@ -109,10 +109,10 @@ class GameResult
     add_observer LoggingObserver.new
 
     if League::Floodgate.game_name?(@game.game_name) &&
-       @game.sente.player_id &&
-       @game.gote.player_id &&
-       $options["floodgate-history"]
-      add_observer League::Floodgate::History.factory
+       @game.sente.player_id && @game.gote.player_id
+      path = League::Floodgate.history_file_path(@game.game_name) 
+      history = League::Floodgate::History.factory(path)
+      add_observer history if history
     end
   end
 
@@ -194,7 +194,7 @@ class GameResultTimeoutWin < GameResultWin
   def process
     @winner.write_safe("#TIME_UP\n#WIN\n")
     @loser.write_safe( "#TIME_UP\n#LOSE\n")
-    # no log
+    log("%TIME_UP")  # a player in turn lost
     log_summary
     notify
   end
@@ -337,6 +337,23 @@ class GameResultSennichiteDraw < GameResultDraw
     @players.each do |player|
       player.write_safe("#SENNICHITE\n#DRAW\n")
     end
+    log("%SENNICHITE")
+    log_summary
+    notify
+  end
+end
+
+class GameResultMaxMovesDraw < GameResultDraw
+  def initialize(game, winner, loser)
+    super
+    @log_summary_type = "max_moves"
+    @result_type      = "#MAX_MOVES"
+  end
+
+  def process
+    @players.each do |player|
+      player.write_safe("#MAX_MOVES\n#CENSORED\n")
+    end
     # no log
     log_summary
     notify