Core/Battle.net: Handle ConnectionClosing

This commit is contained in:
Shauren
2014-10-11 22:45:01 +02:00
parent 26e4b67e85
commit cbabfe9920
15 changed files with 172 additions and 64 deletions

View File

@@ -50,7 +50,7 @@ std::string Battlenet::Authentication::LogonRequest::ToString() const
return stream.str();
}
void Battlenet::Authentication::LogonRequest::CallHandler(Session* session) const
void Battlenet::Authentication::LogonRequest::CallHandler(Session* session)
{
session->HandleLogonRequest(*this);
}
@@ -89,7 +89,7 @@ std::string Battlenet::Authentication::ResumeRequest::ToString() const
return stream.str();
}
void Battlenet::Authentication::ResumeRequest::CallHandler(Session* session) const
void Battlenet::Authentication::ResumeRequest::CallHandler(Session* session)
{
session->HandleResumeRequest(*this);
}
@@ -153,7 +153,7 @@ std::string Battlenet::Authentication::ProofResponse::ToString() const
return stream.str();
}
void Battlenet::Authentication::ProofResponse::CallHandler(Session* session) const
void Battlenet::Authentication::ProofResponse::CallHandler(Session* session)
{
session->HandleProofResponse(*this);
}

View File

@@ -49,7 +49,7 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
std::string Program;
std::string Platform;
@@ -68,7 +68,7 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
std::string Program;
std::string Platform;
@@ -91,23 +91,11 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
std::vector<BitStream*> Modules;
};
class ProofRequest final : public ServerPacket
{
public:
ProofRequest() : ServerPacket(PacketHeader(SMSG_PROOF_REQUEST, AUTHENTICATION)) { }
~ProofRequest();
void Write() override;
std::string ToString() const override;
std::vector<ModuleInfo*> Modules;
};
class ResponseFailure
{
public:
@@ -192,6 +180,18 @@ namespace Battlenet
int32 PingTimeout;
Regulator RegulatorRules;
};
class ProofRequest final : public ServerPacket
{
public:
ProofRequest() : ServerPacket(PacketHeader(SMSG_PROOF_REQUEST, AUTHENTICATION)) { }
~ProofRequest();
void Write() override;
std::string ToString() const override;
std::vector<ModuleInfo*> Modules;
};
}
}

View File

