-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetmatchinfo.rb
executable file
·122 lines (105 loc) · 2.47 KB
/
getmatchinfo.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
114
115
116
117
118
119
120
121
122
#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
require 'bundler/setup'
require 'cgi'
require 'cgi/session'
require 'logger'
require './file/matchinfofile.rb'
require './file/taikyokufile.rb'
require './game/userinfo.rb'
require './util/myhtml.rb'
#
# CGI本体
#
class GetMatchInfo
# 初期化
#
# @param cgi CGIオブジェクト
def initialize(cgi)
@cgi = cgi
@params = cgi.params
@gameid = cgi.query_string
end
# sessionの取得と情報の読み取り
def readuserparam
begin
session = CGI::Session.new(
@cgi,
'new_session' => false,
'session_key' => '_washcrus_session',
'tmpdir' => './tmp'
)
rescue ArgumentError
session = nil
end
@userinfo = UserInfo.new
@userinfo&.readsession(session)
session&.close
end
# 情報のチェック
#
# @return おかしいときnil
def check_param
# gameid が無いよ
return MyHtml.puts_textplain_illegalaccess \
unless @gameid && !@gameid.empty?
# adminじゃないよ
return MyHtml.puts_textplain_errnotadmin unless @userinfo.admin
self
end
# 対局情報の出力
#
# @param mif MatchInfoFileオブジェクト
def put_result(mif)
puts "Content-Type: text/plain;\n\n" \
"#{@gameid}\n先手:#{mif.playerb.name} 後手:#{mif.playerw.name}\n" \
"sfen:#{mif.sfen}"
end
#
# 実行本体。
#
def perform
# gameid が無いよ
# userinfoが変だよ
return unless check_param
tcdb = TaikyokuChuFile.new
tcdb.read
# 存在しないはずのIDだよ
return MyHtml.puts_textplain_illegalaccess unless tcdb.exist?(@gameid)
tkd = TaikyokuData.new
tkd.setid(@gameid)
tkd.read
put_result(tkd.mif)
# mif = tkd.mif
# puts "Content-Type: text/plain;\n\n" \
# "#{@gameid}\n先手:#{mif.playerb.name} 後手:#{mif.playerw.name}\n" \
# "sfen:#{mif.sfen}"
end
end
# -----------------------------------
# main
#
# エラー情報の出力
#
# @param err エラーオブジェクト
def errtrace(err)
puts "Content-Type: text/plain;\n\n" \
"class=[#{err.class}] message=[#{err.message}] " \
"stack=[#{err.backtrace.join("\n")}]"
end
cgi = CGI.new
begin
getsfen = GetMatchInfo.new(cgi)
getsfen.readuserparam
getsfen.perform
rescue ScriptError => e
errtrace(e)
rescue SecurityError => e
errtrace(e)
rescue StandardError => e
errtrace(e)
end
# -----------------------------------
# testing
#