mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-13 03:32:28 -04:00
Core/World: Move linking instance socket to WorldSession
This commit is contained in:
@@ -296,6 +296,24 @@ void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/
|
||||
m_Socket[conIdx]->SendPacket(*packet);
|
||||
}
|
||||
|
||||
void WorldSession::AddInstanceConnection(WorldSession* session, std::weak_ptr<WorldSocket> sockRef, ConnectToKey key)
|
||||
{
|
||||
std::shared_ptr<WorldSocket> socket = sockRef.lock();
|
||||
if (!socket || !socket->IsOpen())
|
||||
return;
|
||||
|
||||
if (!session || session->GetConnectToInstanceKey() != key.Raw)
|
||||
{
|
||||
socket->SendAuthResponseError(ERROR_TIMED_OUT);
|
||||
socket->DelayedCloseSocket();
|
||||
return;
|
||||
}
|
||||
|
||||
socket->SetWorldSession(session);
|
||||
session->m_Socket[CONNECTION_TYPE_INSTANCE] = std::move(socket);
|
||||
session->HandleContinuePlayerLogin();
|
||||
}
|
||||
|
||||
/// Add an incoming packet to the queue
|
||||
void WorldSession::QueuePacket(WorldPacket* new_packet)
|
||||
{
|
||||
|
||||
@@ -989,7 +989,6 @@ class TC_GAME_API WorldSession
|
||||
bool IsAddonRegistered(std::string_view prefix) const;
|
||||
|
||||
void SendPacket(WorldPacket const* packet, bool forced = false);
|
||||
void AddInstanceConnection(std::shared_ptr<WorldSocket> sock) { m_Socket[CONNECTION_TYPE_INSTANCE] = sock; }
|
||||
|
||||
void SendNotification(char const* format, ...) ATTR_PRINTF(2, 3);
|
||||
void SendNotification(uint32 stringId, ...);
|
||||
@@ -1888,6 +1887,7 @@ class TC_GAME_API WorldSession
|
||||
};
|
||||
|
||||
uint64 GetConnectToInstanceKey() const { return _instanceConnectKey.Raw; }
|
||||
static void AddInstanceConnection(WorldSession* session, std::weak_ptr<WorldSocket> sockRef, ConnectToKey key);
|
||||
|
||||
public:
|
||||
QueryCallbackProcessor& GetQueryProcessor() { return _queryProcessor; }
|
||||
|
||||
@@ -105,7 +105,6 @@
|
||||
#include "WeatherMgr.h"
|
||||
#include "WhoListStorage.h"
|
||||
#include "WorldSession.h"
|
||||
#include "WorldSocket.h"
|
||||
#include "WorldStateMgr.h"
|
||||
#include <zlib.h>
|
||||
|
||||
@@ -432,30 +431,6 @@ void World::AddSession_(WorldSession* s)
|
||||
}
|
||||
}
|
||||
|
||||
void World::ProcessLinkInstanceSocket(std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo)
|
||||
{
|
||||
if (std::shared_ptr<WorldSocket> sock = linkInfo.first.lock())
|
||||
{
|
||||
if (!sock->IsOpen())
|
||||
return;
|
||||
|
||||
WorldSession::ConnectToKey key;
|
||||
key.Raw = linkInfo.second;
|
||||
|
||||
WorldSession* session = FindSession(uint32(key.Fields.AccountId));
|
||||
if (!session || session->GetConnectToInstanceKey() != linkInfo.second)
|
||||
{
|
||||
sock->SendAuthResponseError(ERROR_TIMED_OUT);
|
||||
sock->DelayedCloseSocket();
|
||||
return;
|
||||
}
|
||||
|
||||
sock->SetWorldSession(session);
|
||||
session->AddInstanceConnection(sock);
|
||||
session->HandleContinuePlayerLogin();
|
||||
}
|
||||
}
|
||||
|
||||
bool World::HasRecentlyDisconnected(WorldSession* session)
|
||||
{
|
||||
if (!session)
|
||||
@@ -2983,10 +2958,6 @@ void World::SendServerMessage(ServerMessageType messageID, std::string_view stri
|
||||
|
||||
void World::UpdateSessions(uint32 diff)
|
||||
{
|
||||
std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo;
|
||||
while (_linkSocketQueue.next(linkInfo))
|
||||
ProcessLinkInstanceSocket(std::move(linkInfo));
|
||||
|
||||
{
|
||||
TC_METRIC_DETAILED_NO_THRESHOLD_TIMER("world_update_time",
|
||||
TC_METRIC_TAG("type", "Add sessions"),
|
||||
@@ -2997,6 +2968,15 @@ void World::UpdateSessions(uint32 diff)
|
||||
AddSession_(sess);
|
||||
}
|
||||
|
||||
{
|
||||
std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo;
|
||||
while (_linkSocketQueue.next(linkInfo))
|
||||
{
|
||||
WorldSession::ConnectToKey key = { .Raw = linkInfo.second };
|
||||
WorldSession::AddInstanceConnection(FindSession(key.Fields.AccountId), linkInfo.first, key);
|
||||
}
|
||||
}
|
||||
|
||||
///- Then send an update signal to remaining ones
|
||||
for (SessionMap::iterator itr = m_sessions.begin(), next; itr != m_sessions.end(); itr = next)
|
||||
{
|
||||
|
||||
@@ -863,7 +863,6 @@ class TC_GAME_API World
|
||||
void AddSession_(WorldSession* s);
|
||||
LockedQueue<WorldSession*> addSessQueue;
|
||||
|
||||
void ProcessLinkInstanceSocket(std::pair<std::weak_ptr<WorldSocket>, uint64> linkInfo);
|
||||
LockedQueue<std::pair<std::weak_ptr<WorldSocket>, uint64>> _linkSocketQueue;
|
||||
|
||||
// used versions
|
||||
|
||||
Reference in New Issue
Block a user