Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions lua/msync/server/modules/sv_mbsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,29 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
- Create User
- Create ban query
]]
--[[
Add user transaction
]]
transactions[k..'_user'] = MSync.DBServer:prepare( [[
INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE steamid=steamid;
]] )
transactions[k..'_user']:setString(1, k)
transactions[k..'_user']:setString(2, util.SteamIDTo64( k ))
if ULib.ucl.users[k] then
transactions[k..'_user']:setString(3, ULib.ucl.users[k].name or 'None Given')
else
transactions[k..'_user']:setString(3, 'None Given')
end
transactions[k..'_user']:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time()))

banTransaction:addQuery(transactions[k..'_user'])
MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Import Bans: added create user transaction for: " .. k)

--[[
Add ban transaction
]]
transactions[k] = MSync.DBServer:prepare( [[
INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group)
VALUES (
Expand Down Expand Up @@ -703,6 +726,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )

banTransaction:addQuery(transactions[k])
MSync.log(MSYNC_DBG_INFO, "[MBSync] Imported ban for SteamID: " .. k)
MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Import Bans: added create ban transaction for: " .. k)
end

banTransaction.onSuccess = function()
Expand Down Expand Up @@ -786,10 +810,6 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
]]
MSync.modules[info.ModuleIdentifier].loadSettings()

if not MSync.modules[info.ModuleIdentifier].banTable then
MSync.log(MSYNC_DBG_WARNING, "[MBSync] Ban table not found yet, requesting now")
MSync.modules[info.ModuleIdentifier].getActiveBans()
end
end

--[[
Expand All @@ -806,7 +826,7 @@ MSync.modules[info.ModuleIdentifier].net = function()
]]
util.AddNetworkString("msync."..info.ModuleIdentifier..".sendMessage")
MSync.modules[info.ModuleIdentifier].msg = function(ply, content, msgType)
MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.msg Param.: $ply \"$content\" $msgType")
MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.msg Param.: $ply \"$content\" $msgType",{['ply'] = ply, ['content'] = content, ['msgType'] = msgType}))
if type(ply) == "string" and not (ply == "STEAM_0:0:0") then
ply = player.GetBySteamID( ply )
end
Expand Down Expand Up @@ -1371,13 +1391,6 @@ end
Define hooks your module is listening on e.g. PlayerDisconnect
]]
MSync.modules[info.ModuleIdentifier].hooks = function()
--[[
This hook starts the timers for the asynchronous ban data loading and the check if one of the online players has been banned
]]
timer.Create("msync."..info.ModuleIdentifier..".getActiveBans", MSync.modules[info.ModuleIdentifier].settings.syncDelay, 0, function()
MSync.modules[info.ModuleIdentifier].getActiveBans()
end)
MSync.modules[info.ModuleIdentifier].getActiveBans()

hook.Add("CheckPassword", "msync."..info.ModuleIdentifier..".banCheck", function( steamid64 )
MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Checking ban status for \"" .. steamid64 .. "\"")
Expand Down Expand Up @@ -1501,6 +1514,22 @@ MSync.modules[info.ModuleIdentifier].hooks = function()
end
MSync.modules[info.ModuleIdentifier].unBanUser(steamid, admin_id)
end)

hook.Add("MSyncModuleLoaded", "msync.mbsync.loadData", function( msync_module )
if (not msync_module or msync_module == info.ModuleIdentifier) and not MSync.modules[info.ModuleIdentifier].banTable then
if not MSync.modules[info.ModuleIdentifier].banTable then
MSync.log(MSYNC_DBG_WARNING, "[MBSync] Ban table not found yet, requesting now")
MSync.modules[info.ModuleIdentifier].getActiveBans()
end

--[[
Start timer to asynchroniously resync data
]]
timer.Create("msync."..info.ModuleIdentifier..".getActiveBans", MSync.modules[info.ModuleIdentifier].settings.syncDelay, 0, function()
MSync.modules[info.ModuleIdentifier].getActiveBans()
end)
end
end)
end

--[[
Expand Down
3 changes: 3 additions & 0 deletions lua/msync/server/sv_modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function MSync.initModules()

function initTransaction.onSuccess()
MSync.log(MSYNC_DBG_INFO, "Module querys have been completed successfully")
hook.Call("MSyncModuleLoaded", nil, nil)
MSync.mysql.dbstatus = true
end

Expand Down Expand Up @@ -77,6 +78,7 @@ function MSync.loadModule(path)

function initTransaction.onSuccess()
MSync.log(MSYNC_DBG_INFO, "Module query has been completed successfully")
hook.Call("MSyncModuleLoaded", nil, info.ModuleIdentifier)
--MSync.mysql[info.ModuleIdentifier].dbstatus = true
end

Expand Down Expand Up @@ -109,6 +111,7 @@ function MSync.enableModule( module )
function initTransaction.onSuccess()
MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded")
MSync.net.sendModuleEnable( module )
hook.Call("MSyncModuleLoaded", nil, module)
--MSync.mysql[module].dbstatus = true
end

Expand Down
2 changes: 1 addition & 1 deletion lua/msync/server/sv_mysql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ end
Returns: nothing
]]
function MSync.mysql.addUserID(steamid, nickname)
MSync.log(MSYNC_DBG_DEBUG, "Exec: addUserID. Param.: " .. steamid .. " " .. nickname)
MSync.log(MSYNC_DBG_DEBUG, "Exec: addUserID. Param.: " .. steamid .. " " .. (nickname or ""))
if not MSync.DBServer then MSync.log(MSYNC_DBG_DEBUG, "No Database connected yet. Please connect to a Database to be able to create users."); return end;
if not string.match( steamid, "^STEAM_[0-1]:[0-1]:[0-9]+$" ) then return end;

Expand Down