Commit 0969b675 authored by Maximilian Grüttemeier's avatar Maximilian Grüttemeier
Browse files

Functionality and Bugfix

CLIENT:
- Added Ban table init
- Added page scroll functionality for ban view
- Added function to display single table pages
- Added Fake data generator for Debugging
- Code Cleanup
- Added a way to get the active bans table on the client

SERVER:
- Fixed a bug causing the getActiveBan function to not read the data correctly
- Added a way to send the Ban table in parts to the client
- Added function to split tables into 10 part tables
- Added command to edit a ban
parent 9d954c3e
Loading
Loading
Loading
Loading

fake_data.sql

0 → 100644
+14 −0
Original line number Diff line number Diff line
/*INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:1', '760000001', 'User 1', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:2', '760000002', 'User 2', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:3', '760000003', 'User 3', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:4', '760000004', 'User 4', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:5', '760000005', 'User 5', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:6', '760000006', 'User 6', '2020-04-09 17:00');
INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:7', '760000007', 'User 7', '2020-04-09 17:00');*/

INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (7, 2, 'Test 1', 1586445390, 99999999, 1);
INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (2, 3, 'Test 2', 1586445390, 99999999, 1);
INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (3, 4, 'Test 3', 1586445390, 99999999, 1);
INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (4, 5, 'Test 4', 1586445390, 99999999, 1);
INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (5, 6, 'Test 5', 1586445390, 99999999, 1);
INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (6, 7, 'Test 6', 1586445390, 99999999, 1);
 No newline at end of file
+390 −135

File changed.

Preview size limit exceeded, changes collapsed.

+124 −10
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
            SET 
                reason=?,
                length_unix=?,
                adminid=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?),
                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=?
        ]] )
@@ -258,9 +258,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
            LEFT JOIN tbl_server_grp 
                ON tbl_mbsync.server_group = tbl_server_grp.p_group_id
            LEFT JOIN tbl_users AS banned 
                ON tbl_mbsync.userid = banned.p_user_id
                ON tbl_mbsync.user_id = banned.p_user_id
            LEFT JOIN tbl_users AS admin 
                ON tbl_mbsync.adminid = admin.p_user_id
                ON tbl_mbsync.admin_id = admin.p_user_id
            LEFT JOIN tbl_users AS unban_admin 
                ON tbl_mbsync.ban_lifted = unban_admin.p_user_id
            ;
@@ -332,9 +332,9 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
                admin.nickname AS 'admin.nickname'
            FROM `tbl_mbsync`
            LEFT JOIN tbl_users AS banned
                ON tbl_mbsync.userid = banned.p_group_id
                ON tbl_mbsync.user_id = banned.p_user_id
            LEFT JOIN tbl_users AS admin
                ON tbl_mbsync.adminid = admin.p_group_id
                ON tbl_mbsync.admin_id = admin.p_user_id
            WHERE
                ban_lifted IS NULL AND
                (
@@ -349,15 +349,13 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
        getActiveBansQ:setNumber(1, os.time())
        getActiveBansQ:setString(8, MSync.settings.data.serverGroup)
        
        function getActiveBansQ.onData( q, data )
        function getActiveBansQ.onSuccess( q, data )
            
            local banTable = {}

            print("[MBSync] Recieved ban data")

            for k,v in pairs(data) do

                banTable[v.steamid64] = {
                banTable[v["steamid64"]] = {
                    banId = v.p_id,
                    reason = v.reason,
                    timestamp = v.date_unix,
@@ -368,7 +366,6 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
                    },
                    adminNickname = v["admin.nickname"]
                }

            end

            MSync.modules[info.ModuleIdentifier].banTable = banTable
@@ -444,6 +441,29 @@ MSync.modules[info.ModuleIdentifier].init = function( transaction )
        return file.Exists("msync/"..info.ModuleIdentifier..".txt", "DATA")
    end

    --[[
        Description: Function to split table into multible 10er parts
        Returns: table split in 10er part counts
    ]]
    MSync.modules[info.ModuleIdentifier].splitTable = function(tbl)
        local i = 0
        local dataSet = 0
        local splitTableData = {}

        for k,v in pairs(tbl) do
            if not splitTableData[dataSet] then splitTableData[dataSet] = {} end
            if i == 10 then
                dataSet = dataSet + 1
                i = 0
            else
                splitTableData[dataSet][k] = v
                i = i + 1
            end
        end

        return splitTableData
    end

    --[[
        Load settings when module finished loading
    ]]
@@ -639,6 +659,50 @@ MSync.modules[info.ModuleIdentifier].net = function()
        net.Send(ply)
    end

    --[[
        Description: Function to send the data part count to the client
        Arguments:
            player [player] - the player that requests the data
            number [interger] - the count of data parts to be sent to the player
        Returns: nothing
    ]]
    util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveDataCount")
    MSync.modules[info.ModuleIdentifier].sendCount = function(ply, number)
        print(number)
        net.Start("msync."..info.ModuleIdentifier..".recieveDataCount")
            net.WriteFloat(number)
        net.Send(ply)
    end

    --[[
        Description: Function to send a table part to a player
        Arguments:
            player [player] - the player that requests the data
            part [table] - the table part that gets sent to the player
        Returns: nothing
    ]]
    util.AddNetworkString("msync."..info.ModuleIdentifier..".recieveData")
    MSync.modules[info.ModuleIdentifier].sendPart = function(ply, part)
        net.Start("msync."..info.ModuleIdentifier..".recieveData")
            net.WriteTable(part)
        net.Send(ply)
    end

    --[[
        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)
        MSync.modules[info.ModuleIdentifier].sendCount(ply, math.Round(table.Count(MSync.modules[info.ModuleIdentifier].banTable) / 10))

        local tempTable = MSync.modules[info.ModuleIdentifier].splitTable(MSync.modules[info.ModuleIdentifier].banTable)
        PrintTable(tempTable)
        for k,v in pairs(tempTable) do
            MSync.modules[info.ModuleIdentifier].sendPart(ply, v)
        end
    end )

end

--[[
@@ -841,6 +905,56 @@ MSync.modules[info.ModuleIdentifier].ulx = function()
    BanPlayer:defaultAccess( ULib.ACCESS_SUPERADMIN )
    BanPlayer:help( "Opens MSync Settings." )

    --[[
        TODO: The whole Command
        Expected behaviour:
        Edits the ban with the given banID

        Arguments:
            banID [number] - the ban id
            length [number] - the ban length - OPTIONAL - Default: 0/Permanent
            allserver [bool] - if its on all servers - OPTIONAL - Default: 0/false
            reason [string] - the ban reason - OPTIONAL - Default: "banned by staff"
    ]]
    MSync.modules[info.ModuleIdentifier].Chat.editBan = function(calling_ply, ban_id, length, allserver, reason)
        if not calling_ply:query("msync."..(info.ModuleIdentifier)..".editBan") then return end;
        if not IsValid(calling_ply) then return end;

        if calling_ply == target_ply then
            MSync.modules[info.ModuleIdentifier].openBanGUI(calling_ply)
        else
            if not IsValid(target_ply) then return end

            --[[
                Set default values if empty and translate allserver string to bool
            ]]
            if not length then length = 0 end

            if not allserver then
                allserver = true
            else
                if allserver == "true" or allserver == "1" then
                    allserver = true
                else
                    allserver = false
                end
            end

            if not reason then reason = "No reason given" end

            --[[
                Run ban function with given variables
            ]]
            MSync.modules[info.ModuleIdentifier].editBan(ban_id, reason, length, calling_ply, allserver)
        end
    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, if the player should be banned on 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" )

end