TrinityCore/TrinityCore — Issue #5589: [Core/Logging/Patch] New ability to log account IP access history
Author: Toshik
Created: 2012-03-07 07:41:13+00:00
State: open

This patch adds functionality to log all used IP's of each account on each realm.
It might be useful to track account's IP-relations.
It is enableable by config.

```diff

diff --git a/sql/updates/auth/2012_03_xx_yy_auth_account_ip_history.sql b/sql/updates/auth/2012_03_xx_yy_auth_account_ip_history.sql
new file mode 100644
index 0000000..9ea9e6e
--- /dev/null
+++ b/sql/updates/auth/2012_03_xx_yy_auth_account_ip_history.sql
@@ -0,0 +1,8 @@
+DROP TABLE IF EXISTS `account_ip_history`;
+CREATE TABLE `account_ip_history` (
+ `id` int(11) unsigned NOT NULL,
+ `RealmID` int(11) unsigned NOT NULL,
+ `ip` varchar(30) NOT NULL,
+ `last_access` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (`id`,`RealmID`,`ip`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index 2c6098f..64b0668 100755
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -991,6 +991,30 @@ int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)

LoginDatabase.Execute(stmt);

+ // Log account IP history if enabled
+ if (sWorld->getBoolConfig(CONFIG_IP_LOG_ENABLED))
+ {
+ // Add record to account ip history
+
+ stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_ACCOUNT_IP_HISTORY);
+
+ stmt->setUInt32(0, id);
+ stmt->setUInt32(1, realmID);
+ stmt->setString(2, address);
+
+ LoginDatabase.Execute(stmt);
+
+ // Delete if exists record from account ip history
+
+ stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_IP_HISTORY);
+
+ stmt->setUInt32(0, id);
+ stmt->setUInt32(1, realmID);
+ stmt->setString(2, address);
+
+ LoginDatabase.Execute(stmt);
+ }
+
// NOTE ATM the socket is single-threaded, have this in mind ...
ACE_NEW_RETURN (m_Session, WorldSession (id, this, AccountTypes(security), expansion, mutetime, locale, recruiter, isRecruiter), -1);

diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 57df15a..e12d3b1 100755
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -1186,6 +1186,9 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_CHATLOG_ADDON] = ConfigMgr::GetBoolDefault("ChatLogs.Addon", false);
m_bool_configs[CONFIG_CHATLOG_BGROUND] = ConfigMgr::GetBoolDefault("ChatLogs.Battleground", false);

+ // IP logging
+ m_bool_configs[CONFIG_IP_LOG_ENABLED] = ConfigMgr::GetBoolDefault("IPHistoryLog", true);
+
// Warden
m_bool_configs[CONFIG_WARDEN_ENABLED] = ConfigMgr::GetBoolDefault("Warden.Enabled", false);
m_int_configs[CONFIG_WARDEN_NUM_MEM_CHECKS] = ConfigMgr::GetIntDefault("Warden.NumMemChecks", 3);
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 209ab8d..00da9ef 100755
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -163,6 +163,7 @@ enum WorldBoolConfigs
CONFIG_QUEST_IGNORE_AUTO_ACCEPT,
CONFIG_QUEST_IGNORE_AUTO_COMPLETE,
CONFIG_WARDEN_ENABLED,
+ CONFIG_IP_LOG_ENABLED,
BOOL_CONFIG_VALUE_COUNT
};

diff --git a/src/server/shared/Database/Implementation/LoginDatabase.cpp b/src/server/shared/Database/Implementation/LoginDatabase.cpp
index 415edea..22107b6 100755
--- a/src/server/shared/Database/Implementation/LoginDatabase.cpp
+++ b/src/server/shared/Database/Implementation/LoginDatabase.cpp
@@ -62,4 +62,6 @@ void LoginDatabaseConnection::DoPrepareStatements()
PREPARE_STATEMENT(LOGIN_DEL_ACCOUNT_ACCESS, "DELETE FROM account_access WHERE id = ?", CONNECTION_ASYNC);
PREPARE_STATEMENT(LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM, "DELETE FROM account_access WHERE id = ? AND (RealmID = ? OR RealmID = -1)", CONNECTION_ASYNC);
PREPARE_STATEMENT(LOGIN_INS_ACCOUNT_ACCESS, "INSERT INTO account_access (id,gmlevel,RealmID) VALUES (?, ?, ?)", CONNECTION_ASYNC);
+ PREPARE_STATEMENT(LOGIN_DEL_ACCOUNT_IP_HISTORY, "DELETE FROM account_ip_history WHERE id = ? AND RealmID = ? AND ip = ?", CONNECTION_ASYNC);
+ PREPARE_STATEMENT(LOGIN_INS_ACCOUNT_IP_HISTORY, "INSERT INTO account_ip_history (id,RealmID,ip,last_access) VALUES (?, ?, ?, CURRENT_TIMESTAMP())", CONNECTION_ASYNC);
}
diff --git a/src/server/shared/Database/Implementation/LoginDatabase.h b/src/server/shared/Database/Implementation/LoginDatabase.h
index afb1880..204263d 100755
--- a/src/server/shared/Database/Implementation/LoginDatabase.h
+++ b/src/server/shared/Database/Implementation/LoginDatabase.h
@@ -82,6 +82,8 @@ enum LoginDatabaseStatements
LOGIN_DEL_ACCOUNT_ACCESS,
LOGIN_DEL_ACCOUNT_ACCESS_BY_REALM,
LOGIN_INS_ACCOUNT_ACCESS,
+ LOGIN_DEL_ACCOUNT_IP_HISTORY,
+ LOGIN_INS_ACCOUNT_IP_HISTORY,

MAX_LOGINDATABASE_STATEMENTS,
};
diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist
index ab4a8a8..918ed51 100644
--- a/src/server/worldserver/worldserver.conf.dist
+++ b/src/server/worldserver/worldserver.conf.dist
@@ -790,6 +790,14 @@ ChatLogs.Addon = 0
ChatLogs.BattleGround = 0

#
+# IPHistoryLog
+# Description: Log account IP access history.
+# 0 - (Disabled)
+# Default: 1 - (Enabled)
+
+IPHistoryLog = 1
+
+#
###################################################################################################

###################################################################################################