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
|
local sql = {}
--SQL stuff, be careful to keep this secret!
local parse = {
["EnableMySQL"] = tobool,
["Host"] = tostring,
["Username"] = tostring,
["Password"] = tostring,
["Database_name"] = tostring,
["Database_port"] = tonumber,
["Preferred_module"] = tostring,
[""] = function() return nil end
}
local default_file = [[
EnableMySQL=true
Host=localhost
Username=root
Password=root
Database_name=artery
Database_port=3306
Preferred_module=mysqloo
]]
local mysqlconfig = file.Read("artery/mysql.txt")
if not mysqlconfig then
file.Write("artery/mysql.txt",default_file)
error("No sql setup defined, a default config has been given. edit garrysmod/data/artery/mysql.txt to configure it.")
end
for _,line in pairs(string.Explode("\n",mysqlconfig,false)) do
local key, value = unpack(string.Explode("=",line,false))
assert(parse[key],string.format("SQL field unknown:%q known fields:\n\t%s",key,table.concat(table.GetKeys(parse),"\n\t")))
sql[key] = parse[key](value)
end
return sql
|