@@ -23,7 +23,7 @@ std::string Battlenet::Connection::Ping::ToString() const
return "Battlenet::Connection::Ping";
}
void Battlenet::Connection::Ping::CallHandler(Session* session) const
void Battlenet::Connection::Ping::CallHandler(Session* session)
{
session->HandlePing(*this);
}
@@ -33,7 +33,7 @@ std::string Battlenet::Connection::EnableEncryption::ToString() const
return "Battlenet::Connection::EnableEncryption";
}
void Battlenet::Connection::EnableEncryption::CallHandler(Session* session) const
void Battlenet::Connection::EnableEncryption::CallHandler(Session* session)
{
session->HandleEnableEncryption(*this);
}
@@ -43,11 +43,65 @@ std::string Battlenet::Connection::LogoutRequest::ToString() const
return "Battlenet::Connection::LogoutRequest";
}
void Battlenet::Connection::LogoutRequest::CallHandler(Session* session) const
void Battlenet::Connection::LogoutRequest::CallHandler(Session* session)
{
session->HandleLogoutRequest(*this);
}
void Battlenet::Connection::DisconnectRequest::Read()
{
Timeout = _stream.Read<uint16>(16);
Tick = _stream.Read<uint32>(32);
}
std::string Battlenet::Connection::DisconnectRequest::ToString() const
{
std::ostringstream str;
str << "Battlenet::Connection::DisconnectRequest Timeout: " << Timeout << ", Tick: " << Tick;
return str.str();
}
void Battlenet::Connection::ConnectionClosing::Read()
{
Reason = _stream.Read<ClosingReason>(4);
if (_stream.Read<bool>(1)) // HasHeader
{
Header.Opcode = _stream.Read<uint32>(6);
if (_stream.Read<bool>(1))
Header.Channel = _stream.Read<int32>(4);
}
Now = _stream.Read<time_t>(32);
_stream.Read<uint32>(25);
auto bytes = _stream.ReadBytes(_stream.Read<uint8>(8)); // BadData
Packets.resize(_stream.Read<uint8>(6));
for (size_t i = 0; i < Packets.size(); ++i)
{
PacketInfo& info = Packets[i];
info.CommandName = _stream.ReadFourCC();
info.LayerId = _stream.Read<uint32>(16);
info.Channel = _stream.ReadFourCC();
info.Timestamp = _stream.Read<uint32>(32);
info.Size = _stream.Read<uint32>(16);
}
}
std::string Battlenet::Connection::ConnectionClosing::ToString() const
{
std::ostringstream stream;
stream << "Battlenet::Connection::ConnectionClosing Reason: " << Reason << ", Now: " << Now << ", Packet history size: " << Packets.size();
for (PacketInfo const& packet : Packets)
stream << std::endl << "Battlenet::Connection::ConnectionClosing::PacketInfo LayerId: " << packet.LayerId
<< ", Channel: " << packet.Channel << ", CommandName: " << packet.CommandName << ", Size: " << packet.Size << ", Timestamp: " << packet.Timestamp;
return stream.str();
}
void Battlenet::Connection::ConnectionClosing::CallHandler(Session* session)
{
session->HandleConnectionClosing(*this);
}
std::string Battlenet::Connection::Pong::ToString() const
{
return "Battlenet::Connection::Pong";

View File

@@ -29,8 +29,8 @@ namespace Battlenet
CMSG_PING = 0x0,
CMSG_ENABLE_ENCRYPTION = 0x5,
CMSG_LOGOUT_REQUEST = 0x6,
CMSG_DISCONNECT_REQUEST = 0x7, // Not implemented
CMSG_CONNECTION_CLOSING = 0x9, // Not implemented
CMSG_DISCONNECT_REQUEST = 0x7, // Not handled
CMSG_CONNECTION_CLOSING = 0x9,
SMSG_PONG = 0x0,
SMSG_BOOM = 0x1, // Not implemented
@@ -49,7 +49,7 @@ namespace Battlenet
void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
};
class EnableEncryption final : public ClientPacket
@@ -62,7 +62,7 @@ namespace Battlenet
void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
};
class LogoutRequest final : public ClientPacket
@@ -75,7 +75,66 @@ namespace Battlenet
void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
};
class DisconnectRequest final : public ClientPacket
{
public:
DisconnectRequest(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_DISCONNECT_REQUEST, CONNECTION) && "Invalid packet header for DisconnectRequest");
}
void Read() override;
std::string ToString() const override;
uint16 Timeout;
uint32 Tick;
};
class ConnectionClosing final : public ClientPacket
{
public:
enum ClosingReason
{
PACKET_TOO_LARGE,
PACKET_CORRUPT,
PACKET_INVALID,
PACKET_INCORRECT,
HEADER_CORRUPT,
HEADER_IGNORED,
HEADER_INCORRECT,
PACKET_REJECTED,
CHANNEL_UNHANDLED,
COMMAND_UNHANDLED,
COMMAND_BAD_PERMISSIONS,
DIRECT_CALL,
TIMEOUT,
};
struct PacketInfo
{
uint16 LayerId;
std::string Channel;
uint32 Timestamp;
std::string CommandName;
uint16 Size;
};
ConnectionClosing(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_CONNECTION_CLOSING, CONNECTION) && "Invalid packet header for ConnectionClosing");
}
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) override;
PacketHeader Header;
ClosingReason Reason;
std::vector<PacketInfo> Packets;
time_t Now;
};
class Pong final : public ServerPacket

View File

