wip
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using Ragon.Core.Game;
|
||||
|
||||
namespace Ragon.Core.Lobby;
|
||||
|
||||
public interface ILobby
|
||||
{
|
||||
public bool FindRoomById(string roomId, out Room room);
|
||||
public bool FindRoomByMap(string map, out Room room);
|
||||
public void Persist(Room room);
|
||||
public void Remove(Room room);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using Ragon.Core.Game;
|
||||
|
||||
namespace Ragon.Core.Lobby;
|
||||
|
||||
public class LobbyInMemory: ILobby
|
||||
{
|
||||
private readonly List<Room> _rooms = new();
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public bool FindRoomById(string roomId, out Room room)
|
||||
{
|
||||
foreach (var existRoom in _rooms)
|
||||
{
|
||||
var info = existRoom.Info;
|
||||
if (existRoom.Id == roomId && info.Min < info.Max)
|
||||
{
|
||||
room = existRoom;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
room = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool FindRoomByMap(string map, out Room room)
|
||||
{
|
||||
foreach (var existRoom in _rooms)
|
||||
{
|
||||
var info = existRoom.Info;
|
||||
if (info.Map == map && existRoom.Players.Count < info.Max)
|
||||
{
|
||||
room = existRoom;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
room = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Persist(Room room)
|
||||
{
|
||||
_rooms.Add(room);
|
||||
|
||||
foreach (var r in _rooms)
|
||||
_logger.Trace($"{r.Id} {r.Info}");
|
||||
}
|
||||
|
||||
public void Remove(Room room)
|
||||
{
|
||||
_rooms.Remove(room);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Ragon.Server;
|
||||
|
||||
namespace Ragon.Core.Lobby;
|
||||
|
||||
public enum LobbyPlayerStatus
|
||||
{
|
||||
Unauthorized,
|
||||
Authorized,
|
||||
}
|
||||
|
||||
public class LobbyPlayer
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; set; }
|
||||
public byte[] AdditionalData { get; set; }
|
||||
public LobbyPlayerStatus Status { get; set; }
|
||||
public INetworkConnection Connection { get; private set; }
|
||||
|
||||
public LobbyPlayer(INetworkConnection connection)
|
||||
{
|
||||
Id = Guid.NewGuid().ToString();
|
||||
Connection = connection;
|
||||
Status = LobbyPlayerStatus.Unauthorized;
|
||||
Name = "None";
|
||||
AdditionalData = Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user