• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua [TFS 0.X] Reputation System - Help to improve conditionals

potinho

Intermediate OT User
Joined
Oct 11, 2009
Messages
1,397
Solutions
17
Reaction score
148
Location
Brazil
Hello everyone, everything good? I put a reputation system on my server, to encourage the creation of a friendly atmosphere among players, giving rewards to those who achieve more points in this system, but players are managing to circumvent it, using VPN for example. The system checks the player's IP at first, are we able to put in other checks (like the player's own account) to ensure that a player only uses the reputation system once a day? Follow my system:

Lua:
local function file_exists(f)
    local f = io.open("data/logs/repsystem/"..f..".txt", "rb")
      if f then 
          f:close() 
      end
      return f ~= nil
end

local function create_file(f, mode)
      return io.open("data/logs/repsystem/"..f..".txt", mode)
end

local function convertTime(value)
    local text = ""
    if value then
        local time = value
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." hour and "..minutes.." minutes"
        elseif time >= 60 then
            text = minutes.." minutes and "..seconds.." seconds"
        else
            text = seconds.." seconds"
        end
    end
    return text
end

function onSay(cid, words, param, channel)
    local blockTime = 1 * 24 * 60 * 60
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Player name is missing.")
        return true
    end
    
    local reputationStr = 144712
    local pid = getCreatureByName(param)

    if not isPlayer(pid) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Player "..param.." not found.")
    end

    if cid == pid then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add reputation to yourself.")
    end

    local playerIP = getPlayerIp(cid)
    if file_exists(playerIP) then
        local file = create_file(playerIP, "r")
        local lastReputation = tonumber(file:read())
        file:close()

        if lastReputation > os.time() then
            local remainTime = lastReputation - os.time()
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have to wait "..convertTime(remainTime).." to add reputation again.")
        end
    end

    local file = create_file(playerIP, "w")
    file:write(os.time() + blockTime)
    file:close()

    -- save player to update storages on website
    doPlayerSave(pid)

    setPlayerStorageValue(pid, reputationStr, math.max(0, tonumber(getPlayerStorageValue(pid, reputationStr))) + 1)
    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, getCreatureName(cid).." has been sent you +1 reputation.")
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have sent +1 reputation to "..getCreatureName(pid)..".")
    return true
end
 
Solution
I did something similar, but on mysql

  • system checks if player is with active client (IP = 0)
  • checks if the player and the target have different ip

I don't know if in LUA itself it is possible to check if player logs in from vps/proxy


Lua:
--[[ MYSQL
    CREATE TABLE `reputation_system` (
      `ip` int(11) NOT NULL,
      `date` int(11) NOT NULL,
      `to_player` int(10) NOT NULL,
    PRIMARY KEY  (`ip`)
    )ENGINE=MyISAM
]]--


local function setReputationSystemInfo(ip, to_player, dates)
    db.executeQuery('REPLACE INTO `reputation_system` (`ip`, `date`, `to_player`) VALUES ("' .. tonumber(ip) .. '", "' .. tonumber(dates) .. '", "' .. tonumber(to_player) .. '");')
    return true
end

local function...
Lua:
        if lastReputation > os.time() then
            local remainTime = lastReputation - os.time()
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have to wait "..convertTime(remainTime).." to add reputation again.")
        end

Keep that code ouside from

Code:
if file_exists(playerIP) then

and never save on scripts, this is a door to dupe items ;D
 
Lua:
        if lastReputation > os.time() then
            local remainTime = lastReputation - os.time()
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have to wait "..convertTime(remainTime).." to add reputation again.")
        end

Keep that code ouside from

Code:
if file_exists(playerIP) then

and never save on scripts, this is a door to dupe items ;D
Could you help me to construct script? There is any other verification to put?
 
I did something similar, but on mysql

  • system checks if player is with active client (IP = 0)
  • checks if the player and the target have different ip

I don't know if in LUA itself it is possible to check if player logs in from vps/proxy


Lua:
--[[ MYSQL
    CREATE TABLE `reputation_system` (
      `ip` int(11) NOT NULL,
      `date` int(11) NOT NULL,
      `to_player` int(10) NOT NULL,
    PRIMARY KEY  (`ip`)
    )ENGINE=MyISAM
]]--


local function setReputationSystemInfo(ip, to_player, dates)
    db.executeQuery('REPLACE INTO `reputation_system` (`ip`, `date`, `to_player`) VALUES ("' .. tonumber(ip) .. '", "' .. tonumber(dates) .. '", "' .. tonumber(to_player) .. '");')
    return true
end

local function getReputationSystemInfo(ip)
    local result = db.getResult("SELECT `date`, `to_player` FROM `reputation_system` WHERE `ip` = '" .. ip .. "' ;")
    return result:getID() ~= -1 and {result:getDataInt('date'), result:getDataInt('to_player')} or {0,0}
end

local config = {
    addPoint = 1,
    storage = 144712,
    blockTime = 24 * 60 * 60, -- 24h
    exhTime = 2, -- sec
    exhCheck = {},
}

local function convertTime(value)
    local text = ""
    if value then
        local time = value
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." hour and "..minutes.." minutes"
        elseif time >= 60 then
            text = minutes.." minutes and "..seconds.." seconds"
        else
            text = seconds.." seconds"
        end
    end
    return text
end


