From 2ff81e0b903c803ddb707d34918acdd17131f21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sat, 26 Feb 2022 21:41:49 +0100 Subject: [PATCH 1/6] Update Queries Update queries to fir MySQL standard and fix incompability issues with MySQL --- lua/msync/server/modules/sv_mbsync.lua | 121 +++++++++++++++---------- lua/msync/server/modules/sv_mrsync.lua | 25 +++-- lua/msync/server/sv_mysql.lua | 33 ++++--- 3 files changed, 107 insertions(+), 72 deletions(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 0b19f0f..93ddd34 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -71,8 +71,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) MODIFY `length_unix` INT UNSIGNED NOT NULL; ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') - ON DUPLICATE KEY UPDATE version=VALUES(version); + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') AS newVersion + ON DUPLICATE KEY UPDATE version=newVersion.version; ]])) updates:start() else @@ -88,8 +88,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') - ON DUPLICATE KEY UPDATE version=VALUES(version); + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') AS newVersion + ON DUPLICATE KEY UPDATE version=newVersion.version; ]])) updates:start() end @@ -122,21 +122,29 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banUserQ = 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=? AND steamid64=?), - (SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?), - ?, ?, ?, - (SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) - ); + SELECT UserTbl.p_user_id, AdminTbl.p_user_id, ?, ?, ?, tbl_server_grp.p_group_id + FROM tbl_users AS UserTbl, tbl_users AS AdminTbl, tbl_server_grp + WHERE + ( + UserTbl.steamid=? AND + UserTbl.steamid64=? + ) + AND + ( + AdminTbl.steamid=? AND + AdminTbl.steamid64=? + ) + AND + tbl_server_grp.group_name=?; ]] ) local timestamp = os.time() - banUserQ:setString(1, ply:SteamID()) - banUserQ:setString(2, ply:SteamID64()) - banUserQ:setString(3, calling_ply) - banUserQ:setString(4, util.SteamIDTo64(calling_ply)) - banUserQ:setString(5, reason) - banUserQ:setNumber(6, timestamp) - banUserQ:setNumber(7, length*60) + banUserQ:setString(1, reason) + banUserQ:setNumber(2, timestamp) + banUserQ:setNumber(3, length*60) + banUserQ:setString(4, ply:SteamID()) + banUserQ:setString(5, ply:SteamID64()) + banUserQ:setString(6, calling_ply) + banUserQ:setString(7, util.SteamIDTo64(calling_ply)) if not allserver then banUserQ:setString(8, MSync.settings.data.serverGroup) else @@ -202,21 +210,29 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banUserIdQ = 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=? OR steamid64=?), - (SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?), - ?, ?, ?, - (SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) - ); + SELECT UserTbl.p_user_id, AdminTbl.p_user_id, ?, ?, ?, tbl_server_grp.p_group_id + FROM tbl_users AS UserTbl, tbl_users AS AdminTbl, tbl_server_grp + WHERE + ( + UserTbl.steamid=? OR + UserTbl.steamid64=? + ) + AND + ( + AdminTbl.steamid=? AND + AdminTbl.steamid64=? + ) + AND + tbl_server_grp.group_name=? ]] ) local timestamp = os.time() - banUserIdQ:setString(1, userid) - banUserIdQ:setString(2, userid) - banUserIdQ:setString(3, calling_ply) - banUserIdQ:setString(4, util.SteamIDTo64(calling_ply)) - banUserIdQ:setString(5, reason) - banUserIdQ:setNumber(6, timestamp) - banUserIdQ:setNumber(7, length*60) + banUserIdQ:setString(1, reason) + banUserIdQ:setNumber(2, timestamp) + banUserIdQ:setNumber(3, length*60) + banUserIdQ:setString(4, userid) + banUserIdQ:setString(5, userid) + banUserIdQ:setString(6, calling_ply) + banUserIdQ:setString(7, util.SteamIDTo64(calling_ply)) if not allserver then banUserIdQ:setString(8, MSync.settings.data.serverGroup) else @@ -224,6 +240,14 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end banUserIdQ.onSuccess = function( q, data ) + -- Due to the new SQL syntax, mysql does not throw an error anymore if the user does nit exist. We are checking which rows have been affected to work around this issue + if q:affectedRows() == 0 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) + return + end + -- Notify the user about the ban and add it to ULib to prevent data loss on Addon Remove -- Also, kick the user from the server if calling_ply == "STEAM_0:0:0" then @@ -260,6 +284,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end banUserIdQ.onError = function( q, err, sql ) + -- Deprecated check, remove in next minor release 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) @@ -665,8 +690,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] transactions[k..'_user'] = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) - ON DUPLICATE KEY UPDATE steamid=steamid; + VALUES (?, ?, ?, ?) AS newUser + ON DUPLICATE KEY UPDATE steamid=newUser.steamid; ]] ) transactions[k..'_user']:setString(1, k) transactions[k..'_user']:setString(2, util.SteamIDTo64( k )) @@ -685,37 +710,39 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] 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=?) - ); + SELECT UserTbl.p_user_id, AdminTbl.p_user_id, ?, ?, ?, tbl_server_grp.p_group_id + FROM tbl_users AS UserTbl, tbl_users AS AdminTbl, tbl_server_grp + WHERE + UserTbl.steamid=? + AND + AdminTbl.steamid=? + AND + tbl_server_grp.group_name=?; ]] ) local timestamp = os.time() - transactions[k]:setString(1, k) + transactions[k]:setString(4, k) if v['modified_admin'] then if v['modified_admin'] == "(Console)" then - transactions[k]:setString(2,"STEAM_0:0:0") + transactions[k]:setString(5,"STEAM_0:0:0") else - transactions[k]:setString(2,string.match(v['modified_admin'], "STEAM_%d:%d:%d+")) + transactions[k]:setString(5,string.match(v['modified_admin'], "STEAM_%d:%d:%d+")) end else if v['admin'] == "(Console)" then - transactions[k]:setString(2,"STEAM_0:0:0") + transactions[k]:setString(5,"STEAM_0:0:0") else - transactions[k]:setString(2,string.match(v['admin'], "STEAM_%d:%d:%d+")) + transactions[k]:setString(5,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'])) + transactions[k]:setString(1, v['reason'] or "(None given)") + transactions[k]:setNumber(2, tonumber(v['time'])) if tonumber(v['unban']) == 0 then - transactions[k]:setNumber(5, tonumber(v['unban'])) + transactions[k]:setNumber(3, tonumber(v['unban'])) else - transactions[k]:setNumber(5, tonumber(v['unban']) - tonumber(v['time'])) + transactions[k]:setNumber(3, tonumber(v['unban']) - tonumber(v['time'])) end if not allserver then diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 3915de8..6c2fd6b 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -53,17 +53,22 @@ function MSync.modules.MRSync.init( transaction ) 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 ( - (SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?), - ?, - (SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) - ) - ON DUPLICATE KEY UPDATE rank=VALUES(rank); + INSERT INTO `tbl_mrsync` (user_id, `rank`, server_group) + SELECT * FROM ( + SELECT tbl_users.p_user_id, ? AS newRank, tbl_server_grp.p_group_id + FROM tbl_users, tbl_server_grp + WHERE + ( + tbl_users.steamid=? AND tbl_users.steamid64=? + ) + AND + tbl_server_grp.group_name=? + ) AS dataQuery + ON DUPLICATE KEY UPDATE `rank`=newRank; ]] ) - addUserRankQ:setString(1, steamid) - addUserRankQ:setString(2, util.SteamIDTo64( steamid )) - addUserRankQ:setString(3, group) + addUserRankQ:setString(1, group) + addUserRankQ:setString(2, steamid) + addUserRankQ:setString(3, util.SteamIDTo64( steamid )) if not MSync.modules.MRSync.settings.syncall[group] then addUserRankQ:setString(4, MSync.settings.data.serverGroup) else diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index f8c13e1..53cfefe 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -44,8 +44,8 @@ function MSync.mysql.initialize() ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ - INSERT INTO `tbl_server_grp` (group_name) VALUES ('allservers') - ON DUPLICATE KEY UPDATE group_name=VALUES(group_name); + INSERT INTO `tbl_server_grp` (group_name) VALUES ('allservers') AS newGroup + ON DUPLICATE KEY UPDATE group_name=newGroup.group_name; ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ @@ -74,8 +74,8 @@ function MSync.mysql.initialize() ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ - INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:0', '76561197960265728', '(CONSOLE)', '2004-12-24 12:00:00') - ON DUPLICATE KEY UPDATE nickname=VALUES(nickname); + INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:0', '76561197960265728', '(CONSOLE)', '2004-12-24 12:00:00') AS newUser + ON DUPLICATE KEY UPDATE nickname=newUser.nickname; ]] )) function initDatabase.onSuccess() @@ -115,8 +115,8 @@ function MSync.mysql.addUser(ply) local addUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) - ON DUPLICATE KEY UPDATE nickname=VALUES(nickname); + VALUES (?, ?, ?, ?) AS newUser + ON DUPLICATE KEY UPDATE nickname=newUser.nickname; ]] ) local nickname = ply:Nick() @@ -156,8 +156,8 @@ function MSync.mysql.addUserID(steamid, nickname) local addUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) - ON DUPLICATE KEY UPDATE nickname=VALUES(nickname); + VALUES (?, ?, ?, ?) AS newUser + ON DUPLICATE KEY UPDATE nickname=newUser.nickname; ]] ) if string.len(nickname) > 30 then @@ -198,18 +198,21 @@ end function MSync.mysql.saveServer() local addServerGroup = MSync.DBServer:prepare( [[ - INSERT INTO `tbl_server_grp` (group_name) VALUES (?) - ON DUPLICATE KEY UPDATE group_name=VALUES(group_name); + INSERT INTO `tbl_server_grp` (group_name) VALUES (?) AS newGroup + ON DUPLICATE KEY UPDATE group_name=newGroup.group_name; ]] ) addServerGroup:setString(1, MSync.settings.data.serverGroup) function addServerGroup.onSuccess() local addServer = MSync.DBServer:prepare( [[ - INSERT INTO `tbl_msync_servers` (server_name, ip, port, server_group) - VALUES (?,?,?, - (SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) - ) - ON DUPLICATE KEY UPDATE server_name=VALUES(server_name), server_group=VALUES(server_group); + INSERT INTO `tbl_msync_servers` (server_name, ip, `port`, server_group) + SELECT * FROM ( + SELECT ? AS newServerName, ? AS ip, ? AS `port`, tbl_server_grp.p_group_id AS newGroup + FROM tbl_server_grp + WHERE + tbl_server_grp.group_name=? + ) AS dataQuery + ON DUPLICATE KEY UPDATE server_name=newServerName, server_group=newGroup; ]] ) local hostname = GetHostName() From 5154e5cd9371665faed998db25222f0bfc1bc9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 27 Feb 2022 11:24:11 +0100 Subject: [PATCH 2/6] Update Syntax Update SQL syntax to support MySQL below 8.0.19 and MariaDB. The ``AS tbl`` for inserts has only been implemented with MySQL 8.0.19 and thus does not support any prior version or MariaDB. https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html --- lua/msync/server/modules/sv_mbsync.lua | 12 ++++++------ lua/msync/server/sv_mysql.lua | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 93ddd34..9f35004 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -71,8 +71,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) MODIFY `length_unix` INT UNSIGNED NOT NULL; ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') AS newVersion - ON DUPLICATE KEY UPDATE version=newVersion.version; + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') + ON DUPLICATE KEY UPDATE version=1; ]])) updates:start() else @@ -88,8 +88,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') AS newVersion - ON DUPLICATE KEY UPDATE version=newVersion.version; + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') + ON DUPLICATE KEY UPDATE version=1; ]])) updates:start() end @@ -690,8 +690,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] transactions[k..'_user'] = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) AS newUser - ON DUPLICATE KEY UPDATE steamid=newUser.steamid; + SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery + ON DUPLICATE KEY UPDATE steamid=newNick; ]] ) transactions[k..'_user']:setString(1, k) transactions[k..'_user']:setString(2, util.SteamIDTo64( k )) diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index 53cfefe..1022e77 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -44,8 +44,9 @@ function MSync.mysql.initialize() ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ - INSERT INTO `tbl_server_grp` (group_name) VALUES ('allservers') AS newGroup - ON DUPLICATE KEY UPDATE group_name=newGroup.group_name; + INSERT INTO `tbl_server_grp` (group_name) + SELECT * FROM (SELECT 'allservers' AS newGroup) AS dataQuery + ON DUPLICATE KEY UPDATE group_name=newGroup; ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ @@ -74,8 +75,9 @@ function MSync.mysql.initialize() ]] )) initDatabase:addQuery(MSync.DBServer:query( [[ - INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:0', '76561197960265728', '(CONSOLE)', '2004-12-24 12:00:00') AS newUser - ON DUPLICATE KEY UPDATE nickname=newUser.nickname; + INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) + SELECT * FROM (SELECT 'STEAM_0:0:0', '76561197960265728', '(CONSOLE)' AS newUser, '2004-12-24 12:00:00') AS dataQuery + ON DUPLICATE KEY UPDATE nickname=newUser; ]] )) function initDatabase.onSuccess() @@ -115,8 +117,8 @@ function MSync.mysql.addUser(ply) local addUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) AS newUser - ON DUPLICATE KEY UPDATE nickname=newUser.nickname; + SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery + ON DUPLICATE KEY UPDATE nickname=newNick; ]] ) local nickname = ply:Nick() @@ -156,8 +158,8 @@ function MSync.mysql.addUserID(steamid, nickname) local addUserQ = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) - VALUES (?, ?, ?, ?) AS newUser - ON DUPLICATE KEY UPDATE nickname=newUser.nickname; + SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery + ON DUPLICATE KEY UPDATE nickname=newNick; ]] ) if string.len(nickname) > 30 then @@ -198,8 +200,9 @@ end function MSync.mysql.saveServer() local addServerGroup = MSync.DBServer:prepare( [[ - INSERT INTO `tbl_server_grp` (group_name) VALUES (?) AS newGroup - ON DUPLICATE KEY UPDATE group_name=newGroup.group_name; + INSERT INTO `tbl_server_grp` (group_name) + SELECT * FROM (SELECT ? AS newGroup) AS dataQuery + ON DUPLICATE KEY UPDATE group_name=newGroup; ]] ) addServerGroup:setString(1, MSync.settings.data.serverGroup) From 4513962014e4c314c443a1b32c3ec217b94d1092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 27 Feb 2022 12:52:41 +0100 Subject: [PATCH 3/6] Style Update Code style update to be more readable and implement suggestions by glualint --- lua/msync/client_gui/cl_admin_gui.lua | 8 +- lua/msync/client_gui/cl_modules.lua | 10 +- lua/msync/client_gui/cl_net.lua | 4 +- lua/msync/client_gui/modules/cl_mbsync.lua | 127 ++++---- lua/msync/client_gui/modules/cl_mrsync.lua | 4 +- lua/msync/server/modules/sv_mbsync.lua | 355 ++++++++++----------- lua/msync/server/modules/sv_mrsync.lua | 6 +- lua/msync/server/sv_init.lua | 18 +- lua/msync/server/sv_modules.lua | 18 +- lua/msync/server/sv_mysql.lua | 22 +- lua/msync/server/sv_net.lua | 10 +- lua/msync/sh_init.lua | 10 +- 12 files changed, 294 insertions(+), 298 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index cfc47ff..dc3aa07 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -102,11 +102,11 @@ function MSync.AdminPanel.InitMySQL( sheet ) info:InsertColorChange(10, 10, 10, 255) info:AppendText("Copyright 2018 - Aperture Development") - info.Paint = function( pnl, w, h ) + info.Paint = function( parentPanel, w, h ) draw.RoundedBox( 5, 0, 0, w, h, Color(215, 215, 215) ) end - info.ActionSignal = function( pnl, signalName, signalValue ) + info.ActionSignal = function( parentPanel, signalName, signalValue ) if signalName == "TextClicked" then if signalValue == "OpenWebsite" then gui.OpenURL( "https://www.Aperture-Development.de" ) @@ -243,7 +243,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) end end - if not MSync.settings == nil then + if MSync.settings ~= nil then mysqlip:SetText(MSync.settings.mysql.host) mysqlport:SetText(MSync.settings.mysql.port) mysqldb:SetText(MSync.settings.mysql.database) @@ -330,7 +330,7 @@ function MSync.AdminPanel.InitModuleSettings( sheet ) local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") for k, v in pairs(files) do - local info = include("msync/client_gui/modules/"..v) + local info = include("msync/client_gui/modules/" .. v) if MSync.moduleState[info["ModuleIdentifier"]] then MSync.modules[info.ModuleIdentifier]["init"]() diff --git a/lua/msync/client_gui/cl_modules.lua b/lua/msync/client_gui/cl_modules.lua index 9fda110..b7b0748 100644 --- a/lua/msync/client_gui/cl_modules.lua +++ b/lua/msync/client_gui/cl_modules.lua @@ -10,7 +10,7 @@ MSync.modules = MSync.modules or {} function MSync.loadModules() local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") for k, v in pairs(files) do - include("msync/client_gui/modules/"..v) + include("msync/client_gui/modules/" .. v) end MSync.initModules() end @@ -27,7 +27,7 @@ function MSync.initModules() v["net"]() v["ulx"]() v["hooks"]() - MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "[" .. v["info"]["Name"] .. "] Module loaded") end end @@ -46,7 +46,7 @@ function MSync.loadModule(path) MSync.modules[info.ModuleIdentifier].ulx() MSync.modules[info.ModuleIdentifier].hooks() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.ModuleIdentifier]["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[info.ModuleIdentifier]["info"]["Name"] .. "] Module loaded") end @@ -61,7 +61,7 @@ function MSync.enableModule( module ) MSync.modules[module].net() MSync.modules[module].ulx() MSync.modules[module].hooks() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + 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 @@ -76,7 +76,7 @@ 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.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module disabled") else MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") end diff --git a/lua/msync/client_gui/cl_net.lua b/lua/msync/client_gui/cl_net.lua index 7fdc1a0..9fb4dd2 100644 --- a/lua/msync/client_gui/cl_net.lua +++ b/lua/msync/client_gui/cl_net.lua @@ -91,11 +91,11 @@ net.Receive( "msync.sendMessage", function( len, pl ) local state = net.ReadString() if state == "error" then - chat.AddText(Color(255,0,0),"[MSync_ERROR] "..net.ReadString()) + chat.AddText(Color(255,0,0),"[MSync_ERROR] " .. net.ReadString()) elseif state == "advert" then chat.AddText(Color(255,255,255), "[MSync] ", Color(0,0,255), net.ReadString()) else - chat.AddText(Color(255,255,255), "[MSync] "..net.ReadString()) + chat.AddText(Color(255,255,255), "[MSync] " .. net.ReadString()) end end ) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 65033c0..7b550b0 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -37,8 +37,8 @@ MSync.modules[info.ModuleIdentifier].init = function() 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) - local endPos = 19 + (maxResults*page) + local startPos = 0 + (maxResults * page) + local endPos = 19 + (maxResults * page) for k,v in pairs(tbl) do if i >= startPos and i <= endPos then @@ -56,7 +56,7 @@ MSync.modules[info.ModuleIdentifier].init = function() local table = MSync.modules[info.ModuleIdentifier].getTablePage(tbl, maxResults, page) local length = 0 for k,v in pairs(table) do - if v['length'] == 0 then + if v["length"] == 0 then length = "Permanent" else length = ULib.secondsToStringTime(v["length"]) @@ -87,29 +87,29 @@ MSync.modules[info.ModuleIdentifier].init = function() sorting = false for k,v in pairs(keys) do local a, b - if not keys[k+1] then break end + if not keys[k + 1] then break end if type( tempTable[v][key] ) == "string" then a = tempTable[v][key]:lower() - b = tempTable[keys[k+1]][key]:lower() + b = tempTable[keys[k + 1]][key]:lower() else a = tempTable[v][key] - b = tempTable[keys[k+1]][key] + b = tempTable[keys[k + 1]][key] end if asc then if a > b then sorting = true local temp = tempTable[v] - tempTable[v] = tempTable[keys[k+1]] - tempTable[keys[k+1]] = temp + tempTable[v] = tempTable[keys[k + 1]] + tempTable[keys[k + 1]] = temp break end else if a < b then sorting = true - local temp = tempTable[keys[k+1]] - tempTable[keys[k+1]] = tempTable[v] + local temp = tempTable[keys[k + 1]] + tempTable[keys[k + 1]] = tempTable[v] tempTable[v] = temp break end @@ -123,7 +123,7 @@ MSync.modules[info.ModuleIdentifier].init = function() 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 + if type(term) == "string" then searchTerm = term:lower() else searchTerm = tostring(term):lower() @@ -135,12 +135,12 @@ MSync.modules[info.ModuleIdentifier].init = function() for k, v in pairs(tbl) do matches = false for k2, v2 in pairs(v) do - if type(v2) == 'string' then - if string.match(v2:lower(), ".*"..searchTerm..".*") then + if type(v2) == "string" then + if string.match(v2:lower(), ".*" .. searchTerm .. ".*") then matches = true end else - if string.match(tostring( v2 ):lower(), ".*"..searchTerm..".*") then + if string.match(tostring( v2 ):lower(), ".*" .. searchTerm .. ".*") then matches = true end end @@ -220,7 +220,7 @@ MSync.modules[info.ModuleIdentifier].init = function() reason_textentry:SetMultiline(true) reason_textentry:SetUpdateOnType(true) reason_textentry.OnValueChange = function( pnl, value ) - reasonMaxLen_text:SetText(string.len( value ).."/100") + reasonMaxLen_text:SetText(string.len( value ) .. "/100") if string.len( value ) > 100 then reasonMaxLen_text:SetColor( Color( 255, 120, 120 ) ) @@ -229,11 +229,11 @@ MSync.modules[info.ModuleIdentifier].init = function() end end - local reasonMaxLen_text = vgui.Create( "DLabel", panel ) - reasonMaxLen_text:SetPos( 15, 205 ) - reasonMaxLen_text:SetColor( Color( 255, 255, 255 ) ) - reasonMaxLen_text:SetText( "Recently Disconnected Players" ) - reasonMaxLen_text:SetSize(380, 15) + local disconnectedPly_text = vgui.Create( "DLabel", panel ) + disconnectedPly_text:SetPos( 15, 205 ) + disconnectedPly_text:SetColor( Color( 255, 255, 255 ) ) + disconnectedPly_text:SetText( "Recently Disconnected Players" ) + disconnectedPly_text:SetSize(380, 15) local ban_table = vgui.Create( "DListView", panel ) ban_table:SetPos( 15, 220 ) @@ -516,7 +516,7 @@ MSync.modules[info.ModuleIdentifier].init = function() ############ ]] - if not (tbl == nil) then + if (tbl ~= nil) then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); nickname_textentry:SetText( tbl["nickname"] ) @@ -524,10 +524,10 @@ MSync.modules[info.ModuleIdentifier].init = function() steamid64_textentry:SetText( tbl["steamid64"] ) adminnickname_textentry:SetText( tbl["adminNickname"] ) bandate_textentry:SetText( os.date( "%H:%M:%S - %d/%m/%Y" ,tbl["timestamp"]) ) - if not (tbl["length"] == 0) then + if (tbl["length"] ~= 0) then banlength_textentry:SetText( ULib.secondsToStringTime(tbl["length"]) ) unbandate_textentry:SetText( os.date( "%H:%M:%S - %d/%m/%Y" ,tbl["timestamp"] + tbl["length"]) ) - remainingtime_textentry:SetText( ULib.secondsToStringTime((tbl["timestamp"] + tbl["length"])-os.time()) ) + remainingtime_textentry:SetText( ULib.secondsToStringTime((tbl["timestamp"] + tbl["length"]) - os.time()) ) else banlength_textentry:SetText( "Permanent" ) unbandate_textentry:SetText( "Never" ) @@ -723,7 +723,7 @@ MSync.modules[info.ModuleIdentifier].init = function() ########### ]] - if not (tbl == nil) then + if (tbl ~= nil) then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); nickname_textentry:SetText( tbl["nickname"] ) steamid_textentry:SetText( tbl["steamid"] ) @@ -745,6 +745,7 @@ end ]] MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) local pnl = vgui.Create( "DPanel", sheet ) + local tempTable = {}; pnl:Dock(FILL) MSync.modules[info.ModuleIdentifier].getSettings() @@ -906,7 +907,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) ban_table.OnRowRightClick = function(panel, lineID, line) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row " .. lineID .. " right clicked"); - local ident = line:GetValue(1) + --local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) @@ -1090,7 +1091,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() local pageof_text = vgui.Create( "DLabel", panel ) pageof_text:SetPos( 385, 421 ) pageof_text:SetColor( Color( 255, 255, 255 ) ) - pageof_text:SetText( "1/"..pages ) + pageof_text:SetText( "1/" .. pages ) pageof_text:SetSize(30, 20) pageof_text:SetContentAlignment( 5 ) @@ -1121,7 +1122,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() local function checkPage() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: checkPage"); - if ( (tablePage+1) >= pages ) then + if ( (tablePage + 1) >= pages ) then lastpage_button:SetDisabled(true) nextpage_button:SetDisabled(true) else @@ -1129,7 +1130,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() nextpage_button:SetDisabled(false) end - if(tablePage>=1)then + if (tablePage >= 1) then firstpage_button:SetDisabled(false) previouspage_button:SetDisabled(false) else @@ -1138,9 +1139,9 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() end end - ban_table.OnRowRightClick = function(panel, lineID, line) + ban_table.OnRowRightClick = function(parentPanel, lineID, line) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row \"" .. lineID .. "\" right clicked"); - local ident = line:GetValue(1) + --local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) DMenu:SetPos(cursor_x, cursor_y) @@ -1229,7 +1230,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) tablePage = 0 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) if pages > 1 then nextpage_button:SetDisabled(false) @@ -1245,7 +1246,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to first page"); tablePage = 0 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) checkPage() end @@ -1254,7 +1255,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to previous page"); tablePage = tablePage - 1 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) checkPage() end @@ -1263,7 +1264,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to next page"); tablePage = tablePage + 1 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) checkPage() end @@ -1272,7 +1273,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to last page"); tablePage = pages-1 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) checkPage() end @@ -1291,7 +1292,7 @@ MSync.modules[info.ModuleIdentifier].clientPanel = function() pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) tablePage = 0 - pageof_text:SetText( (tablePage+1).."/"..pages ) + pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) if pages > 1 then nextpage_button:SetDisabled(false) @@ -1330,11 +1331,11 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].unban = function(userid) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.unban Param.:" .. userid); - if not type(userid) == "number" then + if type(userid) ~= "number" then userid = tonumber(userid) end - net.Start("msync."..info.ModuleIdentifier..".unban") + net.Start("msync." .. info.ModuleIdentifier .. ".unban") net.WriteFloat(userid) net.SendToServer() end @@ -1342,11 +1343,11 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the server wants to print something to the user chat Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".sendMessage", function( len, ply ) + 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 + local msgType = net.ReadFloat() + if msgType == 0 then chat.AddText( Color( 237, 135, 26 ), "[MBSync] ", Color( 255, 255, 255), net.ReadString()) end end ) @@ -1355,7 +1356,7 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client entered '!mban' Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".openBanGUI", function( len, ply ) + 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()) @@ -1365,7 +1366,7 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client entered '!mbsync' Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".openBanTable", function( len, ply ) + net.Receive( "msync." .. info.ModuleIdentifier .. ".openBanTable", function( len, ply ) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.openBanTable"); MSync.modules[info.ModuleIdentifier].clientPanel() @@ -1383,7 +1384,7 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].temporary = {} MSync.modules[info.ModuleIdentifier].banTable = {} - net.Start("msync."..info.ModuleIdentifier..".getBanTable") + net.Start("msync." .. info.ModuleIdentifier .. ".getBanTable") net.WriteBool(fulltable) net.SendToServer() end @@ -1392,7 +1393,7 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client entered '!mban' Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".recieveDataCount", function( len, ply ) + net.Receive( "msync." .. info.ModuleIdentifier .. ".recieveDataCount", function( len, ply ) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.recieveDataCount"); local num = net.ReadFloat() @@ -1408,7 +1409,7 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client entered '!mban' Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".recieveData", function( len, ply ) + 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()) @@ -1419,21 +1420,21 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].temporary = {} local tempTable = {} for k,v in pairs(MSync.modules[info.ModuleIdentifier].banTable) do - tempTable[v['banId']] = {} - tempTable[v['banId']]['banId'] = v['banId'] - tempTable[v['banId']]['adminNickname'] = v['adminNickname'] - tempTable[v['banId']]['nickname'] = v['banned']['nickname'] - tempTable[v['banId']]['steamid'] = v['banned']['steamid'] - tempTable[v['banId']]['steamid64'] = k - tempTable[v['banId']]['length'] = v['length'] - tempTable[v['banId']]['reason'] = v['reason'] - tempTable[v['banId']]['timestamp'] = v['timestamp'] - tempTable[v['banId']]['servergroup'] = v['servergroup'] - if v['banningAdmin'] then - tempTable[v['banId']]['adminNickname'] = v['banningAdmin']['nickname'] + tempTable[v["banId"]] = {} + tempTable[v["banId"]]["banId"] = v["banId"] + tempTable[v["banId"]]["adminNickname"] = v["adminNickname"] + tempTable[v["banId"]]["nickname"] = v["banned"]["nickname"] + tempTable[v["banId"]]["steamid"] = v["banned"]["steamid"] + tempTable[v["banId"]]["steamid64"] = k + tempTable[v["banId"]]["length"] = v["length"] + tempTable[v["banId"]]["reason"] = v["reason"] + tempTable[v["banId"]]["timestamp"] = v["timestamp"] + tempTable[v["banId"]]["servergroup"] = v["servergroup"] + if v["banningAdmin"] then + tempTable[v["banId"]]["adminNickname"] = v["banningAdmin"]["nickname"] end - if v['unBanningAdmin'] then - tempTable[v['banId']]['unBanningAdmin'] = v['unBanningAdmin']['nickname'] + if v["unBanningAdmin"] then + tempTable[v["banId"]]["unBanningAdmin"] = v["unBanningAdmin"]["nickname"] end end MSync.modules[info.ModuleIdentifier].banTable = tempTable @@ -1444,7 +1445,7 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the server sent settings Returns: nothing ]] - net.Receive( "msync."..info.ModuleIdentifier..".sendSettingsPly", function( len, ply ) + 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() @@ -1457,7 +1458,7 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].getSettings = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getSettings"); - net.Start("msync."..info.ModuleIdentifier..".getSettings") + net.Start("msync." .. info.ModuleIdentifier .. ".getSettings") net.SendToServer() end @@ -1468,7 +1469,7 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].sendSettings = function() MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendSettings"); - net.Start("msync."..info.ModuleIdentifier..".sendSettings") + net.Start("msync." .. info.ModuleIdentifier .. ".sendSettings") net.WriteTable(MSync.modules[info.ModuleIdentifier].settings) net.SendToServer() end diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index f0be49d..45320b1 100644 --- a/lua/msync/client_gui/modules/cl_mrsync.lua +++ b/lua/msync/client_gui/modules/cl_mrsync.lua @@ -52,7 +52,7 @@ function MSync.modules.MRSync.adminPanel(sheet) allserver_table:AddColumn( "Allserver Ranks" ) allserver_table.OnRowRightClick = function(panel, lineID, line) MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); - local ident = line:GetValue(1) + --local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) DMenu:SetPos(cursor_x, cursor_y) @@ -103,7 +103,7 @@ function MSync.modules.MRSync.adminPanel(sheet) nosync_table:AddColumn( "Nosync Ranks" ) nosync_table.OnRowRightClick = function(panel, lineID, line) MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); - local ident = line:GetValue(1) + --local ident = line:GetValue(1) local cursor_x, cursor_y = panel:CursorPos() local DMenu = vgui.Create("DMenu", panel) DMenu:SetPos(cursor_x, cursor_y) diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 9f35004..d6518d6 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -48,7 +48,7 @@ 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 + 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") @@ -71,7 +71,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) MODIFY `length_unix` INT UNSIGNED NOT NULL; ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, "MBSync") ON DUPLICATE KEY UPDATE version=1; ]])) updates:start() @@ -88,7 +88,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]])) updates:addQuery( MSync.DBServer:query([[ - INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, 'MBSync') + INSERT INTO tbl_msyncdb_version (version, module_id) VALUES (1, "MBSync") ON DUPLICATE KEY UPDATE version=1; ]])) updates:start() @@ -96,7 +96,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end selectDbVersion.onError = function( q, err, sql ) - 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})) + 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() @@ -113,10 +113,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) 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 + if length ~= 0 then + length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()].timestamp) + (length * 60)) / 60 end - MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()]['banId'], reason, length, calling_ply, allserver) + MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()]["banId"], reason, length, calling_ply, allserver) return end @@ -140,7 +140,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local timestamp = os.time() banUserQ:setString(1, reason) banUserQ:setNumber(2, timestamp) - banUserQ:setNumber(3, length*60) + banUserQ:setNumber(3, length * 60) banUserQ:setString(4, ply:SteamID()) banUserQ:setString(5, ply:SteamID64()) banUserQ:setString(6, calling_ply) @@ -166,27 +166,27 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banData = { admin = adminNick, reason = reason, - unban = timestamp+(length*60), + unban = timestamp + (length * 60), time = timestamp } if length == 0 then banData["unban"] = length msgLength = "Permanent" else - msgLength = ULib.secondsToStringTime(length*60) + msgLength = ULib.secondsToStringTime(length * 60) end if reason == "" then msgReason = "(None given)" end - ply:Kick("\n"..ULib.getBanMessage( ply:SteamID(), banData)) + ply:Kick("\n" .. ULib.getBanMessage( ply:SteamID(), banData)) MSync.modules[info.ModuleIdentifier].getActiveBans() - MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Banned "..ply:Nick().." for "..msgLength.." with reason "..msgReason) + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Banned " .. ply:Nick() .. " for " .. msgLength .. " with reason " .. msgReason) end banUserQ.onError = function( q, err, sql ) - 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})) + 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() @@ -201,10 +201,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) 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 + if (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) + MSync.modules[info.ModuleIdentifier].editBan( MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)]["banId"], reason, length, calling_ply, allserver) return end @@ -228,7 +228,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local timestamp = os.time() banUserIdQ:setString(1, reason) banUserIdQ:setNumber(2, timestamp) - banUserIdQ:setNumber(3, length*60) + banUserIdQ:setNumber(3, length * 60) banUserIdQ:setString(4, userid) banUserIdQ:setString(5, userid) banUserIdQ:setString(6, calling_ply) @@ -259,14 +259,14 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banData = { admin = adminNick, reason = reason, - unban = timestamp+(length*60), + unban = timestamp + (length * 60), time = timestamp } if length == 0 then banData["unban"] = length msgLength = "Permanent" else - msgLength = ULib.secondsToStringTime(length*60) + msgLength = ULib.secondsToStringTime(length * 60) end if reason == "" then @@ -276,21 +276,21 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end MSync.modules[info.ModuleIdentifier].getActiveBans() - MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Banned "..userid.." for "..msgLength.." with reason "..msgReason) + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Banned " .. userid .. " for " .. msgLength .. " with reason " .. msgReason) if not player.GetBySteamID(userid) then return end - player.GetBySteamID(userid):Kick("\n"..ULib.getBanMessage( userid, banData)) + player.GetBySteamID(userid):Kick("\n" .. ULib.getBanMessage(userid, banData)) end banUserIdQ.onError = function( q, err, sql ) -- Deprecated check, remove in next minor release - if string.match( err, "^Column 'user_id' cannot be null$" ) then + 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 - 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})) + 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 @@ -314,7 +314,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) WHERE p_ID=? ]] ) editBanQ:setString(1, reason) - editBanQ:setNumber(2, length*60) + editBanQ:setNumber(2, length * 60) editBanQ:setString(3, calling_ply) editBanQ:setString(4, util.SteamIDTo64(calling_ply)) if not allserver then @@ -326,11 +326,11 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) editBanQ.onSuccess = function( q, data ) MSync.modules[info.ModuleIdentifier].getActiveBans() - MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Edited ban with id "..banId.." with data: \nLength: "..ULib.secondsToStringTime(length*60).."\nReason: "..reason) + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Edited ban with id " .. banId .. " with data: \nLength: " .. ULib.secondsToStringTime(length * 60) .. "\nReason: " .. reason) end editBanQ.onError = function( q, err, sql ) - 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})) + 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() @@ -354,11 +354,11 @@ 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) + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Removed ban with id " .. banId) end unBanUserIdQ.onError = function( q, err, sql ) - 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})) + 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() @@ -390,11 +390,11 @@ 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) + MSync.modules[info.ModuleIdentifier].msg(calling_ply, "Unbanned " .. ply_steamid) end unBanUserQ.onError = function( q, err, sql ) - 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})) + 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() @@ -412,15 +412,15 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) tbl_mbsync.reason, tbl_mbsync.date_unix, tbl_mbsync.length_unix, - banned.steamid AS 'banned.steamid', - banned.steamid64 AS 'banned.steamid64', - banned.nickname AS 'banned.nickname', - admin.steamid AS 'admin.steamid', - admin.steamid64 AS 'admin.steamid64', - admin.nickname AS 'admin.nickname', - unban_admin.steamid AS 'unban_admin.steamid', - unban_admin.steamid64 AS 'unban_admin.steamid64', - unban_admin.nickname AS 'unban_admin.nickname', + banned.steamid AS "banned.steamid", + banned.steamid64 AS "banned.steamid64", + banned.nickname AS "banned.nickname", + admin.steamid AS "admin.steamid", + admin.steamid64 AS "admin.steamid64", + admin.nickname AS "admin.nickname", + unban_admin.steamid AS "unban_admin.steamid", + unban_admin.steamid64 AS "unban_admin.steamid64", + unban_admin.nickname AS "unban_admin.nickname", tbl_server_grp.group_name FROM `tbl_mbsync` LEFT JOIN tbl_server_grp @@ -450,19 +450,19 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) length = v.length_unix, servergroup = v["group_name"], banned = { - steamid = v['banned.steamid'], - steamid64 = v['banned.steamid64'], - nickname = v['banned.nickname'] + steamid = v["banned.steamid"], + steamid64 = v["banned.steamid64"], + nickname = v["banned.nickname"] }, banningAdmin = { - steamid = v['admin.steamid'], - steamid64 = v['admin.steamid64'], - nickname = v['admin.nickname'] + steamid = v["admin.steamid"], + steamid64 = v["admin.steamid64"], + nickname = v["admin.nickname"] }, unBanningAdmin = { - steamid = v['unban_admin.steamid'], - steamid64 = v['unban_admin.steamid64'], - nickname = v['unban_admin.nickname'] + steamid = v["unban_admin.steamid"], + steamid64 = v["unban_admin.steamid64"], + nickname = v["unban_admin.nickname"] } } @@ -470,7 +470,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) 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 + if not v["unban_admin.steamid"] and (((v.date_unix + v.length_unix) >= os.time()) or (v.length_unix == 0)) then banTable[v["banned.steamid64"]] = { banId = v.p_id, reason = v.reason, @@ -491,7 +491,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) --MSync.modules[info.ModuleIdentifier].sendSettings(ply, banTable) -- We need to add 0.4 to the calculated number to guarantee that we always round up to the next highest number -- Luckily because we always calculate with whole numbers (there is no half ban) this should be enough to guarantee that we always send enough packages - MSync.modules[info.ModuleIdentifier].sendCount(ply, math.Round((table.Count(banTable) / 10)+0.4)) + MSync.modules[info.ModuleIdentifier].sendCount(ply, math.Round((table.Count(banTable) / 10) + 0.4)) local tempTable = MSync.modules[info.ModuleIdentifier].splitTable(banTable) for k,v in pairs(tempTable) do MSync.modules[info.ModuleIdentifier].sendPart(ply, v) @@ -500,7 +500,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end getBansQ.onError = function( q, err, sql ) - 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})) + 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() @@ -517,8 +517,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) tbl_mbsync.*, banned.steamid, banned.steamid64, - banned.nickname AS 'banned.nickname', - admin.nickname AS 'admin.nickname' + banned.nickname AS "banned.nickname", + admin.nickname AS "admin.nickname" FROM `tbl_mbsync` LEFT JOIN tbl_users AS banned ON tbl_mbsync.user_id = banned.p_user_id @@ -532,7 +532,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ) AND ( server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) OR - server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers') + server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name="allservers") ) ]] ) getActiveBansQ:setNumber(1, os.time()) @@ -559,7 +559,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) MSync.modules[info.ModuleIdentifier].banTable = banTable --[[ - Check if a banned player joined while the data wasn't synchronized + Check if a banned player joined while the data wasn"t synchronized ]] for k,v in pairs(player.GetAll()) do if banTable[v:SteamID64()] then @@ -570,22 +570,20 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) local banData = { admin = ban.adminNickname, reason = ban.reason, - unban = ban.length+ban.timestamp, + unban = ban.length + ban.timestamp, time = ban.timestamp } 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") + MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. v:Nick() "\" was banned while data resynchronized, kicking from server") v:Kick(message) - else - -- Do nothing end end end getActiveBansQ.onError = function( q, err, sql ) - 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})) + 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() @@ -602,9 +600,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) tbl_mbsync.*, banned.steamid, banned.steamid64, - banned.nickname AS 'banned.nickname', - admin.nickname AS 'admin.nickname', - admin.steamid AS 'admin.steamid' + banned.nickname AS "banned.nickname", + admin.nickname AS "admin.nickname", + admin.steamid AS "admin.steamid" FROM `tbl_mbsync` LEFT JOIN tbl_users AS banned ON tbl_mbsync.user_id = banned.p_user_id @@ -618,7 +616,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ) AND ( server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) OR - server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers') + server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name="allservers") ) ]] ) exportActiveBans:setNumber(1, os.time()) @@ -639,7 +637,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) if v["admin.steamid"] == "STEAM_0:0:0" then admin = v["admin.nickname"] else - admin = v["admin.nickname"].."("..v["admin.steamid"]..")" + admin = v["admin.nickname"] .. "(" .. v["admin.steamid"] .. ")" end ULib.bans[ v["steamid"] ] = { @@ -658,12 +656,12 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end exportActiveBans.onError = function( q, err, sql ) - 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})) + 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() end - concommand.Add("msync."..info.ModuleIdentifier..".export", function( ply, cmd, args ) + concommand.Add("msync." .. info.ModuleIdentifier .. ".export", function( ply, cmd, args ) if ply:IsValid() then return end MSync.modules[info.ModuleIdentifier].exportBansToULX() end) @@ -688,21 +686,21 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) --[[ Add user transaction ]] - transactions[k..'_user'] = MSync.DBServer:prepare( [[ + transactions[k .. "_user"] = MSync.DBServer:prepare( [[ INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery ON DUPLICATE KEY UPDATE steamid=newNick; ]] ) - transactions[k..'_user']:setString(1, k) - transactions[k..'_user']:setString(2, util.SteamIDTo64( k )) + transactions[k .. "_user"]:setString(1, k) + transactions[k .. "_user"]:setString(2, util.SteamIDTo64( k )) if ULib.ucl.users[k] then - transactions[k..'_user']:setString(3, ULib.ucl.users[k].name or 'None Given') + transactions[k .. "_user"]:setString(3, ULib.ucl.users[k].name or "None Given") else - transactions[k..'_user']:setString(3, 'None Given') + transactions[k .. "_user"]:setString(3, "None Given") end - transactions[k..'_user']:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) + transactions[k .. "_user"]:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) - banTransaction:addQuery(transactions[k..'_user']) + banTransaction:addQuery(transactions[k .. "_user"]) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Import Bans: added create user transaction for: " .. k) --[[ @@ -719,33 +717,32 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) AND tbl_server_grp.group_name=?; ]] ) - local timestamp = os.time() transactions[k]:setString(4, k) - if v['modified_admin'] then - if v['modified_admin'] == "(Console)" then + if v["modified_admin"] then + if v["modified_admin"] == "(Console)" then transactions[k]:setString(5,"STEAM_0:0:0") else - transactions[k]:setString(5,string.match(v['modified_admin'], "STEAM_%d:%d:%d+")) + transactions[k]:setString(5,string.match(v["modified_admin"], "STEAM_%d:%d:%d+")) end else - if v['admin'] == "(Console)" then + if v["admin"] == "(Console)" then transactions[k]:setString(5,"STEAM_0:0:0") else - transactions[k]:setString(5,string.match(v['admin'], "STEAM_%d:%d:%d+")) + transactions[k]:setString(5,string.match(v["admin"], "STEAM_%d:%d:%d+")) end end - transactions[k]:setString(1, v['reason'] or "(None given)") - transactions[k]:setNumber(2, tonumber(v['time'])) + transactions[k]:setString(1, v["reason"] or "(None given)") + transactions[k]:setNumber(2, tonumber(v["time"])) - if tonumber(v['unban']) == 0 then - transactions[k]:setNumber(3, tonumber(v['unban'])) + if tonumber(v["unban"]) == 0 then + transactions[k]:setNumber(3, tonumber(v["unban"])) else - transactions[k]:setNumber(3, tonumber(v['unban']) - tonumber(v['time'])) + transactions[k]:setNumber(3, tonumber(v["unban"]) - tonumber(v["time"])) end - if not allserver then + if not allservers then transactions[k]:setString(6, MSync.settings.data.serverGroup) else transactions[k]:setString(6, "allservers") @@ -761,12 +758,12 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) end banTransaction.onError = function(tr, err) - 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})) + 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() end - concommand.Add("msync."..info.ModuleIdentifier..".import", function( ply, cmd, args ) + concommand.Add("msync." .. info.ModuleIdentifier .. ".import", function( ply, cmd, args ) if ply:IsValid() then return end local allservers = false @@ -783,11 +780,11 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] 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 + 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)) + 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")) @@ -803,8 +800,8 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) ]] 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") + file.Write("msync/" .. info.ModuleIdentifier .. ".txt", util.TableToJSON(MSync.modules[info.ModuleIdentifier].settings, true)) + return file.Exists("msync/" .. info.ModuleIdentifier .. ".txt", "DATA") end --[[ @@ -851,29 +848,29 @@ MSync.modules[info.ModuleIdentifier].net = function() text [string] - the text you want to send to the client Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".sendMessage") + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".sendMessage") MSync.modules[info.ModuleIdentifier].msg = function(ply, content, msgType) - MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.msg Param.: $ply \"$content\" $msgType",{['ply'] = ply, ['content'] = content, ['msgType'] = msgType})) - if type(ply) == "string" and not (ply == "STEAM_0:0:0") then + MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.msg Param.: $ply \"$content\" $msgType",{["ply"] = ply, ["content"] = content, ["msgType"] = msgType})) + if type(ply) == "string" and (ply ~= "STEAM_0:0:0") then ply = player.GetBySteamID( ply ) end if type(ply) == "Entity" or type(ply) == "Player" then if not IsValid(ply) then - print("[MBSync] "..content) + print("[MBSync] " .. content) else - MSync.log(MSYNC_DBG_INFO, "[MBSync] "..content) + MSync.log(MSYNC_DBG_INFO, "[MBSync] " .. content) if not msgType then msgType = 0 end -- Basic message if msgType == 0 then - net.Start("msync."..info.ModuleIdentifier..".sendMessage") + net.Start("msync." .. info.ModuleIdentifier .. ".sendMessage") net.WriteFloat(msgType) net.WriteString(content) net.Send(ply) end end elseif ply == "STEAM_0:0:0" then - print("[MBSync] "..content) + print("[MBSync] " .. content) end end @@ -884,10 +881,10 @@ MSync.modules[info.ModuleIdentifier].net = function() banTable [table] - the ban table Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".sendBanTable") + 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.Start("msync." .. info.ModuleIdentifier .. ".sendBanTable") net.WriteTable(banTable) net.Send(ply) end @@ -898,10 +895,10 @@ MSync.modules[info.ModuleIdentifier].net = function() player [player] - the player that wants to open the admin GUI Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".openBanTable") + 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.Start("msync." .. info.ModuleIdentifier .. ".openBanTable") net.Send(ply) end @@ -909,10 +906,10 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client banned a player with the ban gui Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".banid") - net.Receive("msync."..info.ModuleIdentifier..".banid", function(len, ply) + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".banid") + net.Receive("msync." .. info.ModuleIdentifier .. ".banid", function(len, ply) 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 + 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() @@ -945,10 +942,10 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client edits a ban Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".editBan") - net.Receive("msync."..info.ModuleIdentifier..".editBan", function(len, ply) + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".editBan") + net.Receive("msync." .. info.ModuleIdentifier .. ".editBan", function(len, ply) 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 + 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() @@ -981,12 +978,12 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client tries to unban someone Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".unban") - net.Receive("msync."..info.ModuleIdentifier..".unban", function(len, ply) + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".unban") + net.Receive("msync." .. info.ModuleIdentifier .. ".unban", function(len, ply) 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 + 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() + local banid = net.ReadFloat() -- TODO: Replace with int --[[ Error check and fill in of default data @@ -999,10 +996,10 @@ MSync.modules[info.ModuleIdentifier].net = function() 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 = "" + local target_steamid = "" for k,v in pairs(MSync.modules[info.ModuleIdentifier].banTable) do if v.banid == banid then - steamid = v.banned['steamid'] + target_steamid = v.banned["steamid"] end end @@ -1012,10 +1009,10 @@ MSync.modules[info.ModuleIdentifier].net = function() MSync.modules[info.ModuleIdentifier].unBanUserID(ply, banid) --[[ - 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 + 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) + ULib.unban(target_steamid, ply) end ) --[[ @@ -1024,10 +1021,10 @@ MSync.modules[info.ModuleIdentifier].net = function() player [player] - the player that wants to open the admin GUI Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".sendSettingsPly") + 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.Start("msync." .. info.ModuleIdentifier .. ".sendSettingsPly") net.WriteTable(MSync.modules[info.ModuleIdentifier].settings) net.Send(ply) end @@ -1036,8 +1033,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client requests the settings table Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".getSettings") - net.Receive("msync."..info.ModuleIdentifier..".getSettings", function(len, ply) + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".getSettings") + net.Receive("msync." .. info.ModuleIdentifier .. ".getSettings", function(len, ply) 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 @@ -1048,8 +1045,8 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client wants to open the ban gui Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".sendSettings") - net.Receive("msync."..info.ModuleIdentifier..".sendSettings", function(len, ply) + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".sendSettings") + net.Receive("msync." .. info.ModuleIdentifier .. ".sendSettings", function(len, ply) 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 @@ -1063,7 +1060,7 @@ MSync.modules[info.ModuleIdentifier].net = function() player [player] - the player that requests the data Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".openBanGUI") + 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) @@ -1080,7 +1077,7 @@ MSync.modules[info.ModuleIdentifier].net = function() else disconnectTable = {} end - net.Start("msync."..info.ModuleIdentifier..".openBanGUI") + net.Start("msync." .. info.ModuleIdentifier .. ".openBanGUI") net.WriteTable(disconnectTable) net.Send(ply) end @@ -1092,10 +1089,10 @@ MSync.modules[info.ModuleIdentifier].net = function() number [interger] - the count of data parts to be sent to the player Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveDataCount") + util.AddNetworkString("msync." .. info.ModuleIdentifier .. ".recieveDataCount") MSync.modules[info.ModuleIdentifier].sendCount = function(ply, number) MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendCount Param.: " .. tostring(ply) .. " " .. number) - net.Start("msync."..info.ModuleIdentifier..".recieveDataCount") + net.Start("msync." .. info.ModuleIdentifier .. ".recieveDataCount") net.WriteFloat(number) net.Send(ply) end @@ -1107,10 +1104,10 @@ MSync.modules[info.ModuleIdentifier].net = function() part [table] - the table part that gets sent to the player Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveData") + 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.Start("msync." .. info.ModuleIdentifier .. ".recieveData") net.WriteTable(part) net.Send(ply) end @@ -1119,15 +1116,15 @@ MSync.modules[info.ModuleIdentifier].net = function() Description: Net Receiver - Gets called when the client requests the ban data Returns: nothing ]] - util.AddNetworkString("msync."..info.ModuleIdentifier..".getBanTable") - net.Receive("msync."..info.ModuleIdentifier..".getBanTable", function(len, ply) + 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 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 MSync.log(MSYNC_DBG_WARNING, "[MBSync] User \"" .. ply:Nick() .. "\" tried to get the short ban table without permission");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 ) @@ -1157,7 +1154,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() if not IsValid(calling_ply) then calling_steamid = "STEAM_0:0:0" else - if not calling_ply:query("msync."..info.ModuleIdentifier..".banPlayer") then return end; + if not calling_ply:query("msync." .. info.ModuleIdentifier .. ".banPlayer") then return end; if calling_ply == target_ply then MSync.modules[info.ModuleIdentifier].openBanGUI(calling_ply) return @@ -1189,11 +1186,11 @@ MSync.modules[info.ModuleIdentifier].ulx = function() ]] MSync.modules[info.ModuleIdentifier].banUser(target_ply, calling_steamid, length, reason, allserver) end - local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".banPlayer", MSync.modules[info.ModuleIdentifier].Chat.banPlayer, "!mban" ) - BanPlayer:addParam{ type=ULib.cmds.PlayerArg, hint="player", ULib.cmds.optional} - BanPlayer:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 } - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="true/false, if the player should be banned on all servers", ULib.cmds.optional } - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons } + local BanPlayer = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".banPlayer", MSync.modules[info.ModuleIdentifier].Chat.banPlayer, "!mban" ) + BanPlayer:addParam{ type = ULib.cmds.PlayerArg, hint = "player", ULib.cmds.optional} + BanPlayer:addParam{ type = ULib.cmds.NumArg, hint = "minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min = 0 } + BanPlayer:addParam{ type = ULib.cmds.StringArg, hint = "true/false, if the player should be banned on all servers", ULib.cmds.optional } + 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" ) @@ -1213,7 +1210,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() if not IsValid(calling_ply) then calling_steamid = "STEAM_0:0:0" else - if not calling_ply:query("msync."..info.ModuleIdentifier..".banSteamID") then return end; + if not calling_ply:query("msync." .. info.ModuleIdentifier .. ".banSteamID") then return end; calling_steamid = calling_ply:SteamID() end @@ -1246,13 +1243,13 @@ MSync.modules[info.ModuleIdentifier].ulx = function() MSync.modules[info.ModuleIdentifier].banUserID(target_steamid, calling_steamid, length, reason, allserver) end - local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".banSteamID", MSync.modules[info.ModuleIdentifier].Chat.banSteamID, "!mbanid" ) - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="steamid"} - BanPlayer:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 } - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="true/false, if the player should be banned on all servers", ULib.cmds.optional } - 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( "Bans the given SteamID." ) + local BanPlayerID = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".banSteamID", MSync.modules[info.ModuleIdentifier].Chat.banSteamID, "!mbanid" ) + BanPlayerID:addParam{ type = ULib.cmds.StringArg, hint = "steamid"} + BanPlayerID:addParam{ type = ULib.cmds.NumArg, hint = "minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min = 0 } + BanPlayerID:addParam{ type = ULib.cmds.StringArg, hint = "true/false, if the player should be banned on all servers", ULib.cmds.optional } + BanPlayerID:addParam{ type = ULib.cmds.StringArg, hint = "reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes = ulx.common_kick_reasons } + BanPlayerID:defaultAccess( ULib.ACCESS_SUPERADMIN ) + BanPlayerID:help( "Bans the given SteamID." ) --[[ unban a user with the given steamid @@ -1267,7 +1264,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() if not IsValid(calling_ply) then calling_steamid = "STEAM_0:0:0" else - if not calling_ply:query("msync."..info.ModuleIdentifier..".unBanID") then return end; + if not calling_ply:query("msync." .. info.ModuleIdentifier .. ".unBanID") then return end; calling_steamid = calling_ply:SteamID() end @@ -1282,15 +1279,15 @@ MSync.modules[info.ModuleIdentifier].ulx = function() 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 + 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" ) - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="steamid"} - BanPlayer:defaultAccess( ULib.ACCESS_SUPERADMIN ) - BanPlayer:help( "Unbans the given SteamID." ) + local UnBanPlayerID = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".unBanID", MSync.modules[info.ModuleIdentifier].Chat.unBanID, "!munban" ) + UnBanPlayerID:addParam{ type = ULib.cmds.StringArg, hint = "steamid"} + UnBanPlayerID:defaultAccess( ULib.ACCESS_SUPERADMIN ) + UnBanPlayerID:help( "Unbans the given SteamID." ) --[[ check if a player is banned @@ -1300,10 +1297,8 @@ MSync.modules[info.ModuleIdentifier].ulx = function() ]] 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 - if not calling_ply:query("msync."..info.ModuleIdentifier..".checkBan") then return end; + if IsValid(calling_ply) and not calling_ply:query("msync." .. info.ModuleIdentifier .. ".checkBan") then + return; end if not target_steamid or not ULib.isValidSteamID(target_steamid) then return end @@ -1334,16 +1329,16 @@ MSync.modules[info.ModuleIdentifier].ulx = function() --[[ Message the ban informations to the asking player ]] - MSync.modules[info.ModuleIdentifier].msg(calling_ply,"Player banned!\nBanID: "..banData.banId.."\nReason: "..banData.reason.."\nBanned by: "..banData.adminNickname.."\nBan Date: "..banData.timestamp.."\nBan lasting till: "..banData.length) + MSync.modules[info.ModuleIdentifier].msg(calling_ply,"Player banned!\nBanID: " .. banData.banId .. "\nReason: " .. banData.reason .. "\nBanned by: " .. banData.adminNickname .. "\nBan Date: " .. banData.timestamp .. "\nBan lasting till: " .. banData.length) else -- Respond that the player is not banned MSync.modules[info.ModuleIdentifier].msg(calling_ply,"The target player is not banned from this server.") end end - local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".checkBan", MSync.modules[info.ModuleIdentifier].Chat.checkBan, "!mcheck" ) - BanPlayer:addParam{ type=ULib.cmds.StringArg, hint="steamid"} - BanPlayer:defaultAccess( ULib.ACCESS_SUPERADMIN ) - BanPlayer:help( "Checks if there is currently a active ban for given SteamID." ) + local CheckBan = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".checkBan", MSync.modules[info.ModuleIdentifier].Chat.checkBan, "!mcheck" ) + CheckBan:addParam{ type = ULib.cmds.StringArg, hint = "steamid"} + CheckBan:defaultAccess( ULib.ACCESS_SUPERADMIN ) + CheckBan:help( "Checks if there is currently a active ban for given SteamID." ) --[[ opens the ban table @@ -1354,13 +1349,13 @@ MSync.modules[info.ModuleIdentifier].ulx = function() MSync.modules[info.ModuleIdentifier].Chat.openBanTable = function(calling_ply) 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; + if not calling_ply:query("msync." .. info.ModuleIdentifier .. ".openBanTable") then return end; -- Open Ban Table MSync.modules[info.ModuleIdentifier].openBanTable(calling_ply) end - local BanPlayer = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".openBanTable", MSync.modules[info.ModuleIdentifier].Chat.openBanTable, "!mbsync" ) - BanPlayer:defaultAccess( ULib.ACCESS_SUPERADMIN ) - BanPlayer:help( "Opens the MBSync ban table, this table only shows active bans." ) + local BanTable = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".openBanTable", MSync.modules[info.ModuleIdentifier].Chat.openBanTable, "!mbsync" ) + BanTable:defaultAccess( ULib.ACCESS_SUPERADMIN ) + BanTable:help( "Opens the MBSync ban table, this table only shows active bans." ) --[[ Edits the ban with the given banID @@ -1378,7 +1373,7 @@ MSync.modules[info.ModuleIdentifier].ulx = function() if not IsValid(calling_ply) then calling_steamid = "STEAM_0:0:0" else - if not calling_ply:query("msync."..info.ModuleIdentifier..".editBan") then return end; + if not calling_ply:query("msync." .. info.ModuleIdentifier .. ".editBan") then return end; calling_steamid = calling_ply:SteamID() end @@ -1404,11 +1399,11 @@ MSync.modules[info.ModuleIdentifier].ulx = function() ]] MSync.modules[info.ModuleIdentifier].editBan(tostring(ban_id), tostring(reason), tostring(length), calling_steamid, allserver) end - local EditBan = ulx.command( "MSync", "msync."..info.ModuleIdentifier..".editBan", MSync.modules[info.ModuleIdentifier].Chat.editBan, "!medit" ) - EditBan:addParam{ type=ULib.cmds.NumArg, hint="BanID"} - EditBan:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 } - EditBan:addParam{ type=ULib.cmds.StringArg, hint="true/false, all servers?", ULib.cmds.optional } - EditBan:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons } + local EditBan = ulx.command( "MSync", "msync." .. info.ModuleIdentifier .. ".editBan", MSync.modules[info.ModuleIdentifier].Chat.editBan, "!medit" ) + EditBan:addParam{ type = ULib.cmds.NumArg, hint = "BanID"} + EditBan:addParam{ type = ULib.cmds.NumArg, hint = "minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min = 0 } + EditBan:addParam{ type = ULib.cmds.StringArg, hint = "true/false, all servers?", ULib.cmds.optional } + EditBan:addParam{ type = ULib.cmds.StringArg, hint = "reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes = ulx.common_kick_reasons } EditBan:defaultAccess( ULib.ACCESS_SUPERADMIN ) EditBan:help( "Edits the given ban id with new ban data" ) @@ -1419,7 +1414,7 @@ end ]] MSync.modules[info.ModuleIdentifier].hooks = function() - hook.Add("CheckPassword", "msync."..info.ModuleIdentifier..".banCheck", function( steamid64 ) + 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] @@ -1427,7 +1422,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() if ban.length == 0 then unbanDate = "Never" else - unbanDate = os.date( "%c", ban.timestamp+ban.length) + unbanDate = os.date( "%c", ban.timestamp + ban.length) end --[[ Print to console that a banned user tries to join @@ -1446,7 +1441,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() local banData = { admin = ban.adminNickname, reason = ban.reason, - unban = ban.timestamp+ban.length, + unban = ban.timestamp + ban.length, time = ban.timestamp } @@ -1473,7 +1468,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() end end) - hook.Add("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects", function( ply ) + 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) @@ -1500,7 +1495,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() if banData.unban == 0 then ban.length = 0 else - ban.length = (banData.unban-os.time())/60 + ban.length = (banData.unban-os.time()) / 60 end if not banData.reason then @@ -1552,7 +1547,7 @@ MSync.modules[info.ModuleIdentifier].hooks = function() --[[ Start timer to asynchroniously resync data ]] - timer.Create("msync."..info.ModuleIdentifier..".getActiveBans", MSync.modules[info.ModuleIdentifier].settings.syncDelay, 0, function() + timer.Create("msync." .. info.ModuleIdentifier .. ".getActiveBans", MSync.modules[info.ModuleIdentifier].settings.syncDelay, 0, function() MSync.modules[info.ModuleIdentifier].getActiveBans() end) end @@ -1563,11 +1558,11 @@ end Define a function to run on the server when the module gets disabled ]] MSync.modules[info.ModuleIdentifier].disable = function() - hook.Remove("CheckPassword", "msync."..info.ModuleIdentifier..".banCheck") - hook.Remove("PlayerDisconnected", "msync."..info.ModuleIdentifier..".saveDisconnects") + 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") + timer.Remove("msync." .. info.ModuleIdentifier .. ".getActiveBans") end --[[ diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 6c2fd6b..802e365 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -81,7 +81,7 @@ function MSync.modules.MRSync.init( transaction ) MSync.mysql.addUserID(steamid) MSync.modules.MRSync.saveRankByID(steamid, group) else - 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})) + 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 @@ -138,7 +138,7 @@ function MSync.modules.MRSync.init( transaction ) MSync.mysql.addUserID(steamid) MSync.modules.MRSync.saveRankByID(steamid, group) else - 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})) + 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 @@ -171,7 +171,7 @@ function MSync.modules.MRSync.init( transaction ) function loadUserQ.onData( q, data ) MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Got data for user \"" .. ply:Nick() .. "\". Rank: " .. data.rank); if not ULib.ucl.groups[data.rank] then - MSync.log(MSYNC_DBG_ERROR, "[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 diff --git a/lua/msync/server/sv_init.lua b/lua/msync/server/sv_init.lua index 411d472..bec73d6 100644 --- a/lua/msync/server/sv_init.lua +++ b/lua/msync/server/sv_init.lua @@ -36,16 +36,16 @@ function MSync.func.loadServer() MSync.loadModules() - 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) + local clientfiles, _ = file.Find("msync/client_gui/*.lua", "LUA") + for k, v in pairs(clientfiles) 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) + local clientmodules, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") + for k, v in pairs(clientmodules) do + AddCSLuaFile("msync/client_gui/modules/" .. v) + MSync.log(MSYNC_DBG_DEBUG, "Added client module file: " .. v) end end @@ -127,7 +127,7 @@ function MSync.func.getModuleInfos() 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) + MSync.log(MSYNC_DBG_DEBUG, "[getModuleInfos] Got info for " .. k) end return infoTable diff --git a/lua/msync/server/sv_modules.lua b/lua/msync/server/sv_modules.lua index 4043117..a013e0c 100644 --- a/lua/msync/server/sv_modules.lua +++ b/lua/msync/server/sv_modules.lua @@ -14,8 +14,8 @@ function MSync.loadModules() 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) + include("msync/server/modules/" .. v) + MSync.log(MSYNC_DBG_DEBUG, "Found module: " .. v) end end @@ -39,7 +39,7 @@ function MSync.initModules() v["hooks"]() MSync.loadedModules[v["info"].ModuleIdentifier] = true MSync.net.sendModuleEnable( v["info"].ModuleIdentifier ) - MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "[" .. v["info"]["Name"] .. "] Module loaded") end end @@ -50,7 +50,7 @@ function MSync.initModules() 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.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 @@ -74,7 +74,7 @@ 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.Name] .. "] Module loaded") function initTransaction.onSuccess() MSync.log(MSYNC_DBG_INFO, "Module query has been completed successfully") @@ -83,7 +83,7 @@ function MSync.loadModule(path) 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.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 @@ -109,14 +109,14 @@ function MSync.enableModule( module ) MSync.modules[module].hooks() function initTransaction.onSuccess() - MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded") + MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module loaded") MSync.net.sendModuleEnable( module ) hook.Call("MSyncModuleLoaded", nil, module) --MSync.mysql[module].dbstatus = true end 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.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 @@ -143,7 +143,7 @@ function MSync.disableModule( 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.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 .. "\"") diff --git a/lua/msync/server/sv_mysql.lua b/lua/msync/server/sv_mysql.lua index 1022e77..1c7d2ad 100644 --- a/lua/msync/server/sv_mysql.lua +++ b/lua/msync/server/sv_mysql.lua @@ -87,7 +87,7 @@ function MSync.mysql.initialize() end function initDatabase.onError(tr, 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) + 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() @@ -95,7 +95,7 @@ function MSync.mysql.initialize() end function MSync.DBServer.onConnectionFailed( db, 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.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() @@ -132,11 +132,11 @@ function MSync.mysql.addUser(ply) addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) function addUserQ.onSuccess() - MSync.log(MSYNC_DBG_INFO, "User "..ply:Nick().." successfully created") + MSync.log(MSYNC_DBG_INFO, "User " .. ply:Nick() .. " successfully created") end function addUserQ.onError(q, err, sql) - MSync.log(MSYNC_DBG_ERROR, "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() @@ -172,11 +172,11 @@ function MSync.mysql.addUserID(steamid, nickname) addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) function addUserQ.onSuccess() - MSync.log(MSYNC_DBG_INFO, "User "..steamid.." successfully created") + MSync.log(MSYNC_DBG_INFO, "User " .. steamid .. " successfully created") end function addUserQ.onError(q, err, sql) - MSync.log(MSYNC_DBG_ERROR, "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() @@ -188,9 +188,9 @@ end ]] function MSync.mysql.getInfo() print("--Database Server Information--") - print("Version: "..MSync.DBServer:serverVersion()) - print("Fancy Version: "..MSync.DBServer:serverInfo()) - print("Host Info: "..MSync.DBServer:hostInfo()) + print("Version: " .. MSync.DBServer:serverVersion()) + print("Fancy Version: " .. MSync.DBServer:serverInfo()) + print("Host Info: " .. MSync.DBServer:hostInfo()) end --[[ @@ -235,14 +235,14 @@ function MSync.mysql.saveServer() end function addServer.onError(q, err, sql) - MSync.log(MSYNC_DBG_ERROR, "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) - MSync.log(MSYNC_DBG_ERROR, "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 b2476af..b013907 100644 --- a/lua/msync/server/sv_net.lua +++ b/lua/msync/server/sv_net.lua @@ -11,7 +11,7 @@ MSync.net = MSync.net or {} ]] function MSync.net.sendTable(ply, identifier, table) MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendTable. Param.: " .. tostring(ply) .. " " .. identifier .. " " .. tostring(table)) - local identifier = identifier or "settings" + identifier = identifier or "settings" net.Start("msync.sendTable") net.WriteString(identifier) @@ -30,7 +30,7 @@ util.AddNetworkString("msync.sendTable") ]] function MSync.net.sendMessage(ply, state, string) MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendMessage. Param.: " .. tostring(ply) .. " " .. state .. " " .. tostring(string)) - local state = state or "info" + state = state or "info" net.Start("msync.sendMessage") net.WriteString(state) @@ -127,7 +127,7 @@ net.Receive("msync.sendSettings", function(len, ply) MSync.settings.data.mysql.password = password end - if not type(MSync.settings.data.mysql.port) == number then + if type(MSync.settings.data.mysql.port) ~= number then MSync.settings.data.mysql.port = tonumber(MSync.settings.data.mysql.port) end @@ -177,7 +177,7 @@ net.Receive("msync.toggleModule", function(len, ply) MSync.settings.data.enabledModules[ident] = nil end MSync.func.saveSettings() - MSync.net.sendMessage(ply, "info", state.."d module "..ident) + MSync.net.sendMessage(ply, "info", state .. "d module " .. ident) end ) --[[ @@ -190,7 +190,7 @@ net.Receive("msync.connectDB", function(len, ply) if not ply:query("msync.connectDB") then return end if MSync.DBServer then - if not (MSync.DBServer:status() == mysqloo.DATABASE_CONNECTED) then + if (MSync.DBServer:status() ~= mysqloo.DATABASE_CONNECTED) then MSync.mysql.initialize() else MSync.net.sendMessage(ply, "error", "The database is already connected!") diff --git a/lua/msync/sh_init.lua b/lua/msync/sh_init.lua index 0f7a831..d3930e5 100644 --- a/lua/msync/sh_init.lua +++ b/lua/msync/sh_init.lua @@ -28,7 +28,7 @@ local debugLevels = { --[[ 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 ) +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 @@ -39,7 +39,7 @@ MSync.DebugCVar = CreateConVar( "msync_debug", 0, FCVAR_REPLICATED+FCVAR_ARCHIVE - Nothing ]] MSync.log = function(logLevel, logMessage) - if not type(logLevel) == "number" then return end + if type(logLevel) ~= "number" then return end local DebugCvarValue = MSync.DebugCVar:GetInt() @@ -48,9 +48,9 @@ MSync.log = function(logLevel, logMessage) logMessage = logMessage() end if debugLevels[logLevel] then - MsgC(debugLevels[logLevel].color, debugLevels[logLevel].prefix.." "..logMessage.."\n") + MsgC(debugLevels[logLevel].color, debugLevels[logLevel].prefix .. " " .. logMessage .. "\n") else - MsgC(Color(255, 255, 255), "[MSync_LOG] "..logMessage.."\n") + 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("[]") ) @@ -68,7 +68,7 @@ end MSync.formatString = function(str, tbl) return function() for k,v in pairs(tbl) do - str = string.Replace(str, "$"..k, tostring(v)) + str = string.Replace(str, "$" .. k, tostring(v)) end return str end From 4efcdad6919c3b440b53210caab85ee1d98d8495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 27 Feb 2022 12:55:44 +0100 Subject: [PATCH 4/6] Nil value Fix a bug where a nil value was called to get a players nickname --- lua/msync/server/modules/sv_mrsync.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 6c2fd6b..0a67bd5 100644 --- a/lua/msync/server/modules/sv_mrsync.lua +++ b/lua/msync/server/modules/sv_mrsync.lua @@ -352,7 +352,7 @@ function MSync.modules.MRSync.hooks() return end - MSync.log(MSYNC_DBG_INFO, "[MRSync] User \"" .. ply:Nick() .. "\" was removed from ULX, removing from MRSync"); + MSync.log(MSYNC_DBG_INFO, "[MRSync] User with ID \"" .. sid .. "\" was removed from ULX, removing from MRSync"); MSync.modules.MRSync.removeRank(sid) end) end From 04e0dad2cb306fef41cf8a52722b7ed1436e8e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 27 Feb 2022 14:57:59 +0100 Subject: [PATCH 5/6] Change ban behaviour Editing bans now always adds the time to the current ban length. Meaning if I edit a ban 30 minutes after it was created with 1 hour of ban time, the ban length will be 1 hour 30 minutes, so that the user gets unbanned 1 hour after the edit happened --- lua/msync/client_gui/cl_admin_gui.lua | 2 +- lua/msync/client_gui/modules/cl_mbsync.lua | 1 + lua/msync/server/modules/sv_mbsync.lua | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lua/msync/client_gui/cl_admin_gui.lua b/lua/msync/client_gui/cl_admin_gui.lua index dc3aa07..862b284 100644 --- a/lua/msync/client_gui/cl_admin_gui.lua +++ b/lua/msync/client_gui/cl_admin_gui.lua @@ -243,7 +243,7 @@ function MSync.AdminPanel.InitMySQL( sheet ) end end - if MSync.settings ~= nil then + if MSync.settings and MSync.settings.mysql then mysqlip:SetText(MSync.settings.mysql.host) mysqlport:SetText(MSync.settings.mysql.port) mysqldb:SetText(MSync.settings.mysql.database) diff --git a/lua/msync/client_gui/modules/cl_mbsync.lua b/lua/msync/client_gui/modules/cl_mbsync.lua index 7b550b0..62d0101 100644 --- a/lua/msync/client_gui/modules/cl_mbsync.lua +++ b/lua/msync/client_gui/modules/cl_mbsync.lua @@ -878,6 +878,7 @@ MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) reload_button.DoClick = function() MSync.log(MSYNC_DBG_INFO, "[MBSync] Reloading data"); MSync.modules[info.ModuleIdentifier].getBanTable(true) + ban_table:Clear() timer.Create("msync.mbsync.waitForBanTable", 1, 0, function() if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then return end diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index d6518d6..1cb38da 100644 --- a/lua/msync/server/modules/sv_mbsync.lua +++ b/lua/msync/server/modules/sv_mbsync.lua @@ -113,9 +113,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) 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 length ~= 0 then - length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()].timestamp) + (length * 60)) / 60 - end + -- Editing bans now always adds the time to the current ban length. Meaning if I edit a ban 30 minutes after it was created with 1 hour of ban time, the ban length will be 1 hour 30 minutes, so that the user gets unbanned 1 hour after the edit happened + --if length ~= 0 then + -- length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[ply:SteamID64()].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 @@ -201,9 +202,10 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) 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 (length ~= 0) then - length = ((os.time() - MSync.modules[info.ModuleIdentifier].banTable[util.SteamIDTo64(userid)].timestamp) + (length * 60)) / 60 - end + -- Editing bans now always adds the time to the current ban length. Meaning if I edit a ban 30 minutes after it was created with 1 hour of ban time, the ban length will be 1 hour 30 minutes, so that the user gets unbanned 1 hour after the edit happened + --if (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 @@ -308,7 +310,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction ) UPDATE `tbl_mbsync` SET reason=?, - length_unix=?, + length_unix=(UNIX_TIMESTAMP() - date_unix) + ?, admin_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?), server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) WHERE p_ID=? @@ -1495,7 +1497,11 @@ MSync.modules[info.ModuleIdentifier].hooks = function() if banData.unban == 0 then ban.length = 0 else - ban.length = (banData.unban-os.time()) / 60 + if banData.modified_time then + ban.length = (banData.unban-banData.modified_time) / 60 + else + ban.length = (banData.unban-banData.time) / 60 + end end if not banData.reason then From e06c6f30469ce6f29205cd3ed6f0c311f335c3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Gr=C3=BCttemeier?= Date: Sun, 6 Mar 2022 14:50:59 +0100 Subject: [PATCH 6/6] Bump Version numbers Bump version numbers of modules --- 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 62d0101..d75b643 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.2 + * @version 1.4.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.2" + Version = "1.4.0" } --[[ diff --git a/lua/msync/client_gui/modules/cl_mrsync.lua b/lua/msync/client_gui/modules/cl_mrsync.lua index 45320b1..7f1be94 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.3 + * @version 2.3.0 ]] --[[ @@ -16,7 +16,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.3" + Version = "2.3.0" } --[[ diff --git a/lua/msync/server/modules/sv_mbsync.lua b/lua/msync/server/modules/sv_mbsync.lua index 1cb38da..5ba787f 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.2 + * @version 1.4.0 ]] --[[ @@ -15,7 +15,7 @@ local info = { Name = "MySQL Ban Sync", ModuleIdentifier = "MBSync", Description = "Synchronise bans across your servers", - Version = "1.3.2" + Version = "1.4.0" } --[[ diff --git a/lua/msync/server/modules/sv_mrsync.lua b/lua/msync/server/modules/sv_mrsync.lua index 2976caa..f718705 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.3 + * @version 2.3.0 ]] --[[ @@ -17,7 +17,7 @@ MSync.modules.MRSync.info = { Name = "MySQL Rank Sync", ModuleIdentifier = "MRSync", Description = "Synchronise your ranks across your servers", - Version = "2.2.3" + Version = "2.3.0" } --[[