aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2016-03-13 00:12:09 +0100
committerShauren <shauren.trinity@gmail.com>2016-03-13 00:12:09 +0100
commit5a6db6e84d98949ad511d8fe66752cb0c7d6e6d7 (patch)
tree9340bb221e3536de19d9a747f819f0af5a0ba819 /src
parent811b29c8e1ebdd0e12a2a3eb7c9586b04d7f5e62 (diff)
Core/Misc: Minimize differences between branches in WorldSession::Update
This commit removes OnUnknownPacketReceive script hook - it could never be fired anyway at that point
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp11
-rw-r--r--src/server/game/Scripting/ScriptMgr.h5
-rw-r--r--src/server/game/Server/WorldSession.cpp171
3 files changed, 80 insertions, 107 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index cbf2dde2887..bc43ee10f3d 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -507,17 +507,6 @@ void ScriptMgr::OnPacketSend(WorldSession* session, WorldPacket const& packet)
FOREACH_SCRIPT(ServerScript)->OnPacketSend(session, copy);
}
-void ScriptMgr::OnUnknownPacketReceive(WorldSession* session, WorldPacket const& packet)
-{
- ASSERT(session);
-
- if (SCR_REG_LST(ServerScript).empty())
- return;
-
- WorldPacket copy(packet);
- FOREACH_SCRIPT(ServerScript)->OnUnknownPacketReceive(session, copy);
-}
-
void ScriptMgr::OnOpenStateChange(bool open)
{
FOREACH_SCRIPT(WorldScript)->OnOpenStateChange(open);
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index 750298eec86..905513da896 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -229,10 +229,6 @@ class ServerScript : public ScriptObject
// Called when a (valid) packet is received by a client. The packet object is a copy of the original packet, so
// reading and modifying it is safe. Make sure to check WorldSession pointer before usage, it might be null in case of auth packets
virtual void OnPacketReceive(WorldSession* /*session*/, WorldPacket& /*packet*/) { }
-
- // Called when an invalid (unknown opcode) packet is received by a client. The packet is a reference to the orignal
- // packet; not a copy. This allows you to actually handle unknown packets (for whatever purpose).
- virtual void OnUnknownPacketReceive(WorldSession* /*session*/, WorldPacket& /*packet*/) { }
};
class WorldScript : public ScriptObject
@@ -886,7 +882,6 @@ class ScriptMgr
void OnSocketClose(std::shared_ptr<WorldSocket> socket);
void OnPacketReceive(WorldSession* session, WorldPacket const& packet);
void OnPacketSend(WorldSession* session, WorldPacket const& packet);
- void OnUnknownPacketReceive(WorldSession* session, WorldPacket const& packet);
public: /* WorldScript */
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index 457c8619ae6..0a3562e8f3d 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -278,104 +278,93 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
while (m_Socket && _recvQueue.next(packet, updater))
{
- if (packet->GetOpcode() >= NUM_MSG_TYPES)
+ OpcodeHandler const& opHandle = opcodeTable[packet->GetOpcode()];
+ try
{
- TC_LOG_ERROR("network.opcode", "Received non-existed opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
- , GetPlayerInfo().c_str());
- sScriptMgr->OnUnknownPacketReceive(this, *packet);
- }
- else
- {
- OpcodeHandler& opHandle = opcodeTable[packet->GetOpcode()];
- try
+ switch (opHandle.status)
{
- switch (opHandle.status)
- {
- case STATUS_LOGGEDIN:
- if (!_player)
+ case STATUS_LOGGEDIN:
+ if (!_player)
+ {
+ // skip STATUS_LOGGEDIN opcode unexpected errors if player logout sometime ago - this can be network lag delayed packets
+ //! If player didn't log out a while ago, it means packets are being sent while the server does not recognize
+ //! the client to be in world yet. We will re-add the packets to the bottom of the queue and process them later.
+ if (!m_playerRecentlyLogout)
{
- // skip STATUS_LOGGEDIN opcode unexpected errors if player logout sometime ago - this can be network lag delayed packets
- //! If player didn't log out a while ago, it means packets are being sent while the server does not recognize
- //! the client to be in world yet. We will re-add the packets to the bottom of the queue and process them later.
- if (!m_playerRecentlyLogout)
- {
- requeuePackets.push_back(packet);
- deletePacket = false;
- QueuePacket(packet);
- //! Log
- TC_LOG_DEBUG("network", "Re-enqueueing packet with opcode %s with with status STATUS_LOGGEDIN. "
- "Player is currently not in world yet.", GetOpcodeNameForLogging(packet->GetOpcode()).c_str());
- }
+ requeuePackets.push_back(packet);
+ deletePacket = false;
+ TC_LOG_DEBUG("network", "Re-enqueueing packet with opcode %s with with status STATUS_LOGGEDIN. "
+ "Player is currently not in world yet.", GetOpcodeNameForLogging(packet->GetOpcode()).c_str());
}
- else if (_player->IsInWorld() && AntiDOS.EvaluateOpcode(*packet, currentTime))
- {
- sScriptMgr->OnPacketReceive(this, *packet);
- (this->*opHandle.handler)(*packet);
- LogUnprocessedTail(packet);
- }
- // lag can cause STATUS_LOGGEDIN opcodes to arrive after the player started a transfer
+ }
+ else if (_player->IsInWorld() && AntiDOS.EvaluateOpcode(*packet, currentTime))
+ {
+ sScriptMgr->OnPacketReceive(this, *packet);
+ (this->*opHandle.handler)(*packet);
+ LogUnprocessedTail(packet);
+ }
+ // lag can cause STATUS_LOGGEDIN opcodes to arrive after the player started a transfer
+ break;
+ case STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT:
+ if (!_player && !m_playerRecentlyLogout && !m_playerLogout) // There's a short delay between _player = null and m_playerRecentlyLogout = true during logout
+ LogUnexpectedOpcode(packet, "STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT",
+ "the player has not logged in yet and not recently logout");
+ else if (AntiDOS.EvaluateOpcode(*packet, currentTime))
+ {
+ // not expected _player or must checked in packet hanlder
+ sScriptMgr->OnPacketReceive(this, *packet);
+ (this->*opHandle.handler)(*packet);
+ LogUnprocessedTail(packet);
+ }
+ break;
+ case STATUS_TRANSFER:
+ if (!_player)
+ LogUnexpectedOpcode(packet, "STATUS_TRANSFER", "the player has not logged in yet");
+ else if (_player->IsInWorld())
+ LogUnexpectedOpcode(packet, "STATUS_TRANSFER", "the player is still in world");
+ else if(AntiDOS.EvaluateOpcode(*packet, currentTime))
+ {
+ sScriptMgr->OnPacketReceive(this, *packet);
+ (this->*opHandle.handler)(*packet);
+ LogUnprocessedTail(packet);
+ }
+ break;
+ case STATUS_AUTHED:
+ // prevent cheating with skip queue wait
+ if (m_inQueue)
+ {
+ LogUnexpectedOpcode(packet, "STATUS_AUTHED", "the player not pass queue yet");
break;
- case STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT:
- if (!_player && !m_playerRecentlyLogout && !m_playerLogout) // There's a short delay between _player = null and m_playerRecentlyLogout = true during logout
- LogUnexpectedOpcode(packet, "STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT",
- "the player has not logged in yet and not recently logout");
- else if (AntiDOS.EvaluateOpcode(*packet, currentTime))
- {
- // not expected _player or must checked in packet handler
- sScriptMgr->OnPacketReceive(this, *packet);
- (this->*opHandle.handler)(*packet);
- LogUnprocessedTail(packet);
- }
- break;
- case STATUS_TRANSFER:
- if (!_player)
- LogUnexpectedOpcode(packet, "STATUS_TRANSFER", "the player has not logged in yet");
- else if (_player->IsInWorld())
- LogUnexpectedOpcode(packet, "STATUS_TRANSFER", "the player is still in world");
- else if (AntiDOS.EvaluateOpcode(*packet, currentTime))
- {
- sScriptMgr->OnPacketReceive(this, *packet);
- (this->*opHandle.handler)(*packet);
- LogUnprocessedTail(packet);
- }
- break;
- case STATUS_AUTHED:
- // prevent cheating with skip queue wait
- if (m_inQueue)
- {
- LogUnexpectedOpcode(packet, "STATUS_AUTHED", "the player not pass queue yet");
- break;
- }
-
- // some auth opcodes can be recieved before STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT opcodes
- // however when we recieve CMSG_CHAR_ENUM we are surely no longer during the logout process.
- if (packet->GetOpcode() == CMSG_CHAR_ENUM)
- m_playerRecentlyLogout = false;
-
- if (AntiDOS.EvaluateOpcode(*packet, currentTime))
- {
- sScriptMgr->OnPacketReceive(this, *packet);
- (this->*opHandle.handler)(*packet);
- LogUnprocessedTail(packet);
- }
- break;
- case STATUS_NEVER:
- TC_LOG_ERROR("network.opcode", "Received not allowed opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
- , GetPlayerInfo().c_str());
- break;
- case STATUS_UNHANDLED:
- TC_LOG_DEBUG("network.opcode", "Received not handled opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
- , GetPlayerInfo().c_str());
- break;
- }
- }
- catch (ByteBufferException const&)
- {
- TC_LOG_ERROR("misc", "WorldSession::Update ByteBufferException occured while parsing a packet (opcode: %u) from client %s, accountid=%i. Skipped packet.",
- packet->GetOpcode(), GetRemoteAddress().c_str(), GetAccountId());
- packet->hexlike();
+ }
+
+ // some auth opcodes can be recieved before STATUS_LOGGEDIN_OR_RECENTLY_LOGGOUT opcodes
+ // however when we recieve CMSG_CHAR_ENUM we are surely no longer during the logout process.
+ if (packet->GetOpcode() == CMSG_CHAR_ENUM)
+ m_playerRecentlyLogout = false;
+
+ if (AntiDOS.EvaluateOpcode(*packet, currentTime))
+ {
+ sScriptMgr->OnPacketReceive(this, *packet);
+ (this->*opHandle.handler)(*packet);
+ LogUnprocessedTail(packet);
+ }
+ break;
+ case STATUS_NEVER:
+ TC_LOG_ERROR("network.opcode", "Received not allowed opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
+ , GetPlayerInfo().c_str());
+ break;
+ case STATUS_UNHANDLED:
+ TC_LOG_ERROR("network.opcode", "Received not handled opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str()
+ , GetPlayerInfo().c_str());
+ break;
}
}
+ catch (ByteBufferException const&)
+ {
+ TC_LOG_ERROR("network", "WorldSession::Update ByteBufferException occured while parsing a packet (opcode: %u) from client %s, accountid=%i. Skipped packet.",
+ packet->GetOpcode(), GetRemoteAddress().c_str(), GetAccountId());
+ packet->hexlike();
+ }
if (deletePacket)
delete packet;