function onSay(cid, words, param, channel)
 -- exh check
    local playerGUID = getPlayerGUID(cid)
    if config.exhCheck[playerGUID] and config.exhCheck[playerGUID] >= os.time() then
        return doPlayerSendCancel(cid, "To fast...")
    end
    config.exhCheck[playerGUID] = os.time()+ config.exhTime
    

    if(param == '') then
        local playerRep = getPlayerStorageValue(cid, config.storage)
        if playerRep < 0 then
            playerRep = 0
        end
        
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You reputation points: ".. playerRep .."\n~ To give reputation points to another player, enter his/her nickname!")
        return true
    end

    local pid = getCreatureByName(param)
    if not pid or not isPlayer(pid) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Player [".. param .."] not found.")
    end

    if cid == pid then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add reputation to yourself.")
    end
    
    local pidIP = getPlayerIp(pid)
    local playerIP = getPlayerIp(cid)
    
    if pidIP == 0 then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player [".. param .."] does not have the client enabled")
    elseif pidIP == playerIP then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Detected the same ip address")
    end
    
    
    local repInfo = getReputationSystemInfo(playerIP)
    if repInfo[1] > 0 then
        if repInfo[1] > os.time() then
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have to wait ".. convertTime(repInfo[1] - os.time()) .." to add reputation again.")
        end
    end

    setReputationSystemInfo(playerIP, getPlayerGUID(pid), os.time() + config.blockTime)

    -- save player to update storages on website
    setPlayerStorageValue(pid, config.storage, math.max(0, tonumber(getPlayerStorageValue(pid, config.storage))) + config.addPoint)
    doPlayerSave(pid)

    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "[" .. getCreatureName(cid) .."] has been sent you +".. config.addPoint .." reputation. | To check points write '".. words .."'")
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have sent +".. config.addPoint .." reputation to ["..getCreatureName(pid).."].")
    return true
end
 
Solution
I did something similar, but on mysql

  • system checks if player is with active client (IP = 0)
  • checks if the player and the target have different ip

I don't know if in LUA itself it is possible to check if player logs in from vps/proxy


Lua:
--[[ MYSQL
    CREATE TABLE `reputation_system` (
      `ip` int(11) NOT NULL,
      `date` int(11) NOT NULL,
      `to_player` int(10) NOT NULL,
    PRIMARY KEY  (`ip`)
    )ENGINE=MyISAM
]]--


local function setReputationSystemInfo(ip, to_player, dates)
    db.executeQuery('REPLACE INTO `reputation_system` (`ip`, `date`, `to_player`) VALUES ("' .. tonumber(ip) .. '", "' .. tonumber(dates) .. '", "' .. tonumber(to_player) .. '");')
    return true
end

local function getReputationSystemInfo(ip)
    local result = db.getResult("SELECT `date`, `to_player` FROM `reputation_system` WHERE `ip` = '" .. ip .. "' ;")
    return result:getID() ~= -1 and {result:getDataInt('date'), result:getDataInt('to_player')} or {0,0}
end

local config = {
    addPoint = 1,
    storage = 144712,
    blockTime = 24 * 60 * 60, -- 24h
    exhTime = 2, -- sec
    exhCheck = {},
}

local function convertTime(value)
    local text = ""
    if value then
        local time = value
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
        if time >= 3600 then
            text = hours.." hour and "..minutes.." minutes"
        elseif time >= 60 then
            text = minutes.." minutes and "..seconds.." seconds"
        else
            text = seconds.." seconds"
        end
    end
    return text
end


function onSay(cid, words, param, channel)
 -- exh check
    local playerGUID = getPlayerGUID(cid)
    if config.exhCheck[playerGUID] and config.exhCheck[playerGUID] >= os.time() then
        return doPlayerSendCancel(cid, "To fast...")
    end
    config.exhCheck[playerGUID] = os.time()+ config.exhTime
   

    if(param == '') then
        local playerRep = getPlayerStorageValue(cid, config.storage)
        if playerRep < 0 then
            playerRep = 0
        end
       
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You reputation points: ".. playerRep .."\n~ To give reputation points to another player, enter his/her nickname!")
        return true
    end

    local pid = getCreatureByName(param)
    if not pid or not isPlayer(pid) then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Player [".. param .."] not found.")
    end

    if cid == pid then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add reputation to yourself.")
    end
   
    local pidIP = getPlayerIp(pid)
    local playerIP = getPlayerIp(cid)
   
    if pidIP == 0 then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player [".. param .."] does not have the client enabled")
    elseif pidIP == playerIP then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Detected the same ip address")
    end
   
   
    local repInfo = getReputationSystemInfo(playerIP)
    if repInfo[1] > 0 then
        if repInfo[1] > os.time() then
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You have to wait ".. convertTime(repInfo[1] - os.time()) .." to add reputation again.")
        end
    end

    setReputationSystemInfo(playerIP, getPlayerGUID(pid), os.time() + config.blockTime)

    -- save player to update storages on website
    setPlayerStorageValue(pid, config.storage, math.max(0, tonumber(getPlayerStorageValue(pid, config.storage))) + config.addPoint)
    doPlayerSave(pid)

    doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "[" .. getCreatureName(cid) .."] has been sent you +".. config.addPoint .." reputation. | To check points write '".. words .."'")
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have sent +".. config.addPoint .." reputation to ["..getCreatureName(pid).."].")
    return true
end
Apparently it works fine, thank you very much. I'll keep an eye out to see if players won't be able to bug the system again.
 
Back
Top