@@ -28,7 +28,7 @@ std::string Battlenet::Friends::SocialNetworkCheckConnected::ToString() const
return "Battlenet::Friends::SocialNetworkCheckConnected SocialNetworkId " + std::to_string(SocialNetworkId);
}
void Battlenet::Friends::SocialNetworkCheckConnected::CallHandler(Session* session) const
void Battlenet::Friends::SocialNetworkCheckConnected::CallHandler(Session* session)
{
session->HandleSocialNetworkCheckConnected(*this);
}
@@ -47,11 +47,6 @@ std::string Battlenet::Friends::SocialNetworkConnect::ToString() const
return "Battlenet::Friends::SocialNetworkConnect";
}
void Battlenet::Friends::SocialNetworkConnect::CallHandler(Session* session) const
{
session->LogUnhandledPacket(*this);
}
std::string Battlenet::Friends::SocialNetworkConnectResult::ToString() const
{
return "Battlenet::Friends::SocialNetworkConnectResult";
@@ -84,11 +79,6 @@ std::string Battlenet::Friends::GetFriendsOfFriend::ToString() const
return "Battlenet::Friends::GetFriendsOfFriend";
}
void Battlenet::Friends::GetFriendsOfFriend::CallHandler(Session* session) const
{
session->LogUnhandledPacket(*this);
}
void Battlenet::Friends::RealIdFriendInvite::Read()
{
_stream.Read<uint32>(32);
@@ -139,7 +129,7 @@ std::string Battlenet::Friends::RealIdFriendInvite::ToString() const
return "Battlenet::Friends::RealIdFriendInvite Mail: " + Email + " Message: " + Message;
}
void Battlenet::Friends::RealIdFriendInvite::CallHandler(Session* session) const
void Battlenet::Friends::RealIdFriendInvite::CallHandler(Session* session)
{
FriendInviteResult* result = new FriendInviteResult();
session->AsyncWrite(result);

View File

@@ -59,12 +59,11 @@ namespace Battlenet
public:
SocialNetworkConnect(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)
{
ASSERT(header == PacketHeader(CMSG_SOCIAL_NETWORK_CONNECT, FRIENDS) && "Invalid packet header for SocialnetworkConnect");
ASSERT(header == PacketHeader(CMSG_SOCIAL_NETWORK_CONNECT, FRIENDS) && "Invalid packet header for SocialNetworkConnect");
}
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
};
class SocialNetworkConnectResult final : public ServerPacket
@@ -88,7 +87,7 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
uint32 SocialNetworkId;
};
@@ -117,7 +116,6 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
};
class FriendsOfFriend final : public ServerPacket
@@ -141,7 +139,7 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
std::string Email;
std::string Message;

View File

@@ -55,6 +55,8 @@ namespace Battlenet
_creators[PacketHeader(Connection::CMSG_PING, CONNECTION)] = &New<Connection::Ping>;
_creators[PacketHeader(Connection::CMSG_ENABLE_ENCRYPTION, CONNECTION)] = &New<Connection::EnableEncryption>;
_creators[PacketHeader(Connection::CMSG_LOGOUT_REQUEST, CONNECTION)] = &New<Connection::LogoutRequest>;
_creators[PacketHeader(Connection::CMSG_DISCONNECT_REQUEST, CONNECTION)] = &New<Connection::DisconnectRequest>;
_creators[PacketHeader(Connection::CMSG_CONNECTION_CLOSING, CONNECTION)] = &New<Connection::ConnectionClosing>;
_creators[PacketHeader(WoWRealm::CMSG_LIST_SUBSCRIBE_REQUEST, WOWREALM)] = &New<WoWRealm::ListSubscribeRequest>;
_creators[PacketHeader(WoWRealm::CMSG_LIST_UNSUBSCRIBE, WOWREALM)] = &New<WoWRealm::ListUnsubscribe>;

View File

@@ -36,3 +36,9 @@ Battlenet::ServerPacket::~ServerPacket()
{
delete &_stream;
}
void Battlenet::ClientPacket::CallHandler(Session* session)
{
session->LogUnhandledPacket(*this);
_handled = false;
}

View File

@@ -97,10 +97,14 @@ namespace Battlenet
class ClientPacket : public Packet
{
public:
ClientPacket(PacketHeader const& header, BitStream& stream) : Packet(header, stream) { }
ClientPacket(PacketHeader const& header, BitStream& stream) : Packet(header, stream), _handled(true) { }
void Write() override final { ASSERT(!"Write not implemented for this packet."); }
virtual void CallHandler(Session* session) const = 0;
virtual void CallHandler(Session* session);
bool WasHandled() const { return _handled; }
private:
bool _handled;
};
class ServerPacket : public Packet

View File

