------------------------------------------------------------------- --// PROJECT: Union of Clarity and Diversity Alpha --// RESOURCE: UCDlogging --// DEVELOPER(S): Lewis Watson (Noki) --// DATE: 08.01.15 --// PURPOSE: To create logs of everything for future reference. --// FILE: UCDlogging\logging.slua [server] ------------------------------------------------------------------- local stdLogged = 0 local db = exports.UCDsql:getConnection() --[[ function adminLog() end function stdLog(plr, type1, action, type2) if (not plr) or (not type1) or (not action) then return nil end if (plr:getType() ~= "player") or (type(type1) ~= "string") or (type(action) ~= "string") then return false end if (not type2) then type2 = "N/A" end end --]] function adminLog(admin, log_) local t = getRealTime().timestamp db:exec("INSERT INTO `adminlog` (`name`, `log_`, `datum`, `serial`) VALUES (?, ?, ?, ?)", admin.account.name, log_, t, admin.serial ) end function new(plr, type1, action, type2) if (not plr or not type1 or not action) then return nil end if (type(type1) ~= "string" or type(action) ~= "string") then return false end if (not type2) then type2 = "N/A" end local name local accname local serial if (plr and isElement(plr) and plr.type == "player") then if (exports.UCDaccounts:isPlayerLoggedIn(plr)) then accname = plr.account.name else accname = "N/A" end name = plr.name serial = plr.serial else name = tostring(plr) accname = "N/A" serial = "N/A" end db:exec("INSERT INTO `logging` SET `name`=?, `account`=?, `type`=?, `type2`=?, `tick`=?, `action`=?, `serial`=?", name, accname, type1, type2, getRealTime().timestamp, action, serial ) stdLogged = stdLogged + 1 return true end function outputTotal(reset) if stdLogged ~= 0 then outputDebugString("[UCDlogging] Total standard logs inserted in the past 5 minutes: "..stdLogged) end if (reset) then stdLogged = 0 end end setTimer(outputTotal, 60000 * 5, 0, true) addCommandHandler("logged", outputTotal) ------------------- -- Some stuff we need to log ------------------- function logConnections() -- The account will be guest, so we don't need to worry about the query not being successful new(source, "join", "Joined server", source.ip) end addEventHandler("onPlayerJoin", root, logConnections) function logDisconnections(quitType) new(source, "quit", tostring(quitType), source.ip) end addEventHandler("onPlayerQuit", root, logDisconnections)