X-Git-Url: http://git.sourceforge.jp/view?p=shogi-server%2Fshogi-server.git;a=blobdiff_plain;f=shogi-server;h=049c45faa9c3e9c2c07530d2538f71630848d628;hp=1f5a9f54018b8b82a031fa7da7ef2e788cb1753f;hb=3bb39d8bb22382c0c4a79f251268d6a0c11f0ac3;hpb=a21a12b4c47b3042be1be4927a68e1aee2bca781 diff --git a/shogi-server b/shogi-server index 1f5a9f5..049c45f 100755 --- a/shogi-server +++ b/shogi-server @@ -18,6 +18,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +TOP_DIR = File.expand_path(File.dirname(__FILE__)) $:.unshift File.dirname(__FILE__) require 'shogi_server' @@ -57,6 +58,9 @@ OPTIONS --player-log-dir dir log network messages for each player. Log files will be put in the dir. + --floodgate_history + file name to record Floodgate game history + default: './floodgate_history.yaml' LICENSE GPL versoin 2 or later @@ -79,6 +83,9 @@ end def log_message(str) $logger.info(str) end +def log_info(str) + log_message(str) +end def log_warning(str) $logger.warn(str) @@ -92,9 +99,10 @@ end def parse_command_line options = Hash::new parser = GetoptLong.new( - ["--daemon", GetoptLong::REQUIRED_ARGUMENT], - ["--pid-file", GetoptLong::REQUIRED_ARGUMENT], - ["--player-log-dir", GetoptLong::REQUIRED_ARGUMENT]) + ["--daemon", GetoptLong::REQUIRED_ARGUMENT], + ["--pid-file", GetoptLong::REQUIRED_ARGUMENT], + ["--player-log-dir", GetoptLong::REQUIRED_ARGUMENT], + ["--floodgate-history", GetoptLong::REQUIRED_ARGUMENT]) parser.quiet = true begin parser.each_option do |name, arg| @@ -208,7 +216,7 @@ def setup_floodgate ShogiServer.reload end floodgate = ShogiServer::League::Floodgate.new(LEAGUE, next_time) - log_message("Floodgate will start the next match at %s." % + log_message("Floodgate: The next match will start at %s." % [floodgate.next_time]) rescue Exception => ex # ignore errors @@ -220,8 +228,6 @@ end def main - setup_watchdog_for_giant_lock - $options = parse_command_line if (ARGV.length != 2) usage @@ -235,6 +241,11 @@ def main usage exit 3 end + if $options["pid-file"] + $options["pid-file"] = File.expand_path($options["pid-file"]) + end + $options["floodgate-history"] ||= File.join(File.dirname(__FILE__), "floodgate_history.yaml") + $options["floodgate-history"] = File.expand_path($options["floodgate-history"]) LEAGUE.event = ARGV.shift port = ARGV.shift @@ -248,8 +259,7 @@ def main log_file = dir ? File.join(dir, "shogi-server.log") : STDOUT $logger = setup_logger(log_file) - LEAGUE.dir = dir || File.dirname(__FILE__) - LEAGUE.setup_players_database + LEAGUE.dir = dir || TOP_DIR config = {} config[:Port] = port @@ -257,19 +267,24 @@ def main config[:Logger] = $logger fg_thread = nil + config[:StartCallback] = Proc.new do + srand if $options["pid-file"] write_pid_file($options["pid-file"]) end + setup_watchdog_for_giant_lock + LEAGUE.setup_players_database fg_thread = setup_floodgate end config[:StopCallback] = Proc.new do if $options["pid-file"] - FileUtils.rm(pid_file, :force => true) + FileUtils.rm($options["pid-file"], :force => true) end end + srand server = WEBrick::GenericServer.new(config) ["INT", "TERM"].each do |signal| trap(signal) do @@ -316,9 +331,13 @@ if ($0 == __FILE__) Thread.abort_on_exception = $DEBUG ? true : false begin - LEAGUE = ShogiServer::League::new + LEAGUE = ShogiServer::League.new(TOP_DIR) main rescue Exception => ex - log_error("main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}") + if $logger + log_error("main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}") + else + $stderr.puts "main: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}" + end end end