diff --git a/vrp_punishments/README.md b/vrp_punishments/README.md index 3d35d27..e1512fa 100644 --- a/vrp_punishments/README.md +++ b/vrp_punishments/README.md @@ -56,9 +56,9 @@ end ``` ###### 5) Place sv_warningsystem.lua in vrp/modules/ and cl_warningsystem.lua in vrp/client/ +###### 6) Place cfg_warningsystem.lua in vrp/cfg/ -###### 6) Update your vrp/__resource.lua by putting adding the file names cl_warningsystem.lua & sv_warningsystem.lua in the appropriate section - +###### 7) Update your vrp/__resource.lua by putting adding the file names cl_warningsystem.lua & sv_warningsystem.lua in the appropriate section ## How to use: * F10 to open up the warning sytem diff --git a/vrp_punishments/cfg_warningsystem.lua b/vrp_punishments/cfg_warningsystem.lua new file mode 100644 index 0000000..0f21d60 --- /dev/null +++ b/vrp_punishments/cfg_warningsystem.lua @@ -0,0 +1,13 @@ +local cfg = {} + +cfg.database_driver = "fivem-mysql" + +--[[ + default is fivem-mysql (https://github.com/GHMatti/FiveM-MySQL/releases/tag/0.6.1) + list of supported drivers + fivem-mysql (https://github.com/GHMatti/FiveM-MySQL/releases/tag/0.6.1) + ghmattimysql js version (https://github.com/GHMatti/ghmattimysql/releases/tag/1.3.2) + mysql-async (https://github.com/brouznouf/fivem-mysql-async) +]] + +return cfg \ No newline at end of file diff --git a/vrp_punishments/cl_warningsystem.lua b/vrp_punishments/cl_warningsystem.lua index 67598d2..95d9652 100644 --- a/vrp_punishments/cl_warningsystem.lua +++ b/vrp_punishments/cl_warningsystem.lua @@ -1,31 +1,26 @@ --type,duration(hours),admin_name,date,reason -CMGWarnings = { +local CMGWarnings = { [0] = {"Ban","48","Robbster","10-10-19","You VDM'd x2"}, [1] = {"Warning","24","Rob","1-10-19","You VDM'd x4"}, } -showWarningSystem = false +local showWarningSystem = false -xoffset = 0.031 -rowcounter = 0 -warningColourR = 0 -warningColourG = 0 -warningColourB = 0 +local xoffset = 0.031 +local rowcounter = 0 +local warningColourR = 0 +local warningColourG = 0 +local warningColourB = 0 --- RegisterCommand("tempwarn",function() - -- showWarningSystem = not showWarningSystem --- end) RegisterNetEvent("CMG:showWarningsOfUser") AddEventHandler("CMG:showWarningsOfUser",function(cmgwarningstables) - print("got to showWarningsOfUser") showWarningSystem = true CMGWarnings = cmgwarningstables end) RegisterNetEvent("CMG:recievedRefreshedWarningData") AddEventHandler("CMG:recievedRefreshedWarningData",function(cmgwarningstables) - print("got to recievedRefreshedWarningData") CMGWarnings = cmgwarningstables end) @@ -33,7 +28,6 @@ end) Citizen.CreateThread(function() while true do if IsControlJustPressed(0,57) then - print("toggling warning system") showWarningSystem = not showWarningSystem if showWarningSystem then TriggerServerEvent("CMG:refreshWarningSystem") @@ -93,10 +87,9 @@ RegisterCommand("warn",function() --get ID --get warning msg --send to server to update the database - userIDtoWarn = getWarningUserID() - userWarningMessage = getWarningUserMsg() - - TriggerServerEvent("CMG:warnPlayer",tonumber(userIDtoWarn),GetPlayerName(PlayerId()),userWarningMessage) + local target_id = getWarningUserID() + local warning_reason = getWarningUserMsg() + TriggerServerEvent("CMG:warnPlayer",tonumber(target_id),GetPlayerName(PlayerId()),warning_reason) end) function getWarningUserID() diff --git a/vrp_punishments/sv_warningsystem.lua b/vrp_punishments/sv_warningsystem.lua index 4c20acc..24cb07f 100644 --- a/vrp_punishments/sv_warningsystem.lua +++ b/vrp_punishments/sv_warningsystem.lua @@ -1,78 +1,54 @@ --- CREATE TALBE cmg_warnings ( - -- warning_id INT, - -- user_id INT, - -- warning_type VARCHAR(25), - -- duration INT, - -- admin VARCHAR(100), - -- warning_date DATE, - -- reason VARCHAT(2000), - -- PRIMARY KEY (warning_id) --- ) +local cfg = module("cfg/cfg_warningsystem") ---TODO ---Fix date DONE ---/warn DONE ---make primary key auto_increment DONE ---getCurrentDate function DONE ---bans auto go on log menu DONE ---kicks auto go on log menu DONE ---Whitelist to staff DONE ---Change crossarms key bind DONE ---change requests DONE ---ban duration column needs to show (hrs) DONE ---ban duration not working DONE ---bar colour DONE ---verify kicks work DONE -AddEventHandler('chatMessage', function(player, color, message) - user_id = vRP.getUserId(player) - if message:sub(1, 13) == '/showwarnings' then - local permID = tonumber(message:sub(14, 20)) - if permID ~= nil then - --check if staff - if vRP.hasPermission(user_id,"player.kick") then - --print("Getting warnings of ID: " .. tostring(permID)) - cmgwarningstables = getCMGWarnings(permID,player) - --print("sending to source: " .. tostring(source)) - TriggerClientEvent("CMG:showWarningsOfUser",player,cmgwarningstables) - end - else - --print("Error couldn't get ID: " .. tostring(message:sub(14, 20))) - end - end - CancelEvent() +RegisterCommand("showwarnings", function(source, args) + local user_id = vRP.getUserId(source) + if vRP.hasPermission(user_id, "player.kick") then + local target_id = tonumber(args[1]) + local warnings = getCMGWarnings(target_id,source) + TriggerClientEvent("CMG:showWarningsOfUser",source,warnings) + end end) ---print("start:"..dump(testdate).."end") --- testTime = 1561845600000 --- testTime = testTime / 1000 --- print(os.date('%Y-%m-%d', testTime)) - +--sql + +function querySync(query, params) + if cfg.database_driver == "ghmattimysql-js" then + return exports["ghmattimysql"]:executeSync(query, params) + elseif cfg.database_driver == "fivem-mysql" then + return exports['GHMattiMySQL']:QueryResult(query, params) + elseif cfg.database_driver == "mysql-async" then + return MySQL.Sync.execute(query, params) + end +end + +function query(query, params, callback) + if cfg.database_driver == "ghmattimysql-js" then + exports["ghmattimysql"]:execute(query, params, callback) + elseif cfg.database_driver == "fivem-mysql" then + exports['GHMattiMySQL']:QueryAsync(query, params, callback) + elseif cfg.database_driver == "mysql-async" then + MySQL.Async.execute(query, params, callback) + end +end + function getCMGWarnings(user_id,source) - cmgwarningstables = exports['GHMattiMySQL']:QueryResult("SELECT * FROM cmg_warnings WHERE user_id = @uid", {uid = user_id}) - print("Triggering CMG:showWarningsOfUser") - --print(dump(cmgwarningstables)) - for warningID,warningTable in pairs(cmgwarningstables) do - --print(warningTable["warning_date"]) - date = warningTable["warning_date"] - --print("date1:" .. tostring(date)) - newdate = tonumber(date) / 1000 - --print("date3:" .. tostring(newdate)) + local warnings = querySync("SELECT * FROM cmg_warnings WHERE user_id = @uid", {uid = user_id}) + for warningID,warningTable in pairs(warnings) do + local date = warningTable["warning_date"] + local newdate = tonumber(date) / 1000 newdate = os.date('%Y-%m-%d', newdate) - --print("date4:" .. tostring(newdate)) warningTable["warning_date"] = newdate end - return cmgwarningstables + return warnings end RegisterServerEvent("CMG:refreshWarningSystem") AddEventHandler("CMG:refreshWarningSystem",function() local source = source local user_id = vRP.getUserId(source) - --local user_id = 1 - - cmgwarningstables = getCMGWarnings(user_id,source) - TriggerClientEvent("CMG:recievedRefreshedWarningData",source,cmgwarningstables) + local warnings = getCMGWarnings(user_id,source) + TriggerClientEvent("CMG:recievedRefreshedWarningData",source,warnings) end) RegisterServerEvent("CMG:warnPlayer") @@ -80,35 +56,26 @@ AddEventHandler("CMG:warnPlayer",function(target_id,adminName,warningReason) local source = source local user_id = vRP.getUserId(source) if vRP.hasPermission(user_id,"player.kick") then - warning = "Warning" - warningDate = getCurrentDate() - exports['GHMattiMySQL']:QueryAsync("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, 0, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, warning_date = warningDate, reason = warningReason}, function() end) + local warning = "Warning" + local warningDate = getCurrentDate() + query("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, 0, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, warning_date = warningDate, reason = warningReason}, function() end) else vRPclient.notify(player,{"~r~no perms to warn player"}) end end) function saveKickLog(target_id,adminName,warningReason) - warning = "Kick" - warningDate = getCurrentDate() - exports['GHMattiMySQL']:QueryAsync("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, 0, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, warning_date = warningDate, reason = warningReason}, function() end) - + local warning = "Kick" + local warningDate = getCurrentDate() + query("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, 0, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, warning_date = warningDate, reason = warningReason}, function() end) end function saveBanLog(target_id,adminName,warningReason,warning_duration) - warning = "Ban" - warningDate = getCurrentDate() - exports['GHMattiMySQL']:QueryAsync("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, @duration, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, duration = warning_duration, warning_date = warningDate, reason = warningReason}, function() end) + local warning = "Ban" + local warningDate = getCurrentDate() + query("INSERT INTO cmg_warnings (`warning_id`, `user_id`, `warning_type`, `duration`, `admin`, `warning_date`, `reason`) VALUES (NULL, @user_id, @warning_type, @duration, @admin, @warning_date,@reason);", {user_id = target_id,warning_type = warning, admin = adminName, duration = warning_duration, warning_date = warningDate, reason = warningReason}, function() end) end - function getCurrentDate() - date = os.date("%Y/%m/%d") - - return date + return os.date("%Y/%m/%d") end - --- CMGWarnings = { - -- [0] = {"Ban","48","Rolex","10-10-19","You VDM'd x2"}, - -- [1] = {"Warning","24","Rob","1-10-19","You VDM'd x4"}, --- } \ No newline at end of file