Jump to content

[fix] Ban deactive system.


Guest Unik2psc

Recommended Posts

Currently bans are removed when we turn on server. During action server bans are not removed.

I tried to correct it. Now - ban are removed when running server

diff --git a/src/realmd/Main.cpp b/src/realmd/Main.cpp
index f019e6d..0d4686e 100644
--- a/src/realmd/Main.cpp
+++ b/src/realmd/Main.cpp
@@ -57,6 +57,9 @@ void HookSignals();

bool stopEvent = false;                                     ///< Setting it to true stops the server

+uint32 m_AccountBanDelay = 0;
+time_t m_AccountBanNext = time(NULL);
+
DatabaseType loginDatabase;                                 ///< Accessor to the realm server database

/// Print out the usage string for this program on the console.
@@ -210,10 +213,8 @@ extern int main(int argc, char **argv)
        return 1;
    }

-    // cleanup query
-    //set expired bans to inactive
-    loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
-    loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+    m_AccountBanDelay = sConfig.GetIntDefault( "AccountBanUpdateDelay", 20);
+    m_AccountBanNext  = time(NULL) + m_AccountBanDelay;

    h.Add(&authListenSocket);

@@ -270,6 +271,14 @@ extern int main(int argc, char **argv)
    ///- Wait for termination signal
    while (!stopEvent)
    {
+        
+        if(m_AccountBanDelay > 0 && m_AccountBanNext < time(NULL)){
+            sLog.outDetail("Delete old account ban...");
+            loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+            loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
+
+            m_AccountBanNext = time(NULL) + m_AccountBanDelay;
+        }

        h.Select(0, 100000);

diff --git a/src/realmd/realmd.conf.dist.in b/src/realmd/realmd.conf.dist.in
index 66335b7..04c88b9 100644
--- a/src/realmd/realmd.conf.dist.in
+++ b/src/realmd/realmd.conf.dist.in
@@ -81,6 +81,12 @@ ConfVersion=2007062001
#        Default: 20
#                 0  (Disabled)
#
+#    AccountBanUpdateDelay
+#        Updating ban (exclusion is not active ban)
+#        Default: 20
+#                 0  (Disabled)
+#
+#
#    WrongPass.MaxCount
#        Number of login attemps with wrong password before the account or IP is banned
#        Default: 0  (Never ban)
@@ -111,6 +117,7 @@ LogColors = ""
UseProcessors = 0
ProcessPriority = 1
RealmsStateUpdateDelay = 20
+AccountBanUpdateDelay = 20
WrongPass.MaxCount = 0
WrongPass.BanTime = 600
WrongPass.BanType = 0

I tested it. Code is working good.

(Github username: Emtec)

Link to comment
Share on other sites

The server is deleting bans only when he is launching, he isn't doing it when he is already running in the meantime. I've changed that ( I have seen it as a must ). A player recently wrote to me that 2 days ago his ban was still present and was not removed

Link to comment
Share on other sites

LordJZ. Yes you are right. Player login > check ban > deactive ban per player.For me I noticed that it was not really working well.

My code doesn't delete ban per player (when he logs on). This code does delete all in-active ban (it needn't player logs on) - form time to time (AccountBanUpdateDelay).

This is my solution. This allows me to maintain order in the list ban.

/// Remove a ban from an account or IP address
bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
{
   if (mode == BAN_IP)
   {
       loginDatabase.escape_string(nameOrIP);
       loginDatabase.PExecute("DELETE FROM ip_banned WHERE ip = '%s'",nameOrIP.c_str());
   }
   else
   {
       uint32 account = 0;
       if (mode == BAN_ACCOUNT)
           account = sAccountMgr.GetId (nameOrIP);
       else if (mode == BAN_CHARACTER)
           account = sObjectMgr.GetPlayerAccountIdByPlayerName (nameOrIP);

       if (!account)
           return false;

       //NO SQL injection as account is uint32
       loginDatabase.PExecute("UPDATE account_banned SET active = '0' WHERE id = '%u'",account);
   }

it need player logs on. (mangosd) - it doesn't delete ban when player not logs on

Realmd - only that I changed (when Server startup )

// cleanup query
   //set expired bans to inactive
   loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
   loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");

It work when startup server.

AuthSocket.cpp

///- If the account is banned, reject the logon attempt
               QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE "
                   "id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)", (*result)[1].GetUInt32());
               if(banresult)

This only used select query. Not update & delete query.

Patch is not bad. Because I changed what it was.

Server does delete all ban when we turn on server, now - for time to time.

Link to comment
Share on other sites

Just look at realmd code:

    QueryResult *result = loginDatabase.PQuery("SELECT unbandate FROM ip_banned WHERE "
   //    permanent                    still banned
       "(unbandate = bandate OR unbandate > UNIX_TIMESTAMP()) AND ip = '%s'", address.c_str());

This query will not select not active IP bans.

                ///- If the account is banned, reject the logon attempt
               QueryResult *banresult = loginDatabase.PQuery("SELECT bandate,unbandate FROM account_banned WHERE "
                   "id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)", (*result)[1].GetUInt32());

This query will not select not active account bans.

And also WorldSocket.cpp code:

    // Re-check account ban (same check as in realmd)
   QueryResult *banresult =
         loginDatabase.PQuery ("SELECT 1 FROM account_banned WHERE id = %u AND active = 1 AND (unbandate > UNIX_TIMESTAMP() OR unbandate = bandate)"
                               "UNION "
                               "SELECT 1 FROM ip_banned WHERE (unbandate = bandate OR unbandate > UNIX_TIMESTAMP()) AND ip = '%s'",
                               id, GetRemoteAddress().c_str());

Should I say more?

You have some failure in another place. If you have some 3rd party scripts using mangos ban system with auth and the ban check fails, then you have to rewrite the queries in your script, not in mangos.

Link to comment
Share on other sites

LordJZ - We do not understand. I do not mean - if someone can come or not. Because it works well. I mean the active column. I mean the active column. Mangos has to change status to active to 0 ( when all in-active ban).

I do not have any errors. Maybe I wrote wrong in the beginning. But in this code there is nothing wrong. I changed what was already in the code.

// cleanup query
   //set expired bans to inactive
   loginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
   loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");

this is default code (startup realmd).

If you apply patch it is run from time to time. (chang column active to 0 - not we can connect to server).

So do not say that something is wrong. Because query has not changed. Only be carried out from time to time.

Query for web should be written based on the active column.Mangos decided that bans are not important.

Sorry if you don't understand me. Mayby, I should write "not remove bans, and changing the column active".

You know. I know - that i can build the web query with dates. But - when something is this column is "active".

A simple query on the side and behind. I realizes - that can be otherwise. But why.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use