· 7 years ago · Jan 20, 2019, 11:22 PM
1'local XEON = XEON
2
3local e
4local q
5
6bLogs.Discord = {}
7bLogs.Web = {}
8bLogs.Discord.Enabled = false
9bLogs.Web.Enabled = false
10
11if (file.Exists("blogs_discord_config.lua", "LUA")) then
12 include("blogs_discord_config.lua")
13 if (bLogs.Discord.Enabled == true) then
14 bLogs:print("[Discord] Enabled")
15 end
16end
17
18if (not bLogs_ReplacedServerLog) then
19 bLogs_ReplacedServerLog = ServerLog
20 function ServerLog(...)
21 if (bLogs.InGameConfig) then
22 if (bLogs.InGameConfig.General.DisableServerLog == false) then
23 bLogs_ReplacedServerLog(...)
24 end
25 end
26 end
27end
28bLogs:hook("canSeeLogMessage","HideLogMessages",function()
29 if (not DarkRP) then bLogs:unhook("canSeeLogMessage","HideLogMessages") return end
30 if (bLogs.InGameConfig) then
31 if (bLogs.InGameConfig.General.DisableDarkRPLog == true) then
32 return false
33 end
34 end
35end)
36
37function bLogs.LoadAddonModules()
38 local f = file.Find("blogs/modules/addons/*.lua","LUA")
39 for _,v in pairs(f) do
40 include("blogs/modules/addons/" .. v)
41 end
42 for i,v in pairs(bLogs.InGameConfig.ModulesDisabled) do
43 if (not bLogs.Modules[v]) then continue end
44 bLogs.Modules[v].Enabled = false
45 for _,HookData in pairs(bLogs.Modules[v].Hooks) do
46 hook.Remove(HookData[1],HookData[2])
47 end
48 end
49end
50if (#player.GetAll() > 0) then
51 bLogs.LoadAddonModules()
52else
53 hook.Add("PlayerInitialSpawn","blogs_load_addon_modules",function()
54 bLogs.LoadAddonModules()
55 hook.Remove("PlayerInitialSpawn","blogs_load_addon_modules")
56 end)
57end
58
59local net_m = {
60
61 -- when you start developing in some kind of camel case
62 "OpenMenu",
63 "Send_Setup_Data",
64 "Permission_Failure",
65 "SelectLogs",
66 "GetOfflineName",
67 "AdvancedSelectLogs",
68
69 -- and then forget and do everything like this instead
70 "start_data_flow",
71 "data",
72 "last_data",
73 "no_data",
74 "jump_to_date",
75 "completed",
76 "archive_logs",
77 "wipe_archive",
78 "reset_config",
79 "update_player_format",
80 "update_modules",
81 "permissions",
82 "permissions_update",
83 "permissions_delete",
84 "update_general_config",
85 "update_general_config_num",
86 "update_country",
87 "update_config_broadcast",
88 "send_log",
89 "playerlookup",
90
91} for _,v in pairs(net_m) do util.AddNetworkString("blogs_" .. v) end
92
93bLogs.DataFlows = {}
94bLogs.DataFlowing = {}
95
96require("billyerror")
97
98local function attach_creator_2(ply,ent)
99 ent.bLogs_Creator = ply
100end
101local function attach_creator_3(ply,_,ent)
102 ent.bLogs_Creator = ply
103end
104bLogs:hook("PlayerSpawnedProp","attach_to_prop",attach_creator_3)
105bLogs:hook("PlayerSpawnedEffect","attach_to_effect",attach_creator_3)
106bLogs:hook("PlayerSpawnedRagdoll","attach_to_ragdoll",attach_creator_3)
107bLogs:hook("PlayerSpawnedNPC","attach_to_npc",attach_creator_2)
108bLogs:hook("PlayerSpawnedSENT","attach_to_sent",attach_creator_2)
109bLogs:hook("PlayerSpawnedSWEP","attach_to_swep",attach_creator_2)
110bLogs:hook("PlayerSpawnedVehicle","attach_to_vehicle",attach_creator_2)
111
112bLogs.Logs = {}
113
114local function BroadcastConfigUpdate()
115 local d = util.Compress(util.TableToJSON(bLogs.InGameConfig))
116 local c = #d
117 bLogs:nets("update_config_broadcast")
118 net.WriteDouble(c)
119 net.WriteData(d,c)
120 net.Broadcast()
121end
122
123e = function(s)
124 return sql.SQLStr(s,true)
125end
126q = function(query,cb)
127 if (type(query) == "table") then
128 local r = {}
129 local i = 0
130 local function s(query,i,r,cb)
131 i = i + 1
132 if (bLogs.Config.MySQL.Enabled) then
133 local qu = bLogs.Database:query(query[i])
134 qu.onSuccess = function(q,data)
135 table.insert(r,data)
136 if (i == #query) then
137 if (cb) then
138 cb(r)
139 end
140 else
141 s(query,i,r,cb)
142 end
143 end
144 qu.onError = function(q,err,sql)
145 bLogs:print("MySQL error!: " .. err .. "\n" .. sql,"bad")
146 end
147 qu:start()
148 else
149 local data = sql.Query(query[i])
150 data = data or {}
151 table.insert(r,data)
152 if (i == #query) then
153 if (cb) then
154 cb(r)
155 end
156 else
157 s(query,i,r,cb)
158 end
159 end
160 end
161 s(query,i,r,cb)
162 else
163 if (not bLogs.Config) then
164 bLogs:print("You probably have a config error...","bad")
165 return
166 end
167 if (not bLogs.Config.MySQL) then
168 bLogs:print("You probably have a MySQL config error...","bad")
169 return
170 end
171 if (bLogs.Config.MySQL.Enabled) then
172 local qu = bLogs.Database:query(query)
173 qu.onSuccess = function(q,data)
174 if (cb) then
175 cb(data)
176 end
177 end
178 qu.onError = function(q,err,sql)
179 bLogs:print("MySQL error!: " .. err .. "\n" .. sql,"bad")
180 end
181 qu:start()
182 else
183 local data = sql.Query(query)
184 if (cb) then
185 cb(data or {})
186 end
187 end
188 end
189end
190
191hook.Add("bLogs_FullyLoaded","blogs_insert_queued_logs",function()
192 for _,v in pairs(bLogs.QueuedLogs) do
193 bLogs:Log(unpack(v))
194 end
195 bLogs.QueuedLogs = {}
196end)
197
198local function sql_init()
199
200 if (bLogs.Config.MySQL.Enabled) then
201 bLogs:print("MySQL Database initialised","good")
202 else
203 bLogs:print("SQLite Database initialised","good")
204 end
205
206 if (file.Exists("blogs_web_config.lua", "LUA")) then
207 include("blogs_web_config.lua")
208 if (bLogs.Web.Enabled == true) then
209 bLogs.Web.Enabled = false
210 bLogs:print("[Web] Enabled. Checking license...")
211 if (XEON:OwnsDLC(5652)) then
212 bLogs.Web.Enabled = true
213 bLogs:print("[Web] License check success!", "good")
214 if (bLogs.Config.MySQL.Enabled == false) then
215 bLogs:print("[Web] MySQL is disabled, so bLogs Web is also disabled.", "bad")
216 else
217 local function blogs_web_init()
218 q([[
219
220 SHOW TABLES LIKE ''blogsweb_permissions'';
221
222 ]], function(r)
223
224 if (#r == 0) then
225 bLogs:print("[Web] bLogs Web has not been set up on your webserver''s database yet. Please install bLogs Web on your webserver and run the setup script.", "bad")
226 return
227 end
228
229 q("SELECT `var_str` FROM `blogs_vars` WHERE `var_name`=''blogs_web_url''", function(r)
230 if (#r == 0) then return end
231 bLogs.Web.URL = r[1].var_str
232 end)
233
234 local permissions_query = "TRUNCATE blogsweb_permissions;\n"
235 for value_raw, permissions in pairs(table.Merge(bLogs.InGameConfig.Permissions.Usergroups, bLogs.InGameConfig.Permissions.SteamIDs)) do
236 local value = value_raw
237 if (value_raw:sub(1,1) == "S") then
238 value = util.SteamIDTo64(value_raw)
239 end
240 if (table.HasValue(bLogs.Config.MaxPermitted, value)) then
241 permissions_query = permissions_query .. "INSERT INTO blogsweb_permissions (`server_id`, `value`, `open_menu`, `maxpermitted`, `ip_addresses`, `modules`) " ..
242 "VALUES(''" .. e(bLogs.ServerID) .. "'',''" .. e(value) .. "'',''1'',''1'',''1'',''[]'');\n"
243 else
244 local permissions_encoded = {}
245 local menu = 0
246 local ip_addresses = 0
247
248 for permission, val in pairs(permissions) do
249 if (val == true) then
250 if (permission == "Menu") then
251 menu = 1
252 elseif (permission == "IPAddresses") then
253 ip_addresses = 1
254 else
255 permissions_encoded[permission] = true
256 end
257 end
258 end
259
260 permissions_encoded = util.TableToJSON(permissions_encoded)
261 if (permissions_encoded ~= "[]" or menu == 1 or ip_addresses == 1) then
262 permissions_query = permissions_query .. "INSERT INTO blogsweb_permissions (`server_id`, `value`, `open_menu`, `maxpermitted`, `ip_addresses`, `modules`) " ..
263 "VALUES(''" .. e(bLogs.ServerID) .. "'',''" .. e(value) .. "'',''" .. e(menu) .. "'',''0'',''" .. e(ip_addresses) .. "'',''" .. e(permissions_encoded) .. "'');\n"
264 end
265 end
266 end
267 q(permissions_query)
268
269 local modules_query = ""
270 for name, data in pairs(bLogs.Modules) do
271 local dec_col = math.floor(data.Colour.b + (data.Colour.g * 16^2) + (data.Colour.r * 16^4))
272 modules_query = modules_query .. "INSERT IGNORE INTO blogsweb_modules (`category`,`module`,`color`) VALUES(''" .. e(data.Category) .. "'',''" .. e(data.Name) .. "'',''" .. e(dec_col) .. "'');\n"
273 end
274 q(modules_query)
275
276 local function update_console()
277 if (file.Exists("console.log", "GAME")) then
278 local console_log = file.Read("console.log", "GAME")
279 if (#console_log > bLogs.Web.ConsoleLogLength) then
280 console_log = "..." .. string.sub(console_log, #console_log - bLogs.Web.ConsoleLogLength + 3, #console_log)
281 end
282 local prepare = bLogs.Database:prepare("UPDATE blogsweb_console SET `console`=?")
283 prepare:setString(1, console_log)
284 prepare:start()
285 end
286 end
287 timer.Create("blogs_console_stream", 10, 0, update_console)
288 update_console()
289
290 end)
291 end
292 if (bLogs_FullyLoaded) then
293 blogs_web_init()
294 else
295 bLogs:hook("bLogs_FullyLoaded", "web_init", blogs_web_init)
296 end
297 end
298 else
299 bLogs:print("[Web] License check failed!", "error")
300 end
301 end
302 end
303
304 bLogs:netr("Send_Setup_Data",function(ply)
305 local modules = util.Compress(util.TableToJSON(bLogs.Modules))
306 local settings = util.Compress(util.TableToJSON(bLogs.InGameConfig))
307 bLogs:nets("Send_Setup_Data")
308 net.WriteDouble(#modules)
309 net.WriteData(modules,#modules)
310 net.WriteDouble(#settings)
311 net.WriteData(settings,#settings)
312 net.WriteBool(bLogs.Database ~= nil)
313 net.WriteString(bLogs.Web.URL or "")
314 net.Send(ply)
315 end)
316
317 bLogs:hook("PlayerSay","chatcommand",function(ply,txt)
318 if (txt:lower() == bLogs.Config.ChatCommand:lower()) then
319 if (bLogs:HasAccess(ply)) then
320 bLogs:nets("OpenMenu")
321 net.Send(ply)
322 else
323 bLogs:nets("permission_failure")
324 net.Send(ply)
325 end
326 return ""
327 end
328 end)
329 if (bLogs.Config.AllowConsoleCommand) then
330 bLogs:netr("OpenMenu",function(ply)
331 if (bLogs:HasAccess(ply)) then
332 bLogs:nets("OpenMenu")
333 net.Send(ply)
334 else
335 bLogs:nets("Permission_Failure")
336 net.Send(ply)
337 end
338 end)
339 end
340 if (bLogs.Config.FunctionMenuKey ~= false) then
341 local hook_event
342 if (bLogs.Config.FunctionMenuKey == 1) then
343 hook_event = "ShowHelp"
344 elseif (bLogs.Config.FunctionMenuKey == 2) then
345 hook_event = "ShowTeam"
346 elseif (bLogs.Config.FunctionMenuKey == 3) then
347 hook_event = "ShowSpare1"
348 elseif (bLogs.Config.FunctionMenuKey == 4) then
349 hook_event = "ShowSpare2"
350 end
351 bLogs:unhook("ShowHelp","functionmenukey")
352 bLogs:unhook("ShowTeam","functionmenukey")
353 bLogs:unhook("ShowSpare1","functionmenukey")
354 bLogs:unhook("ShowSpare2","functionmenukey")
355 bLogs:hook(hook_event,"functionmenukey",function(ply)
356 if (bLogs:HasAccess(ply)) then
357 bLogs:nets("OpenMenu")
358 net.Send(ply)
359 else
360 bLogs:nets("Permission_Failure")
361 net.Send(ply)
362 end
363 end)
364 end
365
366 function bLogs:Log(module,log)
367 if (bLogs.InGameConfig.PrintToConsole) then
368 if (bLogs.InGameConfig.PrintToConsole[module]) then
369 for _,v in pairs(player.GetHumans()) do
370 if (bLogs:HasAccess(v,module)) then
371 bLogs:nets("send_log")
372 net.WriteString(module)
373 net.WriteString(log)
374 net.Send(v)
375 end
376 end
377 end
378 end
379 local function store()
380 if (bLogs.Database) then
381 q("INSERT INTO `blogs` (`server_id`,`module`,`log`,`time`,`session`) VALUES(''" .. e(bLogs.ServerID) .. "'',''" .. e(module) .. "'',''" .. e(log) .. "'',UNIX_TIMESTAMP(),''" .. e(bLogs.Session) .. "'')")
382 else
383 q("INSERT INTO `blogs` (`module`,`log`,`time`) VALUES(''" .. e(module) .. "'',''" .. e(log) .. "'',strftime(''%s'',''now''))")
384 end
385 if (file.Exists("blogs_discord_config.lua", "LUA") and bLogs.Discord.Enabled == true and bLogs.InGameConfig.SendToDiscord[module] == true) then
386 local module_tbl = bLogs.Modules[module]
387
388 local timestamp = os.date("!%Y-%m-%dT%H:%M:%S+00:00")
389 local title = ((module_tbl.Category .. " · " .. module_tbl.Name):gsub("\"","\\\""))
390 local color = math.floor(module_tbl.Colour.b + (module_tbl.Colour.g * 16^2) + (module_tbl.Colour.r * 16^4))
391 local footer = bLogs.Discord.ServerName .. " · " .. (game.GetIPAddress():gsub("\"","\\\""))
392
393 local fields = "["
394 local description = log
395 local x = {}
396 local r = {
397 ["{#P%|(%d+)%|(.-)%|#}"] = "**%2**", -- Player
398 ["{#V%|(.-)%|#}"] = "`%1`", -- Vehicle
399 ["{#E%|(.-)%|#}"] = "`%1`", -- Entity
400 ["{#$%|(.-)%|#}"] = "%1", -- Money
401 ["{#H%|(.-)|#}"] = "`%1`", -- Miscellaneous
402 }
403 for i,v in pairs(r) do
404 if (i == "{#P%|(%d+)%|(.-)%|#}") then
405 for steamid,nick in description:gmatch(i) do
406 fields = fields .. ''{"name":"'' .. (nick:gsub("\"","\\\"")) .. ''","value":"'' .. util.SteamIDFrom64(steamid) .. ''","inline":true},''
407 end
408 end
409 description = (description:gsub(i,v))
410 end
411 fields = (fields:gsub(",$","")) .. "]"
412
413 HTTP({
414 method = "POST",
415 url = bLogs.Discord.Webhook,
416 type = "application/json",
417 body = ''{"embeds":[{"timestamp":"'' .. timestamp .. ''","title":"'' .. title .. ''","color":'' .. color .. '',"footer":{"text":"'' .. footer .. ''"},"description":"'' .. description .. ''","fields":'' .. fields .. ''}]}'',
418 success = function(code, body, headers)
419 if (tostring(headers["X-RateLimit-Remaining"]) == "0") then
420 bLogs:print("Couldn''t send a log to Discord due to too many requests. Do not send spammy logs to Discord!", "bad")
421 end
422 end,
423 })
424 end
425 end
426 if (log:find("{#P%|(%d+)%|#}")) then
427 local stuff = {}
428 for i in log:gmatch("{#P%|(%d+)%|#}") do
429 table.insert(stuff,i)
430 end
431 local function iterate(key)
432 if (not stuff[key]) then store() return end
433 bLogs:OfflineName(stuff[key],function(name)
434 log = (log:gsub("{#P|" .. stuff[key] .. "|#}","{#P|" .. stuff[key] .. "|" .. name .. "|#}"))
435 iterate(key + 1)
436 end)
437 end
438 iterate(1)
439 else
440 store()
441 end
442 end
443
444 local function SelectLogs(query,page,ply)
445 query = "{" .. query .. "}"
446 query = util.JSONToTable(query)
447 if (query) then
448 local limit = bLogs.Config.LogsPerPage * page .. "," .. bLogs.Config.LogsPerPage
449
450 local where_clause = ""
451
452 local function cb(r)
453 if (not bLogs.DataFlows[ply]) then
454 bLogs.DataFlows[ply] = {}
455 end
456 local t = table.insert(bLogs.DataFlows[ply],r)
457 local qux = ""
458 if (where_clause == "") then
459 if (query.archive) then
460 qux = "SELECT (`var_int` / " .. bLogs.Config.LogsPerPage .. ") AS ''pages'' FROM `blogs_vars` WHERE `var_name`=''logs_archive''"
461 else
462 qux = "SELECT (`var_int` / " .. bLogs.Config.LogsPerPage .. ") AS ''pages'' FROM `blogs_vars` WHERE `var_name`=''logs''"
463 end
464 else
465 if (query.archive) then
466 qux = "SELECT (COUNT(`" .. bLogs.IDColumn .. "`) / " .. bLogs.Config.LogsPerPage .. ") AS ''pages'' FROM `blogs_archive` WHERE " .. where_clause
467 else
468 qux = "SELECT (COUNT(`" .. bLogs.IDColumn .. "`) / " .. bLogs.Config.LogsPerPage .. ") AS ''pages'' FROM `blogs` WHERE " .. where_clause
469 end
470 end
471 q(qux,function(xr)
472 if (#xr == 0) then
473 xr[1] = {pages = 0}
474 end
475 bLogs:nets("start_data_flow")
476 net.WriteInt(tonumber(math.ceil(xr[1].pages)),32)
477 net.Send(ply)
478 coroutine.resume(coroutine.create(function(t,r,ply)
479 if (#r == 0) then
480 bLogs:nets("no_data")
481 net.Send(ply)
482 else
483 for i,v in pairs(r) do
484 if (not bLogs.DataFlows[ply]) then break end
485 bLogs:nets("data")
486 net.WriteString(v.module)
487 net.WriteString(v.log)
488 net.WriteInt(v.time,32)
489 net.Send(ply)
490 end
491 bLogs:nets("last_data")
492 net.Send(ply)
493 end
494 end),t,r,ply)
495 end)
496 end
497 local build_where_clause = {}
498 if (type(query.module) == "string") then
499 table.insert(build_where_clause,"`module`=''" .. e(query.module) .. "''")
500 end
501 if (type(query.module) == "table") then
502 if (#query.module == 1) then
503 table.insert(build_where_clause,"`module`=''" .. e(query.module[1]) .. "''")
504 else
505 local a = {}
506 for i,v in pairs(query.module) do
507 table.insert(a,"`module`=''" .. e(v) .. "''")
508 end
509 for i,v in pairs(a) do
510 if (i == 1) then
511 table.insert(build_where_clause,"(")
512 table.insert(build_where_clause,v)
513 elseif (i == #a) then
514 table.insert(build_where_clause,v)
515 table.insert(build_where_clause,")")
516 else
517 table.insert(build_where_clause,"(")
518 table.insert(build_where_clause,v)
519 end
520 end
521 end
522 end
523 if (query.search) then
524 table.insert(build_where_clause,"`log` LIKE ''%" .. (e(query.search):gsub("%%","\\%%")) .. "%''")
525 end
526 if (type(query.player) == "string") then
527 table.insert(build_where_clause,"`log` LIKE ''%{#P|" .. (e(query.player):gsub("%%","\\%%")) .. "%''")
528 end
529 if (type(query.player) == "table") then
530 if (#query.player == 1) then
531 table.insert(build_where_clause,"`log` LIKE ''%{#P|" .. (e(query.player[1]):gsub("%%","\\%%")) .. "%''")
532 else
533 local a = {}
534 for i,v in pairs(query.player) do
535 table.insert(a,"`log` LIKE ''%{#P|" .. (e(v):gsub("%%","\\%%")) .. "%''")
536 end
537 for i,v in pairs(a) do
538 if (i == 1) then
539 table.insert(build_where_clause,"(")
540 table.insert(build_where_clause,v)
541 elseif (i == #a) then
542 table.insert(build_where_clause,v)
543 table.insert(build_where_clause,")")
544 else
545 table.insert(build_where_clause,"(")
546 table.insert(build_where_clause,v)
547 end
548 end
549 end
550 end
551 local open_bracket = false
552 local open_bracket_i = 0
553 for i,v in pairs(build_where_clause) do
554 if (i == 1) then
555 where_clause = v
556 elseif (v == "(") then
557 where_clause = where_clause .. " AND ("
558 open_bracket = true
559 elseif (v == ")") then
560 where_clause = where_clause .. ")"
561 open_bracket = false
562 open_bracket_i = 0
563 elseif (open_bracket) then
564 open_bracket_i = open_bracket_i + 1
565 if (open_bracket_i == 1) then
566 where_clause = where_clause .. v
567 else
568 where_clause = where_clause .. " OR " .. v
569 end
570 else
571 where_clause = where_clause .. " AND " .. v
572 end
573 end
574 local tbl = "blogs"
575 if (query.archive) then
576 tbl = "blogs_archive"
577 end
578 if (where_clause == "") then
579 q("SELECT `module`,`log`,`time` FROM `" .. tbl .. "` ORDER BY `time` DESC LIMIT " .. limit,cb)
580 else
581 q("SELECT `module`,`log`,`time` FROM `" .. tbl .. "` WHERE " .. where_clause .. " ORDER BY `time` DESC LIMIT " .. limit,cb)
582 end
583 end
584 end
585
586 bLogs:netr("AdvancedSelectLogs",function(ply)
587 local d = net.ReadDouble()
588 local ds = net.ReadData(d)
589 local p = net.ReadInt(32) - 1
590
591 ds = util.Decompress(ds)
592
593 SelectLogs(ds,p,ply)
594 end)
595 bLogs:netr("SelectLogs",function(ply)
596 local query = net.ReadString()
597 local page = net.ReadInt(32) - 1
598
599 SelectLogs(query,page,ply)
600 end)
601 bLogs:netr("last_data",function(ply)
602 if (not bLogs.DataFlows[ply]) then return end
603 bLogs.DataFlows[ply] = nil
604 end)
605
606 bLogs:netr("playerlookup",function(ply)
607 if (not bLogs:HasAccess(ply)) then return end
608 local data = table.Copy(bLogs.PlayerLookup)
609 if (not bLogs:HasAccess(ply,"IPAddresses")) then
610 for i in pairs(data) do
611 data[i].IP_Address = nil
612 end
613 end
614 data = util.TableToJSON(data)
615 data = util.Compress(data)
616 local d = #data
617 bLogs:nets("playerlookup")
618 net.WriteDouble(d)
619 net.WriteData(data,d)
620 net.Send(ply)
621 end)
622
623 bLogs:netr("jump_to_date",function(ply)
624 local t = net.ReadString()
625 t = util.JSONToTable(t)
626
627 local s = "%s/%s/%s %s:%s"
628 s = s:format(
629 t.day,
630 t.month,
631 t.year,
632 t.hour,
633 t.min
634 )
635
636 q("SELECT (SELECT CEIL(`" .. bLogs.IDColumn .. "` / 60) AS `pages` FROM `blogs` ORDER BY `time` DESC LIMIT 1) - FLOOR(`" .. bLogs.IDColumn .. "` / 60) AS `page` FROM `blogs` WHERE `time` <= unix_timestamp(str_to_date(''" .. e(s) .. "'',''%d/%m/%Y %H:%i'')) ORDER BY `time` DESC LIMIT 1",function(r)
637 if (#r == 0) then
638 bLogs:nets("no_data")
639 net.Send(ply)
640 else
641 bLogs:nets("jump_to_date")
642 net.WriteInt(r[1].page,32)
643 net.Send(ply)
644 end
645 end)
646 end)
647
648 bLogs:netr("archive_logs",function(ply)
649 if (not bLogs:IsMaxPermitted(ply)) then return end
650
651 if (bLogs.Database) then
652 q([[
653
654 INSERT INTO `blogs_archive` (`module`,`log`,`time`) SELECT `module`,`log`,`time` FROM `blogs` ORDER BY `blogs`.`time` ASC;
655 TRUNCATE `blogs`;
656 UPDATE `blogs_vars` SET `var_int`=0 WHERE `var_name`=''logs'';
657 UPDATE `blogs_vars` SET `var_int`=(SELECT COUNT(`id`) FROM `blogs_archive`) WHERE `var_name`=''logs_archive'';
658
659 ]],function()
660
661 bLogs:nets("completed")
662 net.Send(ply)
663
664 end)
665 else
666 q([[
667
668 INSERT INTO `blogs_archive` (`module`,`log`,`time`) SELECT `module`,`log`,`time` FROM `blogs` ORDER BY `blogs`.`time` ASC;
669 DELETE FROM `blogs`; VACUUM;
670 UPDATE `blogs_vars` SET `var_int`=0 WHERE `var_name`=''logs'';
671 UPDATE `blogs_vars` SET `var_int`=(SELECT COUNT(`ROWID`) FROM `blogs_archive`) WHERE `var_name`=''logs_archive'';
672
673 ]],function()
674
675 bLogs:nets("completed")
676 net.Send(ply)
677
678 end)
679 end
680 end)
681
682 bLogs:netr("wipe_archive",function(ply)
683 if (not bLogs:IsMaxPermitted(ply)) then return end
684
685 if (bLogs.Database) then
686 q([[
687
688 TRUNCATE `blogs_archive`;
689
690 UPDATE `blogs_vars` SET `var_int`=0 WHERE `var_name`=''logs_archive'';
691
692 ]],function()
693
694 bLogs:nets("completed")
695 net.Send(ply)
696
697 end)
698 else
699 q([[
700
701 DELETE FROM `blogs_archive`; VACUUM;
702
703 UPDATE `blogs_vars` SET `var_int`=0 WHERE `var_name`=''logs_archive'';
704
705 ]],function()
706
707 bLogs:nets("completed")
708 net.Send(ply)
709
710 end)
711 end
712 end)
713
714 bLogs:netr("reset_config",function(ply)
715 if (not bLogs:IsMaxPermitted(ply)) then return end
716
717 bLogs.InGameConfig = bLogs.DefaultInGameConfig
718
719 file.Write("blogs/config.txt",util.TableToJSON(bLogs.DefaultInGameConfig))
720
721 bLogs:nets("completed")
722 net.Send(ply)
723 end)
724
725 bLogs:netr("update_general_config",function(ply)
726 if (not bLogs:IsMaxPermitted(ply)) then return end
727
728 local key = net.ReadString()
729 local value = net.ReadBool()
730
731 bLogs.InGameConfig.General[key] = value
732
733 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
734 BroadcastConfigUpdate()
735 end)
736 bLogs:netr("update_general_config_num",function(ply)
737 if (not bLogs:IsMaxPermitted(ply)) then return end
738
739 local key = net.ReadString()
740 local value = net.ReadInt(32)
741
742 bLogs.InGameConfig.General[key] = value
743
744 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
745 BroadcastConfigUpdate()
746 end)
747
748 bLogs:netr("update_player_format",function(ply)
749 if (not bLogs:IsMaxPermitted(ply)) then return end
750
751 local key = net.ReadString()
752 local value = net.ReadBool()
753
754 bLogs.InGameConfig.Info[key] = value
755
756 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
757 BroadcastConfigUpdate()
758 end)
759
760 bLogs:netr("update_modules",function(ply)
761 if (not bLogs:IsMaxPermitted(ply)) then return end
762
763 local n = net.ReadString()
764 local disabled = net.ReadBool()
765 local print_to_console = net.ReadBool()
766 local send_to_discord = net.ReadBool()
767
768 bLogs.InGameConfig.ModulesDisabled[n] = disabled or nil
769 bLogs.InGameConfig.PrintToConsole[n] = print_to_console or nil
770 bLogs.InGameConfig.SendToDiscord[n] = send_to_discord or nil
771
772 if (disabled) then
773 for _,HookData in pairs(bLogs.Modules[n].Hooks) do
774 hook.Remove(HookData[1],HookData[2])
775 end
776 else
777 include(bLogs.Modules[n].File)
778 end
779
780 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
781 BroadcastConfigUpdate()
782
783 --[[local n = net.ReadDouble()
784 local d = net.ReadData(n)
785
786 bLogs:nets("update_modules")
787 net.WriteDouble(n)
788 net.WriteData(d,n)
789 net.Broadcast()
790
791 d = util.Decompress(d)
792 d = util.JSONToTable(d)
793
794 --for _,DisabledModule in pairs(d.disabled) do
795
796 for ModuleKey,ModuleData in pairs(bLogs.Modules) do
797
798 --if (ModuleKey ~= DisabledModule) then continue end
799
800 --bLogs.Modules[ModuleKey].Enabled = false
801
802 for _,HookData in pairs(ModuleData.Hooks) do
803 hook.Remove(HookData[1],HookData[2])
804 end
805
806 end
807
808 --end
809
810 --[[for _,EnabledModule in pairs(d.enabled) do
811
812 for ModuleKey,ModuleData in pairs(bLogs.Modules) do
813
814 if (ModuleKey ~= DisabledModule) then continue end
815
816 bLogs.Modules[ModuleKey].Enabled = true
817
818 for _,HookData in pairs(ModuleData.Hooks) do
819 hook.Add(HookData[1],HookData[2],HookData[3])
820 end
821
822 end
823
824 end--]]
825
826 --[[bLogs.InGameConfig.ModulesDisabled = d.disabled
827
828 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
829 BroadcastConfigUpdate()
830
831 bLogs.LoadModules()
832 bLogs.LoadDelayedModules()
833 bLogs.LoadAddonModules()]]
834
835 end)
836
837 bLogs.DefaultPermissions = {
838 Menu = false,
839 IPAddresses = false,
840 }
841
842 bLogs:netr("permissions",function(ply)
843 if (not bLogs:IsMaxPermitted(ply)) then return end
844
845 local type = net.ReadInt(16)
846 local data = net.ReadString()
847 if (type == 1) then
848 -- Job
849 if (not tonumber(data)) then
850 bLogs:print("This shouldn''t be happening! Please make a ticket and show this: " .. tostring(data),"bad")
851 end
852 data = tonumber(data)
853 if (RPExtraTeams[data]) then
854 data = RPExtraTeams[data].name
855 if (not bLogs.InGameConfig.Permissions.Jobs[data]) then
856 bLogs.InGameConfig.Permissions.Jobs[data] = table.Copy(bLogs.DefaultPermissions)
857 end
858 for i in pairs(bLogs.Modules) do
859 if (bLogs.InGameConfig.Permissions.Jobs[data][i] == nil) then
860 bLogs.InGameConfig.Permissions.Jobs[data][i] = false
861 end
862 end
863 for i,v in pairs(bLogs.DefaultPermissions) do
864 if (bLogs.InGameConfig.Permissions.Jobs[data][i] == nil) then
865 bLogs.InGameConfig.Permissions.Jobs[data][i] = v
866 end
867 end
868 local c = util.Compress(util.TableToJSON(bLogs.InGameConfig.Permissions.Jobs[data]))
869 local d = #c
870 bLogs:nets("permissions")
871 net.WriteDouble(d)
872 net.WriteData(c,d)
873 net.Send(ply)
874 end
875 elseif (type == 2 or type == 4 or type == 5) then
876 -- CAMI/Usergroup
877 if (not bLogs.InGameConfig.Permissions.Usergroups[data]) then
878 bLogs.InGameConfig.Permissions.Usergroups[data] = table.Copy(bLogs.DefaultPermissions)
879 end
880 for i in pairs(bLogs.Modules) do
881 if (bLogs.InGameConfig.Permissions.Usergroups[data][i] == nil) then
882 bLogs.InGameConfig.Permissions.Usergroups[data][i] = false
883 end
884 end
885 for i,v in pairs(bLogs.DefaultPermissions) do
886 if (bLogs.InGameConfig.Permissions.Usergroups[data][i] == nil) then
887 bLogs.InGameConfig.Permissions.Usergroups[data][i] = v
888 end
889 end
890 local c = util.Compress(util.TableToJSON(bLogs.InGameConfig.Permissions.Usergroups[data]))
891 local d = #c
892 bLogs:nets("permissions")
893 net.WriteDouble(d)
894 net.WriteData(c,d)
895 net.Send(ply)
896 elseif (type == 3 or type == 6 and data:find("^STEAM_%d:%d:%d+$")) then
897 -- SteamID
898 if (not bLogs.InGameConfig.Permissions.SteamIDs[data]) then
899 bLogs.InGameConfig.Permissions.SteamIDs[data] = table.Copy(bLogs.DefaultPermissions)
900 end
901 for i in pairs(bLogs.Modules) do
902 if (bLogs.InGameConfig.Permissions.SteamIDs[data][i] == nil) then
903 bLogs.InGameConfig.Permissions.SteamIDs[data][i] = false
904 end
905 end
906 for i,v in pairs(bLogs.DefaultPermissions) do
907 if (bLogs.InGameConfig.Permissions.SteamIDs[data][i] == nil) then
908 bLogs.InGameConfig.Permissions.SteamIDs[data][i] = v
909 end
910 end
911 local c = util.Compress(util.TableToJSON(bLogs.InGameConfig.Permissions.SteamIDs[data]))
912 local d = #c
913 bLogs:nets("permissions")
914 net.WriteDouble(d)
915 net.WriteData(c,d)
916 net.Send(ply)
917 end
918 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
919 BroadcastConfigUpdate()
920 end)
921
922 bLogs:netr("permissions_update",function(ply)
923 if (not bLogs:IsMaxPermitted(ply)) then return end
924
925 local key = net.ReadString()
926 local per = net.ReadString()
927 local val = net.ReadBool()
928 per = ({
929 ["## Open Menu"] = "Menu",
930 ["## See IP Addresses"] = "IPAddresses",
931 })[per] or per
932 if (per:find("^.-: .-$")) then
933 per = (per:gsub("^(.-): (.-)$","%1_%2"))
934 end
935 if (key:sub(1,5) == "Job: " or key:sub(1,6) == "Team: ") then
936 local x
937 if (key:sub(1,5) == "Job: ") then
938 x = key:sub(6)
939 else
940 x = key:sub(7)
941 end
942 for _,v in pairs(RPExtraTeams) do
943 if (v.name == x) then
944 bLogs.InGameConfig.Permissions.Jobs[v.name][per] = val
945 break
946 end
947 end
948 elseif (key:sub(1,6) == "CAMI: ") then
949 bLogs.InGameConfig.Permissions.Usergroups[key:sub(7)][per] = val
950 elseif (key:sub(1,9) == "SteamID: ") then
951 bLogs.InGameConfig.Permissions.SteamIDs[key:sub(10)][per] = val
952 elseif (key:sub(1,11) == "Usergroup: ") then
953 bLogs.InGameConfig.Permissions.Usergroups[key:sub(12)][per] = val
954 end
955 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
956 BroadcastConfigUpdate()
957 end)
958
959 bLogs:netr("permissions_delete",function(ply)
960 if (not bLogs:IsMaxPermitted(ply)) then return end
961
962 local key = net.ReadString()
963
964 if (key:sub(1,5) == "Job: " or key:sub(1,6) == "Team: ") then
965 local x
966 if (key:sub(1,5) == "Job: ") then
967 x = key:sub(6)
968 else
969 x = key:sub(7)
970 end
971 for _,v in pairs(RPExtraTeams) do
972 if (v.name == x) then
973 bLogs.InGameConfig.Permissions.Jobs[v.name] = nil
974 break
975 end
976 end
977 elseif (key:sub(1,6) == "CAMI: ") then
978 bLogs.InGameConfig.Permissions.Usergroups[key:sub(7)] = nil
979 elseif (key:sub(1,9) == "SteamID: ") then
980 bLogs.InGameConfig.Permissions.SteamIDs[key:sub(10)] = nil
981 elseif (key:sub(1,11) == "Usergroup: ") then
982 bLogs.InGameConfig.Permissions.Usergroups[key:sub(12)] = nil
983 end
984 file.Write("blogs/config.txt",util.TableToJSON(bLogs.InGameConfig))
985 BroadcastConfigUpdate()
986 end)
987
988 bLogs_FullyLoaded = true
989 hook.Run("bLogs_FullyLoaded")
990
991end
992
993include("blogs_mysql_config.lua")
994if (bLogs.Config.MySQL.Enabled) then
995 if (system.IsWindows()) then
996 if (not file.Exists("bin/gmsv_mysqloo_win32.dll","LUA")) then
997 bLogs.Config.MySQL = false
998 if (file.Exists("bin/gmsv_mysqloo_linux.dll","LUA")) then
999 BillyError("bLogs","Why have you installed the Linux version of mysqloo when your server is running Windows?")
1000 else
1001 BillyError("bLogs","You don''t have mysqloo installed, but have MySQL enabled.")
1002 end
1003 else
1004 local worked,err = pcall(require,"mysqloo")
1005 if (worked) then
1006 require("mysqloo")
1007 elseif (err == "Couldn''t load module library!") then
1008 bLogs.Config.MySQL = false
1009 BillyError("bLogs","You don''t have libmysql.dll installed. https://facepunch.com/showthread.php?t=1515853")
1010 end
1011 bLogs:print("Initialized mysqloo","good")
1012 end
1013 end
1014 if (system.IsLinux()) then
1015 if (not file.Exists("bin/gmsv_mysqloo_linux.dll","LUA")) then
1016 bLogs.Config.MySQL = false
1017 if (file.Exists("bin/gmsv_mysqloo_win32.dll","LUA")) then
1018 BillyError("bLogs","Why have you installed the Windows version of mysqloo when your server is running Linux?")
1019 else
1020 BillyError("bLogs","You don''t have mysqloo installed, but have MySQL enabled.")
1021 end
1022 else
1023 local worked,err = pcall(require,"mysqloo")
1024 if (worked) then
1025 require("mysqloo")
1026 elseif (err == "Couldn''t load module library!") then
1027 bLogs.Config.MySQL = false
1028 BillyError("bLogs","You don''t have libmysqlclient.so installed. https://facepunch.com/showthread.php?t=1515853")
1029 end
1030 bLogs:print("Initialized mysqloo","good")
1031 end
1032 end
1033end
1034if (bLogs.Config.MySQL.Enabled) then
1035 bLogs.IDColumn = "id"
1036 if (bLogs.Config.MySQL.Host) then
1037 if (type(bLogs.Config.MySQL.Host) ~= "string") then
1038 BillyError("bLogs","You have an error in your MySQL config related to config.Host.")
1039 end
1040 else
1041 BillyError("bLogs","You have an error in your MySQL config related to config.Host. It is not a string.")
1042 end
1043 if (bLogs.Config.MySQL.Username) then
1044 if (type(bLogs.Config.MySQL.Username) ~= "string") then
1045 BillyError("bLogs","You have an error in your MySQL config related to config.Username.")
1046 end
1047 else
1048 BillyError("bLogs","You have an error in your MySQL config related to config.Username. It is not a string.")
1049 end
1050 if (bLogs.Config.MySQL.Password) then
1051 if (type(bLogs.Config.MySQL.Password) ~= "string") then
1052 BillyError("bLogs","You have an error in your MySQL config related to config.Password.")
1053 end
1054 else
1055 BillyError("bLogs","You have an error in your MySQL config related to config.Password.")
1056 end
1057 if (bLogs.Config.MySQL.Database) then
1058 if (type(bLogs.Config.MySQL.Database) ~= "string") then
1059 BillyError("bLogs","You have an error in your MySQL config related to config.Database. It is not a string.")
1060 end
1061 else
1062 BillyError("bLogs","You have an error in your MySQL config related to config.Database.")
1063 end
1064 if (bLogs.Config.MySQL.Port) then
1065 if (type(bLogs.Config.MySQL.Port) ~= "number") then
1066 BillyError("bLogs","You have an error in your MySQL config related to config.Port. It is not a number.")
1067 end
1068 else
1069 BillyError("bLogs","You have an error in your MySQL config related to config.Port.")
1070 end
1071 bLogs.Database = mysqloo.connect(
1072 bLogs.Config.MySQL.Host,
1073 bLogs.Config.MySQL.Username,
1074 bLogs.Config.MySQL.Password,
1075 bLogs.Config.MySQL.Database,
1076 bLogs.Config.MySQL.Port
1077 )
1078 bLogs:print("Connecting to remote database...")
1079 bLogs.Database.onConnectionFailed = function(_,err)
1080 BillyError("bLogs","There was an error connecting to your MySQL server. The error was:\n\n" .. err .. "\n\nThe script is still running but is not using MySQL.")
1081 bLogs.Database = nil
1082 sql_init()
1083 end
1084 bLogs.Database.onConnected = function()
1085 bLogs.Database:setCharacterSet("utf8")
1086 bLogs:print("Successfully connected to remote database on " .. bLogs.Config.MySQL.Host .. ":" .. bLogs.Config.MySQL.Port .. ".","good")
1087
1088 local blogs_player_sql = [[
1089
1090 CREATE TABLE IF NOT EXISTS `blogs_players` (
1091 `server_id` int(11) NOT NULL DEFAULT ''1'',
1092 `steamid64` varchar(191) NOT NULL,
1093 `name` varchar(191) CHARACTER SET utf8mb4 NOT NULL,
1094 `usergroup` varchar(191) CHARACTER SET utf8mb4 DEFAULT NULL,
1095 `ip_address` varchar(191) DEFAULT NULL,
1096 `last_updated` int(11) NOT NULL,
1097 PRIMARY KEY (`server_id`,`steamid64`)
1098 );
1099
1100 ]]
1101
1102 q([[
1103
1104 CREATE TABLE IF NOT EXISTS `blogs` (
1105 `id` int(11) NOT NULL AUTO_INCREMENT,
1106 `server_id` int(11) NOT NULL,
1107 `session` int(11) NOT NULL,
1108 `module` varchar(191) NOT NULL,
1109 `log` text CHARACTER SET utf8mb4 NOT NULL,
1110 `time` int(11) NOT NULL,
1111 PRIMARY KEY (`id`)
1112 );
1113
1114 CREATE TABLE IF NOT EXISTS `blogs_archive` (
1115 `id` int(11) NOT NULL AUTO_INCREMENT,
1116 `server_id` int(11) NOT NULL,
1117 `module` varchar(191) NOT NULL,
1118 `log` text CHARACTER SET utf8mb4 NOT NULL,
1119 `time` int(11) NOT NULL,
1120 PRIMARY KEY (`id`)
1121 );
1122
1123 CREATE TABLE IF NOT EXISTS `blogs_servers` (
1124 `id` varchar(191) CHARACTER SET utf8mb4 NOT NULL,
1125 `numeric_id` int(11) NOT NULL AUTO_INCREMENT,
1126 `hostname` varchar(191) CHARACTER SET utf8mb4 NOT NULL,
1127 `ip_address` varchar(191) NOT NULL,
1128 `last_updated` int(11) NOT NULL,
1129 `deleted` tinyint(4) NOT NULL DEFAULT ''0'',
1130 PRIMARY KEY (`id`),
1131 UNIQUE KEY `numeric_id` (`numeric_id`)
1132 );
1133
1134 CREATE TABLE IF NOT EXISTS `blogs_vars` (
1135 `var_name` varchar(191) NOT NULL,
1136 `var_str` varchar(191) NOT NULL,
1137 `var_int` int(11) NOT NULL,
1138 PRIMARY KEY (`var_name`)
1139 );
1140
1141 ]] .. blogs_player_sql .. [[
1142
1143 INSERT IGNORE INTO `blogs_vars` (`var_name`,`var_str`,`var_int`) VALUES (''session'','''',''0'');
1144 INSERT IGNORE INTO `blogs_vars` (`var_name`,`var_str`,`var_int`) VALUES (''logs'','''',''0'');
1145 INSERT IGNORE INTO `blogs_vars` (`var_name`,`var_str`,`var_int`) VALUES (''logs_archive'','''',''0'');
1146
1147 UPDATE `blogs_vars` SET `var_int`=`var_int` + 1 WHERE `var_name`=''session'';
1148 INSERT INTO `blogs_archive` (`server_id`,`module`,`log`,`time`) SELECT `server_id`,`module`,`log`,`time` FROM `blogs` WHERE `session` != (SELECT `var_int` FROM `blogs_vars` WHERE `var_name`=''session'') ORDER BY `blogs`.`time` ASC;
1149 TRUNCATE `blogs`;
1150
1151 ]],function()
1152
1153 q("SHOW COLUMNS FROM `blogs_players` WHERE `Field`=''usergroup''", function(rows)
1154 if (#rows == 0) then
1155 q("DROP TABLE `blogs_players`", function()
1156 q(blogs_player_sql)
1157 end)
1158 else
1159 q(blogs_player_sql)
1160 end
1161 end)
1162
1163 if (bLogs.InGameConfig.General.AutoDeleteEnabled) then
1164 local s = bLogs.InGameConfig.General.AutoDelete * 86400
1165 q("DELETE FROM `blogs_archive` WHERE `time` < (UNIX_TIMESTAMP() - " .. s .. ")")
1166 end
1167
1168 if (bLogs.InGameConfig.General.VolatileLogs) then
1169 q("TRUNCATE `blogs_archive`")
1170 end
1171
1172 q(
1173 "INSERT INTO `blogs_servers` (`id`, `hostname`, `ip_address`, `last_updated`) VALUES(''" .. e(bLogs.Config.MySQL.ServerID) .. "'',''" .. e(GetConVar("hostname"):GetString()) .. "'',''" .. e(game.GetIPAddress()) .. "'',''" .. e(os.time()) .. "'') " ..
1174 "ON DUPLICATE KEY UPDATE `hostname`=''" .. e(GetConVar("hostname"):GetString()) .. "'', `last_updated`=''" .. e(os.time()) .. "'', `ip_address`=''" .. e(game.GetIPAddress()) .. "''",
1175
1176 function()
1177 q("SELECT `numeric_id` FROM `blogs_servers` WHERE `id`=''" .. e(bLogs.Config.MySQL.ServerID) .. "''", function(r)
1178 bLogs.ServerID = r[1]["numeric_id"]
1179
1180 local function update_players_tbl()
1181 local players_query = ""
1182 for _,v in pairs(player.GetHumans()) do
1183 players_query = players_query ..
1184 "INSERT INTO `blogs_players` (`server_id`,`steamid64`,`usergroup`,`name`,`ip_address`,`last_updated`) VALUES(''" .. e(bLogs.ServerID) .. "'',''" .. e(v:SteamID64()) .. "'',''" .. e(v:GetUserGroup()) .. "'',''" .. e(v:Nick()) .. "'',''" .. e(v:IPAddress()) .. "'',''" .. e(os.time()) .. "'') " ..
1185 "ON DUPLICATE KEY UPDATE `usergroup`=''" .. e(v:GetUserGroup()) .. "'', `name`=''" .. e(v:Nick()) .. "'', `ip_address`=''" .. e(v:IPAddress()) .. "'', `last_updated`=''" .. e(os.time()) .. "'';\n"
1186 end
1187 if (players_query ~= "") then
1188 q(players_query)
1189 end
1190 end
1191 update_players_tbl()
1192 timer.Create("blogs_update_players_tbl", 60, 0, update_players_tbl)
1193
1194 local function print_info()
1195 q("SELECT COUNT(`id`) FROM `blogs`",function(r)
1196 q("UPDATE `blogs_vars` SET `var_int`=''" .. e(r[1]["COUNT(`id`)"]) .. "'' WHERE `var_name`=''logs''",function()
1197 q("SELECT COUNT(`id`) FROM `blogs_archive`",function(r)
1198 q("UPDATE `blogs_vars` SET `var_int`=''" .. e(r[1]["COUNT(`id`)"]) .. "'' WHERE `var_name`=''logs_archive''",function()
1199
1200 q("SELECT `var_name`,`var_int` FROM `blogs_vars` WHERE `var_name`=''session'' OR `var_name`=''logs'' OR `var_name`=''logs_archive''",function(r)
1201 for _,v in pairs(r) do
1202 if (v.var_name == "session") then
1203 bLogs.Session = v.var_int
1204 bLogs:print("Session # : " .. v.var_int)
1205 elseif (v.var_name == "logs") then
1206 bLogs:print("Active Logs : " .. v.var_int)
1207 elseif (v.var_name == "logs_archive") then
1208 bLogs:print("Archived Logs: " .. v.var_int)
1209 end
1210 end
1211 bLogs:print("Server ID : " .. bLogs.Config.MySQL.ServerID)
1212 bLogs:print("Server # : " .. bLogs.ServerID)
1213 sql_init()
1214 end)
1215
1216 end)
1217 end)
1218 end)
1219 end)
1220 end
1221
1222 print_info()
1223 end)
1224 end
1225 )
1226
1227 end)
1228 end
1229 bLogs.Database:connect()
1230else
1231 bLogs.IDColumn = "ROWID"
1232
1233 q({
1234
1235 [[
1236 CREATE TABLE IF NOT EXISTS `blogs` (
1237 `module` varchar NOT NULL,
1238 `log` text NOT NULL,
1239 `time` int NOT NULL
1240 )
1241 ]],
1242
1243 [[
1244 CREATE TABLE IF NOT EXISTS `blogs_archive` (
1245 `module` varchar NOT NULL,
1246 `log` text NOT NULL,
1247 `time` int NOT NULL
1248 )
1249 ]],
1250
1251 [[
1252 CREATE TABLE IF NOT EXISTS `blogs_vars` (
1253 `var_name` varchar NOT NULL,
1254 `var_str` varchar NOT NULL,
1255 `var_int` int NOT NULL,
1256 PRIMARY KEY (`var_name`)
1257 )
1258 ]],
1259
1260 "INSERT OR IGNORE INTO `blogs_vars` (`var_name`,`var_str`,`var_int`) VALUES (''logs'','''',''0'')",
1261 "INSERT OR IGNORE INTO `blogs_vars` (`var_name`,`var_str`,`var_int`) VALUES (''logs_archive'','''',''0'')",
1262
1263 [[
1264 CREATE TABLE IF NOT EXISTS `blogs_players` (
1265 `steamid64` NOT NULL,
1266 `name` NOT NULL,
1267 PRIMARY KEY (`steamid64`)
1268 )
1269 ]],
1270
1271 "DELETE FROM `blogs_archive`",
1272 "VACUUM",
1273
1274 "INSERT INTO `blogs_archive` (`module`,`log`,`time`) SELECT `module`,`log`,`time` FROM `blogs` ORDER BY `blogs`.`time` ASC",
1275
1276 "UPDATE `blogs_vars` SET `var_int`=(SELECT COUNT(`ROWID`) FROM `blogs_archive`) WHERE `var_name`=''logs_archive''",
1277
1278 "DELETE FROM `blogs`",
1279 "VACUUM",
1280
1281 "CREATE TRIGGER IF NOT EXISTS lognum_add AFTER INSERT ON `blogs` FOR EACH ROW BEGIN UPDATE `blogs_vars` SET `var_int`=`var_int`+1 WHERE `var_name`=''logs''; END",
1282 "CREATE TRIGGER IF NOT EXISTS lognum_sub AFTER DELETE ON `blogs` FOR EACH ROW BEGIN UPDATE `blogs_vars` SET `var_int`=`var_int`-1 WHERE `var_name`=''logs''; END",
1283
1284 },function()
1285
1286 sql_init()
1287
1288 end)
1289end
1290
1291concommand.Add("blogs_licensekey",function(ply)
1292 ply:PrintMessage(HUD_PRINTCONSOLE, bLogs.LicenseKey)
1293end)'