• 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!

TFS 1.X+ banniment system tfs 1.5 7.72

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
928
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
hello guys, would anyone know how to make the bans gradual? for example, first ban 7 days, second ban 14 days, third ban 30 days, 4 ban deleted.
something else, for example
I was banned for 30 days or 7 or 14 but I behaved for 90 days, so if I get banned again my ban would be the initial 7 days.
would anyone know how to do this in ban.cpp?




Lua:
bool Ban::acceptConnection(uint32_t clientIP)
{
    std::lock_guard<std::recursive_mutex> lockClass(lock);


    uint64_t currentTime = OTSYS_TIME();


    auto it = ipConnectMap.find(clientIP);
    if (it == ipConnectMap.end()) {
        ipConnectMap.emplace(clientIP, ConnectBlock(currentTime, 0, 1));
        return true;
    }


    ConnectBlock& connectBlock = it->second;
    if (connectBlock.blockTime > currentTime) {
        connectBlock.blockTime += 250;
        return false;
    }


    int64_t timeDiff = currentTime - connectBlock.lastAttempt;
    connectBlock.lastAttempt = currentTime;
    if (timeDiff <= 5000) {
        if (++connectBlock.count > 5) {
            connectBlock.count = 0;
            if (timeDiff <= 500) {
                connectBlock.blockTime = currentTime + 3000;
                return false;
            }
        }
    } else {
        connectBlock.count = 1;
    }
    return true;
}


bool IOBan::isAccountBanned(uint32_t accountId, BanInfo& banInfo)
{
    Database& db = Database::getInstance();


    DBResult_ptr result = db.storeQuery(fmt::format("SELECT `reason`, `expires_at`, `banned_at`, `banned_by`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `account_bans` WHERE `account_id` = {:d}", accountId));
    if (!result) {
        return false;
    }


    int64_t expiresAt = result->getNumber<int64_t>("expires_at");
    if (expiresAt != 0 && time(nullptr) > expiresAt) {
        // Move the ban to history if it has expired
        g_databaseTasks.addTask(fmt::format("INSERT INTO `account_ban_history` (`account_id`, `reason`, `banned_at`, `expired_at`, `banned_by`) VALUES ({:d}, {:s}, {:d}, {:d}, {:d})", accountId, db.escapeString(result->getString("reason")), result->getNumber<time_t>("banned_at"), expiresAt, result->getNumber<uint32_t>("banned_by")));
        g_databaseTasks.addTask(fmt::format("DELETE FROM `account_bans` WHERE `account_id` = {:d}", accountId));
        return false;
    }


    banInfo.expiresAt = expiresAt;
    banInfo.reason = result->getString("reason");
    banInfo.bannedBy = result->getString("name");
    return true;
}


bool IOBan::isIpBanned(uint32_t clientIP, BanInfo& banInfo)
{
    if (clientIP == 0) {
        return false;
    }


    Database& db = Database::getInstance();


    DBResult_ptr result = db.storeQuery(fmt::format("SELECT `reason`, `expires_at`, (SELECT `name` FROM `players` WHERE `id` = `banned_by`) AS `name` FROM `ip_bans` WHERE `ip` = {:d}", clientIP));
    if (!result) {
        return false;
    }


    int64_t expiresAt = result->getNumber<int64_t>("expires_at");
    if (expiresAt != 0 && time(nullptr) > expiresAt) {
        g_databaseTasks.addTask(fmt::format("DELETE FROM `ip_bans` WHERE `ip` = {:d}", clientIP));
        return false;
    }


    banInfo.expiresAt = expiresAt;
    banInfo.reason = result->getString("reason");
    banInfo.bannedBy = result->getString("name");
    return true;
}


bool IOBan::isPlayerNamelocked(uint32_t playerId)
{
    return Database::getInstance().storeQuery(fmt::format("SELECT 1 FROM `player_namelocks` WHERE `player_id` = {:d}", playerId)).get() != nullptr;
}
 
I think it's better to put a stogarevalue when the player receives the message at the time of banning. if he takes another ban, stogarevalue increases += +1,
then create a Creaturescripts by copying the Remove Murders part in startup.lua and edit it to check if stogarevalue > 1 or 2 or 3.
As the days go by, the value of the stock decreases little by little.
and you can even configure it to be automatically deleted if you pass 4.
 
Back
Top