From 4463e85ed91c1080e43fcccecb11c1c71a273d6f Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Wed, 13 Aug 2025 22:11:58 -0400 Subject: [PATCH] Core/World: Move linking instance socket to WorldSession Port From (https://github.com/TrinityCore/TrinityCore/commit/cb837ce926d6a8c13d5f74faea246fea19db91d0) --- Source/Game/Server/WorldSession.cs | 19 ++++++++++++++-- Source/Game/World/WorldManager.cs | 35 +++++++----------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Source/Game/Server/WorldSession.cs b/Source/Game/Server/WorldSession.cs index cff2668d6..d90a0df60 100644 --- a/Source/Game/Server/WorldSession.cs +++ b/Source/Game/Server/WorldSession.cs @@ -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() : "")}' {(_player != null ? _player.GetGUID() : "")} kicked with reason: {reason}"); diff --git a/Source/Game/World/WorldManager.cs b/Source/Game/World/WorldManager.cs index 2b15e6e15..87e9e8e0b 100644 --- a/Source/Game/World/WorldManager.cs +++ b/Source/Game/World/WorldManager.cs @@ -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 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 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 m_QueuedPlayer = new(); ConcurrentQueue addSessQueue = new(); - ConcurrentQueue> _linkSocketQueue = new(); + ConcurrentQueue<(WorldSocket, ulong)> _linkSocketQueue = new(); AsyncCallbackProcessor _queryProcessor = new();