-
Notifications
You must be signed in to change notification settings - Fork 0
/
shogi_server.rb
113 lines (102 loc) · 3.34 KB
/
shogi_server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
## $Id$
## Copyright (C) 2004 NABEYA Kenichi (aka nanami@2ch)
## Copyright (C) 2007-2008 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
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require 'kconv'
require 'getoptlong'
require 'thread'
require 'timeout'
require 'socket'
require 'yaml'
require 'yaml/store'
require 'digest/md5'
require 'digest/sha1'
require 'webrick'
require 'fileutils'
require 'logger'
require 'shogi_server/board'
require 'shogi_server/game'
require 'shogi_server/league'
require 'shogi_server/login'
require 'shogi_server/piece'
require 'shogi_server/player'
require 'shogi_server/timeout_queue'
require 'shogi_server/usi'
require 'shogi_server/util'
require 'shogi_server/command'
require 'shogi_server/buoy'
require 'shogi_server/kifu'
require 'shogi_server/server'
require 'shogi_server/rate_change_history'
module ShogiServer # for a namespace
Max_Identifier_Length = 32
Default_Timeout = 60 # for single socket operation
Default_Game_Name = "default-1500-0"
One_Time = 10
Least_Time_Per_Move = 1
Login_Time = 300 # time for LOGIN
Release = "$Id$"
Revision = (r = /Revision: (\d+)/.match("$Revision$") ? r[1] : 0)
RELOAD_FILES = ["shogi_server/league/floodgate.rb",
"shogi_server/league/persistent.rb",
"shogi_server/pairing.rb"]
BASE_DIR = File.expand_path(File.dirname(__FILE__))
def reload
RELOAD_FILES.each do |f|
load File.join(BASE_DIR, f)
end
end
module_function :reload
class Logger < ::Logger
def initialize(logdev, shift_age = 0, shift_size = 1048576)
super
class << @logdev
def shift_log_period(now)
postfix = previous_period_end(now).strftime("%Y%m%d") # YYYYMMDD
age_file = File.join(
File.dirname(@filename),
postfix[0..3], # YYYY
postfix[4..5], # MM
postfix[6..7], # DD
File.basename(@filename))
if FileTest.exist?(age_file)
raise RuntimeError.new("'#{ age_file }' already exists.")
end
unless FileTest.directory?(File.dirname(age_file))
begin
FileUtils.mkdir_p File.dirname(age_file)
rescue
raise RuntimeError.new("Could not create a directory: %s" % [File.dirname(age_file)])
end
end
@dev.close
File.rename("#{@filename}", age_file)
@dev = create_logfile(@filename)
return true
end
end
end
end
class Formatter < ::Logger::Formatter
def initialize
super
@datetime_format = "%Y-%m-%dT%H:%M:%S"
end
def call(severity, time, progname, msg)
%!%s [%s] %s\n! % [format_datetime(time), severity, msg2str(msg)]
end
end
end # module ShogiServer