fixed: crash on concurrent authorization

This commit is contained in:
2022-11-13 00:20:41 +04:00
parent 6bda468607
commit 3531432758
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -5,7 +5,7 @@ using Ragon.Common;
namespace Ragon.Core; namespace Ragon.Core;
public class AuthorizationManager public class AuthorizationManager
{ {
private Logger _logger = LogManager.GetCurrentClassLogger(); private Logger _logger = LogManager.GetCurrentClassLogger();
private IApplicationHandler _provider; private IApplicationHandler _provider;
@@ -29,12 +29,12 @@ public class AuthorizationManager
{ {
if (_playersByPeers.ContainsKey(peerId)) if (_playersByPeers.ContainsKey(peerId))
{ {
_logger.Warn($"Connection already authorized {peerId}"); _logger.Warn($"Connection already authorized {peerId}");
return; return;
} }
var dispatcher = _gameThread.Dispatcher; var dispatcher = _gameThread.Dispatcher;
_provider.OnAuthorizationRequest(key, name, additionalData.ToArray(), _provider.OnAuthorizationRequest(key, name, additionalData.ToArray(),
(playerId, playerName) => { dispatcher.Dispatch(() => Accepted(peerId, playerId, playerName)); }, (playerId, playerName) => { dispatcher.Dispatch(() => Accepted(peerId, playerId, playerName)); },
(errorCode) => { dispatcher.Dispatch(() => Rejected(peerId, errorCode)); }); (errorCode) => { dispatcher.Dispatch(() => Rejected(peerId, errorCode)); });
@@ -42,6 +42,12 @@ public class AuthorizationManager
public void Accepted(ushort peerId, string playerId, string playerName) public void Accepted(ushort peerId, string playerId, string playerName)
{ {
if (_playersByPeers.ContainsKey(peerId))
{
_logger.Warn($"Connection already authorized {peerId}");
return;
}
_serializer.Clear(); _serializer.Clear();
_serializer.WriteOperation(RagonOperation.AUTHORIZED_SUCCESS); _serializer.WriteOperation(RagonOperation.AUTHORIZED_SUCCESS);
_serializer.WriteString(playerId); _serializer.WriteString(playerId);
+1 -1
View File
@@ -21,7 +21,7 @@ namespace Ragon.Core
public int MaxRooms; public int MaxRooms;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
private static readonly string _serverVersion = "1.0.23-rc"; private static readonly string _serverVersion = "1.0.24-rc";
private static void CopyrightInfo() private static void CopyrightInfo()
{ {