From eec8913ad33f819cf3b6ffa2e10e0ac3767a8ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 28 Jun 2020 18:53:54 +0200 Subject: [PATCH 01/37] Change ban behaviour Changed ban behaviour, instead of telling the user that someone is already banned we edit the ban with the new data. --- lua/msync/server/modules/sv_mbsync.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 56b80b8..74b64dc 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -108,7 +108,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].banUser = function(ply, calling_ply, length, reason, allserver) - if MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()] then MSync.modules[info.ModuleIdentifier].msg(calling_ply, "User "..ply:Nick().." is already banned from this server."); return end + if MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()] then + MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()]['banId'], reason, length, calling_ply, allserver) + return + end local banUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES ( @@ -186,7 +189,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].banUserID = function(userid, calling_ply, length, reason, allserver) - if MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)] then MSync.modules[info.ModuleIdentifier].msg(calling_ply, "User "..userid.." is already banned from this server."); return end + if MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)] then + MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)]['banId'], reason, length, calling_ply, allserver) + return + end local banUserIdQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES ( From 183c7e9e82d5af4b62f4b7f3d121118e72c0fe51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 28 Jun 2020 20:40:39 +0200 Subject: [PATCH 02/37] Implement ULX hooks We implemented ULX hooks to be able to catch ban and unban events by ULX and use those in MBSync, this way when someone gets banned using ULX we can ban him cross network too. One issue is the way ULX stores banData, because we are unable to define if the ban should be on all servers or not using this method. Another issue is that we need to use a regex to be able to get the steamid of the banning admin ( come on ULX team, are you serious? Why do you save the Nickname + Steamid in the same variable ) --- lua/msync/server/modules/sv_mbsync.lua | 53 ++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 74b64dc..78195b2 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -109,6 +109,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] MSync.modules[info.ModuleIdentifier].banUser = function(ply, calling_ply, length, reason, allserver) if MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()] then + if not length == 0 then + length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)].timestamp)+(length*60))/60 + end MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()]['banId'], reason, length, calling_ply, allserver) return end @@ -157,7 +160,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) banData["unban"] = length msgLength = "Permanent" else - msgLength = ULib.secondsToStringTime(length) + msgLength = ULib.secondsToStringTime(length*60) end if reason == "" then @@ -190,6 +193,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] MSync.modules[info.ModuleIdentifier].banUserID = function(userid, calling_ply, length, reason, allserver) if MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)] then + if not (length == 0) then + length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)].timestamp)+(length*60))/60 + end MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)]['banId'], reason, length, calling_ply, allserver) return end @@ -235,7 +241,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) banData["unban"] = length msgLength = "Permanent" else - msgLength = ULib.secondsToStringTime(length) + msgLength = ULib.secondsToStringTime(length*60) end if reason == "" then @@ -295,7 +301,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) else editBanQ:setString(5, "allservers") end - editBanQ:setString(6, banId) + editBanQ:setString(6, tostring(banId)) editBanQ.onSuccess = function( q, data ) MSync.modules[info.ModuleIdentifier].getActiveBans() @@ -1334,6 +1340,47 @@ MSync.modules[info.ModuleIdentifier].hooks = function() MSync.modules[info.ModuleIdentifier].recentDisconnects[tableLength] = data end) + + hook.Add("ULibPlayerBanned", "msync.mbsync.ulxban", function(steamid, banData) + local ban = {} + + if banData.unban == 0 then + ban.length = 0 + else + ban.length = (banData.unban-os.time())/60 + end + + if not banData.reason then + banData.reason = "(None given)" + end + + if banData.modified_admin then + if banData.modified_admin == "(Console)" then + ban.admin = "STEAM_0:0:0" + else + ban.admin = string.match(banData.modified_admin, "STEAM_%d:%d:%d+") + end + else + if banData.admin == "(Console)" then + ban.admin = "STEAM_0:0:0" + else + ban.admin = string.match(banData.admin, "STEAM_%d:%d:%d+") + end + end + + MSync.modules[info.ModuleIdentifier].banUserID(steamid, ban.admin, ban.length, banData.reason, false) + end) + + hook.Add("ULibPlayerUnBanned", "msync.mbsync.ulxunban", function(steamid, admin) + local admin_id = "" + if not IsValid(admin) then + admin_id = "STEAM_0:0:0" + else + admin_id = admin:SteamID() + end + + MSync.modules[info.ModuleIdentifier].unBanUser(steamid, admin_id) + end) end --[[ From 4007880db6ce0d9168d7b18d55d3c00bea85a445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 17 Jul 2020 23:57:01 +0200 Subject: [PATCH 03/37] Unban prototype Unban prototype to unban someone in ULib after they got unbanned using MBSync commands. The issue of double command execution still persists --- lua/msync/server/modules/sv_mbsync.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 78195b2..9b4a7e8 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -892,9 +892,25 @@ MSync.modules[info.ModuleIdentifier].net = function() if not banid then return end; --[[ - Run edit function to edit ban data + When unbanning someone using the banid, we need to still unban the user in ULX, so this is the best solution. + + We loop trough the active ban table, search for the banid ( it has to be there, otherwise the user can't know it ) and then unban the steamid + ]] + local steamid = "" + for k,v in pairs(MSync.modules[info.ModuleIdentifier].banTable) do + if v.banid == banid then + steamid = v.banned['steamid'] + end + end + + --[[ + Run unban function that takes the banid ]] MSync.modules[info.ModuleIdentifier].unBanUserID(ply, banid) + + --[[ + ULib.unban for con + ]] end ) --[[ @@ -1149,6 +1165,11 @@ MSync.modules[info.ModuleIdentifier].ulx = function() Unban user with given steamid ]] MSync.modules[info.ModuleIdentifier].unBanUser(target_steamid, calling_steamid) + + --[[ + For ulx's sake, we unban the user in ulx for the case that a user has been banned using ulx ban and now gets unbanned using mbsync unbanid + ]] + ULib.unban(target_steamid, calling_ply) end local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".unBanID", MSync.modules[info.ModuleIdentifier].Chat.unBanID, "!munban" ) BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="steamid"} From 2f5db5c439891bf7236bcf2ffc360a2863577147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 18 Jul 2020 00:57:57 +0200 Subject: [PATCH 04/37] Bugfix #56 - Change behaviour how MRSync handles deleted ranks. If a user has been removed he gets deleted from the dabase, and if the user joins the server, the rank gets removed from him using "ulx removeuser" --- lua/msync/server/modules/sv_mrsync.lua | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index e1ca581..e1b81e5 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -1,6 +1,7 @@ MSync = MSync or {} MSync.modules = MSync.modules or {} MSync.modules.MRSync = MSync.modules.MRSync or {} +local userTransaction = userTransaction or {} --[[ * @file sv_mrsync.lua * @package MySQL Rank Sync @@ -37,6 +38,9 @@ function MSync.modules.MRSync.init( transaction ) --[[ Description: Function to save a players rank using steamid and group name + Arguments: + - steamid [string] : The steamid of the user to be saved + - group [string] : the group to be saved in combination with the steamid Returns: nothing ]] function MSync.modules.MRSync.saveRankByID(steamid, group) @@ -139,6 +143,8 @@ function MSync.modules.MRSync.init( transaction ) --[[ Description: Function to load a players rank + Arguments: + - ply [playerEntity] : The player to be loaded Returns: nothing ]] function MSync.modules.MRSync.loadRank(ply) @@ -158,6 +164,8 @@ function MSync.modules.MRSync.init( transaction ) loadUserQ:setString(3, MSync.settings.data.serverGroup) function loadUserQ.onData( q, data ) + print("Data!") + PrintTable(data) if not ULib.ucl.groups[data.rank] then print("[MRSync] Could not load rank "..data.rank.." for "..ply:Nick()..". Rank does not exist on this server") return @@ -168,9 +176,43 @@ function MSync.modules.MRSync.init( transaction ) ply:SetUserGroup(data.rank) end + function loadUserQ.onSuccess( q, data ) + if not data[1] then + if ply:GetUserGroup() == "user" or MSync.modules.MRSync.settings.nosync[ply:GetUserGroup()] then return end + + print("[MRSync] Assuming user has been removed from rank, setting them to default") + + userTransaction[ply:SteamID64()] = true + ULib.ucl.removeUser(ply:SteamID()) + end + end + loadUserQ:start() end + --[[ + Description: Function to remove a user entirely from MRSync + Arguments: + - steamid [string] : The steamid of the user to be removed + Returns: nothing + ]] + function MSync.modules.MRSync.removeRank(steamid) + + local removeUserRankQ = MSync.DBServer:prepare( [[ + DELETE FROM `tbl_mrsync` WHERE + user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND + ( + server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers') OR + server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) + ); + ]] ) + removeUserRankQ:setString(1, steamid) + removeUserRankQ:setString(2, util.SteamIDTo64( steamid )) + removeUserRankQ:setString(3, MSync.settings.data.serverGroup) + + removeUserRankQ:start() + end + --[[ Description: Function to load the MSync settings file Returns: true @@ -280,6 +322,16 @@ function MSync.modules.MRSync.hooks() --MSync.modules.MRSync.saveRankByID(sid, new_group) MSync.modules.MRSync.validateData(sid, new_group) end) + + -- Remove Rank on ULX Remove + hook.Add("ULibUserRemoved", "mrsync.H.saveRankOnUpdate", function(sid) + if userTransaction[util.SteamIDTo64(sid)] then + userTransaction[util.SteamIDTo64(sid)] = nil + return + end + + MSync.modules.MRSync.removeRank(sid) + end) end --[[ From 1ca4d4d7b92d28c773ebe5edc3ea9e3e55365f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 18 Jul 2020 01:09:23 +0200 Subject: [PATCH 05/37] Forgot to change version numbers .. again --- lua/msync/client_gui/modules/cl_mrsync.lua | 4 ++-- lua/msync/server/modules/sv_mrsync.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index b74ecde..2ea2e9d 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -6,7 +6,7 @@ MSync.modules.MRSync = MSync.modules.MRSync or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.0 + * @version 2.2.1 ]] --[[ @@ -16,7 +16,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.0" + Version = "2.2.1" } --[[ diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index e1b81e5..ca5e292 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -7,7 +7,7 @@ local userTransaction = userTransaction or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.0 + * @version 2.2.1 ]] --[[ @@ -17,7 +17,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.0" + Version = "2.2.1" } --[[ From 23ae845fa4c4bb367adc35ef36fbc5010ebdcf25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 18 Jul 2020 02:03:34 +0200 Subject: [PATCH 06/37] ULX Ban feature - Added ULX ban and unban for convenience sake. By default all ULX bans will be server group bans, for global bans the user is supposed to use the MBSync commands --- lua/msync/server/modules/sv_mbsync.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 9b4a7e8..ee36b2c 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -24,6 +24,7 @@ local info = { MSync.modules[info.ModuleIdentifier] = MSync.modules[info.ModuleIdentifier] or {} MSync.modules[info.ModuleIdentifier].info = info MSync.modules[info.ModuleIdentifier].recentDisconnects = MSync.modules[info.ModuleIdentifier].recentDisconnects or {} +local userTransactions = userTransactions or {} --[[ Define mysql table and additional functions that are later used @@ -909,8 +910,10 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].unBanUserID(ply, banid) --[[ - ULib.unban for con + For ulx's sake, we unban the user in ulx for the case that a user has been banned using ulx ban and now gets unbanned using mbsync unbanid ]] + userTransactions[util.SteamIDTo64(target_steamid)] = true + ULib.unban(target_steamid, calling_ply) end ) --[[ @@ -1169,6 +1172,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() --[[ For ulx's sake, we unban the user in ulx for the case that a user has been banned using ulx ban and now gets unbanned using mbsync unbanid ]] + userTransactions[util.SteamIDTo64(target_steamid)] = true ULib.unban(target_steamid, calling_ply) end local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".unBanID", MSync.modules[info.ModuleIdentifier].Chat.unBanID, "!munban" ) @@ -1346,6 +1350,16 @@ MSync.modules[info.ModuleIdentifier].hooks = function() local message = ULib.getBanMessage( ban.banned.steamid, banData) return false, message else + if ULib.bans[util.SteamIDFrom64(steamid64)] then + userTransactions[steamid64] = true + ULib.unban(target_steamid, calling_ply) + --[[ + Sorry for whitelist users, but to prevent a inocent by ULX banned player from being banned even if he got unbanned on another server + + EDIT: Actually, I just leave this as comment here in case it is wanted by multible users + ]] + --return true + end return end end) @@ -1393,6 +1407,11 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end) hook.Add("ULibPlayerUnBanned", "msync.mbsync.ulxunban", function(steamid, admin) + if userTransactions[util.SteamIDTo64(steamid)] then + userTransactions[util.SteamIDTo64(steamid)] = nil + return + end + local admin_id = "" if not IsValid(admin) then admin_id = "STEAM_0:0:0" From 6e808a1596ab3b619af19d8b207341709450772a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 18 Jul 2020 02:04:32 +0200 Subject: [PATCH 07/37] Updated MBSync feature version Updated the feature version of the MBSync module to 1.2 --- lua/msync/client_gui/modules/cl_mbsync.lua | 4 ++-- lua/msync/server/modules/sv_mbsync.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index a9c1cfe..16bdefd 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 1.1.1 + * @version 1.2.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.1.1" + Version = "1.2.0" } --[[ diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index ee36b2c..90b161b 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENSE - * @version 1.1.1 + * @version 1.2.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.1.1" + Version = "1.2.0" } --[[ From eeb18c0d7eec4f5aae583339a14bd4e22f7838eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 23 Jul 2020 19:09:27 +0200 Subject: [PATCH 08/37] Import function - Added import functionality to import bans from ULX into MBSync - Fixed export ban function to prevent adding the bans fo MBSync twice --- lua/msync/client_gui/modules/cl_mbsync.lua | 4 +- lua/msync/server/modules/sv_mbsync.lua | 126 ++++++++++++++++++--- 2 files changed, 111 insertions(+), 19 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 16bdefd..06dc103 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 1.2.0 + * @version 1.3.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.2.0" + Version = "1.3.0" } --[[ diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 90b161b..d6fb0f1 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENSE - * @version 1.2.0 + * @version 1.3.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.2.0" + Version = "1.3.0" } --[[ @@ -636,14 +636,6 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) exportActiveBans.onSuccess = function( q, data ) - local function escapeString( str ) - if not str then - return "NULL" - else - return sql.SQLStr(str) - end - end - print("[MBSync] Exporting Bans to ULX") for k,v in pairs(data) do local unban @@ -653,13 +645,21 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) unban = v.date_unix + v.length_unix end + local admin + if v["admin.steamid"] == "STEAM_0:0:0" then + admin = v["admin.nickname"] + else + admin = v["admin.nickname"].."("..v["admin.steamid"]..")" + end + ULib.bans[ v["steamid"] ] = { - admin = v["admin.nickname"], + admin = admin, time = v.date_unix, unban = unban, reason = v.reason, name = v["banned.nickname"] } + userTransactions[v["steamid64"]] = true hook.Call( ULib.HOOK_USER_BANNED, _, v["steamid"], ULib.bans[ v["steamid"] ] ) end ULib.fileWrite( ULib.BANS_FILE, ULib.makeKeyValues( ULib.bans ) ) @@ -685,6 +685,93 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) MSync.modules[info.ModuleIdentifier].exportBansToULX() end) + --[[ + Description: Function to allow the import of all ULX bans to MBSync + Returns: nothing + ]] + MSync.modules[info.ModuleIdentifier].importBansFromULX = function( allservers ) + local transactions = {} + local banTransaction = MSync.DBServer:createTransaction() + + print("[MBSync] Ban import from ULX started ...") + for k,v in pairs(ULib.bans) do + --[[ + - Create User + - Create ban query + ]] + transactions[k] = MSync.DBServer:prepare( [[ + INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group) + VALUES ( + (SELECT p_user_id FROM tbl_users WHERE steamid=?), + (SELECT p_user_id FROM tbl_users WHERE steamid=?), + ?, ?, ?, + (SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) + ); + ]] ) + local timestamp = os.time() + transactions[k]:setString(1, k) + + if v['modified_admin'] then + if v['modified_admin'] == "(Console)" then + transactions[k]:setString(2,"STEAM_0:0:0") + else + transactions[k]:setString(2,string.match(v['modified_admin'], "STEAM_%d:%d:%d+")) + end + else + if v['admin'] == "(Console)" then + transactions[k]:setString(2,"STEAM_0:0:0") + else + transactions[k]:setString(2,string.match(v['admin'], "STEAM_%d:%d:%d+")) + end + end + + transactions[k]:setString(3, v['reason'] or "(None given)") + transactions[k]:setNumber(4, tonumber(v['time'])) + + if tonumber(v['unban']) == 0 then + transactions[k]:setNumber(5, tonumber(v['unban'])) + else + transactions[k]:setNumber(5, tonumber(v['unban']) - tonumber(v['time'])) + end + + if not allserver then + transactions[k]:setString(6, MSync.settings.data.serverGroup) + else + transactions[k]:setString(6, "allservers") + end + + banTransaction:addQuery(transactions[k]) + print("[MBSync] Added ban for SteamID: "..k) + end + + banTransaction.onSuccess = function() + print("[MBSync] Ban import completed!") + end + + banTransaction.onError = function(tr, err) + print("------------------------------------") + print("[MBSync] SQL Error!") + print("------------------------------------") + print("Please include this in a Bug report:\n") + print(err.."\n") + print("------------------------------------") + print("Do not include this, this is for debugging only:\n") + print(tr.."\n") + print("------------------------------------") + end + + banTransaction:start() + end + concommand.Add("msync."..info.ModuleIdentifier..".import", function( ply, cmd, args ) + local allservers = false + + if args[1] == "true" then + allservers = true + end + + MSync.modules[info.ModuleIdentifier].importBansFromULX( allservers ) + end) + --[[ Description: Function to load the MSync settings file Returns: true @@ -1350,16 +1437,17 @@ MSync.modules[info.ModuleIdentifier].hooks = function() local message = ULib.getBanMessage( ban.banned.steamid, banData) return false, message else + --[[ + This function has been disabled in favor of security and to not cause previously ulx banned players to be unbanned. + It has been commented out because of possible usage in the future + if ULib.bans[util.SteamIDFrom64(steamid64)] then userTransactions[steamid64] = true ULib.unban(target_steamid, calling_ply) - --[[ - Sorry for whitelist users, but to prevent a inocent by ULX banned player from being banned even if he got unbanned on another server - - EDIT: Actually, I just leave this as comment here in case it is wanted by multible users - ]] + -- Disabled because it could cause security issues with whitelisted servers --return true end + ]] return end end) @@ -1379,6 +1467,11 @@ MSync.modules[info.ModuleIdentifier].hooks = function() hook.Add("ULibPlayerBanned", "msync.mbsync.ulxban", function(steamid, banData) local ban = {} + if userTransactions[util.SteamIDTo64(steamid)] then + userTransactions[util.SteamIDTo64(steamid)] = nil + return + end + if banData.unban == 0 then ban.length = 0 else @@ -1418,7 +1511,6 @@ MSync.modules[info.ModuleIdentifier].hooks = function() else admin_id = admin:SteamID() end - MSync.modules[info.ModuleIdentifier].unBanUser(steamid, admin_id) end) end From 025ea9fff1e1495f54922ba7fbaeee71a70096e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Mon, 24 Aug 2020 08:43:54 +0200 Subject: [PATCH 09/37] Logging System Add log function to easily log data with different logging levels --- lua/msync/sh_init.lua | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lua/msync/sh_init.lua b/lua/msync/sh_init.lua index df7e2ed..459d8d1 100644 --- a/lua/msync/sh_init.lua +++ b/lua/msync/sh_init.lua @@ -1,2 +1,55 @@ MSync = MSync or {} MSync.net = MSync.net or {} + +MSYNC_DBG_ERROR = 0 +MSYNC_DBG_WARNING = 1 +MSYNC_DBG_INFO = 2 +MSYNC_DBG_DEBUG = 3 + +local debugLevels = { + [MSYNC_DBG_ERROR] = { + color = Color(255, 44, 44), + prefix = "[MSync_ERROR]" + }, + [MSYNC_DBG_WARNING] = { + color = Color(255, 160, 17), + prefix = "[MSync_WARN]" + }, + [MSYNC_DBG_INFO] = { + color = Color(255, 255, 255), + prefix = "[MSync_INFO]" + }, + [MSYNC_DBG_DEBUG] = { + color = Color(180, 180, 180), + prefix = "[MSync_DEGUB]" + } +} + +--[[ + MSync debug level convar +]] +MSync.DebugCVar = CreateConVar( "msync_debug", 0, FCVAR_REPLICATED+FCVAR_ARCHIVE, "Set the MSync debug level. 0 = Error, 1 = Warning, 2 = Info, 3 = Debug", 0, 3 ) + +--[[ + Description: MSync logging function, allowing log levels and formated console logs + Arguments: + - logLevel [number] - The log level this message requires to be sent. Valid Globals are: MSYNC_DBG_ERROR, MSYNC_DBG_WARNING, MSYNC_DBG_INFO and MSYNC_DBG_DEBUG + - logMessage [string] - The log message to be sent into the console ( should Prefix the module like "[MBSync]...") + Returns: + - Nothing +]] +MSync.log = function(logLevel, logMessage) + if not type(logLevel) == "number" then return end + + local DebugCvarValue = MSync.DebugCVar:GetInt() + + if DebugCvarValue >= logLevel then + if debugLevels[logLevel] then + MsgC(debugLevels[logLevel].color, debugLevels[logLevel].prefix.." "..logMessage.."\n") + else + MsgC(Color(255, 255, 255), "[MSync_LOG] "..logMessage.."\n") + end + -- Feature(?): Log files? Client GUI log viewer? + --file.Append( "msync/logs/msync_"..os.date("[]")..".log", os.date("[]") ) + end +end \ No newline at end of file From ab944c9cea28922184eba14290d9d6a838db1c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Mon, 24 Aug 2020 09:29:44 +0200 Subject: [PATCH 10/37] MSync server logging Add logging abilities to server side part of ULX. --- lua/msync/server/sv_init.lua | 18 +++++++++++++++++ lua/msync/server/sv_modules.lua | 21 +++++++++++++------- lua/msync/server/sv_mysql.lua | 34 ++++++++++++++++++++------------- lua/msync/server/sv_net.lua | 10 ++++++++++ lua/msync/server/sv_ulx.lua | 2 ++ 5 files changed, 65 insertions(+), 20 deletions(-) diff --git a/lua/msync/server/sv_init.lua b/lua/msync/server/sv_init.lua index 15565b6..a4e7b0a 100644 --- a/lua/msync/server/sv_init.lua +++ b/lua/msync/server/sv_init.lua @@ -12,6 +12,8 @@ MSync.ulx = MSync.ulx or {} ]] function MSync.func.loadServer() + MSync.log(MSYNC_DBG_DEBUG, "Loading Server") + include("msync/server/sv_net.lua") include("msync/server/sv_mysql.lua") include("msync/server/sv_modules.lua") @@ -23,6 +25,8 @@ function MSync.func.loadServer() timer.Create("msync.t.checkForULXandULib", 5, 0, function() if not ulx or not ULib then return end; + MSync.log(MSYNC_DBG_DEBUG, "ULX Loaded, continuing startup") + timer.Remove("msync.t.checkForULXandULib") MSync.ulx.createPermissions() MSync.ulx.createCommands() @@ -34,11 +38,13 @@ function MSync.func.loadServer() local files, _ = file.Find("msync/client_gui/*.lua", "LUA") for k, v in pairs(files) do AddCSLuaFile("msync/client_gui/"..v) + MSync.log(MSYNC_DBG_DEBUG, "Added client Lua file: "..v) end local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") for k, v in pairs(files) do AddCSLuaFile("msync/client_gui/modules/"..v) + MSync.log(MSYNC_DBG_DEBUG, "Added client module file: "..v) end end @@ -47,6 +53,7 @@ end Returns: true ]] function MSync.func.loadSettings() + MSync.log(MSYNC_DBG_INFO, "Loading Settings") if not file.Exists("msync/settings.txt", "DATA") then MSync.settings.data = { mysql = { @@ -63,8 +70,10 @@ function MSync.func.loadSettings() } file.CreateDir("msync") file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) + MSync.log(MSYNC_DBG_DEBUG, "Created new configuration") else MSync.settings.data = util.JSONToTable(file.Read("msync/settings.txt", "DATA")) + MSync.log(MSYNC_DBG_DEBUG, "Loaded found configuration") end return true @@ -76,6 +85,9 @@ end ]] function MSync.func.saveSettings() file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) + + MSync.log(MSYNC_DBG_INFO, "Saved configuration") + return file.Exists("msync/settings.txt", "DATA") end @@ -86,9 +98,12 @@ end function MSync.func.getModuleInfos() local infoTable = {} + MSync.log(MSYNC_DBG_DEBUG, "Getting module informations...") + for k,v in pairs(MSync.modules) do infoTable[k] = v.info infoTable[k].state = MSync.settings.data.enabledModules[v.info.ModuleIdentifier] or false + MSync.log(MSYNC_DBG_DEBUG, "[getModuleInfos] Got info for "..k) end return infoTable @@ -101,6 +116,9 @@ end ]] function MSync.func.getSafeSettings() local settings = table.Copy(MSync.settings.data) + + MSync.log(MSYNC_DBG_DEBUG, "Generating safe settings to be sent to the player") + settings.mysql.password = nil return settings diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index 32bfc1d..5cb242c 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -8,9 +8,13 @@ MSync.modules = MSync.modules or {} Returns: nothing ]] function MSync.loadModules() + + MSync.log(MSYNC_DBG_DEBUG, "Loading modules") + local files, _ = file.Find("msync/server/modules/*.lua", "LUA") for k, v in pairs(files) do include("msync/server/modules/"..v) + MSync.log(MSYNC_DBG_DEBUG, "Found module: "..v) end end @@ -19,6 +23,9 @@ end Returns: nothing ]] function MSync.initModules() + + MSync.log(MSYNC_DBG_DEBUG, "Initializing modules") + MSync.mysql.dbstatus = false if MSync.DBServer then local initTransaction = MSync.DBServer:createTransaction() @@ -29,23 +36,23 @@ function MSync.initModules() v["net"]() v["ulx"]() v["hooks"]() - print("["..v["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded") end end function initTransaction.onSuccess() - print("[MSync] Module querys have been completed successfully") + MSync.log(MSYNC_DBG_INFO, "Module querys have been completed successfully") MSync.mysql.dbstatus = true end function initTransaction.onError(tr, err) - print("[MSync] There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) MSync.mysql.dbstatus = false end initTransaction:start() else - print("[MSync] No MySQL server connected, aborting module loading.") + MSync.log(MSYNC_DBG_ERROR, "No MySQL server connected, aborting module loading.") end end @@ -63,15 +70,15 @@ function MSync.loadModule(path) MSync.modules[info.ModuleIdentifier].ulx() MSync.modules[info.ModuleIdentifier].hooks() - print("["..MSync.modules[info.Name].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.Name].."] Module loaded") function initTransaction.onSuccess() - print("[MSync] Module query has been completed successfully") + MSync.log(MSYNC_DBG_INFO, "Module query has been completed successfully") MSync.mysql[info.ModuleIdentifier].dbstatus = true end function initTransaction.onError(tr, err) - print("[MSync] There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) MSync.mysql[info.ModuleIdentifier].dbstatus = false end diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index b75b6d5..ecfda79 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -12,6 +12,8 @@ function MSync.mysql.initialize() if (file.Exists( "bin/gmsv_mysqloo_linux.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win32.dll", "LUA" )) and MSync.settings.data.mysql then require("mysqloo") + MSync.log(MSYNC_DBG_INFO, "Initializing database") + MSync.DBServer = mysqloo.connect( MSync.settings.data.mysql.host, MSync.settings.data.mysql.username, @@ -23,6 +25,8 @@ function MSync.mysql.initialize() function MSync.DBServer.onConnected( db ) local initDatabase = MSync.DBServer:createTransaction() + MSync.log(MSYNC_DBG_INFO, "Connected to database, running database preparation ( this is done at each startup )") + initDatabase:addQuery(MSync.DBServer:query([[ CREATE TABLE IF NOT EXISTS `tbl_msyncdb_version` ( `version` INT UNSIGNED NOT NULL, @@ -77,10 +81,11 @@ function MSync.mysql.initialize() function initDatabase.onSuccess() MSync.mysql.saveServer() MSync.initModules() + MSync.log(MSYNC_DBG_INFO, "Database prepared") end function initDatabase.onError(tr, err) - print("[MSync] There has been a error while initializing the database.\nPlease inform the Developer and send him this:\n"..err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while initializing the database.\nPlease inform the Developer and send him this:\n"..err) end initDatabase:start() @@ -88,14 +93,14 @@ function MSync.mysql.initialize() end function MSync.DBServer.onConnectionFailed( db, err ) - print("[MSync] There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) end MSync.DBServer:connect() elseif not MSync.settings then - print("[MSync] Settings not found") + MSync.log(MSYNC_DBG_ERROR, "Settings not found") else - print("[MSync] Could not locate MySQLoo") + MSync.log(MSYNC_DBG_ERROR, "Could not locate MySQLoo") end end @@ -105,7 +110,8 @@ end Returns: nothing ]] function MSync.mysql.addUser(ply) - if not MSync.DBServer then print("[MSync] No Database connected yet. Please connect to a Database to be able to create users."); return end; + MSync.log(MSYNC_DBG_DEBUG, "Exec: addUser. Param.: " .. ply) + 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; local addUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) @@ -124,11 +130,11 @@ function MSync.mysql.addUser(ply) addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) function addUserQ.onSuccess() - print("[MSync] User "..ply:Nick().." successfully created") + MSync.log(MSYNC_DBG_INFO, "User "..ply:Nick().." successfully created") end function addUserQ.onError(q, err, sql) - print("[MSync] Failed to create user "..ply:Nick().." !\nPlease report this to the developer: "..err) + MSync.log(MSYNC_DBG_ERROR, "Failed to create user "..ply:Nick().." !\nPlease report this to the developer: "..err) end addUserQ:start() @@ -142,7 +148,8 @@ end Returns: nothing ]] function MSync.mysql.addUserID(steamid, nickname) - if not MSync.DBServer then print("[MSync] No Database connected yet. Please connect to a Database to be able to create users."); return end; + MSync.log(MSYNC_DBG_DEBUG, "Exec: addUserID. Param.: " .. steamid .. " " .. nickname) + 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; nickname = nickname or "None Given" @@ -163,11 +170,11 @@ function MSync.mysql.addUserID(steamid, nickname) addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) function addUserQ.onSuccess() - print("[MSync] User "..steamid.." successfully created") + MSync.log(MSYNC_DBG_INFO, "User "..steamid.." successfully created") end function addUserQ.onError(q, err, sql) - print("[MSync] Failed to create user "..steamid.." !\nPlease report this to the developer: "..err) + MSync.log(MSYNC_DBG_ERROR, "Failed to create user "..steamid.." !\nPlease report this to the developer: "..err) end addUserQ:start() @@ -210,6 +217,7 @@ function MSync.mysql.saveServer() if string.len(hostname) > 75 then hostname = string.sub( hostname, 1, 75 ) + MSync.log(MSYNC_DBG_WARNING, "Hostname too long, shorting it down to a max of 75 letters") end addServer:setString(1, hostname) addServer:setString(2, gameAddress[1]) @@ -217,18 +225,18 @@ function MSync.mysql.saveServer() addServer:setString(4, MSync.settings.data.serverGroup) function addServer.onSuccess() - print("[MSync] Server saved to database") + MSync.log(MSYNC_DBG_INFO, "Server saved to database") end function addServer.onError(q, err, sql) - print("[MSync] Failed to create server !\nPlease report this to the developer: "..err) + MSync.log(MSYNC_DBG_ERROR, "Failed to create server !\nPlease report this to the developer: "..err) end addServer:start() end function addServerGroup.onError(q, err, sql) - print("[MSync] Failed to create server !\nPlease report this to the developer: "..err) + MSync.log(MSYNC_DBG_ERROR, "Failed to create server !\nPlease report this to the developer: "..err) end addServerGroup:start() diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index 467c029..d344147 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -10,6 +10,7 @@ MSync.net = MSync.net or {} Returns: nothing ]] function MSync.net.sendTable(ply, identifier, table) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendTable. Param.: " .. ply .. " " .. identifier .. " " .. table) local identifier = identifier or "settings" net.Start("msync.sendTable") @@ -28,6 +29,7 @@ util.AddNetworkString("msync.sendTable") Returns: nothing ]] function MSync.net.sendMessage(ply, state, string) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendMessage. Param.: " .. ply .. " " .. state .. " " .. string) local state = state or "info" net.Start("msync.sendMessage") @@ -44,6 +46,7 @@ util.AddNetworkString("msync.sendMessage") Returns: nothing ]] function MSync.net.openAdminGUI(ply) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.openAdminGUI. Param.: " .. ply) net.Start("msync.openAdminGUI") net.Send(ply) end @@ -56,6 +59,7 @@ util.AddNetworkString("msync.openAdminGUI") Returns: nothing ]] function MSync.net.dbStatus(ply) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.dbStatus. Param.: " .. ply) net.Start("msync.dbStatus") if MSync.DBServer then net.WriteBool(true) @@ -72,6 +76,7 @@ util.AddNetworkString("msync.dbStatus") ]] util.AddNetworkString("msync.getTable") net.Receive("msync.getTable", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getTable. Ply.: " .. ply) if not ply:query("msync.getTable") then return end local identifier = net.ReadString() @@ -84,6 +89,7 @@ end ) ]] util.AddNetworkString("msync.sendSettings") net.Receive("msync.sendSettings", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendSettings. Ply.: " .. ply) if not ply:query("msync.sendSettings") then return end local password = MSync.settings.data.mysql.password @@ -106,6 +112,7 @@ end ) ]] util.AddNetworkString("msync.getSettings") net.Receive("msync.getSettings", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getSettings. Ply.: " .. ply) if not ply:query("msync.getSettings") then return end MSync.net.sendTable(ply, "settings", MSync.func.getSafeSettings()) end ) @@ -116,6 +123,7 @@ end ) ]] util.AddNetworkString("msync.getModules") net.Receive("msync.getModules", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getModules. Ply.: " .. ply) if not ply:query("msync.getModules") then return end MSync.net.sendTable(ply, "modules", MSync.func.getModuleInfos()) @@ -127,6 +135,7 @@ end ) ]] util.AddNetworkString("msync.toggleModule") net.Receive("msync.toggleModule", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.toggleModule. Ply.: " .. ply) if not ply:query("msync.toggleModule") then return end @@ -147,6 +156,7 @@ end ) ]] util.AddNetworkString("msync.connectDB") net.Receive("msync.connectDB", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectDB. Ply.: " .. ply) if not ply:query("msync.connectDB") then return end MSync.mysql.initialize() diff --git a/lua/msync/server/sv_ulx.lua b/lua/msync/server/sv_ulx.lua index f8acdb1..59bf021 100644 --- a/lua/msync/server/sv_ulx.lua +++ b/lua/msync/server/sv_ulx.lua @@ -6,6 +6,7 @@ MSync.ulx = MSync.ulx or {} Returns: nothing ]] function MSync.ulx.createPermissions() + MSync.log(MSYNC_DBG_DEBUG, "Creating ULX permissions") ULib.ucl.registerAccess("msync.getTable", "superadmin", "Allows player to get MSync tables", "MSync") ULib.ucl.registerAccess("msync.sendSettings", "superadmin", "Allows player to send settings to server", "MSync") ULib.ucl.registerAccess("msync.connectDB", "superadmin", "Allows player to connect the server to the database server", "MSync") @@ -22,6 +23,7 @@ end Returns: nothing ]] function MSync.ulx.createCommands() + MSync.log(MSYNC_DBG_DEBUG, "Creating ULX commands") function MSync.func.openAdminGUI(calling_ply) if not calling_ply:query("msync.openAdminGUI") then return end; if not IsValid(calling_ply) then return end; From 4e959f7a6d31842005d8642481ae8bf4ae4b653d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Mon, 24 Aug 2020 11:17:38 +0200 Subject: [PATCH 11/37] Clientside Logging and Bugfix Add clientside logging abilities and fixed a bug on the serverside --- lua/msync/client_gui/cl_admin_gui.lua | 18 ++++++++++++++++++ lua/msync/client_gui/cl_modules.lua | 4 ++-- lua/msync/client_gui/cl_net.lua | 14 ++++++++++++-- lua/msync/server/sv_mysql.lua | 2 +- lua/msync/server/sv_net.lua | 20 ++++++++++---------- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index ef16f88..5b7a8ba 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -7,6 +7,9 @@ MSync.AdminPanel = MSync.AdminPanel or {} Returns: panel ]] function MSync.AdminPanel.InitMySQL( sheet ) + + MSync.log(MSYNC_DBG_DEBUG, "Initializing MySQL settings panel") + local pnl = vgui.Create( "DPanel", sheet ) local mysqlip_text = vgui.Create( "DLabel", pnl ) @@ -101,6 +104,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) save_button:SetPos( 25, 290 ) save_button:SetSize( 130, 30 ) save_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "Saving settings") MSync.settings.mysql.host = mysqlip:GetValue() MSync.settings.mysql.port = mysqlport:GetValue() MSync.settings.mysql.database = mysqldb:GetValue() @@ -115,6 +119,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) saveconnect_button:SetPos( 155, 290 ) saveconnect_button:SetSize( 130, 30 ) saveconnect_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "Saving settings and connecting to the database") MSync.settings.mysql.host = mysqlip:GetValue() MSync.settings.mysql.port = mysqlport:GetValue() MSync.settings.mysql.database = mysqldb:GetValue() @@ -130,6 +135,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) connect_button:SetPos( 285, 290 ) connect_button:SetSize( 130, 30 ) connect_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "Connecting to the database") MSync.net.connectDB() end @@ -138,6 +144,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) reset_button:SetPos( 415, 290 ) reset_button:SetSize( 130, 30 ) reset_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "Reset mysql configuration") mysqlip:SetText("127.0.0.1") mysqlport:SetText("3306") mysqldb:SetText("msync") @@ -163,6 +170,8 @@ function MSync.AdminPanel.InitMySQL( sheet ) timer.Create("msync.t.checkForSettings", 0.5, 0, function() if not MSync.settings or not MSync.settings.mysql then return end; + MSync.log(MSYNC_DBG_DEBUG, "Got server settings, updating MySQL settings panel") + mysqlip:SetText(MSync.settings.mysql.host) mysqlport:SetText(MSync.settings.mysql.port) mysqldb:SetText(MSync.settings.mysql.database) @@ -181,6 +190,9 @@ end Returns: panel ]] function MSync.AdminPanel.InitModules( sheet ) + + MSync.log(MSYNC_DBG_DEBUG, "Initializing modulestate panel") + local pnl = vgui.Create( "DPanel", sheet ) local ModuleList = vgui.Create( "DListView", pnl ) @@ -220,6 +232,9 @@ end Returns: panel ]] function MSync.AdminPanel.InitModuleSettings( sheet ) + + MSync.log(MSYNC_DBG_DEBUG, "Initializing module settings panel") + local pnl = vgui.Create( "DColumnSheet", sheet ) local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") @@ -231,6 +246,7 @@ function MSync.AdminPanel.InitModuleSettings( sheet ) MSync.modules[info.ModuleIdentifier]["init"]() MSync.modules[info.ModuleIdentifier]["net"]() pnl:AddSheet( info.Name, MSync.modules[info.ModuleIdentifier].adminPanel(pnl)) + MSync.log(MSYNC_DBG_DEBUG, "Added settings tab for module: ") end end @@ -243,6 +259,8 @@ end ]] function MSync.AdminPanel.InitPanel() + MSync.log(MSYNC_DBG_DEBUG, "Opening Admin GUI") + --if not LocalPlayer():query("msync.admingui") then return false end; MSync.net.getSettings() diff --git a/lua/msync/client_gui/cl_modules.lua b/lua/msync/client_gui/cl_modules.lua index 81ee7a4..07fdfd8 100644 --- a/lua/msync/client_gui/cl_modules.lua +++ b/lua/msync/client_gui/cl_modules.lua @@ -27,7 +27,7 @@ function MSync.initModules() v["net"]() v["ulx"]() v["hooks"]() - print("["..v["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded") end end @@ -47,6 +47,6 @@ function MSync.loadModule(path) MSync.modules[info.ModuleIdentifier].ulx() MSync.modules[info.ModuleIdentifier].hooks() - print("["..MSync.modules[info.Name].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.Name].."] Module loaded") end diff --git a/lua/msync/client_gui/cl_net.lua b/lua/msync/client_gui/cl_net.lua index 74a92c3..e8fa735 100644 --- a/lua/msync/client_gui/cl_net.lua +++ b/lua/msync/client_gui/cl_net.lua @@ -6,6 +6,7 @@ MSync.net = MSync.net or {} Returns: nothing ]] function MSync.net.getSettings() + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.getSettings") net.Start("msync.getSettings") net.SendToServer() end @@ -15,6 +16,7 @@ end Returns: nothing ]] function MSync.net.getModules() + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.getModules") net.Start("msync.getModules") net.SendToServer() end @@ -24,6 +26,7 @@ end Returns: nothing ]] function MSync.net.toggleModule(ident, state) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.toggleModule Param.: " .. ident .. " " .. state) net.Start("msync.toggleModule") net.WriteString(ident) net.WriteString(state) @@ -35,6 +38,7 @@ end Returns: nothing ]] function MSync.net.sendSettings(table) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendSettings Param.: " .. tostring(table)) net.Start("msync.sendSettings") net.WriteTable(table) net.SendToServer() @@ -45,6 +49,7 @@ end Returns: nothing ]] function MSync.net.connectDB() + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.connectDB") net.Start("msync.connectDB") net.SendToServer() end @@ -54,14 +59,16 @@ end Returns: nothing ]] net.Receive( "msync.sendTable", function( len, pl ) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendTable") local type = net.ReadString() local table = net.ReadTable() - if type == "settings" then MSync.settings = table; print("Got Settings!") - elseif type == "modules" then MSync.serverModules = table + if type == "settings" then MSync.settings = table; MSync.log(MSYNC_DBG_INFO, "Got settings from server") + elseif type == "modules" then MSync.serverModules = table; MSync.log(MSYNC_DBG_INFO, "Got modules from server") elseif type == "modulestate" then MSync.moduleState = table MSync.loadModules() + MSync.log(MSYNC_DBG_INFO, "Got module states from server") end end ) @@ -70,6 +77,7 @@ end ) Returns: nothing ]] net.Receive( "msync.sendMessage", function( len, pl ) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendMessage") local state = net.ReadString() if state == "error" then @@ -86,6 +94,7 @@ end ) Returns: nothing ]] net.Receive( "msync.openAdminGUI", function( len, pl ) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.openAdminGUI") MSync.AdminPanel.InitPanel() end ) @@ -95,4 +104,5 @@ end ) ]] net.Receive( "msync.dbStatus", function( len, pl ) MSync.DBStatus = net.ReadBool() + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.dbStatus Return: " .. tostring(MSync.DBStatus)) end ) \ No newline at end of file diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index ecfda79..f08d484 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -110,7 +110,7 @@ end Returns: nothing ]] function MSync.mysql.addUser(ply) - MSync.log(MSYNC_DBG_DEBUG, "Exec: addUser. Param.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Exec: addUser. Param.: " .. tostring(ply)) 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; local addUserQ = MSync.DBServer:prepare( [[ diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index d344147..627388a 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -10,7 +10,7 @@ MSync.net = MSync.net or {} Returns: nothing ]] function MSync.net.sendTable(ply, identifier, table) - MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendTable. Param.: " .. ply .. " " .. identifier .. " " .. table) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendTable. Param.: " .. tostring(ply) .. " " .. identifier .. " " .. tostring(table)) local identifier = identifier or "settings" net.Start("msync.sendTable") @@ -29,7 +29,7 @@ util.AddNetworkString("msync.sendTable") Returns: nothing ]] function MSync.net.sendMessage(ply, state, string) - MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendMessage. Param.: " .. ply .. " " .. state .. " " .. string) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendMessage. Param.: " .. tostring(ply) .. " " .. state .. " " .. tostring(string)) local state = state or "info" net.Start("msync.sendMessage") @@ -46,7 +46,7 @@ util.AddNetworkString("msync.sendMessage") Returns: nothing ]] function MSync.net.openAdminGUI(ply) - MSync.log(MSYNC_DBG_DEBUG, "Exec: net.openAdminGUI. Param.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.openAdminGUI. Param.: " .. tostring(ply)) net.Start("msync.openAdminGUI") net.Send(ply) end @@ -59,7 +59,7 @@ util.AddNetworkString("msync.openAdminGUI") Returns: nothing ]] function MSync.net.dbStatus(ply) - MSync.log(MSYNC_DBG_DEBUG, "Exec: net.dbStatus. Param.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.dbStatus. Param.: " .. tostring(ply)) net.Start("msync.dbStatus") if MSync.DBServer then net.WriteBool(true) @@ -76,7 +76,7 @@ util.AddNetworkString("msync.dbStatus") ]] util.AddNetworkString("msync.getTable") net.Receive("msync.getTable", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getTable. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getTable. Ply.: " .. ply:Nick()) if not ply:query("msync.getTable") then return end local identifier = net.ReadString() @@ -89,7 +89,7 @@ end ) ]] util.AddNetworkString("msync.sendSettings") net.Receive("msync.sendSettings", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendSettings. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendSettings. Ply.: " .. ply:Nick()) if not ply:query("msync.sendSettings") then return end local password = MSync.settings.data.mysql.password @@ -112,7 +112,7 @@ end ) ]] util.AddNetworkString("msync.getSettings") net.Receive("msync.getSettings", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getSettings. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getSettings. Ply.: " .. ply:Nick()) if not ply:query("msync.getSettings") then return end MSync.net.sendTable(ply, "settings", MSync.func.getSafeSettings()) end ) @@ -123,7 +123,7 @@ end ) ]] util.AddNetworkString("msync.getModules") net.Receive("msync.getModules", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getModules. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getModules. Ply.: " .. ply:Nick()) if not ply:query("msync.getModules") then return end MSync.net.sendTable(ply, "modules", MSync.func.getModuleInfos()) @@ -135,7 +135,7 @@ end ) ]] util.AddNetworkString("msync.toggleModule") net.Receive("msync.toggleModule", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.toggleModule. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.toggleModule. Ply.: " .. ply:Nick()) if not ply:query("msync.toggleModule") then return end @@ -156,7 +156,7 @@ end ) ]] util.AddNetworkString("msync.connectDB") net.Receive("msync.connectDB", function(len, ply) - MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectDB. Ply.: " .. ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectDB. Ply.: " .. ply:Nick()) if not ply:query("msync.connectDB") then return end MSync.mysql.initialize() From 0e277ff6078c991412551c38a3040218010d7bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Wed, 26 Aug 2020 03:57:10 +0200 Subject: [PATCH 12/37] MRSync SV - Logging implementation - Add logging implementation for server-side part of MRSync module - Add function to use variables in strings and replace them --- lua/msync/server/modules/sv_mrsync.lua | 64 ++++++++++++++++---------- lua/msync/sh_init.lua | 25 +++++++++- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index ca5e292..1f0c884 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -24,6 +24,7 @@ MSync.modules.MRSync.info = { Define mysql table and additional functions that are later used ]] function MSync.modules.MRSync.init( transaction ) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.init") transaction:addQuery( MSync.DBServer:query([[ CREATE TABLE IF NOT EXISTS `tbl_mrsync` ( `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, @@ -45,7 +46,9 @@ function MSync.modules.MRSync.init( transaction ) ]] function MSync.modules.MRSync.saveRankByID(steamid, group) - if MSync.modules.MRSync.settings.nosync[group] then return end; + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.saveRankByID Params: " .. steamid .. " " .. group) + + if MSync.modules.MRSync.settings.nosync[group] then MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Group \"" .. group .. "\" is set to No-Sync. Not sending data to the database"); return end; local addUserRankQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mrsync` (user_id, rank, server_group) @@ -67,18 +70,11 @@ function MSync.modules.MRSync.init( transaction ) addUserRankQ.onError = function( q, err, sql ) if string.match( err, "^Column 'user_id' cannot be null$" ) then + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User does not exist, creating user and repeating"); MSync.mysql.addUserID(steamid) MSync.modules.MRSync.saveRankByID(steamid, group) else - print("------------------------------------") - print("[MRSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end end @@ -93,12 +89,16 @@ function MSync.modules.MRSync.init( transaction ) ]] function MSync.modules.MRSync.validateData( steamid, group ) - if MSync.modules.MRSync.settings.nosync[group] then return end; + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.validateData Param.: " .. steamid .. " " .. group); + + if MSync.modules.MRSync.settings.nosync[group] then MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Group \"" .. group .. "\" is set to No-Sync. Not sending data to the database"); return end; local removeOldRanksQ if not MSync.modules.MRSync.settings.syncall[group] then + MSync.log(MSYNC_DBG_INFO, "[MRSync] Non-Syncall group, removing all \"allservers\" ranks from user"); + removeOldRanksQ = MSync.DBServer:prepare( [[ DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers'); ]] ) @@ -106,10 +106,13 @@ function MSync.modules.MRSync.init( transaction ) removeOldRanksQ:setString(2, util.SteamIDTo64(steamid)) removeOldRanksQ.onSuccess = function( q, data ) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Data validation completed successfully, saving user"); MSync.modules.MRSync.saveRankByID(steamid, group) end else + MSync.log(MSYNC_DBG_INFO, "[MRSync] Syncall group, removing all groups from user that are not \"allservers\""); + removeOldRanksQ = MSync.DBServer:prepare( [[ DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND server_group<>(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers'); ]] ) @@ -117,24 +120,18 @@ function MSync.modules.MRSync.init( transaction ) removeOldRanksQ:setString(2, util.SteamIDTo64(steamid)) removeOldRanksQ.onSuccess = function( q, data ) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Data validation completed successfully, saving user"); MSync.modules.MRSync.saveRankByID(steamid, group) end end removeOldRanksQ.onError = function( q, err, sql ) if string.match( err, "^Column 'user_id' cannot be null$" ) then + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User not found, creating user before trying again"); MSync.mysql.addUserID(steamid) MSync.modules.MRSync.saveRankByID(steamid, group) else - print("------------------------------------") - print("[MRSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end end @@ -148,6 +145,7 @@ function MSync.modules.MRSync.init( transaction ) Returns: nothing ]] function MSync.modules.MRSync.loadRank(ply) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.loadRank Param.:" .. ply:Nick()); local loadUserQ = MSync.DBServer:prepare( [[ SELECT `rank` FROM `tbl_mrsync` WHERE user_id=( @@ -164,23 +162,24 @@ function MSync.modules.MRSync.init( transaction ) loadUserQ:setString(3, MSync.settings.data.serverGroup) function loadUserQ.onData( q, data ) - print("Data!") - PrintTable(data) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Got data for user \"" .. ply:Nick() .. "\". Rank: " .. data.rank); if not ULib.ucl.groups[data.rank] then - print("[MRSync] Could not load rank "..data.rank.." for "..ply:Nick()..". Rank does not exist on this server") + MSync.log(MSYNC_DBG_ERROR, "[MRSync] Could not load rank "..data.rank.." for "..ply:Nick()..". Rank does not exist on this server") return end if data.rank == ply:GetUserGroup() then return end; + MSync.log(MSYNC_DBG_INFO, "[MRSync] Data for user \"" .. ply:Nick() .. "\" valid and user does not have the right group, changing to " .. data.rank); ply:SetUserGroup(data.rank) end function loadUserQ.onSuccess( q, data ) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] loadUser query executed successfully"); if not data[1] then if ply:GetUserGroup() == "user" or MSync.modules.MRSync.settings.nosync[ply:GetUserGroup()] then return end - print("[MRSync] Assuming user has been removed from rank, setting them to default") + MSync.log(MSYNC_DBG_INFO, "[MRSync] Assuming user \"" .. ply:Nick() .. "\" has been removed from rank, setting them to default") userTransaction[ply:SteamID64()] = true ULib.ucl.removeUser(ply:SteamID()) @@ -198,6 +197,8 @@ function MSync.modules.MRSync.init( transaction ) ]] function MSync.modules.MRSync.removeRank(steamid) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.removeRank Param.: " .. steamid); + local removeUserRankQ = MSync.DBServer:prepare( [[ DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND @@ -218,6 +219,9 @@ function MSync.modules.MRSync.init( transaction ) Returns: true ]] function MSync.modules.MRSync.loadSettings() + + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.loadSettings"); + if not file.Exists("msync/mrsync.txt", "DATA") then MSync.modules.MRSync.settings = { nosync = { @@ -228,8 +232,10 @@ function MSync.modules.MRSync.init( transaction ) } } file.Write("msync/mrsync.txt", util.TableToJSON(MSync.modules.MRSync.settings, true)) + MSync.log(MSYNC_DBG_INFO, "[MRSync] No config file, creating one now"); else MSync.modules.MRSync.settings = util.JSONToTable(file.Read("msync/mrsync.txt", "DATA")) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Found config file, loading it now"); end return true @@ -240,6 +246,7 @@ function MSync.modules.MRSync.init( transaction ) Returns: true if the settings file exists ]] function MSync.modules.MRSync.saveSettings() + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.saveSettings"); file.Write("msync/mrsync.txt", util.TableToJSON(MSync.modules.MRSync.settings, true)) return file.Exists("msync/mrsync.txt", "DATA") end @@ -263,6 +270,7 @@ function MSync.modules.MRSync.net() ]] util.AddNetworkString("msync.mrsync.sendSettingsPly") function MSync.modules.MRSync.sendSettings(ply) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.sendSettings Param.: " .. ply:Nick()); net.Start("msync.mrsync.sendSettingsPly") net.WriteTable(MSync.modules.MRSync.settings) net.Send(ply) @@ -274,6 +282,7 @@ function MSync.modules.MRSync.net() ]] util.AddNetworkString("msync.mrsync.getSettings") net.Receive("msync.mrsync.getSettings", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.getSettings Ply.: " .. ply:Nick()); if not ply:query("msync.getSettings") then return end MSync.modules.MRSync.sendSettings(ply) @@ -285,6 +294,7 @@ function MSync.modules.MRSync.net() ]] util.AddNetworkString("msync.mrsync.sendSettings") net.Receive("msync.mrsync.sendSettings", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.sendSettings Ply.: " .. ply:Nick()); if not ply:query("msync.sendSettings") then return end MSync.modules.MRSync.settings = net.ReadTable() @@ -308,28 +318,34 @@ function MSync.modules.MRSync.hooks() -- Load rank on spawn hook.Add("PlayerInitialSpawn", "mrsync.H.loadRank", function(ply) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Loading user rank for \"" .. ply:Nick() .. "\""); MSync.modules.MRSync.loadRank(ply) end) -- Save rank on disconnect hook.Add("PlayerDisconnected", "mrsync.H.saveRank", function(ply) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Saving user rank for \"" .. ply:Nick() .. "\""); --MSync.modules.MRSync.saveRank(ply) MSync.modules.MRSync.validateData(ply:SteamID(), ply:GetUserGroup()) end) -- Save rank on GroupChange hook.Add("ULibUserGroupChange", "mrsync.H.saveRankOnUpdate", function(sid, _, _, new_group, _) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Rank changed for user \"" .. sid .. "\" updating it now"); --MSync.modules.MRSync.saveRankByID(sid, new_group) MSync.modules.MRSync.validateData(sid, new_group) end) -- Remove Rank on ULX Remove hook.Add("ULibUserRemoved", "mrsync.H.saveRankOnUpdate", function(sid) + MSync.log(MSYNC_DBG_INFO, "[MRSync] User deletion detected for \"" .. sid .. "\""); if userTransaction[util.SteamIDTo64(sid)] then userTransaction[util.SteamIDTo64(sid)] = nil + MSync.log(MSYNC_DBG_INFO, "[MRSync] User has already been removed from MRSync, aborting removal"); return end + MSync.log(MSYNC_DBG_INFO, "[MRSync] User \"" .. ply:Nick() .. "\" was removed from ULX, removing from MRSync"); MSync.modules.MRSync.removeRank(sid) end) end diff --git a/lua/msync/sh_init.lua b/lua/msync/sh_init.lua index 459d8d1..09f4812 100644 --- a/lua/msync/sh_init.lua +++ b/lua/msync/sh_init.lua @@ -52,4 +52,27 @@ MSync.log = function(logLevel, logMessage) -- Feature(?): Log files? Client GUI log viewer? --file.Append( "msync/logs/msync_"..os.date("[]")..".log", os.date("[]") ) end -end \ No newline at end of file +end + +--[[ + Description: MSync string format function, allows easy and fast formating of long strings + Arguments: + - str [string] - The string containing the variables formated like $ + - tbl [table] - The table containing the variable name as key and the value as key value ( e.g. {["variable"] = "My first variable"}) + Returns: + - formatedString [string] - the string with all variables replaced +]] +MSync.formatString = function(str, tbl) + for k,v in pairs(tbl) do + str = string.Replace(str, "$"..k, v) + end + return str +end + +function testlog() + local err = "No Error" + local sql = "Test" + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) +end +local test = {["1"] = "this",["string"] = "shit"} +print(MSync.formatString("Test $1 $string", test)) From 0207691da465aecc60544b7fc99f54f725cf5163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Wed, 26 Aug 2020 15:04:22 +0200 Subject: [PATCH 13/37] MRSync CL - Logging implementation - Add log implementation to Clientside part of MRSync - Removed unecessary test functions from sh_init --- lua/msync/client_gui/modules/cl_mrsync.lua | 19 +++++++++++++++++-- lua/msync/sh_init.lua | 10 +--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index 2ea2e9d..3d13328 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -30,6 +30,7 @@ end Define the admin panel for the settings ]] function MSync.modules.MRSync.adminPanel(sheet) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Initializing AdminGUI panel"); local pnl = vgui.Create( "DPanel", sheet ) pnl:Dock(FILL) @@ -50,6 +51,7 @@ function MSync.modules.MRSync.adminPanel(sheet) allserver_table:SetMultiSelect( false ) allserver_table:AddColumn( "Allserver Ranks" ) allserver_table.OnRowRightClick = function(panel, lineID, line) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Right clicked " .. line:GetValue(1)); local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -58,6 +60,7 @@ function MSync.modules.MRSync.adminPanel(sheet) DMenu.OptionSelected = function(menu,optPnl,optStr) if MSync.modules.MRSync.settings.syncall[line:GetValue(1)] then + MSync.log(MSYNC_DBG_INFO, "[MRSync] Removing \"" .. line:GetValue(1) .. "\" from allservers ranks"); allserver_table:RemoveLine(lineID) MSync.modules.MRSync.settings.syncall[line:GetValue(1)] = nil MSync.modules.MRSync.sendSettings() @@ -72,7 +75,9 @@ function MSync.modules.MRSync.adminPanel(sheet) allserver_button:SetSize( 130, 20 ) allserver_button.DoClick = function() if string.len(allserver_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[allserver_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] then - if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then return end + if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_INFO, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end + + MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to allservers rank list"); allserver_table:AddLine(allserver_textentry:GetValue()) MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] = true allserver_textentry:SetText("") @@ -97,6 +102,7 @@ function MSync.modules.MRSync.adminPanel(sheet) nosync_table:SetMultiSelect( false ) nosync_table:AddColumn( "Nosync Ranks" ) nosync_table.OnRowRightClick = function(panel, lineID, line) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Right clicked " .. line:GetValue(1)); local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -105,6 +111,7 @@ function MSync.modules.MRSync.adminPanel(sheet) DMenu.OptionSelected = function(menu,optPnl,optStr) if MSync.modules.MRSync.settings.nosync[line:GetValue(1)] then + MSync.log(MSYNC_DBG_INFO, "[MRSync] Removing \"" .. line:GetValue(1) .. "\" from nosync ranks"); nosync_table:RemoveLine(lineID) MSync.modules.MRSync.settings.nosync[line:GetValue(1)] = nil MSync.modules.MRSync.sendSettings() @@ -119,7 +126,9 @@ function MSync.modules.MRSync.adminPanel(sheet) nosync_button:SetSize( 130, 20 ) nosync_button.DoClick = function() if string.len(nosync_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[nosync_textentry:GetValue()] then - if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then return end + if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_INFO, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end + + MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to nosync rank list"); nosync_table:AddLine(nosync_textentry:GetValue()) MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] = true nosync_textentry:SetText("") @@ -135,6 +144,7 @@ function MSync.modules.MRSync.adminPanel(sheet) timer.Create("mrsync.t.checkSettings", 1, 0, function() if not MSync.modules.MRSync.settings then return end + MSync.log(MSYNC_DBG_INFO, "[MRSync] Got settings from server, adding to panel"); for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do allserver_table:AddLine(k) end @@ -146,6 +156,8 @@ function MSync.modules.MRSync.adminPanel(sheet) timer.Remove("mrsync.t.checkSettings") end) else + + MSync.log(MSYNC_DBG_INFO, "[MRSync] Settings found, adding to panel"); for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do allserver_table:AddLine(k) end @@ -179,6 +191,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] function MSync.modules.MRSync.sendSettings() + MSync.log(MSYNC_DBG_INFO, "[MRSync] Exec: MRSync.sendSettings"); net.Start("msync.mrsync.sendSettings") net.WriteTable(MSync.modules.MRSync.settings) net.SendToServer() @@ -191,6 +204,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] function MSync.modules.MRSync.getSettings() + MSync.log(MSYNC_DBG_INFO, "[MRSync] Exec: MRSync.getSettings"); net.Start("msync.mrsync.getSettings") net.SendToServer() end @@ -200,6 +214,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] net.Receive("msync.mrsync.sendSettingsPly", function(len, ply) + MSync.log(MSYNC_DBG_INFO, "[MRSync] Net: msync.mrsync.sendSettingsPly"); MSync.modules.MRSync.settings = net.ReadTable() end ) end diff --git a/lua/msync/sh_init.lua b/lua/msync/sh_init.lua index 09f4812..3806047 100644 --- a/lua/msync/sh_init.lua +++ b/lua/msync/sh_init.lua @@ -67,12 +67,4 @@ MSync.formatString = function(str, tbl) str = string.Replace(str, "$"..k, v) end return str -end - -function testlog() - local err = "No Error" - local sql = "Test" - MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) -end -local test = {["1"] = "this",["string"] = "shit"} -print(MSync.formatString("Test $1 $string", test)) +end \ No newline at end of file From b593dc60584a2f03a06204feaca3c5d65f47a523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Wed, 26 Aug 2020 17:27:44 +0200 Subject: [PATCH 14/37] MRSync - Logging implementation - Change debug levels of ClientSide log messages - Update log messages on ServerSide --- lua/msync/client_gui/modules/cl_mrsync.lua | 20 ++++++++++---------- lua/msync/server/modules/sv_mrsync.lua | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index 3d13328..f1824ad 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -30,7 +30,7 @@ end Define the admin panel for the settings ]] function MSync.modules.MRSync.adminPanel(sheet) - MSync.log(MSYNC_DBG_INFO, "[MRSync] Initializing AdminGUI panel"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Initializing AdminGUI panel"); local pnl = vgui.Create( "DPanel", sheet ) pnl:Dock(FILL) @@ -51,7 +51,7 @@ function MSync.modules.MRSync.adminPanel(sheet) allserver_table:SetMultiSelect( false ) allserver_table:AddColumn( "Allserver Ranks" ) allserver_table.OnRowRightClick = function(panel, lineID, line) - MSync.log(MSYNC_DBG_INFO, "[MRSync] Right clicked " .. line:GetValue(1)); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -75,7 +75,7 @@ function MSync.modules.MRSync.adminPanel(sheet) allserver_button:SetSize( 130, 20 ) allserver_button.DoClick = function() if string.len(allserver_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[allserver_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] then - if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_INFO, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end + if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_WARNING, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to allservers rank list"); allserver_table:AddLine(allserver_textentry:GetValue()) @@ -102,7 +102,7 @@ function MSync.modules.MRSync.adminPanel(sheet) nosync_table:SetMultiSelect( false ) nosync_table:AddColumn( "Nosync Ranks" ) nosync_table.OnRowRightClick = function(panel, lineID, line) - MSync.log(MSYNC_DBG_INFO, "[MRSync] Right clicked " .. line:GetValue(1)); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -126,7 +126,7 @@ function MSync.modules.MRSync.adminPanel(sheet) nosync_button:SetSize( 130, 20 ) nosync_button.DoClick = function() if string.len(nosync_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[nosync_textentry:GetValue()] then - if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_INFO, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end + if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_WARNING, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to nosync rank list"); nosync_table:AddLine(nosync_textentry:GetValue()) @@ -144,7 +144,7 @@ function MSync.modules.MRSync.adminPanel(sheet) timer.Create("mrsync.t.checkSettings", 1, 0, function() if not MSync.modules.MRSync.settings then return end - MSync.log(MSYNC_DBG_INFO, "[MRSync] Got settings from server, adding to panel"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Got settings from server, adding to panel"); for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do allserver_table:AddLine(k) end @@ -157,7 +157,7 @@ function MSync.modules.MRSync.adminPanel(sheet) end) else - MSync.log(MSYNC_DBG_INFO, "[MRSync] Settings found, adding to panel"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Settings found, adding to panel"); for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do allserver_table:AddLine(k) end @@ -191,7 +191,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] function MSync.modules.MRSync.sendSettings() - MSync.log(MSYNC_DBG_INFO, "[MRSync] Exec: MRSync.sendSettings"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.sendSettings"); net.Start("msync.mrsync.sendSettings") net.WriteTable(MSync.modules.MRSync.settings) net.SendToServer() @@ -204,7 +204,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] function MSync.modules.MRSync.getSettings() - MSync.log(MSYNC_DBG_INFO, "[MRSync] Exec: MRSync.getSettings"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.getSettings"); net.Start("msync.mrsync.getSettings") net.SendToServer() end @@ -214,7 +214,7 @@ function MSync.modules.MRSync.net() Returns: nothing ]] net.Receive("msync.mrsync.sendSettingsPly", function(len, ply) - MSync.log(MSYNC_DBG_INFO, "[MRSync] Net: msync.mrsync.sendSettingsPly"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.sendSettingsPly"); MSync.modules.MRSync.settings = net.ReadTable() end ) end diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 1f0c884..089ea03 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -70,7 +70,7 @@ function MSync.modules.MRSync.init( transaction ) addUserRankQ.onError = function( q, err, sql ) if string.match( err, "^Column 'user_id' cannot be null$" ) then - MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User does not exist, creating user and repeating"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User does not exist, creating user \"" .. steamid .. "\" and repeating"); MSync.mysql.addUserID(steamid) MSync.modules.MRSync.saveRankByID(steamid, group) else @@ -111,7 +111,7 @@ function MSync.modules.MRSync.init( transaction ) end else - MSync.log(MSYNC_DBG_INFO, "[MRSync] Syncall group, removing all groups from user that are not \"allservers\""); + MSync.log(MSYNC_DBG_INFO, "[MRSync] Syncall group, removing all groups from user \"" .. steamid .. "\" that are not \"allservers\""); removeOldRanksQ = MSync.DBServer:prepare( [[ DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND server_group<>(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers'); From d9e296c993fc1783d04b4cbce219078a79db0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 17:12:03 +0200 Subject: [PATCH 15/37] Performance Update FormatString function now returns a executable function to get the return value, that way the loop is not always executed, only when you need the formated string --- lua/msync/sh_init.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/msync/sh_init.lua b/lua/msync/sh_init.lua index 3806047..0f7a831 100644 --- a/lua/msync/sh_init.lua +++ b/lua/msync/sh_init.lua @@ -44,6 +44,9 @@ MSync.log = function(logLevel, logMessage) local DebugCvarValue = MSync.DebugCVar:GetInt() if DebugCvarValue >= logLevel then + if type(logMessage) == "function" then + logMessage = logMessage() + end if debugLevels[logLevel] then MsgC(debugLevels[logLevel].color, debugLevels[logLevel].prefix.." "..logMessage.."\n") else @@ -63,8 +66,10 @@ end - formatedString [string] - the string with all variables replaced ]] MSync.formatString = function(str, tbl) - for k,v in pairs(tbl) do - str = string.Replace(str, "$"..k, v) + return function() + for k,v in pairs(tbl) do + str = string.Replace(str, "$"..k, tostring(v)) + end + return str end - return str end \ No newline at end of file From f750b3c62fded51c2751f154169ca761b2d8ff0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 17:12:42 +0200 Subject: [PATCH 16/37] MBSync SV - logging implementation Add logging implementation to server-side part of MBSync --- lua/msync/server/modules/sv_mbsync.lua | 213 ++++++++++++------------- 1 file changed, 99 insertions(+), 114 deletions(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index d6fb0f1..e33eb1e 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -30,6 +30,7 @@ local userTransactions = userTransactions or {} Define mysql table and additional functions that are later used ]] MSync.modules[info.ModuleIdentifier].init = function( transaction ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.init") transaction:addQuery( MSync.DBServer:query([[ CREATE TABLE IF NOT EXISTS `tbl_mbsync` ( `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, @@ -50,6 +51,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Description: Function to update the database to the newest version, in case it isn't up to date ]] MSync.modules[info.ModuleIdentifier].updateDB = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.updateDB") + local selectDbVersion = MSync.DBServer:prepare( [[ SELECT version FROM `tbl_msyncdb_version` WHERE module_id=?; ]] ) @@ -57,8 +60,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) selectDbVersion.onSuccess = function( q, data ) -- Do nothing for now + MSync.log(MSYNC_DBG_INFO, "[MBSync] Checking database version") if data[1] then if data[1].version < 1 then + MSync.log(MSYNC_DBG_INFO, "[MBSync] Database version of MBSync is too old, updating it to Version 1") local updates = MSync.DBServer:createTransaction() updates:addQuery( MSync.DBServer:query([[ ALTER TABLE tbl_mbsync @@ -70,8 +75,11 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ON DUPLICATE KEY UPDATE version=VALUES(version); ]])) updates:start() + else + MSync.log(MSYNC_DBG_INFO, "[MBSync] Database version is up-to-date. No update necessary") end else + MSync.log(MSYNC_DBG_INFO, "[MBSync] No data was returned, updating MBSync table to current version") local updates = MSync.DBServer:createTransaction() updates:addQuery( MSync.DBServer:query([[ ALTER TABLE tbl_mbsync @@ -88,15 +96,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end selectDbVersion.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end selectDbVersion:start() @@ -109,13 +109,17 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].banUser = function(ply, calling_ply, length, reason, allserver) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.banUser Param.: $ply $calling_ply $length \"$reason\" $allserver", {["ply"] = ply:Nick(),["calling_ply"] = tostring(calling_ply),["length"] = length,["reason"] = reason,["allserver"] = allserver})) + if MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()] then + MSync.log(MSYNC_DBG_INFO, "[MBSync] User \"" .. ply:SteamID64() .. "\" is already banned, editing old ban instead") if not length == 0 then length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)].timestamp)+(length*60))/60 end MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()]['banId'], reason, length, calling_ply, allserver) return end + local banUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES ( @@ -174,15 +178,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end banUserQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end banUserQ:start() @@ -193,13 +189,17 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].banUserID = function(userid, calling_ply, length, reason, allserver) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.banUserID Param.: $userid $calling_ply $length \"$reason\" $allserver", {["userid"] = userid,["calling_ply"] = tostring(calling_ply),["length"] = length,["reason"] = reason,["allserver"] = allserver})) + if MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)] then + MSync.log(MSYNC_DBG_INFO, "[MBSync] User \"" .. userid .. "\" is already banned, editing old ban instead") if not (length == 0) then length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)].timestamp)+(length*60))/60 end MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)]['banId'], reason, length, calling_ply, allserver) return end + local banUserIdQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mbsync` (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES ( @@ -261,18 +261,11 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) banUserIdQ.onError = function( q, err, sql ) if string.match( err, "^Column 'user_id' cannot be null$" ) then + MSync.log(MSYNC_DBG_INFO, "[MBSync] User does not exist! Creating user before retrying") MSync.mysql.addUserID(userid) MSync.modules[info.ModuleIdentifier].banUserID(userid, calling_ply, length, reason, allserver) else - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end end @@ -284,6 +277,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].editBan = function(banId, reason, length, calling_ply, allserver) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.editBan Param.: $banid \"$reason\" $length $calling_ply $allserver", {["banid"] = banId,["reason"] = reason,["length"] = length,["calling_ply"] = tostring(calling_ply),["allserver"] = allserver})) + local editBanQ = MSync.DBServer:prepare( [[ UPDATE `tbl_mbsync` SET @@ -310,15 +305,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end editBanQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end editBanQ:start() @@ -329,6 +316,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].unBanUserID = function(calling_ply, banId) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.unBanUserID Param: " .. tostring(calling_ply) .. " " .. banId) local unBanUserIdQ = MSync.DBServer:prepare( [[ UPDATE `tbl_mbsync` SET ban_lifted=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) @@ -340,19 +328,12 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) unBanUserIdQ.onSuccess = function( q, data ) MSync.modules[info.ModuleIdentifier].getActiveBans() + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Removed ban with id "..banId) end unBanUserIdQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end unBanUserIdQ:start() @@ -363,6 +344,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].unBanUser = function(ply_steamid, calling_ply) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.unBanUser Param.: " .. ply_steamid .. " " .. tostring(calling_ply)) local unBanUserQ = MSync.DBServer:prepare( [[ UPDATE `tbl_mbsync` SET @@ -382,19 +364,12 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) unBanUserQ.onSuccess = function( q, data ) MSync.modules[info.ModuleIdentifier].getActiveBans() + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Unbanned "..ply_steamid) end unBanUserQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end unBanUserQ:start() @@ -405,6 +380,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].getBans = function(ply, fullTable) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getBans Param.: " .. ply:Nick() .. " " .. tostring(fullTable)) local getBansQ = MSync.DBServer:prepare( [[ SELECT tbl_mbsync.p_id, @@ -437,8 +413,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banTable = {} - print("[MBSync] Recieved all ban data") + MSync.log(MSYNC_DBG_INFO, "[MBSync] Recieved ban data from Database") if fullTable then + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Generating full ban table to send to \"" .. ply:Nick() .. "\"") for k,v in pairs(data) do banTable[v.p_id] = { @@ -466,6 +443,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end else + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Generating short ban table to send to \"" .. ply:Nick() .. "\"") for k,v in pairs(data) do if not v['unban_admin.steamid'] and ((not((v.date_unix+v.length_unix) < os.time())) or (v.length_unix==0)) then banTable[v["banned.steamid64"]] = { @@ -497,15 +475,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end getBansQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end getBansQ:start() @@ -516,6 +486,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].getActiveBans = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getActiveBans") local getActiveBansQ = MSync.DBServer:prepare( [[ SELECT tbl_mbsync.*, @@ -545,7 +516,6 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) getActiveBansQ.onSuccess = function( q, data ) local banTable = {} - print("[MBSync] Recieved ban data") for k,v in pairs(data) do banTable[v["steamid64"]] = { banId = v.p_id, @@ -559,6 +529,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) adminNickname = v["admin.nickname"] } end + MSync.log(MSYNC_DBG_INFO, "[MBSync] Local ban table updated with new data") MSync.modules[info.ModuleIdentifier].banTable = banTable @@ -580,6 +551,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local message = ULib.getBanMessage( ban.banned.steamid, banData) + MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() "\" was banned while data resynchronized, kicking from server") v:Kick(message) else -- Do nothing @@ -588,15 +560,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end getActiveBansQ.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end getActiveBansQ:start() @@ -607,6 +571,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].exportBansToULX = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.exportBansToULX") local exportActiveBans = MSync.DBServer:prepare( [[ SELECT tbl_mbsync.*, @@ -636,7 +601,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) exportActiveBans.onSuccess = function( q, data ) - print("[MBSync] Exporting Bans to ULX") + print("[MBSync] Exporting all MBSync bans to ULX. Please wait...") for k,v in pairs(data) do local unban if v.length_unix == 0 then @@ -668,15 +633,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end exportActiveBans.onError = function( q, err, sql ) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(sql.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end exportActiveBans:start() @@ -687,13 +644,16 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) --[[ Description: Function to allow the import of all ULX bans to MBSync + Arguments: + - allservers [boolean] - Should all bans be imported as local bans or as allserver bans? ( true = allservers, false = server group) Returns: nothing ]] MSync.modules[info.ModuleIdentifier].importBansFromULX = function( allservers ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.importBansFromULX Param.: " .. tostring(allservers)) local transactions = {} local banTransaction = MSync.DBServer:createTransaction() - print("[MBSync] Ban import from ULX started ...") + print("[MBSync] Importing bans from ULX into MBSync, please wait...") for k,v in pairs(ULib.bans) do --[[ - Create User @@ -741,23 +701,15 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end banTransaction:addQuery(transactions[k]) - print("[MBSync] Added ban for SteamID: "..k) + MSync.log(MSYNC_DBG_INFO, "[MBSync] Imported ban for SteamID: " .. k) end banTransaction.onSuccess = function() - print("[MBSync] Ban import completed!") + print("[MBSync] Ban import from ULX finished successfully") end banTransaction.onError = function(tr, err) - print("------------------------------------") - print("[MBSync] SQL Error!") - print("------------------------------------") - print("Please include this in a Bug report:\n") - print(err.."\n") - print("------------------------------------") - print("Do not include this, this is for debugging only:\n") - print(tr.."\n") - print("------------------------------------") + MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MBSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {['err'] = err, ['sql'] = sql})) end banTransaction:start() @@ -777,13 +729,16 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: true ]] MSync.modules[info.ModuleIdentifier].loadSettings = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec.: MBSync.loadSettings") if not file.Exists("msync/"..info.ModuleIdentifier..".txt", "DATA") then MSync.modules[info.ModuleIdentifier].settings = { syncDelay = 300 } file.Write("msync/"..info.ModuleIdentifier..".txt", util.TableToJSON(MSync.modules[info.ModuleIdentifier].settings, true)) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] No configuration found, generated default one") else MSync.modules[info.ModuleIdentifier].settings = util.JSONToTable(file.Read("msync/mbsync.txt", "DATA")) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Configuration found, loaded into MBSync") end return true @@ -794,6 +749,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: true if the settings file exists ]] MSync.modules[info.ModuleIdentifier].saveSettings = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.saveSettings") file.Write("msync/"..info.ModuleIdentifier..".txt", util.TableToJSON(MSync.modules[info.ModuleIdentifier].settings, true)) return file.Exists("msync/"..info.ModuleIdentifier..".txt", "DATA") end @@ -803,6 +759,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) Returns: table split in 10er part counts ]] MSync.modules[info.ModuleIdentifier].splitTable = function(tbl) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.splitTable Param.: " .. tostring(tbl)) + local i = 0 local dataSet = 0 local splitTableData = {} @@ -827,6 +785,7 @@ 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 @@ -845,6 +804,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") if type(ply) == "string" and not (ply == "STEAM_0:0:0") then ply = player.GetBySteamID( ply ) end @@ -853,6 +813,7 @@ MSync.modules[info.ModuleIdentifier].net = function() if not IsValid(ply) then print("[MBSync] "..content) else + MSync.log(MSYNC_DBG_INFO, "[MBSync] "..content) if not msgType then msgType = 0 end -- Basic message if msgType == 0 then @@ -876,6 +837,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".sendBanTable") MSync.modules[info.ModuleIdentifier].sendSettings = function(ply, banTable) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendSettings Param.: " .. tostring(ply) .. " " .. tostring(banTable)) net.Start("msync."..info.ModuleIdentifier..".sendBanTable") net.WriteTable(banTable) net.Send(ply) @@ -889,6 +851,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".openBanTable") MSync.modules[info.ModuleIdentifier].openBanTable = function(ply) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.openBanTable Param.: " .. tostring(ply)) net.Start("msync."..info.ModuleIdentifier..".openBanTable") net.Send(ply) end @@ -899,7 +862,8 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".banid") net.Receive("msync."..info.ModuleIdentifier..".banid", function(len, ply) - if not ply:query("msync."..info.ModuleIdentifier..".banPlayer") then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.banid Player: " .. tostring(ply)) + if not ply:query("msync."..info.ModuleIdentifier..".banPlayer") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to ban a user without permission");return end local ban = net.ReadTable() @@ -934,7 +898,8 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".editBan") net.Receive("msync."..info.ModuleIdentifier..".editBan", function(len, ply) - if not ply:query("msync."..info.ModuleIdentifier..".banPlayer") then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.editBan Player: " .. tostring(ply)) + if not ply:query("msync."..info.ModuleIdentifier..".banPlayer") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to ban a user without permission");return end local editedBan = net.ReadTable() @@ -969,7 +934,8 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".unban") net.Receive("msync."..info.ModuleIdentifier..".unban", function(len, ply) - if not ply:query("msync."..info.ModuleIdentifier..".unBanID") then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.unban Player: " .. tostring(ply)) + if not ply:query("msync."..info.ModuleIdentifier..".unBanID") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to unban a user without permission");return end local banid = net.ReadFloat() @@ -1011,6 +977,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".sendSettingsPly") MSync.modules[info.ModuleIdentifier].sendSettings = function(ply) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendSettings Param.: " .. tostring(ply)) net.Start("msync."..info.ModuleIdentifier..".sendSettingsPly") net.WriteTable(MSync.modules[info.ModuleIdentifier].settings) net.Send(ply) @@ -1022,7 +989,8 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".getSettings") net.Receive("msync."..info.ModuleIdentifier..".getSettings", function(len, ply) - if not ply:query("msync.getSettings") then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.getSettings Player: " .. tostring(ply)) + if not ply:query("msync.getSettings") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to get the settings without permission");return end MSync.modules[info.ModuleIdentifier].sendSettings(ply) end ) @@ -1033,7 +1001,8 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".sendSettings") net.Receive("msync."..info.ModuleIdentifier..".sendSettings", function(len, ply) - if not ply:query("msync.sendSettings") then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.sendSettings Player: " .. tostring(ply)) + if not ply:query("msync.sendSettings") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to send settings to the server without permission");return end MSync.modules[info.ModuleIdentifier].settings = net.ReadTable() MSync.modules[info.ModuleIdentifier].saveSettings() @@ -1047,6 +1016,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".openBanGUI") MSync.modules[info.ModuleIdentifier].openBanGUI = function(ply) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.openBanGUI Param.: " .. tostring(ply)) local tableLength = table.Count(MSync.modules[info.ModuleIdentifier].recentDisconnects) local disconnectTable = {} @@ -1075,7 +1045,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveDataCount") MSync.modules[info.ModuleIdentifier].sendCount = function(ply, number) - print(number) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendCount Param.: " .. tostring(ply) .. " " .. number) net.Start("msync."..info.ModuleIdentifier..".recieveDataCount") net.WriteFloat(number) net.Send(ply) @@ -1090,6 +1060,7 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveData") MSync.modules[info.ModuleIdentifier].sendPart = function(ply, part) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendPart Param.: " .. tostring(ply) .. " " .. tostring(part)) net.Start("msync."..info.ModuleIdentifier..".recieveData") net.WriteTable(part) net.Send(ply) @@ -1101,12 +1072,13 @@ MSync.modules[info.ModuleIdentifier].net = function() ]] util.AddNetworkString("msync."..info.ModuleIdentifier..".getBanTable") net.Receive("msync."..info.ModuleIdentifier..".getBanTable", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.getBanTable Player: " .. tostring(ply)) local fullTable = net.ReadBool() if fullTable then - if not ply:query("msync.openAdminGUI") then return end + if not ply:query("msync.openAdminGUI") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to get the full ban table without permission");return end MSync.modules[info.ModuleIdentifier].getBans(ply, fullTable) else - if not ply:query("msync."..info.ModuleIdentifier..".openBanTable") then return end + if not ply:query("msync."..info.ModuleIdentifier..".openBanTable") then MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to get the short ban table without permission");return end MSync.modules[info.ModuleIdentifier].getBans(ply, false) end end ) @@ -1130,6 +1102,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() reason [string] - the ban reason - OPTIONAL - Default: "banned by staff" ]] MSync.modules[info.ModuleIdentifier].Chat.banPlayer = function(calling_ply, target_ply, length, allserver, reason) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.banPlayer Param.: $calling_ply $target_player $length $allserver \"$reason\"", {["calling_ply"] = calling_ply,["target_player"] = target_ply,["length"] = length,["allserver"] = allserver,["reason"] = reason})) local calling_steamid = "" if not IsValid(calling_ply) then @@ -1184,6 +1157,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() reason [string] - the ban reason - OPTIONAL - Default: "banned by staff" ]] MSync.modules[info.ModuleIdentifier].Chat.banSteamID = function(calling_ply, target_steamid, length, allserver, reason) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.banSteamID Param.: $calling_ply $target_steamid $length $allserver \"$reason\"", {["calling_ply"] = calling_ply,["target_steamid"] = target_steamid,["length"] = length,["allserver"] = allserver,["reason"] = reason})) local calling_steamid = "" if not IsValid(calling_ply) then @@ -1237,6 +1211,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() target_steamid [string] - the target steamid ]] MSync.modules[info.ModuleIdentifier].Chat.unBanID = function(calling_ply, target_steamid) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.unBanID Param.: $calling_ply $target_steamid", {["calling_ply"] = calling_ply,["target_steamid"] = target_steamid})) local calling_steamid = "" if not IsValid(calling_ply) then @@ -1274,6 +1249,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() target_steamid [string] - the target steamid ]] MSync.modules[info.ModuleIdentifier].Chat.checkBan = function(calling_ply, target_steamid) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.checkBan Param.: $calling_ply $target_player", {["calling_ply"] = calling_ply,["target_steamid"] = target_steamid})) if not IsValid(calling_ply) then -- Do nothing else @@ -1326,7 +1302,8 @@ MSync.modules[info.ModuleIdentifier].ulx = function() none ]] MSync.modules[info.ModuleIdentifier].Chat.openBanTable = function(calling_ply) - if not IsValid(calling_ply) then print("[MBSync] This command can only be executed in-game"); return; end + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.openBanTable Param.: $calling_ply", {["calling_ply"] = calling_ply})) + if not IsValid(calling_ply) then MSync.log(MSYNC_DBG_ERROR, "[MBSync] This command can only be executed in-game"); return; end if not calling_ply:query("msync."..info.ModuleIdentifier..".openBanTable") then return end; -- Open Ban Table MSync.modules[info.ModuleIdentifier].openBanTable(calling_ply) @@ -1345,6 +1322,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() reason [string] - the ban reason - OPTIONAL - Default: "banned by staff" ]] MSync.modules[info.ModuleIdentifier].Chat.editBan = function(calling_ply, ban_id, length, allserver, reason) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.Chat.banPlayer Param.: $calling_ply $ban_id $length $allserver \"$reason\"", {["calling_ply"] = calling_ply,["ban_id"] = ban_id,["length"] = length,["allserver"] = allserver,["reason"] = reason})) local calling_steamid = "" if not IsValid(calling_ply) then @@ -1399,6 +1377,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() 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 .. "\"") if MSync.modules[info.ModuleIdentifier].banTable[steamid64] then local ban = MSync.modules[info.ModuleIdentifier].banTable[steamid64] local unbanDate @@ -1410,15 +1389,13 @@ MSync.modules[info.ModuleIdentifier].hooks = function() --[[ Print to console that a banned user tries to join ]] - print("---== [MBSync] ==---") - print("A banned player tried to join the server.") - print("-- Informations --") - print("Nickname: "..ban.banned.nickname) - print("SteamID: "..ban.banned.steamid) - print("Ban Date: "..os.date( "%c", ban.timestamp)) - print("Unban Date: "..unbanDate) - print("Banned by: "..ban.adminNickname) - print("---== [END] ==---") + MSync.log(MSYNC_DBG_WARNING, MSync.formatString("---== [MBSync] ==---\nA banned player tried to join the server.\n-- Informations --\nNickname: $nickname\nSteamID: $steamid\nBan Date: $date\nUnban Date: $unbanDate\nBanned by: $admin\n---== [END] ==---", { + ["nickname"] = ban.banned.nickname, + ["steamid"] = ban.banned.steamid, + ["date"] = os.date( "%c", ban.timestamp), + ["unbanDate"] = unbanDate, + ["admin"] = ban.adminNickname + })) --[[ Translate ban data for ULib @@ -1448,11 +1425,13 @@ MSync.modules[info.ModuleIdentifier].hooks = function() --return true end ]] + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] User with steamid \"" .. steamid64 .. "\" has passed the ban check") return end end) hook.Add("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects", function( ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Disconnect: Adding player \"" .. tostring(ply) .. "\" to list of recent disconnects") if ply:IsBot() then return end local tableLength = table.Count(MSync.modules[info.ModuleIdentifier].recentDisconnects) local data = { @@ -1465,10 +1444,13 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end) hook.Add("ULibPlayerBanned", "msync.mbsync.ulxban", function(steamid, banData) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] ULX ban detected for user \"" .. steamid .. "\"") + local ban = {} if userTransactions[util.SteamIDTo64(steamid)] then userTransactions[util.SteamIDTo64(steamid)] = nil + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] User has already been banned in MBSync, aborting ban") return end @@ -1500,8 +1482,11 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end) hook.Add("ULibPlayerUnBanned", "msync.mbsync.ulxunban", function(steamid, admin) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] ULX Unban detected for user \"" .. steamid .. "\"") + if userTransactions[util.SteamIDTo64(steamid)] then userTransactions[util.SteamIDTo64(steamid)] = nil + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] User already has been unbanned from MBSync, aborting unban") return end From 25b989b418ec8fc9bf415ad7d5272a2675a8ce4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 22:46:07 +0200 Subject: [PATCH 17/37] MBSync CL - Logging Implementation Add logging implementation to MBSync client-side --- lua/msync/client_gui/modules/cl_mbsync.lua | 98 ++++++++++++++++++++-- 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 06dc103..e093a3d 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -29,10 +29,12 @@ MSync.modules[info.ModuleIdentifier].info = info Define additional functions that are later used ]] MSync.modules[info.ModuleIdentifier].init = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Initializing"); MSync.modules[info.ModuleIdentifier].banTable = {} MSync.modules[info.ModuleIdentifier].getTablePage = function(tbl, maxResults, page) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.getTablePage Param.: $tbl $maxResults $page",{["tbl"] = tbl,["maxResults"] = maxResults,["page"] = page})); local tempTbl = {} local i = 0 local startPos = 0 + (maxResults*page) @@ -49,6 +51,7 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].displayTable = function(panel, tbl, maxResults, page) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.displayTable Param.: $panel $tbl $maxResults $page",{["panel"] = panel,["tbl"] = tbl,["maxResults"] = maxResults,["page"] = page})); panel:Clear() local table = MSync.modules[info.ModuleIdentifier].getTablePage(tbl, maxResults, page) local length = 0 @@ -63,16 +66,19 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].getTablePages = function(tbl, resultsPerPage) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.getTablePages Param.: $tbl $resultsPerPage",{["tbl"] = tbl, ["resultsPerPage"] = resultsPerPage})); return math.Round(#tbl / resultsPerPage) end MSync.modules[info.ModuleIdentifier].explodeTable = function(tbl, part) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.explodeTable Param.: $tbl $part",{["tbl"] = tbl, ["part"] = part})); for k,v in pairs(part) do tbl[k] = v end end MSync.modules[info.ModuleIdentifier].sortTable = function(tbl, key, asc) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.sortTable Param.: $tbl $key $asc",{["tbl"] = tbl, ["key"] = key, ["asc"] = asc})); local sorting = true local tempTable = table.DeSanitise( tbl ) local keys = table.GetKeys( tempTable ) @@ -114,6 +120,7 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].searchTable = function(tbl, term) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.searchTable Param.: $tbl $term", {["tbl"] = tbl,["term"] = term})); local searchTerm = "" if type(term) == 'string' then @@ -140,6 +147,7 @@ MSync.modules[info.ModuleIdentifier].init = function() end if matches then + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Search: Found match " .. k); tempTbl[k] = v end end @@ -148,6 +156,8 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].banPanel = function( tbl ) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.banPanel Param.: $tbl",{["tbl"] = tbl})); + local panel = vgui.Create( "DFrame" ) panel:SetSize( 350, 500 ) panel:SetTitle( "MBSync - Ban User " ) @@ -233,6 +243,8 @@ MSync.modules[info.ModuleIdentifier].init = function() ban_table:AddColumn( "SteamID" ) ban_table:AddColumn( "SteamID64" ) ban_table.OnRowSelected = function( lst, index, pnl ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban Panel: Selected row " .. index); + steamid_textentry:SetText(pnl:GetColumnText( 2 )) end @@ -247,6 +259,8 @@ MSync.modules[info.ModuleIdentifier].init = function() ban_button:SetPos( 15, 425 ) ban_button:SetSize( 320, 30 ) ban_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban confirm request"); + local banConfirm_panel = vgui.Create( "DFrame" ) banConfirm_panel:SetSize( 350, 100 ) banConfirm_panel:SetTitle( "MBSync Ban - Confirm" ) @@ -265,6 +279,8 @@ MSync.modules[info.ModuleIdentifier].init = function() accept_button:SetPos( 15, 70 ) accept_button:SetSize( 160, 20 ) accept_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban confirmed, banning player and closing panel"); + RunConsoleCommand("msync.MBSync.banSteamID", steamid_textentry:GetValue(), length_textentry:GetValue(), allservers_dropdown:GetValue(), reason_textentry:GetValue()) panel:Close() banConfirm_panel:Close() @@ -275,6 +291,8 @@ MSync.modules[info.ModuleIdentifier].init = function() deny_button:SetPos( 175, 70 ) deny_button:SetSize( 160, 20 ) deny_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban denied, closing confirmation panel"); + banConfirm_panel:Close() end end @@ -284,6 +302,7 @@ MSync.modules[info.ModuleIdentifier].init = function() cancel_button:SetPos( 15, 460 ) cancel_button:SetSize( 320, 30 ) cancel_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban cancellation request"); local cancel_panel = vgui.Create( "DFrame" ) cancel_panel:SetSize( 350, 100 ) cancel_panel:SetTitle( "MBSync Ban - Confirm" ) @@ -302,6 +321,7 @@ MSync.modules[info.ModuleIdentifier].init = function() accept_button:SetPos( 15, 70 ) accept_button:SetSize( 160, 20 ) accept_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban canceled, closing panels"); -- do nothing and close panel panel:Close() cancel_panel:Close() @@ -312,6 +332,7 @@ MSync.modules[info.ModuleIdentifier].init = function() deny_button:SetPos( 175, 70 ) deny_button:SetSize( 160, 20 ) deny_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban cancel aborted, returning to ban panel"); cancel_panel:Close() end end @@ -319,6 +340,7 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].advancedInfoPanel = function(tbl) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.advancedInfoPanel Param.: $tbl",{["tbl"] = tbl})); local panel = vgui.Create( "DFrame" ) panel:SetSize( 350, 455 ) @@ -484,6 +506,7 @@ MSync.modules[info.ModuleIdentifier].init = function() close_button:SetPos( 15, 410 ) close_button:SetSize( 320, 30 ) close_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Close info panel"); panel:Close() end @@ -494,6 +517,8 @@ MSync.modules[info.ModuleIdentifier].init = function() ]] if not (tbl == nil) then + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); + nickname_textentry:SetText( tbl["nickname"] ) steamid_textentry:SetText( tbl["steamid"] ) steamid64_textentry:SetText( tbl["steamid64"] ) @@ -515,6 +540,8 @@ MSync.modules[info.ModuleIdentifier].init = function() end MSync.modules[info.ModuleIdentifier].editBanPanel = function(tbl) + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.editBanPanel Param.: $tbl",{["tbl"] = tbl})); + local panel = vgui.Create( "DFrame" ) panel:SetSize( 350, 280 ) panel:SetTitle( "MBSync Edit Ban" ) @@ -591,11 +618,7 @@ MSync.modules[info.ModuleIdentifier].init = function() banallservers_textentry:AddChoice( "false" ) banallservers_textentry:SetSortItems( false ) banallservers_textentry.OnSelect = function( self, index, value ) - if value == "true" then - print("True") - elseif value == "false" then - print("False") - end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban on all servers: " .. value); end local banlreason_text = vgui.Create( "DLabel", panel ) @@ -619,6 +642,7 @@ MSync.modules[info.ModuleIdentifier].init = function() save_button:SetPos( 15, 200 ) save_button:SetSize( 320, 30 ) save_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit confirmation request"); local save_panel = vgui.Create( "DFrame" ) save_panel:SetSize( 350, 100 ) save_panel:SetTitle( "MBSync Edit Ban - Edit" ) @@ -637,6 +661,7 @@ MSync.modules[info.ModuleIdentifier].init = function() accept_button:SetPos( 15, 70 ) accept_button:SetSize( 160, 20 ) accept_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Edited data accepted, editing ban and closing panel"); RunConsoleCommand( "msync.MBSync.editBan", tbl["banId"], banlength_textentry:GetValue(), banallservers_textentry:GetValue(), banreason_textentry:GetValue()) panel:Close() save_panel:Close() @@ -647,6 +672,7 @@ MSync.modules[info.ModuleIdentifier].init = function() deny_button:SetPos( 175, 70 ) deny_button:SetSize( 160, 20 ) deny_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Edited data denied, closing panel"); -- CLOSE ACCEPT PANEL save_panel:Close() end @@ -657,6 +683,7 @@ MSync.modules[info.ModuleIdentifier].init = function() cancel_button:SetPos( 15, 235 ) cancel_button:SetSize( 320, 30 ) cancel_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancellation request"); local cancel_panel = vgui.Create( "DFrame" ) cancel_panel:SetSize( 350, 100 ) cancel_panel:SetTitle( "MBSync Edit Ban - Cancel" ) @@ -675,6 +702,7 @@ MSync.modules[info.ModuleIdentifier].init = function() accept_button:SetPos( 15, 70 ) accept_button:SetSize( 160, 20 ) accept_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancelled"); panel:Close() cancel_panel:Close() end @@ -684,6 +712,7 @@ MSync.modules[info.ModuleIdentifier].init = function() deny_button:SetPos( 175, 70 ) deny_button:SetSize( 160, 20 ) deny_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancellation request denied"); cancel_panel:Close() end end @@ -695,6 +724,7 @@ MSync.modules[info.ModuleIdentifier].init = function() ]] if not (tbl == nil) then + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); nickname_textentry:SetText( tbl["nickname"] ) steamid_textentry:SetText( tbl["steamid"] ) steamid64_textentry:SetText( tbl["steamid64"] ) @@ -793,6 +823,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) ban_table:SortByColumn( sortby.Column, sortby.Descending ) function displayTable(tbl) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Displaying data to table"); ban_table:Clear() for k,v in pairs(tbl) do local length = "" @@ -813,20 +844,24 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) end save_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Save settings requested"); local num = tonumber(delay_textentry:GetValue()) if num then if num < 30 then + MSync.log(MSYNC_DBG_ERROR, "[MBSync] You should not select a value below \"30\" seconds. We recommend to have it at \"300\" seconds"); chat.AddText(Color(255, 60, 60),"[MBSync_ERROR] ",Color(255,170,0),"You should not select a value below ",Color(60, 255, 60),"30",Color(255,170,0)," seconds. We recommend to have it at ",Color(60, 255, 60),"300",Color(255,170,0)," seconds") else MSync.modules[info.ModuleIdentifier].settings["syncDelay"] = num MSync.modules[info.ModuleIdentifier].sendSettings() end else + MSync.log(MSYNC_DBG_ERROR, "[MBSync] The value you entered is invalid"); chat.AddText(Color(255, 60, 60),"[MBSync_ERROR] ",Color(255,170,0),"That is not a valid value!") end end search_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Searching table"); if search_textentry:GetValue() then tempTable = {} tempTable = MSync.modules[info.ModuleIdentifier].searchTable(MSync.modules[info.ModuleIdentifier].banTable, search_textentry:GetValue()) @@ -840,6 +875,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) end reload_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Reloading data"); MSync.modules[info.ModuleIdentifier].getBanTable(true) timer.Create("msync.mbsync.waitForBanTable", 1, 0, function() @@ -868,9 +904,10 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) end ban_table.OnRowRightClick = function(panel, lineID, line) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row " .. lineID .. " right clicked"); + local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() - print(cursor_x) local DMenu = vgui.Create("DMenu", panel) if cursor_y > 170 then @@ -886,6 +923,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) DMenu:AddOption("Edit") DMenu:AddOption("Advanced Info") DMenu.OptionSelected = function(menu,optPnl,optStr) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Option \"" .. optStr .. "\" selected"); if optStr == "Unban" then MSync.modules[info.ModuleIdentifier].unban(line:GetColumnText( 1 )) elseif optStr == "Edit" then @@ -897,6 +935,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) end sortby_dropdown.OnSelect = function( self, index, value ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Sortby dropdown selected"); if value == "Ban ID" then sortby.Column = 1 if sortby.Descending then @@ -961,6 +1000,8 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) timer.Create("msync.mbsync.waitForSettings", 1, 0, function() if not MSync.modules[info.ModuleIdentifier].settings then return end + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Got settings from server, filling in data"); + delay_textentry:SetText(MSync.modules[info.ModuleIdentifier].settings["syncDelay"]) timer.Remove("msync.mbsync.waitForSettings") @@ -973,6 +1014,7 @@ end Define the client panel for client usage ( or as example: use it as additional admin gui which does not need msync.admingui permission) ]] MSync.modules[info.ModuleIdentifier].clientPanel = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.clientPanel"); --[[ Get Ban table and then wait for the reply before showing it @@ -1078,6 +1120,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() } local function checkPage() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: checkPage"); if ( (tablePage+1) >= pages ) then lastpage_button:SetDisabled(true) nextpage_button:SetDisabled(true) @@ -1096,6 +1139,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end ban_table.OnRowRightClick = function(panel, lineID, line) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row \"" .. lineID .. "\" right clicked"); local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -1104,6 +1148,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() DMenu:AddOption("Edit") DMenu:AddOption("Advanced Info") DMenu.OptionSelected = function(menu,optPnl,optStr) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Option \"" .. optStr .. "\" selected"); if optStr == "Unban" then MSync.modules[info.ModuleIdentifier].unban(line:GetColumnText( 1 )) elseif optStr == "Edit" then @@ -1115,6 +1160,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end sortby_dropdown.OnSelect = function( self, index, value ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Sortby: Selected \"" .. value .. "\""); --ban_table if value == "Ban ID" then sortby.Column = "banId" @@ -1144,6 +1190,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end listascdesc_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Changing if list should be ascending or descending"); if sortby.Descending then sortby.Descending = false listascdesc_button:SetText( "List: Desc" ) @@ -1157,6 +1204,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end search_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Searching table"); if search_textentry:GetValue() then tempTable = {} tempTable = MSync.modules[info.ModuleIdentifier].searchTable(MSync.modules[info.ModuleIdentifier].banTable, search_textentry:GetValue()) @@ -1171,10 +1219,12 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end sync_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "[MBSync] Reloading ban table"); MSync.modules[info.ModuleIdentifier].getBanTable() timer.Create("msync.mbsync.waitForBanTable", 3, 0, function() - if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then return end + if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Still waiting for some data from server"); return end + MSync.log(MSYNC_DBG_INFO, "[MBSync] Got all ban data from server! Reloading table now"); tempTable = MSync.modules[info.ModuleIdentifier].sortTable(MSync.modules[info.ModuleIdentifier].banTable, sortby.Column, sortby.Descending) pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) tablePage = 0 @@ -1192,6 +1242,8 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end firstpage_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to first page"); + tablePage = 0 pageof_text:SetText( (tablePage+1).."/"..pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) @@ -1199,6 +1251,8 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end previouspage_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to previous page"); + tablePage = tablePage - 1 pageof_text:SetText( (tablePage+1).."/"..pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) @@ -1206,6 +1260,8 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end nextpage_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to next page"); + tablePage = tablePage + 1 pageof_text:SetText( (tablePage+1).."/"..pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) @@ -1213,6 +1269,8 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end lastpage_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to last page"); + tablePage = pages-1 pageof_text:SetText( (tablePage+1).."/"..pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) @@ -1225,7 +1283,9 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end timer.Create("msync.mbsync.waitForBanTable", 1, 0, function() - if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then return end + if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Still waiting for some data from server");return end + + MSync.log(MSYNC_DBG_INFO, "[MBSync] Got all ban data from server! Reloading table now"); tempTable = MSync.modules[info.ModuleIdentifier].sortTable(MSync.modules[info.ModuleIdentifier].banTable, sortby.Column, sortby.Descending) pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) @@ -1268,6 +1328,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] MSync.modules[info.ModuleIdentifier].unban = function(userid) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.unban Param.:" .. userid); + if not type(userid) == "number" then userid = tonumber(userid) end @@ -1281,6 +1343,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".sendMessage", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.sendMessage"); + local type = net.ReadFloat() if type == 0 then chat.AddText( Color( 237, 135, 26 ), "[MBSync] ", Color( 255, 255, 255), net.ReadString()) @@ -1292,6 +1356,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".openBanGUI", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.openBanGUI"); + MSync.modules[info.ModuleIdentifier].banPanel(net.ReadTable()) end ) @@ -1300,6 +1366,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".openBanTable", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.openBanTable"); + MSync.modules[info.ModuleIdentifier].clientPanel() end ) @@ -1310,6 +1378,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] MSync.modules[info.ModuleIdentifier].getBanTable = function(fulltable) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getBanTable Param.: " .. tostring(fulltable)); + MSync.modules[info.ModuleIdentifier].temporary = {} MSync.modules[info.ModuleIdentifier].banTable = {} @@ -1323,8 +1393,10 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".recieveDataCount", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.recieveDataCount"); + local num = net.ReadFloat() - if not MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then + if num > 0 and not MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then MSync.modules[info.ModuleIdentifier].temporary["count"] = num MSync.modules[info.ModuleIdentifier].temporary["recieved"] = 0 MSync.modules[info.ModuleIdentifier].temporary["unfinished"] = true @@ -1337,6 +1409,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".recieveData", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] msync.MBSync.recieveData"); + MSync.modules[info.ModuleIdentifier].explodeTable(MSync.modules[info.ModuleIdentifier].banTable, net.ReadTable()) MSync.modules[info.ModuleIdentifier].temporary["recieved"] = MSync.modules[info.ModuleIdentifier].temporary["recieved"] + 1 @@ -1371,6 +1445,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] net.Receive( "msync."..info.ModuleIdentifier..".sendSettingsPly", function( len, ply ) + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.sendSettingsPly"); + MSync.modules[info.ModuleIdentifier].settings = net.ReadTable() end ) @@ -1379,6 +1455,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] MSync.modules[info.ModuleIdentifier].getSettings = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getSettings"); + net.Start("msync."..info.ModuleIdentifier..".getSettings") net.SendToServer() end @@ -1388,6 +1466,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Returns: nothing ]] MSync.modules[info.ModuleIdentifier].sendSettings = function() + MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendSettings"); + net.Start("msync."..info.ModuleIdentifier..".sendSettings") net.WriteTable(MSync.modules[info.ModuleIdentifier].settings) net.SendToServer() From 60704a5fbe1f9815bea9194bc7d58d6cb10bd7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 22:51:57 +0200 Subject: [PATCH 18/37] MBSync log message fix Fixed log message for MBSync checkPassword --- lua/msync/server/modules/sv_mbsync.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index e33eb1e..4997fe8 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -1389,7 +1389,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() --[[ Print to console that a banned user tries to join ]] - MSync.log(MSYNC_DBG_WARNING, MSync.formatString("---== [MBSync] ==---\nA banned player tried to join the server.\n-- Informations --\nNickname: $nickname\nSteamID: $steamid\nBan Date: $date\nUnban Date: $unbanDate\nBanned by: $admin\n---== [END] ==---", { + MSync.log(MSYNC_DBG_WARNING, MSync.formatString("\n---== [MBSync] ==---\nA banned player tried to join the server.\n-- Informations --\nNickname: $nickname\nSteamID: $steamid\nBan Date: $date\nUnban Date: $unbanDate\nBanned by: $admin\n---== [END] ==---", { ["nickname"] = ban.banned.nickname, ["steamid"] = ban.banned.steamid, ["date"] = os.date( "%c", ban.timestamp), From 6a9e27bc674469ccc69f21ad4474c9887a121fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 22:55:31 +0200 Subject: [PATCH 19/37] Updated Version numbers Due to the logging implementation, all modules were uppdated by one minor version --- lua/msync/client_gui/modules/cl_mbsync.lua | 4 ++-- lua/msync/client_gui/modules/cl_mrsync.lua | 4 ++-- lua/msync/server/modules/sv_mbsync.lua | 4 ++-- lua/msync/server/modules/sv_mrsync.lua | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index e093a3d..698faab 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 1.3.0 + * @version 1.3.1 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.0" + Version = "1.3.1" } --[[ diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index f1824ad..9c60b49 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -6,7 +6,7 @@ MSync.modules.MRSync = MSync.modules.MRSync or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.1 + * @version 2.2.2 ]] --[[ @@ -16,7 +16,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.1" + Version = "2.2.2" } --[[ diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 4997fe8..a2b65e4 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENSE - * @version 1.3.0 + * @version 1.3.1 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.0" + Version = "1.3.1" } --[[ diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 089ea03..5b26856 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -7,7 +7,7 @@ local userTransaction = userTransaction or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.1 + * @version 2.2.2 ]] --[[ @@ -17,7 +17,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.1" + Version = "2.2.2" } --[[ From 2391faf0390663866e12a4f0ef26b61663a0d7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 23:19:14 +0200 Subject: [PATCH 20/37] Updating old settings files Add ability to automatically update old settings file if found --- lua/msync/server/sv_init.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lua/msync/server/sv_init.lua b/lua/msync/server/sv_init.lua index a4e7b0a..5de4940 100644 --- a/lua/msync/server/sv_init.lua +++ b/lua/msync/server/sv_init.lua @@ -73,6 +73,27 @@ function MSync.func.loadSettings() MSync.log(MSYNC_DBG_DEBUG, "Created new configuration") else MSync.settings.data = util.JSONToTable(file.Read("msync/settings.txt", "DATA")) + + if MSync.settings.data.EnabledModules and MSync.settings.data.DisabledModules then + MSync.log(MSYNC_DBG_WARNING, "Old settings file found! Updating to new format") + file.Delete( "msync/settings.txt" ) + local oldSettings = table.Copy(MSync.settings.data) + MSync.settings.data = { + mysql = { + host = oldSettings.mysql.Host, + port = oldSettings.mysql.Port, + username = oldSettings.mysql.Username, + password = oldSettings.mysql.Password, + database = oldSettings.mysql.Database + }, + enabledModules = { + ["mrsync"] = true + }, + serverGroup = "allservers" + } + file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) + MSync.log(MSYNC_DBG_WARNING, "Settings imported! Module settings cannot be ported and need to be re-done") + end MSync.log(MSYNC_DBG_DEBUG, "Loaded found configuration") end From ffc772079f6a0c8eca0d7a53babb10afe5a7640c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 27 Aug 2020 23:24:21 +0200 Subject: [PATCH 21/37] Fix wrong default modules Fixed a issue that caused the default settings to not enable MRSync ( which is enabled by default ) --- lua/msync/server/sv_init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/msync/server/sv_init.lua b/lua/msync/server/sv_init.lua index 5de4940..5c79b97 100644 --- a/lua/msync/server/sv_init.lua +++ b/lua/msync/server/sv_init.lua @@ -64,7 +64,7 @@ function MSync.func.loadSettings() database = "msync" }, enabledModules = { - ["mrsync"] = true + ["MRSync"] = true }, serverGroup = "allservers" } @@ -77,6 +77,7 @@ function MSync.func.loadSettings() if MSync.settings.data.EnabledModules and MSync.settings.data.DisabledModules then MSync.log(MSYNC_DBG_WARNING, "Old settings file found! Updating to new format") file.Delete( "msync/settings.txt" ) + local oldSettings = table.Copy(MSync.settings.data) MSync.settings.data = { mysql = { @@ -87,10 +88,11 @@ function MSync.func.loadSettings() database = oldSettings.mysql.Database }, enabledModules = { - ["mrsync"] = true + ["MRSync"] = true }, serverGroup = "allservers" } + file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) MSync.log(MSYNC_DBG_WARNING, "Settings imported! Module settings cannot be ported and need to be re-done") end From 5edc733e8673c33f03a192a8adbad886500b85ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 11:11:50 +0200 Subject: [PATCH 22/37] Update GUI - Add clickable links in MSync admin panel - Add working database status showcase in admin panel --- lua/msync/client_gui/cl_admin_gui.lua | 79 ++++++++++++++++++++++----- lua/msync/client_gui/cl_net.lua | 10 ++++ lua/msync/server/sv_net.lua | 13 ++++- 3 files changed, 86 insertions(+), 16 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index 5b7a8ba..769994f 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -78,26 +78,55 @@ function MSync.AdminPanel.InitMySQL( sheet ) title_info:SetSize(400, 15) title_info:SetText( "--Information--" ) - local info = vgui.Create( "DLabel", pnl ) - info:SetPos( 200, 30 ) - info:SetColor( Color( 0, 0, 0 ) ) - info:SetSize(400, 200) - info:SetText( [[ - Support: https://www.Aperture-Development.de - GitHub: https://github.com/Aperture-Development/MSync-2 - LICENCE: To know what you are allowed to do and what not, - read the LICENCE file in the root directory of the addon. - If there is no file, the Licence by-nc-sa 4.0 International applies. - - Developer: This Addon was created by Aperture Development. - Copyright 2018 - Aperture Development - ]] ) + local info = vgui.Create( "RichText", pnl ) + info:SetPos( 200, 45 ) + info:SetSize(350, 150) + info:InsertColorChange(10, 10, 10, 255) + info:AppendText("MSync2 - Now with Steak\n\nSupport: ") + info:InsertColorChange(72, 72, 155, 255) + info:InsertClickableTextStart("OpenWebsite") + info:AppendText("https://www.Aperture-Development.de") + info:InsertClickableTextEnd() + info:InsertColorChange(10, 10, 10, 255) + info:AppendText("\nGitHub: ") + info:InsertColorChange(72, 72, 155, 255) + info:InsertClickableTextStart("OpenGitHub") + info:AppendText("https://github.com/Aperture-Development/MSync-2") + info:InsertClickableTextEnd() + info:InsertColorChange(10, 10, 10, 255) + info:AppendText("\nLicence:\n") + info:InsertColorChange(80, 80, 80, 255) + info:AppendText("To know what you are allowed to do and what not, read the LICENCE file in the root directory of the addon. If there is no file, the licence by-nc-sa 4.0 International applies.\n\n") + info:InsertColorChange(10, 10, 10, 255) + info:AppendText("This addon was created by Aperture Development\n") + info:InsertColorChange(10, 10, 10, 255) + info:AppendText("Copyright 2018 - Aperture Development") + + info.Paint = function( pnl, w, h ) + draw.RoundedBox( 5, 0, 0, w, h, Color(215, 215, 215) ) + end + + info.ActionSignal = function( pnl, signalName, signalValue ) + if signalName == "TextClicked" then + if signalValue == "OpenWebsite" then + gui.OpenURL( "https://www.Aperture-Development.de" ) + elseif signalValue == "OpenGitHub" then + gui.OpenURL( "https://github.com/Aperture-Development/MSync-2" ) + end + end + end local dbstatus = vgui.Create( "DLabel", pnl ) dbstatus:SetPos( 200, 210 ) dbstatus:SetColor( Color( 0, 0, 0 ) ) dbstatus:SetSize(400, 15) - dbstatus:SetText( "DB Connection status: -Not Implemented-" ) + dbstatus:SetText( "Database Status: " ) + + local dbstatus_info = vgui.Create( "DLabel", pnl ) + dbstatus_info:SetPos( 300, 210 ) + dbstatus_info:SetColor( Color( 80, 80, 80 ) ) + dbstatus_info:SetSize(400, 15) + dbstatus_info:SetText( "Please wait..." ) local save_button = vgui.Create( "DButton", pnl ) save_button:SetText( "Save Settings" ) @@ -128,6 +157,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) MSync.settings.serverGroup = servergroup:GetValue() MSync.net.sendSettings(MSync.settings) MSync.net.connectDB() + getConnectionStatus() end local connect_button = vgui.Create( "DButton", pnl ) @@ -137,6 +167,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) connect_button.DoClick = function() MSync.log(MSYNC_DBG_DEBUG, "Connecting to the database") MSync.net.connectDB() + getConnectionStatus() end local reset_button = vgui.Create( "DButton", pnl ) @@ -181,6 +212,24 @@ function MSync.AdminPanel.InitMySQL( sheet ) end) end + local function getConnectionStatus() + MSync.net.getDBStatus() + timer.Create("msync.dbConnectionStatus", 3, 10, function() + if MSync.DBStatus == nil then return end + + if MSync.DBStatus then + dbstatus_info:SetColor( Color( 80, 255, 80 ) ) + dbstatus_info:SetText( "Connected" ) + else + dbstatus_info:SetColor( Color( 255, 80, 80 ) ) + dbstatus_info:SetText( "Not Connected" ) + end + timer.Remove("msync.dbConnectionStatus") + end) + end + + getConnectionStatus() + return pnl end diff --git a/lua/msync/client_gui/cl_net.lua b/lua/msync/client_gui/cl_net.lua index e8fa735..5203b9d 100644 --- a/lua/msync/client_gui/cl_net.lua +++ b/lua/msync/client_gui/cl_net.lua @@ -54,6 +54,16 @@ function MSync.net.connectDB() net.SendToServer() end +--[[ + Description: function to ask for database connection + Returns: nothing +]] +function MSync.net.getDBStatus() + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.connectionStatus") + net.Start("msync.connectionStatus") + net.SendToServer() +end + --[[ Description: Net Receiver - Gets called when the server sends a table to the client Returns: nothing diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index 627388a..7bd31c1 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -62,7 +62,7 @@ function MSync.net.dbStatus(ply) MSync.log(MSYNC_DBG_DEBUG, "Exec: net.dbStatus. Param.: " .. tostring(ply)) net.Start("msync.dbStatus") if MSync.DBServer then - net.WriteBool(true) + net.WriteBool(MSync.DBServer:ping()) else net.WriteBool(false) end @@ -161,3 +161,14 @@ net.Receive("msync.connectDB", function(len, ply) MSync.mysql.initialize() end ) + +--[[ + Description: Net Receiver - Gets called when the client requests the database status + Returns: nothing +]] +util.AddNetworkString("msync.connectionStatus") +net.Receive("msync.connectionStatus", function(len, ply) + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectionStatus. Ply.: " .. ply:Nick()) + if not ply:query("msync.getSettings") then return end + MSync.net.dbStatus(ply) +end ) From dfe0fe26141ce24b30eb07ea98e7f9eb16beb431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 11:22:09 +0200 Subject: [PATCH 23/37] Reset confirmation Add reset confirmation before resetting the MySQL configuration --- lua/msync/client_gui/cl_admin_gui.lua | 60 ++++++++++++++++++++------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index 769994f..b562222 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -175,20 +175,52 @@ function MSync.AdminPanel.InitMySQL( sheet ) reset_button:SetPos( 415, 290 ) reset_button:SetSize( 130, 30 ) reset_button.DoClick = function() - MSync.log(MSYNC_DBG_DEBUG, "Reset mysql configuration") - mysqlip:SetText("127.0.0.1") - mysqlport:SetText("3306") - mysqldb:SetText("msync") - mysqluser:SetText("root") - mysqlpassword:SetText("****") - servergroup:SetText("allserver") - MSync.settings.mysql.host = mysqlip:GetValue() - MSync.settings.mysql.port = mysqlport:GetValue() - MSync.settings.mysql.database = mysqldb:GetValue() - MSync.settings.mysql.username = mysqluser:GetValue() - MSync.settings.mysql.password = "" - MSync.settings.serverGroup = servergroup:GetValue() - MSync.net.sendSettings(MSync.settings) + MSync.log(MSYNC_DBG_DEBUG, "Reset confirm request"); + + local resetConfirm_panel = vgui.Create( "DFrame" ) + resetConfirm_panel:SetSize( 350, 100 ) + resetConfirm_panel:SetTitle( "MSync Reset - Confirm" ) + resetConfirm_panel:Center() + resetConfirm_panel:MakePopup() + + local save_text = vgui.Create( "DLabel", resetConfirm_panel ) + save_text:SetPos( 15, 20 ) + save_text:SetColor( Color( 255, 255, 255 ) ) + save_text:SetText( "This action will reset all MySQL settings back to default, causing MSync to be unable to connect to the database when restarting the server. Are you sure you want to do that?" ) + save_text:SetSize(320, 50) + save_text:SetWrap( true ) + + local accept_button = vgui.Create( "DButton", resetConfirm_panel ) + accept_button:SetText( "Yes" ) + accept_button:SetPos( 15, 70 ) + accept_button:SetSize( 160, 20 ) + accept_button.DoClick = function() + MSync.log(MSYNC_DBG_DEBUG, "Reset of MySQL configuration confirmed") + mysqlip:SetText("127.0.0.1") + mysqlport:SetText("3306") + mysqldb:SetText("msync") + mysqluser:SetText("root") + mysqlpassword:SetText("****") + servergroup:SetText("allserver") + MSync.settings.mysql.host = mysqlip:GetValue() + MSync.settings.mysql.port = mysqlport:GetValue() + MSync.settings.mysql.database = mysqldb:GetValue() + MSync.settings.mysql.username = mysqluser:GetValue() + MSync.settings.mysql.password = "" + MSync.settings.serverGroup = servergroup:GetValue() + MSync.net.sendSettings(MSync.settings) + + resetConfirm_panel:Close() + end + + local deny_button = vgui.Create( "DButton", resetConfirm_panel ) + deny_button:SetText( "No" ) + deny_button:SetPos( 175, 70 ) + deny_button:SetSize( 160, 20 ) + deny_button.DoClick = function() + MSync.log(MSYNC_DBG_INFO, "Reset of MySQL configuration cancelled"); + resetConfirm_panel:Close() + end end if not MSync.settings == nil then From dcb899576a8e047306e4b094b335013be5622fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 12:37:54 +0200 Subject: [PATCH 24/37] Initial loader update - Add enable and disable functions to enable and disable modules in real-time - Update sample module for new module loader API - Addnet broadcast to enable and disable modules on clients --- lua/msync/client_gui/cl_modules.lua | 38 +++++++++++++- lua/msync/client_gui/cl_net.lua | 20 +++++++ .../client_gui/modules/cl_samplemodule.lua | 33 ++++++++---- lua/msync/server/modules/sv_samplemodule.lua | 7 +++ lua/msync/server/sv_modules.lua | 52 +++++++++++++++++++ lua/msync/server/sv_net.lua | 30 +++++++++++ 6 files changed, 168 insertions(+), 12 deletions(-) diff --git a/lua/msync/client_gui/cl_modules.lua b/lua/msync/client_gui/cl_modules.lua index 07fdfd8..9fda110 100644 --- a/lua/msync/client_gui/cl_modules.lua +++ b/lua/msync/client_gui/cl_modules.lua @@ -39,7 +39,6 @@ end Returns: nothing ]] function MSync.loadModule(path) - local initTransaction = MSync.DBServer:createTransaction() local info = include(path) MSync.modules[info.ModuleIdentifier].init() @@ -47,6 +46,41 @@ function MSync.loadModule(path) MSync.modules[info.ModuleIdentifier].ulx() MSync.modules[info.ModuleIdentifier].hooks() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.Name].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.ModuleIdentifier]["info"]["Name"].."] Module loaded") end + +--[[ + Description: Enables a single already loaded clientside module + Arguments: Module path + Returns: nothing +]] +function MSync.enableModule( module ) + if MSync.modules[module] then + MSync.modules[module].init() + MSync.modules[module].net() + MSync.modules[module].ulx() + MSync.modules[module].hooks() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + else + MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"") + end +end + +--[[ + Description: Disabled a single already loaded clientside module + Arguments: Module path + Returns: nothing +]] +function MSync.disableModule( module ) + if MSync.modules[module] then + if MSync.modules[module].disable then + MSync.modules[module].disable() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module disabled") + else + MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") + end + else + MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"") + end +end diff --git a/lua/msync/client_gui/cl_net.lua b/lua/msync/client_gui/cl_net.lua index 5203b9d..b78b681 100644 --- a/lua/msync/client_gui/cl_net.lua +++ b/lua/msync/client_gui/cl_net.lua @@ -115,4 +115,24 @@ end ) net.Receive( "msync.dbStatus", function( len, pl ) MSync.DBStatus = net.ReadBool() MSync.log(MSYNC_DBG_DEBUG, "Net: msync.dbStatus Return: " .. tostring(MSync.DBStatus)) +end ) + +--[[ + Description: Net Receiver - Gets called when a module has been enabled + Returns: nothing +]] +net.Receive( "msync.enableModule", function( len, pl ) + local module = net.ReadString() + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.enableModule Return: " .. module) + MSync.enableModule( module ) +end ) + +--[[ + Description: Net Receiver - Gets called when a module has been disabled + Returns: nothing +]] +net.Receive( "msync.disableModule", function( len, pl ) + local module = net.ReadString() + MSync.log(MSYNC_DBG_DEBUG, "Net: msync.disableModule Return: " .. module) + MSync.disableModule( module ) end ) \ No newline at end of file diff --git a/lua/msync/client_gui/modules/cl_samplemodule.lua b/lua/msync/client_gui/modules/cl_samplemodule.lua index e9ac24d..f273a23 100644 --- a/lua/msync/client_gui/modules/cl_samplemodule.lua +++ b/lua/msync/client_gui/modules/cl_samplemodule.lua @@ -6,23 +6,29 @@ MSync.modules.SampleModule = MSync.modules.SampleModule or {} * @package Sample Module * @author Aperture Development * @license root_dir/LICENCE - * @version 1.0.0 + * @version 1.0.1 ]] --[[ Define name, description and module identifier ]] -MSync.modules.SampleModule.info = { +local info = { Name = "Sample Module", ModuleIdentifier = "SampleModule", Description = "A basic example module on how to create modules", - Version = "0.0.1" + Version = "1.0.1" } +--[[ + Prepare Module +]] +MSync.modules[info.ModuleIdentifier] = MSync.modules[info.ModuleIdentifier] or {} +MSync.modules[info.ModuleIdentifier].info = info + --[[ Define additional functions that are later used ]] -function MSync.modules.SampleModule.init() +MSync.modules[info.ModuleIdentifier].init = function() function MSync.modules.SampleModule.SampleFunction() return true @@ -33,7 +39,7 @@ end --[[ Define the admin panel for the settings ]] -function MSync.modules.SampleModule.adminPanel(sheet) +MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) local pnl = vgui.Create( "DPanel", sheet ) pnl:Dock(FILL) return pnl @@ -42,7 +48,7 @@ end --[[ Define the client panel for client usage ( or as example: use it as additional admin gui which does not need msync.admingui permission) ]] -function MSync.modules.SampleModule.clientPanel() +MSync.modules[info.ModuleIdentifier].clientPanel = function() local pnl = vgui.Create( "DPanel" ) return pnl @@ -51,7 +57,7 @@ end --[[ Define net receivers and util.AddNetworkString ]] -function MSync.modules.SampleModule.net() +MSync.modules[info.ModuleIdentifier].net = function() net.Receive( "my_message", function( len, pl ) if ( IsValid( pl ) and pl:IsPlayer() ) then print( "Message from " .. pl:Nick() .. " received. Its length is " .. len .. "." ) @@ -64,20 +70,27 @@ end --[[ Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) ]] -function MSync.modules.SampleModule.ulx() +MSync.modules[info.ModuleIdentifier].ulx = function() end --[[ Define hooks your module is listening on e.g. PlayerDisconnect ]] -function MSync.modules.SampleModule.hooks() +MSync.modules[info.ModuleIdentifier].hooks = function() hook.Add("initialize", "msync_sampleModule_init", function() end) end +--[[ + Define a function to run on the clients when the module gets disabled +]] +MSync.modules[info.ModuleIdentifier].disable = function() + +end + --[[ Return info ( Just for single module loading ) ]] -return MSync.modules.SampleModule.info \ No newline at end of file +return MSync.modules[info.ModuleIdentifier].info \ No newline at end of file diff --git a/lua/msync/server/modules/sv_samplemodule.lua b/lua/msync/server/modules/sv_samplemodule.lua index f523b32..a20b8b0 100644 --- a/lua/msync/server/modules/sv_samplemodule.lua +++ b/lua/msync/server/modules/sv_samplemodule.lua @@ -69,6 +69,13 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end) end +--[[ + Define a function to run on the server when the module gets disabled +]] +MSync.modules[info.ModuleIdentifier].disable = function() + +end + --[[ Return info ( Just for single module loading ) ]] diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index 5cb242c..a404978 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -84,3 +84,55 @@ function MSync.loadModule(path) initTransaction:start() end + +--[[ + Description: Enables a single already loaded clientside module + Arguments: + - module [string] - the module to be enabled + Returns: nothing +]] +function MSync.enableModule( module ) + if MSync.modules[module] then + local initTransaction = MSync.DBServer:createTransaction() + + MSync.modules[module].init(initTransaction) + MSync.modules[module].net() + MSync.modules[module].ulx() + MSync.modules[module].hooks() + + function initTransaction.onSuccess() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + MSync.net.sendModuleEnable( module ) + MSync.mysql[info.ModuleIdentifier].dbstatus = true + end + + function initTransaction.onError(tr, err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + MSync.mysql[info.ModuleIdentifier].dbstatus = false + end + + initTransaction:start() + else + MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"") + end +end + +--[[ + Description: Disabled a single already loaded clientside module + Arguments: + - module [string] - the module to be disabled + Returns: nothing +]] +function MSync.disableModule( module ) + if MSync.modules[module] then + if MSync.modules[module].disable then + MSync.modules[module].disable() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module disabled") + MSync.net.sendModuleDisable( module ) + else + MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") + end + else + MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"") + end +end \ No newline at end of file diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index 7bd31c1..65164de 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -70,6 +70,34 @@ function MSync.net.dbStatus(ply) end util.AddNetworkString("msync.dbStatus") +--[[ + Description: Function to enable a module on all clients + Arguments: + module [string] - the module to be enabled + Returns: nothing +]] +function MSync.net.sendModuleEnable( module ) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.enableModule. Param.: " .. module) + net.Start("msync.enableModule") + net.WriteString(module) + net.Broadcast() +end +util.AddNetworkString("msync.enableModule") + +--[[ + Description: Function to disable a module on all clients + Arguments: + module [string] - the module to be disabled + Returns: nothing +]] +function MSync.net.sendModuleDisable( module ) + MSync.log(MSYNC_DBG_DEBUG, "Exec: net.disableModule. Param.: " .. module) + net.Start("msync.disableModule") + net.WriteString(module) + net.Broadcast() +end +util.AddNetworkString("msync.disableModule") + --[[ Description: Net Receiver - Gets called when the client requests a table Returns: nothing @@ -143,8 +171,10 @@ net.Receive("msync.toggleModule", function(len, ply) local state = net.ReadString() if state == "Enable" then MSync.settings.data.enabledModules[ident] = true + MSync.enableModule( ident ) elseif state == "Disable" then MSync.settings.data.enabledModules[ident] = nil + MSync.disableModule( ident ) end MSync.func.saveSettings() MSync.net.sendMessage(ply, "info", state.."d module "..ident) From 6e4999930daa2b5b05ed7d83906c8bd69a45885e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 14:26:13 +0200 Subject: [PATCH 25/37] Fixed enableModule and disableModule - Fix modules not enabling and disabling properly - Add check for already enabled/disabled modules to not load/unload a module twice - Fix enabling and disabling order --- lua/msync/server/sv_modules.lua | 55 +++++++++++++++++++-------------- lua/msync/server/sv_net.lua | 4 +-- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index a404978..aa19b99 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -74,12 +74,12 @@ function MSync.loadModule(path) function initTransaction.onSuccess() MSync.log(MSYNC_DBG_INFO, "Module query has been completed successfully") - MSync.mysql[info.ModuleIdentifier].dbstatus = true + --MSync.mysql[info.ModuleIdentifier].dbstatus = true end function initTransaction.onError(tr, err) MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) - MSync.mysql[info.ModuleIdentifier].dbstatus = false + --MSync.mysql[info.ModuleIdentifier].dbstatus = false end initTransaction:start() @@ -93,25 +93,30 @@ end ]] function MSync.enableModule( module ) if MSync.modules[module] then - local initTransaction = MSync.DBServer:createTransaction() - - MSync.modules[module].init(initTransaction) - MSync.modules[module].net() - MSync.modules[module].ulx() - MSync.modules[module].hooks() + MSync.log(MSYNC_DBG_DEBUG, "Module \"" .. module .. "\" enabled?: " .. tostring(MSync.settings.data.enabledModules[module])) + if not MSync.settings.data.enabledModules[module] then + local initTransaction = MSync.DBServer:createTransaction() + + MSync.modules[module].init(initTransaction) + MSync.modules[module].net() + MSync.modules[module].ulx() + MSync.modules[module].hooks() + + function initTransaction.onSuccess() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + MSync.net.sendModuleEnable( module ) + --MSync.mysql[module].dbstatus = true + end - function initTransaction.onSuccess() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") - MSync.net.sendModuleEnable( module ) - MSync.mysql[info.ModuleIdentifier].dbstatus = true - end + function initTransaction.onError(tr, err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + --MSync.mysql[module].dbstatus = false + end - function initTransaction.onError(tr, err) - MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) - MSync.mysql[info.ModuleIdentifier].dbstatus = false + initTransaction:start() + else + MSync.log(MSYNC_DBG_WARNING, "Module \"" .. module .. "\" is already enabled") end - - initTransaction:start() else MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"") end @@ -125,12 +130,16 @@ end ]] function MSync.disableModule( module ) if MSync.modules[module] then - if MSync.modules[module].disable then - MSync.modules[module].disable() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module disabled") - MSync.net.sendModuleDisable( module ) + if MSync.settings.data.enabledModules[module] then + if MSync.modules[module].disable then + MSync.modules[module].disable() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module disabled") + MSync.net.sendModuleDisable( module ) + else + MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") + end else - MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") + MSync.log(MSYNC_DBG_WARNING, "Module \"" .. module .. "\" is already disabled") end else MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"") diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index 65164de..ae6d3d5 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -170,11 +170,11 @@ net.Receive("msync.toggleModule", function(len, ply) local ident = net.ReadString() local state = net.ReadString() if state == "Enable" then - MSync.settings.data.enabledModules[ident] = true MSync.enableModule( ident ) + MSync.settings.data.enabledModules[ident] = true elseif state == "Disable" then - MSync.settings.data.enabledModules[ident] = nil MSync.disableModule( ident ) + MSync.settings.data.enabledModules[ident] = nil end MSync.func.saveSettings() MSync.net.sendMessage(ply, "info", state.."d module "..ident) From 7de894b266ee59ede70a1f5e373812d29216243f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 14:26:49 +0200 Subject: [PATCH 26/37] Update MRSync module Update MRSync module to implement the new disable functionality --- lua/msync/client_gui/modules/cl_mrsync.lua | 7 +++++++ lua/msync/server/modules/sv_mrsync.lua | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index 9c60b49..56e07b6 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -233,6 +233,13 @@ function MSync.modules.MRSync.hooks() end +--[[ + Define a function to run on the clients when the module gets disabled +]] +MSync.modules.MRSync.disable = function() + +end + --[[ Return info ( Just for single module loading ) ]] diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 5b26856..6c5698f 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -232,10 +232,10 @@ function MSync.modules.MRSync.init( transaction ) } } file.Write("msync/mrsync.txt", util.TableToJSON(MSync.modules.MRSync.settings, true)) - MSync.log(MSYNC_DBG_INFO, "[MRSync] No config file, creating one now"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] No config file, creating one now"); else MSync.modules.MRSync.settings = util.JSONToTable(file.Read("msync/mrsync.txt", "DATA")) - MSync.log(MSYNC_DBG_INFO, "[MRSync] Found config file, loading it now"); + MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Found config file, loading it now"); end return true @@ -350,6 +350,16 @@ function MSync.modules.MRSync.hooks() end) end +--[[ + Define a function to run on the server when the module gets disabled +]] +MSync.modules.MRSync.disable = function() + hook.Remove("PlayerInitialSpawn", "mrsync.H.loadRank") + hook.Remove("PlayerDisconnected", "mrsync.H.saveRank") + hook.Remove("ULibUserGroupChange", "mrsync.H.saveRankOnUpdate") + hook.Remove("ULibUserRemoved", "mrsync.H.saveRankOnUpdate") +end + --[[ Return info ( Just for single module loading ) ]] From cd7dc878dbd457652a4a797c5de5709c232a5c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 14:27:13 +0200 Subject: [PATCH 27/37] Update MBSync module Implemented new disable functionality into MBSync module --- lua/msync/client_gui/modules/cl_mbsync.lua | 7 +++++++ lua/msync/server/modules/sv_mbsync.lua | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 698faab..9fe9f0f 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -1488,6 +1488,13 @@ MSync.modules[info.ModuleIdentifier].hooks = function() -- end +--[[ + Define a function to run on the clients when the module gets disabled +]] +MSync.modules[info.ModuleIdentifier].disable = function() + +end + --[[ Return info ( Just for single module loading ) ]] diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index a2b65e4..86599d0 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -1147,6 +1147,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons } BanPlayer:defaultAccess( ULib.ACCESS_SUPERADMIN ) BanPlayer:help( "Opens the MBSync GUI ( without parameters ) or bans a player" ) + --[[ ban the targeted steamid @@ -1500,6 +1501,17 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end) end +--[[ + Define a function to run on the server when the module gets disabled +]] +MSync.modules.MRSync.disable = function() + hook.Remove("CheckPassword", "msync."..info.ModuleIdentifier..".banCheck") + hook.Remove("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects") + hook.Remove("ULibPlayerBanned", "msync.mbsync.ulxban") + hook.Remove("ULibPlayerUnBanned", "msync.mbsync.ulxunban") + timer.Remove("msync."..info.ModuleIdentifier..".getActiveBans") +end + --[[ Return info ( Just for single module loading ) ]] From cbd6cab7aba74ff05565b7c019e90d2e4e36f1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 15:35:38 +0200 Subject: [PATCH 28/37] MBSync fix Fixed a overlook while implementing the disable function --- lua/msync/server/modules/sv_mbsync.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 86599d0..90ec011 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -1504,7 +1504,7 @@ end --[[ Define a function to run on the server when the module gets disabled ]] -MSync.modules.MRSync.disable = function() +MSync.modules[info.ModuleIdentifier].disable = function() hook.Remove("CheckPassword", "msync."..info.ModuleIdentifier..".banCheck") hook.Remove("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects") hook.Remove("ULibPlayerBanned", "msync.mbsync.ulxban") From d629636469bf2fdaec5a9cc41c4a4c3ac2138ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 15:37:53 +0200 Subject: [PATCH 29/37] Updated Version numbers Version numbers of modules were all increased by one minor version due to the real-time disable implementation --- lua/msync/client_gui/modules/cl_mbsync.lua | 4 ++-- lua/msync/client_gui/modules/cl_mrsync.lua | 4 ++-- lua/msync/server/modules/sv_mbsync.lua | 4 ++-- lua/msync/server/modules/sv_mrsync.lua | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 9fe9f0f..65033c0 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 1.3.1 + * @version 1.3.2 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.1" + Version = "1.3.2" } --[[ diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index 56e07b6..f0be49d 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -6,7 +6,7 @@ MSync.modules.MRSync = MSync.modules.MRSync or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.2 + * @version 2.2.3 ]] --[[ @@ -16,7 +16,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.2" + Version = "2.2.3" } --[[ diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 90ec011..75b8b15 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -5,7 +5,7 @@ MSync.modules = MSync.modules or {} * @package MySQL Ban Sync * @author Aperture Development * @license root_dir/LICENSE - * @version 1.3.1 + * @version 1.3.2 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.1" + Version = "1.3.2" } --[[ diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 6c5698f..db41870 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -7,7 +7,7 @@ local userTransaction = userTransaction or {} * @package MySQL Rank Sync * @author Aperture Development * @license root_dir/LICENCE - * @version 2.2.2 + * @version 2.2.3 ]] --[[ @@ -17,7 +17,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.2" + Version = "2.2.3" } --[[ From 43c77b559a1ca906444a940512a2d388faa256d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 15:45:05 +0200 Subject: [PATCH 30/37] Database Check Add checking database before enabling a module to prevent errors --- lua/msync/server/sv_modules.lua | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index aa19b99..2b2e1ec 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -94,26 +94,30 @@ end function MSync.enableModule( module ) if MSync.modules[module] then MSync.log(MSYNC_DBG_DEBUG, "Module \"" .. module .. "\" enabled?: " .. tostring(MSync.settings.data.enabledModules[module])) - if not MSync.settings.data.enabledModules[module] then - local initTransaction = MSync.DBServer:createTransaction() - - MSync.modules[module].init(initTransaction) - MSync.modules[module].net() - MSync.modules[module].ulx() - MSync.modules[module].hooks() - - function initTransaction.onSuccess() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") - MSync.net.sendModuleEnable( module ) - --MSync.mysql[module].dbstatus = true - end - - function initTransaction.onError(tr, err) - MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) - --MSync.mysql[module].dbstatus = false + if MSync.settings.data.enabledModules[module] then + if not MSync.DBServer:ping() then + local initTransaction = MSync.DBServer:createTransaction() + + MSync.modules[module].init(initTransaction) + MSync.modules[module].net() + MSync.modules[module].ulx() + MSync.modules[module].hooks() + + function initTransaction.onSuccess() + MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + MSync.net.sendModuleEnable( module ) + --MSync.mysql[module].dbstatus = true + end + + function initTransaction.onError(tr, err) + MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n"..err) + --MSync.mysql[module].dbstatus = false + end + + initTransaction:start() + else + MSync.log(MSYNC_DBG_WARNING, "Cannot enable \"" .. module .. "\". Database isn't connected") end - - initTransaction:start() else MSync.log(MSYNC_DBG_WARNING, "Module \"" .. module .. "\" is already enabled") end From 3e46674421fea17e83b2693e5c8a917f622c5dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 15:53:35 +0200 Subject: [PATCH 31/37] MRSync soft error Add a soft error to MRSync to prevent SQL errors related to the groupname length --- lua/msync/server/modules/sv_mrsync.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index db41870..3915de8 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -50,6 +50,8 @@ function MSync.modules.MRSync.init( transaction ) if MSync.modules.MRSync.settings.nosync[group] then MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Group \"" .. group .. "\" is set to No-Sync. Not sending data to the database"); return end; + if string.len(group) > 15 then MSync.log(MSYNC_DBG_ERROR, "[MRSync] Groupname \"" .. group .. "\" is too long for MRSync! Please use rank names with max. 15 characters instead."); return end; + local addUserRankQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_mrsync` (user_id, rank, server_group) VALUES ( From ed06089e074afd9c69c3158c06a60d28a766c5d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 28 Aug 2020 15:58:11 +0200 Subject: [PATCH 32/37] 64bit compability Add 64bit mysqloo DLLs to installation check --- lua/msync/server/sv_mysql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index f08d484..3b1db2b 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -9,7 +9,7 @@ MSync.func = MSync.func or {} Returns: nothing ]] function MSync.mysql.initialize() - if (file.Exists( "bin/gmsv_mysqloo_linux.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win32.dll", "LUA" )) and MSync.settings.data.mysql then + if (file.Exists( "bin/gmsv_mysqloo_linux.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win32.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_linux64.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win64.dll", "LUA" )) and MSync.settings.data.mysql then require("mysqloo") MSync.log(MSYNC_DBG_INFO, "Initializing database") From 90871fd2920eb6e009b973a445fd1e58ba800cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Thu, 1 Oct 2020 21:57:52 +0200 Subject: [PATCH 33/37] Fixed nil value getConnectionStatus - Fix a bug that caused the MSync gui to error out when clicking connect or save and connect --- lua/msync/client_gui/cl_admin_gui.lua | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index b562222..0867f69 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -128,6 +128,26 @@ function MSync.AdminPanel.InitMySQL( sheet ) dbstatus_info:SetSize(400, 15) dbstatus_info:SetText( "Please wait..." ) + local function getConnectionStatus() + dbstatus_info:SetColor( Color( 80, 80, 80 ) ) + dbstatus_info:SetText( "Please wait..." ) + timer.Simple(3, function() + MSync.net.getDBStatus() + timer.Create("msync.dbConnectionStatus", 3, 10, function() + if MSync.DBStatus == nil then return end + + if MSync.DBStatus then + dbstatus_info:SetColor( Color( 80, 255, 80 ) ) + dbstatus_info:SetText( "Connected" ) + else + dbstatus_info:SetColor( Color( 255, 80, 80 ) ) + dbstatus_info:SetText( "Not Connected" ) + end + timer.Remove("msync.dbConnectionStatus") + end) + end) + end + local save_button = vgui.Create( "DButton", pnl ) save_button:SetText( "Save Settings" ) save_button:SetPos( 25, 290 ) @@ -244,22 +264,6 @@ function MSync.AdminPanel.InitMySQL( sheet ) end) end - local function getConnectionStatus() - MSync.net.getDBStatus() - timer.Create("msync.dbConnectionStatus", 3, 10, function() - if MSync.DBStatus == nil then return end - - if MSync.DBStatus then - dbstatus_info:SetColor( Color( 80, 255, 80 ) ) - dbstatus_info:SetText( "Connected" ) - else - dbstatus_info:SetColor( Color( 255, 80, 80 ) ) - dbstatus_info:SetText( "Not Connected" ) - end - timer.Remove("msync.dbConnectionStatus") - end) - end - getConnectionStatus() return pnl From 151eaa5316d1390e58b109a6456ad445b95468e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 3 Oct 2020 21:44:12 +0200 Subject: [PATCH 34/37] Bugfix - Loading modules - Fix a bug that caused MSync 2 to load modules on the clientside, despite the module not having loaded on the server ( mainly due to a "Not connected" error ) --- lua/msync/client_gui/cl_net.lua | 2 ++ lua/msync/server/sv_hooks.lua | 6 +++++- lua/msync/server/sv_init.lua | 15 ++++++++------- lua/msync/server/sv_modules.lua | 11 +++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lua/msync/client_gui/cl_net.lua b/lua/msync/client_gui/cl_net.lua index b78b681..7fdc1a0 100644 --- a/lua/msync/client_gui/cl_net.lua +++ b/lua/msync/client_gui/cl_net.lua @@ -125,6 +125,7 @@ net.Receive( "msync.enableModule", function( len, pl ) local module = net.ReadString() MSync.log(MSYNC_DBG_DEBUG, "Net: msync.enableModule Return: " .. module) MSync.enableModule( module ) + MSync.moduleState[module] = true end ) --[[ @@ -135,4 +136,5 @@ net.Receive( "msync.disableModule", function( len, pl ) local module = net.ReadString() MSync.log(MSYNC_DBG_DEBUG, "Net: msync.disableModule Return: " .. module) MSync.disableModule( module ) + MSync.moduleState[module] = nil end ) \ No newline at end of file diff --git a/lua/msync/server/sv_hooks.lua b/lua/msync/server/sv_hooks.lua index 5f479a2..706a31d 100644 --- a/lua/msync/server/sv_hooks.lua +++ b/lua/msync/server/sv_hooks.lua @@ -1,3 +1,7 @@ +MSync = MSync or {} +MSync.mysql = MSync.mysql or {} +MSync.net = MSync.net or {} +MSync.loadedModules = MSync.loadedModules or {} --[[ Description: hook to initialize MSync 2 Returns: nothing @@ -27,7 +31,7 @@ end) ]] hook.Add("PlayerInitialSpawn", "msync.createUser", function( ply ) MSync.mysql.addUser(ply) - MSync.net.sendTable(ply, "modulestate", MSync.settings.data.enabledModules) + MSync.net.sendTable(ply, "modulestate", MSync.loadedModules) if ply:query("msync.openAdminGUI") then MSync.net.dbStatus(ply) diff --git a/lua/msync/server/sv_init.lua b/lua/msync/server/sv_init.lua index 5c79b97..411d472 100644 --- a/lua/msync/server/sv_init.lua +++ b/lua/msync/server/sv_init.lua @@ -1,10 +1,11 @@ -MSync = MSync or {} -MSync.net = MSync.net or {} -MSync.mysql = MSync.mysql or {} -MSync.modules = MSync.modules or {} -MSync.settings = MSync.settings or {} -MSync.func = MSync.func or {} -MSync.ulx = MSync.ulx or {} +MSync = MSync or {} +MSync.net = MSync.net or {} +MSync.mysql = MSync.mysql or {} +MSync.modules = MSync.modules or {} +MSync.settings = MSync.settings or {} +MSync.func = MSync.func or {} +MSync.ulx = MSync.ulx or {} +MSync.loadedModules = MSync.loadedModules or {} --[[ Description: Function to load the server side files diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index 2b2e1ec..0ef8895 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -1,7 +1,8 @@ -MSync = MSync or {} -MSync.mysql = MSync.mysql or {} -MSync.settings = MSync.settings or {} -MSync.modules = MSync.modules or {} +MSync = MSync or {} +MSync.mysql = MSync.mysql or {} +MSync.settings = MSync.settings or {} +MSync.modules = MSync.modules or {} +MSync.loadedModules = MSync.loadedModules or {} --[[ Description: Loads all server side modules @@ -36,6 +37,8 @@ function MSync.initModules() v["net"]() v["ulx"]() v["hooks"]() + MSync.loadedModules[v["info"].ModuleIdentifier] = true + MSync.net.sendModuleEnable( v["info"].ModuleIdentifier ) MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded") end end From e643949cffd88226c30329173965b31b829749be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 3 Oct 2020 21:57:23 +0200 Subject: [PATCH 35/37] Bugfix - SUP Add prevent database from connecting if connection is already established --- lua/msync/server/sv_modules.lua | 2 +- lua/msync/server/sv_net.lua | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index 0ef8895..ef008e4 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -98,7 +98,7 @@ function MSync.enableModule( module ) if MSync.modules[module] then MSync.log(MSYNC_DBG_DEBUG, "Module \"" .. module .. "\" enabled?: " .. tostring(MSync.settings.data.enabledModules[module])) if MSync.settings.data.enabledModules[module] then - if not MSync.DBServer:ping() then + if MSync.DBServer:ping() then local initTransaction = MSync.DBServer:createTransaction() MSync.modules[module].init(initTransaction) diff --git a/lua/msync/server/sv_net.lua b/lua/msync/server/sv_net.lua index ae6d3d5..431c053 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -189,7 +189,16 @@ net.Receive("msync.connectDB", function(len, ply) MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectDB. Ply.: " .. ply:Nick()) if not ply:query("msync.connectDB") then return end - MSync.mysql.initialize() + if MSync.DBServer then + if not MSync.DBServer:ping() then + MSync.mysql.initialize() + else + MSync.net.sendMessage(ply, "error", "The database is already connected!") + MSync.log(MSYNC_DBG_DEBUG, "Aborted database connect because connection is already established") + end + else + MSync.mysql.initialize() + end end ) --[[ From 4c4b1a01eb4c6714562a7f74e1099767dd442af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 3 Oct 2020 22:21:59 +0200 Subject: [PATCH 36/37] Bugfix - Module GUI - Add update to module GUI, if you enable a module the enabled value will change to true, otherwise it will turn to false - Fixed a bug causing the real-time module enabling not to work properly --- lua/msync/client_gui/cl_admin_gui.lua | 7 ++++++- lua/msync/server/sv_modules.lua | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index 0867f69..cfc47ff 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -300,12 +300,17 @@ function MSync.AdminPanel.InitModules( sheet ) local cursor_x, cursor_y = ModuleList:CursorPos() local DMenu = vgui.Create("DMenu", ModuleList) DMenu:SetPos(cursor_x, cursor_y) - DMenu:AddOption(MSync.serverModules[ident].Description) + DMenu:AddOption(MSync.serverModules[ident].Description):SetDisabled(true) DMenu:AddSpacer() DMenu:AddOption("Enable") DMenu:AddOption("Disable") DMenu.OptionSelected = function(menu,optPnl,optStr) MSync.net.toggleModule(ident, optStr) + if optStr == "Enable" then + line:SetColumnText( 3, "true" ) + elseif optStr == "Disable" then + line:SetColumnText( 3, "false" ) + end end end return pnl diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index ef008e4..17ac4e9 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -97,7 +97,7 @@ end function MSync.enableModule( module ) if MSync.modules[module] then MSync.log(MSYNC_DBG_DEBUG, "Module \"" .. module .. "\" enabled?: " .. tostring(MSync.settings.data.enabledModules[module])) - if MSync.settings.data.enabledModules[module] then + if not MSync.settings.data.enabledModules[module] then if MSync.DBServer:ping() then local initTransaction = MSync.DBServer:createTransaction() From 50e97857a2dbe1e3ba1fad8f5c8b3e738c9c5992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Fri, 9 Oct 2020 22:31:16 +0200 Subject: [PATCH 37/37] Security Fix: Export and import command Fixed that the export and import command of MSync could be executed on clientside, this was not the intended behaviour, these commands were only intended for server side usage --- lua/msync/server/modules/sv_mbsync.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 75b8b15..fc96ba1 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -639,6 +639,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) exportActiveBans:start() end concommand.Add("msync."..info.ModuleIdentifier..".export", function( ply, cmd, args ) + if ply:IsValid() then return end MSync.modules[info.ModuleIdentifier].exportBansToULX() end) @@ -715,6 +716,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) banTransaction:start() end concommand.Add("msync."..info.ModuleIdentifier..".import", function( ply, cmd, args ) + if ply:IsValid() then return end local allservers = false if args[1] == "true" then