Core/World: Move linking instance socket to WorldSession

Port From (https://github.com/TrinityCore/TrinityCore/commit/cb837ce926d6a8c13d5f74faea246fea19db91d0)
This commit is contained in:
Hondacrx
2025-08-13 22:11:58 -04:00
parent 442e7dcde2
commit 4463e85ed9
2 changed files with 25 additions and 29 deletions
+17 -2
View File
@@ -373,6 +373,23 @@ namespace Game
return true;
}
public static void AddInstanceConnection(WorldSession session, WorldSocket socket, ConnectToKey key)
{
if (socket == null || !socket.IsOpen())
return;
if (session == null || session.GetConnectToInstanceKey() != key.Raw)
{
socket.SendAuthResponseError(BattlenetRpcErrorCode.TimedOut);
socket.CloseSocket();
return;
}
socket.SetWorldSession(session);
session.m_Socket[(int)ConnectionType.Instance] = socket;
session.HandleContinuePlayerLogin();
}
public void QueuePacket(WorldPacket packet)
{
_recvQueue.Enqueue(packet);
@@ -411,8 +428,6 @@ namespace Game
m_Socket[(int)conIdx].SendPacket(packet);
}
public void AddInstanceConnection(WorldSocket sock) { m_Socket[(int)ConnectionType.Instance] = sock; }
public void KickPlayer(string reason)
{
Log.outInfo(LogFilter.Network, $"Account: {GetAccountId()} Character: '{(_player != null ? _player.GetName() : "<none>")}' {(_player != null ? _player.GetGUID() : "")} kicked with reason: {reason}");
+8 -27
View File
@@ -187,7 +187,7 @@ namespace Game
public void AddInstanceSocket(WorldSocket sock, ulong connectToKey)
{
_linkSocketQueue.Enqueue(Tuple.Create(sock, connectToKey));
_linkSocketQueue.Enqueue((sock, connectToKey));
}
void AddSession_(WorldSession s)
@@ -261,27 +261,6 @@ namespace Game
}
}
void ProcessLinkInstanceSocket(Tuple<WorldSocket, ulong> linkInfo)
{
if (!linkInfo.Item1.IsOpen())
return;
ConnectToKey key = new();
key.Raw = linkInfo.Item2;
WorldSession session = FindSession(key.AccountId);
if (session == null || session.GetConnectToInstanceKey() != linkInfo.Item2)
{
linkInfo.Item1.SendAuthResponseError(BattlenetRpcErrorCode.TimedOut);
linkInfo.Item1.CloseSocket();
return;
}
linkInfo.Item1.SetWorldSession(session);
session.AddInstanceConnection(linkInfo.Item1);
session.HandleContinuePlayerLogin();
}
bool HasRecentlyDisconnected(WorldSession session)
{
if (session == null)
@@ -1980,15 +1959,17 @@ namespace Game
public void UpdateSessions(uint diff)
{
Tuple<WorldSocket, ulong> linkInfo;
while (_linkSocketQueue.TryDequeue(out linkInfo))
ProcessLinkInstanceSocket(linkInfo);
// Add new sessions
WorldSession sess;
while (addSessQueue.TryDequeue(out sess))
AddSession_(sess);
while (_linkSocketQueue.TryDequeue(out (WorldSocket, ulong) linkInfo))
{
ConnectToKey key = new() { Raw = linkInfo.Item2 };
WorldSession.AddInstanceConnection(FindSession(key.AccountId), linkInfo.Item1, key);
}
// Then send an update signal to remaining ones
foreach (var pair in m_sessions)
{
@@ -2629,7 +2610,7 @@ namespace Game
List<WorldSession> m_QueuedPlayer = new();
ConcurrentQueue<WorldSession> addSessQueue = new();
ConcurrentQueue<Tuple<WorldSocket, ulong>> _linkSocketQueue = new();
ConcurrentQueue<(WorldSocket, ulong)> _linkSocketQueue = new();
AsyncCallbackProcessor<QueryCallback> _queryProcessor = new();