refactor: added error message on creation or joining to room
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NetStack.Serialization;
|
using NetStack.Serialization;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ragon.Common;
|
using Ragon.Common;
|
||||||
@@ -13,12 +14,14 @@ public class Lobby : ILobby
|
|||||||
private readonly BitBuffer _buffer;
|
private readonly BitBuffer _buffer;
|
||||||
private readonly RoomManager _roomManager;
|
private readonly RoomManager _roomManager;
|
||||||
private readonly AuthorizationManager _authorizationManager;
|
private readonly AuthorizationManager _authorizationManager;
|
||||||
|
private readonly IGameThread _gameThread;
|
||||||
|
|
||||||
public AuthorizationManager AuthorizationManager => _authorizationManager;
|
public AuthorizationManager AuthorizationManager => _authorizationManager;
|
||||||
|
|
||||||
public Lobby(IAuthorizationProvider provider, RoomManager manager, IGameThread gameThread)
|
public Lobby(IAuthorizationProvider provider, RoomManager manager, IGameThread gameThread)
|
||||||
{
|
{
|
||||||
_roomManager = manager;
|
_roomManager = manager;
|
||||||
|
_gameThread = gameThread;
|
||||||
_buffer = new BitBuffer();
|
_buffer = new BitBuffer();
|
||||||
_serializer = new RagonSerializer();
|
_serializer = new RagonSerializer();
|
||||||
_authorizationManager = new AuthorizationManager(provider, gameThread, this, _serializer);
|
_authorizationManager = new AuthorizationManager(provider, gameThread, this, _serializer);
|
||||||
@@ -50,6 +53,17 @@ public class Lobby : ILobby
|
|||||||
case RagonOperation.JOIN_ROOM:
|
case RagonOperation.JOIN_ROOM:
|
||||||
{
|
{
|
||||||
var roomId = _serializer.ReadString();
|
var roomId = _serializer.ReadString();
|
||||||
|
roomId = _serializer.ReadString();
|
||||||
|
var exists = _roomManager.Rooms.Any(r => r.Id == roomId);
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
_serializer.Clear();
|
||||||
|
_serializer.WriteOperation(RagonOperation.JOIN_FAILED);
|
||||||
|
_serializer.WriteString($"Room with id {roomId} not exists");
|
||||||
|
var sendData = _serializer.ToArray();
|
||||||
|
_gameThread.Server.Send(peerId, sendData, DeliveryType.Reliable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_roomManager.RoomsBySocket.ContainsKey(peerId))
|
if (_roomManager.RoomsBySocket.ContainsKey(peerId))
|
||||||
_roomManager.Left(player, Array.Empty<byte>());
|
_roomManager.Left(player, Array.Empty<byte>());
|
||||||
@@ -62,7 +76,20 @@ public class Lobby : ILobby
|
|||||||
var roomId = Guid.NewGuid().ToString();
|
var roomId = Guid.NewGuid().ToString();
|
||||||
var custom = _serializer.ReadBool();
|
var custom = _serializer.ReadBool();
|
||||||
if (custom)
|
if (custom)
|
||||||
|
{
|
||||||
roomId = _serializer.ReadString();
|
roomId = _serializer.ReadString();
|
||||||
|
var exists = _roomManager.Rooms.Any(r => r.Id == roomId);
|
||||||
|
if (exists)
|
||||||
|
{
|
||||||
|
_serializer.Clear();
|
||||||
|
_serializer.WriteOperation(RagonOperation.JOIN_FAILED);
|
||||||
|
_serializer.WriteString($"Room with id {roomId} already exists");
|
||||||
|
|
||||||
|
var sendData = _serializer.ToArray();
|
||||||
|
_gameThread.Server.Send(peerId, sendData, DeliveryType.Reliable);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var propertiesPayload = _serializer.ReadData(_serializer.Size);
|
var propertiesPayload = _serializer.ReadData(_serializer.Size);
|
||||||
_buffer.Clear();
|
_buffer.Clear();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class RoomManager
|
|||||||
private readonly IGameThread _gameThread;
|
private readonly IGameThread _gameThread;
|
||||||
private readonly PluginFactory _factory;
|
private readonly PluginFactory _factory;
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
private readonly List<GameRoom> _rooms = new List<GameRoom>();
|
private readonly List<GameRoom> _rooms = new();
|
||||||
private readonly Dictionary<uint, GameRoom> _roomsBySocket;
|
private readonly Dictionary<uint, GameRoom> _roomsBySocket;
|
||||||
|
|
||||||
public IReadOnlyDictionary<uint, GameRoom> RoomsBySocket => _roomsBySocket;
|
public IReadOnlyDictionary<uint, GameRoom> RoomsBySocket => _roomsBySocket;
|
||||||
@@ -83,7 +83,7 @@ public class RoomManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Trace($"Player ({player.PlayerName}|{player.Id}) create room with Id {roomId} and params ({map}|{min}|{max})");
|
_logger.Trace($"Room not found for Player ({player.PlayerName}|{player.Id}), create room with Id {roomId} and params ({map}|{min}|{max})");
|
||||||
|
|
||||||
var plugin = _factory.CreatePlugin(map);
|
var plugin = _factory.CreatePlugin(map);
|
||||||
if (plugin == null)
|
if (plugin == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user