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
|
--- Defaults relating to the sql database.
-- If you need to change the defaults, nrequire() thi
-- module, then change any of the fields.
-- @server sv_sql.lua
local sql = {}
--SQL stuff, be careful to keep this secret!
--- The values in the sql table
-- @table mysql_config
-- @field boolean EnableMySQL=true Should we use MySQLOO to store the data?
-- @field string Host=localhost The hostname that the mysql database lives on
-- @field string Username=root The username to log into the database
-- @field string Password=root The password to log into the database
-- @field number Database_port=3306 The port to connect to the database on
-- @field string Preferred_module=mysqloo The perfered module to use for sql, when multiple are avaliable.
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=false
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
|