@@ -28,11 +28,6 @@ std::string Battlenet::Presence::UpdateRequest::ToString() const
return "Battlenet::Presence::UpdateRequest";
}
void Battlenet::Presence::UpdateRequest::CallHandler(Session* session) const
{
session->LogUnhandledPacket(*this);
}
void Battlenet::Presence::StatisticSubscribe::Read()
{
}
@@ -41,8 +36,3 @@ std::string Battlenet::Presence::StatisticSubscribe::ToString() const
{
return "Battlenet::Presence::StatisticSubscribe";
}
void Battlenet::Presence::StatisticSubscribe::CallHandler(Session* session) const
{
session->LogUnhandledPacket(*this);
}

View File

@@ -44,7 +44,6 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
};
class StatisticSubscribe final : public ClientPacket
@@ -57,7 +56,6 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
};
}
}

View File

@@ -25,7 +25,7 @@ std::string Battlenet::WoWRealm::ListSubscribeRequest::ToString() const
return "Battlenet::WoWRealm::ListSubscribeRequest";
}
void Battlenet::WoWRealm::ListSubscribeRequest::CallHandler(Session* session) const
void Battlenet::WoWRealm::ListSubscribeRequest::CallHandler(Session* session)
{
session->HandleListSubscribeRequest(*this);
}
@@ -35,7 +35,7 @@ std::string Battlenet::WoWRealm::ListUnsubscribe::ToString() const
return "Battlenet::WoWRealm::ListUnsubscribe";
}
void Battlenet::WoWRealm::ListUnsubscribe::CallHandler(Session* session) const
void Battlenet::WoWRealm::ListUnsubscribe::CallHandler(Session* session)
{
session->HandleListUnsubscribe(*this);
}
@@ -152,7 +152,7 @@ std::string Battlenet::WoWRealm::JoinRequestV2::ToString() const
return stream.str().c_str();
}
void Battlenet::WoWRealm::JoinRequestV2::CallHandler(Session* session) const
void Battlenet::WoWRealm::JoinRequestV2::CallHandler(Session* session)
{
session->HandleJoinRequestV2(*this);
}

View File

@@ -50,7 +50,7 @@ namespace Battlenet
void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
};
class ListUnsubscribe final : public ClientPacket
@@ -63,7 +63,7 @@ namespace Battlenet
void Read() override { }
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
};
class JoinRequestV2 final : public ClientPacket
@@ -76,7 +76,7 @@ namespace Battlenet
void Read() override;
std::string ToString() const override;
void CallHandler(Session* session) const override;
void CallHandler(Session* session) override;
uint32 ClientSeed;
RealmId Realm;

View File

@@ -396,6 +396,10 @@ void Battlenet::Session::HandleLogoutRequest(Connection::LogoutRequest const& /*
LoginDatabase.Execute(stmt);
}
void Battlenet::Session::HandleConnectionClosing(Connection::ConnectionClosing const& /*connectionClosing*/)
{
}
void Battlenet::Session::HandleListSubscribeRequest(WoWRealm::ListSubscribeRequest const& /*listSubscribeRequest*/)
{
WoWRealm::ListSubscribeResponse* listSubscribeResponse = new WoWRealm::ListSubscribeResponse();
@@ -497,8 +501,10 @@ void Battlenet::Session::ReadHandler()
if (ClientPacket* packet = sPacketFactory.Create(header, stream))
{
TC_LOG_TRACE("server.battlenet", "Battlenet::Session::ReadDataHandler %s", packet->ToString().c_str());
packet->CallHandler(this);
if (packet->WasHandled())
TC_LOG_TRACE("server.battlenet", "Battlenet::Session::ReadDataHandler %s", packet->ToString().c_str());
delete packet;
}
else

View File

@@ -71,6 +71,7 @@ namespace Battlenet
void HandlePing(Connection::Ping const& ping);
void HandleEnableEncryption(Connection::EnableEncryption const& enableEncryption);
void HandleLogoutRequest(Connection::LogoutRequest const& logoutRequest);
void HandleConnectionClosing(Connection::ConnectionClosing const& connectionClosing);
// WoWRealm
void HandleListSubscribeRequest(WoWRealm::ListSubscribeRequest const& listSubscribeRequest);