/
settings.lua
210 lines (183 loc) · 6.29 KB
/
settings.lua
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2018 Timo 'Timothy' Smit
-- 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 3 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, see <http://www.gnu.org/licenses/>.
local toml = require "toml"
local events = require (wolfa_getLuaPath()..".util.events")
local settings = {}
local data = {
["g_logChat"] = "chat.log",
["g_logAdmin"] = "admin.log",
["g_fileGreetings"] = "greetings.toml",
["g_fileRules"] = "rules.toml",
["g_fileSprees"] = "sprees.toml",
["g_playerHistory"] = 1,
["g_spreeMessages"] = 7,
["g_spreeRecords"] = 1,
["g_botRecords"] = 1,
["g_announceRevives"] = 1,
["g_greetingArea"] = 3,
["g_botGreetings"] = 1,
["g_welcomeMessage"] = "^dwolfadmin: ^9This server is running WolfAdmin, type ^7/wolfadmin ^9for more information.",
["g_welcomeArea"] = 3,
["g_evenerMinDifference"] = 2,
["g_evenerMaxDifference"] = 5,
["g_evenerPlayerSelection"] = 0,
["g_evenerInterval"] = 30,
["g_voteNextMapTimeout"] = 0,
["g_restrictedVotes"] = "",
["g_renameLimit"] = 80,
["g_standalone"] = 1,
["g_debugWolfAdmin"] = 0,
["omnibot_maxbots"] = 10,
["db_type"] = "sqlite3",
["db_file"] = "wolfadmin.db",
["db_hostname"] = "localhost",
["db_port"] = 3306,
["db_database"] = "wolfadmin",
["db_username"] = "",
["db_password"] = "",
["sv_os"] = "unix"
}
local cfgStructure = {
["main"] = {
["os"] = "sv_os",
["standalone"] = "g_standalone",
["debug"] = "g_debugWolfAdmin",
},
["db"] = {
["type"] = "db_type",
["file"] = "db_file",
["hostname"] = "db_hostname",
["port"] = "db_port",
["database"] = "db_database",
["username"] = "db_username",
["password"] = "db_password",
},
["logs"] = {
["chat"] = "g_logChat",
["admin"] = "g_logAdmin"
},
["omnibot"] = {
["minbots"] = "omnibot_minbots",
["maxbots"] = "omnibot_maxbots"
},
["admin"] = {
["history"] = "g_playerHistory",
["maxrenames"] = "g_renameLimit"
},
["balancer"] = {
["mindif"] = "g_evenerMinDifference",
["maxdif"] = "g_evenerMaxDifference",
["selection"] = "g_evenerPlayerSelection",
["interval"] = "g_evenerInterval"
},
["game"] = {
["announcerevives"] = "g_announceRevives"
},
["voting"] = {
["timeout"] = "g_voteNextMapTimeout",
["restricted"] = "g_restrictedVotes"
},
["banners"] = {
["welcome"] = "g_welcomeMessage",
["area"] = "g_welcomeArea"
},
["rules"] = {
["file"] = "g_fileRules"
},
["greetings"] = {
["file"] = "g_fileGreetings",
["area"] = "g_greetingsArea",
["bots"] = "g_botGreetings"
},
["records"] = {
["bots"] = "g_botRecords"
},
["sprees"] = {
["file"] = "g_fileSprees",
["messages"] = "g_spreeMessages",
["records"] = "g_spreeRecords"
}
}
function settings.get(name)
return data[name]
end
function settings.set(name, value)
data[name] = value
end
function settings.load()
for setting, default in pairs(data) do
local cvar = et.trap_Cvar_Get(setting)
if type(default) == "string" then
data[setting] = (cvar ~= "" and tostring(cvar) or default)
elseif type(default) == "number" then
data[setting] = (cvar ~= "" and tonumber(cvar) or default)
end
end
local fileDescriptor, fileLength = et.trap_FS_FOpenFile("wolfadmin.toml", et.FS_READ)
if fileLength ~= -1 then
local fileString = et.trap_FS_Read(fileDescriptor, fileLength)
et.trap_FS_FCloseFile(fileDescriptor)
local fileTable = toml.parse(fileString)
for module, settings in pairs(fileTable) do
for setting, value in pairs(settings) do
if cfgStructure[module][setting] then
data[cfgStructure[module][setting]] = value
end
end
end
-- compatibility for 1.1.* and lower
if type(data["g_restrictedVotes"]) == "table" then
data["g_restrictedVotes"] = table.concat(data["g_restrictedVotes"], " ")
end
else
-- compatibility for 1.1.* and lower
outputDebug("Using .cfg files is deprecated as of 1.2.0. Please consider updating to .toml files.", 3)
local files = require (wolfa_getLuaPath()..".util.files")
local _, array = files.loadFromCFG("wolfadmin.cfg", "[a-z]+")
for blocksname, settings in pairs(array) do
for k, v in pairs(settings[1]) do
data[cfgStructure[blocksname][k]] = v
end
end
end
local platform = string.lower(data["sv_os"])
if not (platform == "unix" or platform == "windows") then
settings.set("sv_os", settings.determineOS())
end
local mod = et.trap_Cvar_Get("fs_game")
local shrubbot = et.trap_Cvar_Get("g_shrubbot") -- etpub, nq
local dbDir = et.trap_Cvar_Get("g_dbDirectory") -- silent
if mod == "legacy" or mod == "etpro" then
settings.set("g_standalone", 1)
elseif (not shrubbot or shrubbot == "") and (not dbDir or dbDir == "") then
settings.set("g_standalone", 1)
else
settings.set("g_standalone", 0)
end
outputDebug("WolfAdmin running in "..(settings.get("g_standalone") == 1 and "standalone" or "add-on").." mode.")
end
function settings.determineOS()
local system = io.popen("uname -s"):read("*l")
local platform
if system then
platform = "unix"
else
platform = "windows"
end
return platform
end
function settings.oninit(levelTime, randomSeed, restartMap)
settings.load()
end
events.handle("onGameInit", settings.oninit)
return settings