feat: Added logs_ip_action + more (#1157)

This commit is contained in:
Nefertumm
2019-02-08 19:52:22 -03:00
committed by Francesco Borzì
parent 6750fd5a73
commit 2a71b2a666
19 changed files with 564 additions and 45 deletions

View File

@@ -90,7 +90,7 @@ struct ClientPktHeader
#pragma pack(pop)
#endif
WorldSocket::WorldSocket (void): WorldHandler(),
WorldSocket::WorldSocket(void): WorldHandler(),
m_LastPingTime(ACE_Time_Value::zero), m_OverSpeedPings(0), m_Session(0),
m_RecvWPct(0), m_RecvPct(), m_Header(sizeof (ClientPktHeader)),
m_OutBuffer(0), m_OutBufferSize(65536), m_OutActive(false),
@@ -102,7 +102,7 @@ m_Seed(static_cast<uint32> (rand32()))
msg_queue()->low_water_mark(8*1024*1024);
}
WorldSocket::~WorldSocket (void)
WorldSocket::~WorldSocket(void)
{
delete m_RecvWPct;
@@ -114,12 +114,12 @@ WorldSocket::~WorldSocket (void)
peer().close();
}
bool WorldSocket::IsClosed (void) const
bool WorldSocket::IsClosed(void) const
{
return closing_;
}
void WorldSocket::CloseSocket (void)
void WorldSocket::CloseSocket(void)
{
{
ACE_GUARD (LockType, Guard, m_OutBufferLock);
@@ -138,7 +138,7 @@ void WorldSocket::CloseSocket (void)
}
}
const std::string& WorldSocket::GetRemoteAddress (void) const
const std::string& WorldSocket::GetRemoteAddress(void) const
{
return m_Address;
}
@@ -190,17 +190,17 @@ int WorldSocket::SendPacket(WorldPacket const& pct)
return 0;
}
long WorldSocket::AddReference (void)
long WorldSocket::AddReference(void)
{
return static_cast<long> (add_reference());
}
long WorldSocket::RemoveReference (void)
long WorldSocket::RemoveReference(void)
{
return static_cast<long> (remove_reference());
}
int WorldSocket::open (void *a)
int WorldSocket::open(void *a)
{
ACE_UNUSED_ARG (a);
@@ -259,7 +259,7 @@ int WorldSocket::open (void *a)
return 0;
}
int WorldSocket::close (u_long)
int WorldSocket::close(u_long)
{
shutdown();
@@ -270,7 +270,7 @@ int WorldSocket::close (u_long)
return 0;
}
int WorldSocket::handle_input (ACE_HANDLE)
int WorldSocket::handle_input(ACE_HANDLE)
{
if (closing_)
return -1;
@@ -310,7 +310,7 @@ int WorldSocket::handle_input (ACE_HANDLE)
ACE_NOTREACHED(return -1);
}
int WorldSocket::handle_output (ACE_HANDLE)
int WorldSocket::handle_output(ACE_HANDLE)
{
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
@@ -356,7 +356,7 @@ int WorldSocket::handle_output (ACE_HANDLE)
ACE_NOTREACHED (return 0);
}
int WorldSocket::handle_output_queue (GuardType& g)
int WorldSocket::handle_output_queue(GuardType& g)
{
if (msg_queue()->is_empty())
return cancel_wakeup_output(g);
@@ -417,7 +417,7 @@ int WorldSocket::handle_output_queue (GuardType& g)
ACE_NOTREACHED(return -1);
}
int WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
int WorldSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
{
// Critical section
{
@@ -440,7 +440,7 @@ int WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
return 0;
}
int WorldSocket::Update (void)
int WorldSocket::Update(void)
{
if (closing_)
return -1;
@@ -462,7 +462,7 @@ int WorldSocket::Update (void)
return ret;
}
int WorldSocket::handle_input_header (void)
int WorldSocket::handle_input_header(void)
{
ACE_ASSERT (m_RecvWPct == NULL);
@@ -501,7 +501,7 @@ int WorldSocket::handle_input_header (void)
return 0;
}
int WorldSocket::handle_input_payload (void)
int WorldSocket::handle_input_payload(void)
{
// set errno properly here on error !!!
// now have a header and payload
@@ -524,7 +524,7 @@ int WorldSocket::handle_input_payload (void)
return ret;
}
int WorldSocket::handle_input_missing_data (void)
int WorldSocket::handle_input_missing_data(void)
{
char buf [4096];
@@ -613,7 +613,7 @@ int WorldSocket::handle_input_missing_data (void)
return size_t(n) == recv_size ? 1 : 2;
}
int WorldSocket::cancel_wakeup_output (GuardType& g)
int WorldSocket::cancel_wakeup_output(GuardType& g)
{
if (!m_OutActive)
return 0;
@@ -633,7 +633,7 @@ int WorldSocket::cancel_wakeup_output (GuardType& g)
return 0;
}
int WorldSocket::schedule_wakeup_output (GuardType& g)
int WorldSocket::schedule_wakeup_output(GuardType& g)
{
if (m_OutActive)
return 0;
@@ -741,6 +741,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
WorldPacket packet, SendAddonPacked;
BigNumber k;
bool wardenActive = sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED);
if (sWorld->IsClosed())
{
@@ -779,6 +780,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// Stop if the account is not found
if (!result)
{
// We can not log here, as we do not know the account. Thus, no accountId.
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
packet << uint8 (AUTH_UNKNOWN_ACCOUNT);
@@ -795,21 +797,37 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
if (expansion > world_expansion)
expansion = world_expansion;
// For hook purposes, we get Remoteaddress at this point
std::string address = GetRemoteAddress(); // Originally, this variable should be called address, but for some reason, that variable name was already on the core.
// As we don't know if attempted login process by ip works, we update last_attempt_ip right away
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_ATTEMPT_IP);
stmt->setString(0, address);
stmt->setString(1, account);
LoginDatabase.Execute(stmt);
// This also allows to check for possible "hack" attempts on account
// id has to be fetched at this point, so that first actual account response that fails can be logged
id = fields[0].GetUInt32();
///- Re-check ip locking (same check as in realmd).
if (fields[3].GetUInt8() == 1) // if ip is locked
{
if (strcmp (fields[2].GetCString(), GetRemoteAddress().c_str()))
if (strcmp (fields[2].GetCString(), address.c_str()))
{
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
packet << uint8 (AUTH_FAILED);
SendPacket(packet);
sLog->outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs).");
sLog->outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: %s, new IP: %s).", fields[2].GetCString(), address.c_str());
// We could log on hook only instead of an additional db log, however action logger is config based. Better keep DB logging as well
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
}
id = fields[0].GetUInt32();
/*
if (security > SEC_ADMINISTRATOR) // prevent invalid security settings in DB
security = SEC_ADMINISTRATOR;
@@ -840,13 +858,13 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
TotalTime = fields[10].GetUInt32();
// Must be done before WorldSession is created
if (sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED) && os != "Win" && os != "OSX")
if (wardenActive && os != "Win" && os != "OSX")
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(AUTH_REJECT);
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", GetRemoteAddress().c_str(), os.c_str());
sLog->outError("WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", address.c_str(), os.c_str());
return -1;
}
@@ -871,7 +889,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BANS);
stmt->setUInt32(0, id);
stmt->setString(1, GetRemoteAddress());
stmt->setString(1, address);
PreparedQueryResult banresult = LoginDatabase.Query(stmt);
@@ -882,6 +900,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -900,6 +919,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDetail("WorldSocket::HandleAuthSession: User tries to login but his security level is not enough");
#endif
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -914,8 +934,6 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
sha.UpdateBigNumbers (&k, NULL);
sha.Finalize();
std::string address = GetRemoteAddress();
if (memcmp (sha.GetDigest(), digest, 20))
{
packet.Initialize (SMSG_AUTH_RESPONSE, 1);
@@ -943,8 +961,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
if (result)
isRecruiter = true;
// Update the last_ip in the database
// Update the last_ip in the database as it was successful for login
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_IP);
stmt->setString(0, address);
@@ -965,6 +982,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendPacket(packet);
sLog->outError("WorldSocket::HandleAuthSession: World closed, denying client (%s).", address.c_str());
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -976,6 +994,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
sLog->outError("WorldSocket::HandleAuthSession: Client %s requested connecting with realm id %u but this realm has id %u set in config.",
address.c_str(), realm, realmID);
sScriptMgr->OnFailedAccountLogin(id);
return -1;
}
@@ -983,8 +1002,11 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
m_Session->LoadTutorialsData();
m_Session->ReadAddonsInfo(recvPacket);
// At this point, we can safely hook a successful login
sScriptMgr->OnAccountLogin(id);
// Initialize Warden system only if it is enabled by config
if (sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
if (wardenActive)
m_Session->InitWarden(&k, os);
// Sleep this Network thread for
@@ -996,7 +1018,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
return 0;
}
int WorldSocket::HandlePing (WorldPacket& recvPacket)
int WorldSocket::HandlePing(WorldPacket& recvPacket)
{
uint32 ping;
uint32 latency;
@@ -1022,7 +1044,7 @@ int WorldSocket::HandlePing (WorldPacket& recvPacket)
if (max_count && m_OverSpeedPings > max_count)
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);
if (m_Session && AccountMgr::IsPlayerAccount(m_Session->GetSecurity()))
{
@@ -1043,7 +1065,7 @@ int WorldSocket::HandlePing (WorldPacket& recvPacket)
// critical section
{
ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);
if (m_Session)
{