Jump to content

checking values in table


toxicsmoke11

Recommended Posts

hello guys i am not really experienced in tables, i'm still learning how they work, how to use/read whatever them and so on

anyway let's say instead of default ban system i have made "hell"

however i am not sure how to check is player's serial in this table

hellList = { 
-- stars were put for privacy reasons 
{"***569FE453BD4260ECAB1BA18F382A2"},  
{"***C4B55138CDE1251CC684759FB23F2"},  
{"***0FD3104DD5F1768A20CA2E6C8AEA3"},  
{"***DEF127AD04771C1CB847F0B480BE3"},  
{"***E4510F78C3E0AB1474292DACAADC4"},  
{"***24608511608C41E9D94A3D4E7F742"},  
{"***02F041B50CC509B1CC9EEA81F6EA2"},  
{"***96EEFFA5FE6B5E9A826ABF4A25584"},  
{"***790600040ABF44115F80E117841E4"},  
{"***49AD57FD37519BBA9A1DADD168D12"}  
} 
  
function cIsPlayerBanned(noob,serial) 
if not noob then return end 
if not serial then return end 
  
   for i,serials in ipairs(hellList) do 
      if serials[getPlayerSerial(noob)] then 
          return outputDebugString("player is banned") true 
      else return outputDebugString("player aint banned") false end 
   end 
end 

few notes:

- this is client sided

- using this as exported function

this simply doesnt work and i dont know how to make it work

please somebody, help me

Link to comment
  • MTA Team

Here:

-- How Lua will see the table 
hellList = { 
    [1] = { [1] = "***569FE453BD4260ECAB1BA18F382A2" }, 
    [2] = { [1] = "***C4B55138CDE1251CC684759FB23F2" }, 
    [3] = { [1] = "***0FD3104DD5F1768A20CA2E6C8AEA3" }, 
    [4] = { [1] = "***DEF127AD04771C1CB847F0B480BE3" }, 
    [5] = { [1] = "***E4510F78C3E0AB1474292DACAADC4" }, 
    [6] = { [1] = "***24608511608C41E9D94A3D4E7F742" }, 
    [7] = { [1] = "***02F041B50CC509B1CC9EEA81F6EA2" }, 
    [8] = { [1] = "***96EEFFA5FE6B5E9A826ABF4A25584" }, 
    [9] = { [1] = "***790600040ABF44115F80E117841E4" }, 
    [10] = { [1] = "***49AD57FD37519BBA9A1DADD168D12" } 
} 
  
-- How to access the main table 
local first = hellList[1]    --// = { [1] = "***569FE453BD4260ECAB1BA18F382A2" } 
  
-- How to access the second table 
local serial = first[1]    --// = "***569FE453BD4260ECAB1BA18F382A2" 
  
-- How to loop through the table 
for i = 1, #hellList do 
    local serial = hellList[i][1] 
  
    if (serial == "***E4510F78C3E0AB1474292DACAADC4") then 
        break 
    end 
end 
  
for index, subtable in pairs(hellList) do 
    local serial = subtable[1] 
  
    if (serial == "***E4510F78C3E0AB1474292DACAADC4") then 
        break 
    end 
end 
  

How you might have done it:

  
bannedSerials = { 
    ["***569FE453BD4260ECAB1BA18F382A2"] = true, 
    ["***C4B55138CDE1251CC684759FB23F2"] = true, 
    ["***0FD3104DD5F1768A20CA2E6C8AEA3"] = true, 
    --// ... 
} 
  
function hasPlayerBannedSerial(player) 
    if (isElement(player) and getElementType(player) == "player") then 
        return bannedSerials[ getPlayerSerial(player) ] or false 
    else 
        return false 
    end 
end 
  

Link to comment
  • Moderators
hellList = { 
    -- stars were put for privacy reasons 
    ["***569FE453BD4260ECAB1BA18F382A2"]=true, 
    ["***C4B55138CDE1251CC684759FB23F2"]=true, 
    ["***0FD3104DD5F1768A20CA2E6C8AEA3"]=true, 
    ["***DEF127AD04771C1CB847F0B480BE3"]=true, 
    ["***E4510F78C3E0AB1474292DACAADC4"]=true, 
    ["***24608511608C41E9D94A3D4E7F742"]=true, 
    ["***02F041B50CC509B1CC9EEA81F6EA2"]=true, 
    ["***96EEFFA5FE6B5E9A826ABF4A25584"]=true, 
    ["***790600040ABF44115F80E117841E4"]=true, 
    ["***49AD57FD37519BBA9A1DADD168D12"]=true 
} 
  
function cIsPlayerBanned(noob,serial) 
    if not isElement(noob) then return false end 
    local serial = serial or getPlayerSerial(noob) 
    if serial then 
        if hellList[serial] then 
            outputDebugString("player is banned") 
            return true 
        else  
            outputDebugString("player isn't banned") 
            return false  
        end 
    end 
    return false 
end 

syntax

cIsPlayerBanned(noob [,serial]) 
  
-- use as:  
cIsPlayerBanned(noob) 
-- or 
cIsPlayerBanned(noob,serial) 
  

Link to comment

thanks guys tho but i got some weird issue

admin\server\admin_server.lua:1458 admin security client/player mismatch from **.***.*.**(<-- this is hidden ip address)

( onElementDataChange player.state )

this player.state data is my custom data usually used to see what is player doing, not related with this "custom banning" at all, and yet its giving out this warnings if a banned person is playing and being in hell

this admin function is causing this error

function checkClient(checkAccess,player,...) 
    if client and client ~= player and g_Prefs.securitylevel >= 2 then 
        local desc = table.concat({...}," ") 
        local ipAddress = getPlayerIP(client) 
        outputDebugString( "Admin security - Client/player mismatch from " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")", 1 ) -- thats line 1458 
        cancelEvent() 
        if g_Prefs.clientcheckban then 
            local reason = "admin checkClient (" .. tostring(desc) .. ")" 
            addBan ( ipAddress, nil, nil, getRootElement(), reason ) 
        end 
        return true 
    end 
    if checkAccess and g_Prefs.securitylevel >= 1 then 
        if type(checkAccess) == 'string' then 
            if hasObjectPermissionTo ( player, checkAccess ) then 
                return false    -- Access ok 
            end 
            if hasObjectPermissionTo ( player, "general.adminpanel" ) then 
                outputDebugString( "Admin security - Client does not have required rights ("..checkAccess.."). " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")" ) 
                return true     -- Low risk fail - Can't do specific command, but has access to admin panel 
            end 
        end 
        if not hasObjectPermissionTo ( player, "general.adminpanel" ) then 
            local desc = table.concat({...}," ") 
            local ipAddress = getPlayerIP(client or player) 
            outputDebugString( "Admin security - Client without admin panel rights trigged an admin panel event. " .. tostring(ipAddress) .. " (" .. tostring(desc) .. ")", 2 ) 
            return true         -- High risk fail - No access to admin panel 
        end 
    end 
    return false 
end 

please somebody help me im so confused

edit:

only thing that could be cause of this error would be this

  
-- one tiny part of code 
     if exports.security:cIsPlayerBanned(player,getPlayerSerial(player)) then 
     setElementData(player,"player.state","hellbanned") 

but not sure why is this making the client not validated?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...