-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.azr
146 lines (141 loc) · 3.25 KB
/
main.azr
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// プロトコル制御用
dict dictOptionalHeader;
// セーブ用
dict dictSaveData;
load()
{
// 辞書読み込み
_script_load("plugin_init");
_script_load("plugin_menu");
_script_load("plugin_util");
// SAORIロード
_saoriload("saori\HandUtil\HandUtil.dll", "HandUtil");
_saoriload("saori\httpc\httpc.dll", "httpc");
_saoriload("saori\imgctl_saori\imgctl_saori.dll", "imgctl_saori");
_saoriload("saori\textcopy2\textcopy2.dll", "textcopy2");
// オプションヘッダ初期化
resetOptionalHeader();
// セーブデータ読み込み
dictSaveData = _vload("savedata");
// プラグイン初期化処理
loadPlugin();
}
unload()
{
// セーブデータ保存
_vsave("savedata", dictSaveData);
// プラグイン後始末処理
unloadPlugin();
//SAORIアンロード
_saoriunload("HandUtil");
_saoriunload("httpc");
_saoriunload("imgctl_saori");
_saoriunload("textcopy2");
}
array _customrequest(dict ref)
{
array ar;
// PLUGINに対するリクエストでない場合
if (_strstr(ref["head"], "PLUGIN") == -1) {
ar += "PLUGIN/2.0 400 Bad Request";
ar += "Sender: akari";
ar += "Charset: UTF-8";
ar += "";
return ar;
}
// セキュリティレベル="External"なら即返る
if (ref["SecurityLevel"] == "External") {
ar += "PLUGIN/2.0 204 No Content";
ar += "Sender: akari";
ar += "Charset: UTF-8";
ar += "";
return ar;
}
string s = _eventdict[ref["ID"]];
if (s == "") s = _fncstr(ref["ID"], ref);
// version
if (ref["ID"] == "version") {
ar += "PLUGIN/2.0 200 OK";
ar += "Sender: akari";
ar += "Charset: UTF-8";
ar += "Value: " + s;
ar += "";
return ar;
}
// NOTIFY
if (_strstr(ref["head"], "NOTIFY") != -1) {
resetOptionalHeader();
ar += "PLUGIN/2.0 200 OK";
ar += "Sender: akari";
ar += "Charset: UTF-8";
ar += "";
return ar;
}
// GET
if (_strstr(ref["head"], "GET") != -1) {
ar += "PLUGIN/2.0 200 OK";
ar += "Sender: akari";
ar += "Charset: UTF-8";
if (s != "") {
ar += "Script: " + s;
makeDefaultEventAndReference(ref, s);
}
dict d = dictOptionalHeader;
if (d["target"] != "") {
ar += "Target: " + d["target"];
}
if (d["event"] != "") {
ar += "Event: " + d["event"];
}
if (d["event_option"] != "") {
ar += "EventOption: " + d["event_option"];
}
if (d["script_option"] != "") {
ar += "ScriptOption: " + d["script_option"];
}
if (_aryvn(d["reference"]) > 0) {
for(int i = 0; d["reference"][i] != nil; i++) {
ar += "Reference" + i + ": " + d["reference"][i];
}
}
if (d["marker"] != "") {
ar += "Marker: " + d["marker"];
}
resetOptionalHeader();
ar += "";
return ar;
}
// 未知のリクエスト
else {
ar += "PLUGIN/2.0 400 Bad Request";
ar += "Sender: akari";
ar += "Charset: UTF-8";
ar += "";
return ar;
}
}
makeDefaultEventAndReference(dict ref, string script)
{
dictOptionalHeader["event"] = "OnPluginExec";
array a = {
"Version=" + version(),
"From=" + pluginname(),
"Script=" + script,
"Event=" + ref["ID"]
};
for (int i = 0; ref["Reference" + i] != nil; i++) {
a += ref["Reference" + i];
}
dictOptionalHeader["reference"] = a;
}
resetOptionalHeader()
{
dictOptionalHeader = ${
$("target", ""),
$("event", ""),
$("event_option", ""),
$("script_option", ""),
$("reference", {}),
$("marker", "")
};
}