From 5fc55eaddc17ecec22346884bed47bba584266b3 Mon Sep 17 00:00:00 2001 From: edmand45 Date: Sun, 30 Jul 2023 21:14:14 +0300 Subject: [PATCH] wip --- Ragon.Client.Simulation/Sources/Game.cs | 46 ++++++++++--------- .../Sources/Handler/JoinSuccessHandler.cs | 7 +-- .../Sources/Handler/LoadSceneHandler.cs | 3 +- .../Sources/Handler/SnapshotHandler.cs | 5 +- .../Sources/Listener/IRagonListener.cs | 3 +- ...evelListener.cs => IRagonSceneListener.cs} | 4 +- .../Listener/IRagonSceneRequestListener.cs | 6 +++ Ragon.Client/Sources/RagonClient.cs | 4 +- Ragon.Client/Sources/RagonListenerList.cs | 37 +++++++++++---- Ragon.Client/Sources/RagonRoom.cs | 8 +++- Ragon.Client/Sources/RagonScene.cs | 15 ++++-- Ragon.Client/Sources/RagonSession.cs | 12 ++--- Ragon.Protocol/Sources/RagonRoomParameters.cs | 6 +-- .../Sources/Handler/RoomCreateOperation.cs | 6 +-- .../Sources/Handler/RoomJoinOperation.cs | 2 +- .../Handler/RoomJoinOrCreateOperation.cs | 8 ++-- .../Sources/Handler/SceneLoadOperation.cs | 2 +- Ragon.Server/Sources/Lobby/IRagonLobby.cs | 2 +- .../Sources/Lobby/RagonLobbyInMemory.cs | 8 ++-- Ragon.Server/Sources/Room/RagonRoom.cs | 16 +++---- .../Sources/Room/RagonRoomInformation.cs | 2 +- 21 files changed, 124 insertions(+), 78 deletions(-) rename Ragon.Client/Sources/Listener/{IRagonLevelListener.cs => IRagonSceneListener.cs} (87%) create mode 100644 Ragon.Client/Sources/Listener/IRagonSceneRequestListener.cs diff --git a/Ragon.Client.Simulation/Sources/Game.cs b/Ragon.Client.Simulation/Sources/Game.cs index a785029..0eb7ecb 100644 --- a/Ragon.Client.Simulation/Sources/Game.cs +++ b/Ragon.Client.Simulation/Sources/Game.cs @@ -4,7 +4,7 @@ using Ragon.Protocol; namespace Ragon.Client.Simulation; -public class Game : IRagonListener +public class Game : IRagonListener, IRagonSceneRequestListener { private RagonFloat _health; private RagonInt _points; @@ -36,23 +36,7 @@ public class Game : IRagonListener public void OnJoined(RagonClient client) { - RagonLog.Trace("Joined"); - - _health = new RagonFloat(100.0f, false, 0); - _health.Changed += () => Console.WriteLine($"[Ragon Property] Health: {_health.Value}"); - - _points = new RagonInt(0, -1000, 1000, false, 0); - _points.Changed += () => Console.WriteLine($"[Ragon Property] Points: {_points.Value}"); - - _name = new RagonString("Edmand 000", false); - _name.Changed += () => Console.WriteLine($"[Ragon Property] Name: {_name.Value}"); - - _entity = new RagonEntity(12, 0); - _entity.State.AddProperty(_health); - _entity.State.AddProperty(_points); - _entity.State.AddProperty(_name); - - client.Room.CreateEntity(_entity); + } public void OnFailed(RagonClient client, string message) @@ -85,11 +69,25 @@ public class Game : IRagonListener RagonLog.Trace("Owner ship changed"); } - public void OnLevel(RagonClient client, string sceneName) + public void OnSceneLoaded(RagonClient client) { - RagonLog.Trace($"New level: {sceneName}"); + RagonLog.Trace("Joined"); - client.Room.SceneLoaded(); + _health = new RagonFloat(100.0f, false, 0); + _health.Changed += () => Console.WriteLine($"[Ragon Property] Health: {_health.Value}"); + + _points = new RagonInt(0, -1000, 1000, false, 0); + _points.Changed += () => Console.WriteLine($"[Ragon Property] Points: {_points.Value}"); + + _name = new RagonString("Edmand 000", false); + _name.Changed += () => Console.WriteLine($"[Ragon Property] Name: {_name.Value}"); + + _entity = new RagonEntity(12, 0); + _entity.State.AddProperty(_health); + _entity.State.AddProperty(_points); + _entity.State.AddProperty(_name); + + client.Room.CreateEntity(_entity); } private float _timer = 0; @@ -109,4 +107,10 @@ public class Game : IRagonListener _timer = 0; } } + + public void OnRequestScene(RagonClient client, string sceneName) + { + client.Room.SceneLoaded(); + + } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs b/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs index 1ad67b5..5aaf3dc 100644 --- a/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs +++ b/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs @@ -67,14 +67,15 @@ internal class JoinSuccessHandler : Handler var ownerId = buffer.ReadString(); var min = buffer.ReadUShort(); var max = buffer.ReadUShort(); - var map = buffer.ReadString(); + var sceneName = buffer.ReadString(); - var scene = new RagonScene(_client, _playerCache, _entityCache); + var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName); var roomInfo = new RagonRoomInformation(roomId, localId, ownerId, min, max); var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene); _playerCache.SetOwnerAndLocal(ownerId, localId); _client.AssignRoom(room); - _listenerList.OnLevel(map); + + _listenerList.OnSceneRequest(sceneName); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/LoadSceneHandler.cs b/Ragon.Client/Sources/Handler/LoadSceneHandler.cs index 1479275..2f13925 100644 --- a/Ragon.Client/Sources/Handler/LoadSceneHandler.cs +++ b/Ragon.Client/Sources/Handler/LoadSceneHandler.cs @@ -38,7 +38,8 @@ internal class SceneLoadHandler: Handler var room = _client.Room; room.Cleanup(); + room.Update(sceneName); - _listenerList.OnLevel(sceneName); + _listenerList.OnSceneRequest(sceneName); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/SnapshotHandler.cs b/Ragon.Client/Sources/Handler/SnapshotHandler.cs index a9d46c7..eb3d52d 100644 --- a/Ragon.Client/Sources/Handler/SnapshotHandler.cs +++ b/Ragon.Client/Sources/Handler/SnapshotHandler.cs @@ -117,6 +117,9 @@ internal class SnapshotHandler : Handler entity.Attach(_client, entityId, entityType, hasAuthority, player); } - _listenerList.OnJoined(); + if (_client.Status != RagonStatus.ROOM) + _listenerList.OnJoined(); + + _listenerList.OnSceneLoaded(); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Listener/IRagonListener.cs b/Ragon.Client/Sources/Listener/IRagonListener.cs index d5f9c0d..8b55a16 100644 --- a/Ragon.Client/Sources/Listener/IRagonListener.cs +++ b/Ragon.Client/Sources/Listener/IRagonListener.cs @@ -22,10 +22,11 @@ namespace Ragon.Client IRagonFailedListener, IRagonJoinListener, IRagonLeftListener, - IRagonLevelListener, + IRagonSceneListener, IRagonOwnershipChangedListener, IRagonPlayerJoinListener, IRagonPlayerLeftListener { + } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Listener/IRagonLevelListener.cs b/Ragon.Client/Sources/Listener/IRagonSceneListener.cs similarity index 87% rename from Ragon.Client/Sources/Listener/IRagonLevelListener.cs rename to Ragon.Client/Sources/Listener/IRagonSceneListener.cs index f527caa..f81d5de 100644 --- a/Ragon.Client/Sources/Listener/IRagonLevelListener.cs +++ b/Ragon.Client/Sources/Listener/IRagonSceneListener.cs @@ -16,7 +16,7 @@ namespace Ragon.Client; -public interface IRagonLevelListener +public interface IRagonSceneListener { - void OnLevel(RagonClient client, string sceneName); + void OnSceneLoaded(RagonClient client); } \ No newline at end of file diff --git a/Ragon.Client/Sources/Listener/IRagonSceneRequestListener.cs b/Ragon.Client/Sources/Listener/IRagonSceneRequestListener.cs new file mode 100644 index 0000000..3ae6040 --- /dev/null +++ b/Ragon.Client/Sources/Listener/IRagonSceneRequestListener.cs @@ -0,0 +1,6 @@ +namespace Ragon.Client; + +public interface IRagonSceneRequestListener +{ + void OnRequestScene(RagonClient client, string sceneName); +} \ No newline at end of file diff --git a/Ragon.Client/Sources/RagonClient.cs b/Ragon.Client/Sources/RagonClient.cs index 655c9b0..7dc6086 100644 --- a/Ragon.Client/Sources/RagonClient.cs +++ b/Ragon.Client/Sources/RagonClient.cs @@ -162,7 +162,7 @@ namespace Ragon.Client public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener); public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener); public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener); - public void AddListener(IRagonLevelListener listener) => _listenerList.Add(listener); + public void AddListener(IRagonSceneListener listener) => _listenerList.Add(listener); public void AddListener(IRagonOwnershipChangedListener listener) => _listenerList.Add(listener); public void AddListener(IRagonPlayerJoinListener listener) => _listenerList.Add(listener); public void AddListener(IRagonPlayerLeftListener listener) => _listenerList.Add(listener); @@ -173,7 +173,7 @@ namespace Ragon.Client public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener); - public void RemoveListener(IRagonLevelListener listener) => _listenerList.Remove(listener); + public void RemoveListener(IRagonSceneListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonOwnershipChangedListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonPlayerJoinListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonPlayerLeftListener listener) => _listenerList.Remove(listener); diff --git a/Ragon.Client/Sources/RagonListenerList.cs b/Ragon.Client/Sources/RagonListenerList.cs index f3ebe16..c03455d 100644 --- a/Ragon.Client/Sources/RagonListenerList.cs +++ b/Ragon.Client/Sources/RagonListenerList.cs @@ -26,7 +26,8 @@ namespace Ragon.Client private readonly List _failedListeners = new(); private readonly List _joinListeners = new(); private readonly List _leftListeners = new(); - private readonly List _levelListeners = new(); + private readonly List _sceneListeners = new(); + private readonly List _sceneRequestListeners = new(); private readonly List _ownershipChangedListeners = new(); private readonly List _playerJoinListeners = new(); private readonly List _playerLeftListeners = new(); @@ -44,7 +45,7 @@ namespace Ragon.Client _failedListeners.Add(listener); _joinListeners.Add(listener); _leftListeners.Add(listener); - _levelListeners.Add(listener); + _sceneListeners.Add(listener); _ownershipChangedListeners.Add(listener); _playerJoinListeners.Add(listener); _playerLeftListeners.Add(listener); @@ -59,7 +60,7 @@ namespace Ragon.Client _failedListeners.Remove(listener); _joinListeners.Remove(listener); _leftListeners.Remove(listener); - _levelListeners.Remove(listener); + _sceneListeners.Remove(listener); _ownershipChangedListeners.Remove(listener); _playerJoinListeners.Remove(listener); _playerLeftListeners.Remove(listener); @@ -80,6 +81,11 @@ namespace Ragon.Client _authorizationListeners.Add(listener); } + public void Add(IRagonSceneRequestListener listener) + { + _sceneRequestListeners.Add(listener); + } + public void Add(IRagonConnectionListener listener) { _connectionListeners.Add(listener); @@ -100,9 +106,9 @@ namespace Ragon.Client _leftListeners.Add(listener); } - public void Add(IRagonLevelListener listener) + public void Add(IRagonSceneListener listener) { - _levelListeners.Add(listener); + _sceneListeners.Add(listener); } public void Add(IRagonOwnershipChangedListener listener) @@ -120,6 +126,11 @@ namespace Ragon.Client _playerLeftListeners.Add(listener); } + public void Remove(IRagonSceneRequestListener listener) + { + _delayedActions.Add(() => _sceneRequestListeners.Remove(listener)); + } + public void Remove(IRagonAuthorizationListener listener) { _delayedActions.Add(() => _authorizationListeners.Remove(listener)); @@ -146,9 +157,9 @@ namespace Ragon.Client _delayedActions.Add(() => _leftListeners.Remove(listener)); } - public void Remove(IRagonLevelListener listener) + public void Remove(IRagonSceneListener listener) { - _delayedActions.Add(() => _levelListeners.Remove(listener)); + _delayedActions.Add(() => _sceneListeners.Remove(listener)); } public void Remove(IRagonOwnershipChangedListener listener) @@ -208,10 +219,16 @@ namespace Ragon.Client listener.OnPlayerJoined(_client, player); } - public void OnLevel(string sceneName) + public void OnSceneLoaded() { - foreach (var listener in _levelListeners) - listener.OnLevel(_client, sceneName); + foreach (var listener in _sceneListeners) + listener.OnSceneLoaded(_client); + } + + public void OnSceneRequest(string sceneName) + { + foreach (var listener in _sceneRequestListeners) + listener.OnRequestScene(_client, sceneName); } public void OnJoined() diff --git a/Ragon.Client/Sources/RagonRoom.cs b/Ragon.Client/Sources/RagonRoom.cs index cd00af9..ca9fd6b 100644 --- a/Ragon.Client/Sources/RagonRoom.cs +++ b/Ragon.Client/Sources/RagonRoom.cs @@ -27,6 +27,7 @@ namespace Ragon.Client public string Id => _information.RoomId; public int MinPlayers => _information.Min; public int MaxPlayers => _information.Max; + public string Scene => _scene.Name; public IReadOnlyList Players => _playerCache.Players; public RagonPlayer Local => _playerCache.Local; @@ -51,7 +52,12 @@ namespace Ragon.Client _playerCache.Cleanup(); } - public void LoadScene(string map) => _scene.Load(map); + internal void Update(string sceneName) + { + _scene.Update(sceneName); + } + + public void LoadScene(string sceneName) => _scene.Load(sceneName); public void SceneLoaded() => _scene.SceneLoaded(); public void CreateEntity(RagonEntity entity) => CreateEntity(entity, null); diff --git a/Ragon.Client/Sources/RagonScene.cs b/Ragon.Client/Sources/RagonScene.cs index 38ccab3..fdeee30 100644 --- a/Ragon.Client/Sources/RagonScene.cs +++ b/Ragon.Client/Sources/RagonScene.cs @@ -20,24 +20,33 @@ namespace Ragon.Client; public class RagonScene { + public string Name { get; private set; } + private readonly RagonClient _client; private readonly RagonEntityCache _entityCache; private readonly RagonPlayerCache _playerCache; - public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache) + public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache, string sceneName) { + Name = sceneName; + _client = client; _playerCache = playerCache; _entityCache = entityCache; } - internal void Load(string map) + internal void Update(string scene) + { + Name = scene; + } + + internal void Load(string sceneName) { var buffer = _client.Buffer; buffer.Clear(); buffer.WriteOperation(RagonOperation.LOAD_SCENE); - buffer.WriteString(map); + buffer.WriteString(sceneName); var sendData = buffer.ToArray(); _client.Reliable.Send(sendData); diff --git a/Ragon.Client/Sources/RagonSession.cs b/Ragon.Client/Sources/RagonSession.cs index fba61ae..44e13a7 100644 --- a/Ragon.Client/Sources/RagonSession.cs +++ b/Ragon.Client/Sources/RagonSession.cs @@ -29,9 +29,9 @@ namespace Ragon.Client _buffer = buffer; } - public void CreateOrJoin(string map, int minPlayers, int maxPlayers) + public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers) { - var parameters = new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}; + var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}; CreateOrJoin(parameters); } @@ -46,14 +46,14 @@ namespace Ragon.Client _client.Reliable.Send(sendData); } - public void Create(string map, int minPlayers, int maxPlayers) + public void Create(string sceneName, int minPlayers, int maxPlayers) { - Create(null, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}); + Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}); } - public void Create(string roomId, string map, int minPlayers, int maxPlayers) + public void Create(string roomId, string sceneNa, int minPlayers, int maxPlayers) { - Create(roomId, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}); + Create(roomId, new RagonRoomParameters() {Scene = sceneNa, Min = minPlayers, Max = maxPlayers}); } public void Create(string roomId, RagonRoomParameters parameters) diff --git a/Ragon.Protocol/Sources/RagonRoomParameters.cs b/Ragon.Protocol/Sources/RagonRoomParameters.cs index f219809..b205173 100644 --- a/Ragon.Protocol/Sources/RagonRoomParameters.cs +++ b/Ragon.Protocol/Sources/RagonRoomParameters.cs @@ -19,20 +19,20 @@ namespace Ragon.Protocol { public class RagonRoomParameters: IRagonSerializable { - public string Map { get; set; } + public string Scene { get; set; } public int Min { get; set; } public int Max { get; set; } public void Serialize(RagonBuffer buffer) { - buffer.WriteString(Map); + buffer.WriteString(Scene); buffer.WriteInt(Min, 1, 32); buffer.WriteInt(Max, 1, 32); } public void Deserialize(RagonBuffer buffer) { - Map = buffer.ReadString(); + Scene = buffer.ReadString(); Min = buffer.ReadInt(1, 32); Max = buffer.ReadInt(1, 32); } diff --git a/Ragon.Server/Sources/Handler/RoomCreateOperation.cs b/Ragon.Server/Sources/Handler/RoomCreateOperation.cs index 011edd5..c36c18b 100644 --- a/Ragon.Server/Sources/Handler/RoomCreateOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomCreateOperation.cs @@ -68,7 +68,7 @@ public sealed class RoomCreateOperation: IRagonOperation var information = new RoomInformation() { - Map = _roomParameters.Map, + Scene = _roomParameters.Scene, Max = _roomParameters.Max, Min = _roomParameters.Min, }; @@ -87,7 +87,7 @@ public sealed class RoomCreateOperation: IRagonOperation _ragonWebHookPlugin.RoomCreated(context, room, roomPlayer); - _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}"); + _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}"); JoinSuccess(roomPlayer, room, writer); @@ -103,7 +103,7 @@ public sealed class RoomCreateOperation: IRagonOperation writer.WriteString(room.Owner.Id); writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMax); - writer.WriteString(room.Map); + writer.WriteString(room.Scene); var sendData = writer.ToArray(); player.Connection.Reliable.Send(sendData); diff --git a/Ragon.Server/Sources/Handler/RoomJoinOperation.cs b/Ragon.Server/Sources/Handler/RoomJoinOperation.cs index 9359b81..dc1e1ec 100644 --- a/Ragon.Server/Sources/Handler/RoomJoinOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomJoinOperation.cs @@ -68,7 +68,7 @@ public sealed class RoomJoinOperation : IRagonOperation writer.WriteString(room.Owner.Id); writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMax); - writer.WriteString(room.Map); + writer.WriteString(room.Scene); var sendData = writer.ToArray(); context.Connection.Reliable.Send(sendData); diff --git a/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs b/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs index 74f1a4d..95226aa 100644 --- a/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs @@ -49,7 +49,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation _roomParameters.Deserialize(reader); - if (context.Lobby.FindRoomByMap(_roomParameters.Map, out var existsRoom)) + if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom)) { var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name); context.SetRoom(existsRoom, player); @@ -62,7 +62,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation { var information = new RoomInformation() { - Map = _roomParameters.Map, + Scene = _roomParameters.Scene, Max = _roomParameters.Max, Min = _roomParameters.Min, }; @@ -77,7 +77,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation context.Scheduler.Run(room); context.SetRoom(room, roomPlayer); - _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}"); + _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}"); JoinSuccess(roomPlayer, room, writer); } @@ -92,7 +92,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation writer.WriteString(room.Owner.Id); writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMax); - writer.WriteString(room.Map); + writer.WriteString(room.Scene); var sendData = writer.ToArray(); player.Connection.Reliable.Send(sendData); diff --git a/Ragon.Server/Sources/Handler/SceneLoadOperation.cs b/Ragon.Server/Sources/Handler/SceneLoadOperation.cs index c92069c..5fee7e6 100644 --- a/Ragon.Server/Sources/Handler/SceneLoadOperation.cs +++ b/Ragon.Server/Sources/Handler/SceneLoadOperation.cs @@ -33,7 +33,7 @@ public class SceneLoadOperation: IRagonOperation if (roomOwner.Connection.Id != currentPlayer.Connection.Id) { - _logger.Warn("Only owner can change map!"); + _logger.Warn("Only owner can change scene!"); return; } diff --git a/Ragon.Server/Sources/Lobby/IRagonLobby.cs b/Ragon.Server/Sources/Lobby/IRagonLobby.cs index 439b66d..2c047a3 100644 --- a/Ragon.Server/Sources/Lobby/IRagonLobby.cs +++ b/Ragon.Server/Sources/Lobby/IRagonLobby.cs @@ -22,7 +22,7 @@ namespace Ragon.Server.Lobby; public interface IRagonLobby { public bool FindRoomById(string roomId, [MaybeNullWhen(false)] out RagonRoom room); - public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room); + public bool FindRoomByScene(string sceneName, [MaybeNullWhen(false)] out RagonRoom room); public void Persist(RagonRoom room); public bool RemoveIfEmpty(RagonRoom room); } \ No newline at end of file diff --git a/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs b/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs index 0d7b4c8..b8bcefe 100644 --- a/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs +++ b/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs @@ -40,11 +40,11 @@ public class LobbyInMemory : IRagonLobby return false; } - public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room) + public bool FindRoomByScene(string sceneName, [MaybeNullWhen(false)] out RagonRoom room) { foreach (var existsRoom in _rooms) { - if (existsRoom.Map == map && existsRoom.PlayerCount < existsRoom.PlayerMax) + if (existsRoom.Scene == sceneName && existsRoom.PlayerCount < existsRoom.PlayerMax) { room = existsRoom; return true; @@ -61,7 +61,7 @@ public class LobbyInMemory : IRagonLobby _logger.Trace($"New room: {room.Id}"); foreach (var r in _rooms) - _logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}"); + _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count} Entities: {r.Entities.Count}"); } public bool RemoveIfEmpty(RagonRoom room) @@ -76,7 +76,7 @@ public class LobbyInMemory : IRagonLobby } foreach (var r in _rooms) - _logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}"); + _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count} Entities: {r.Entities.Count}"); return result; } diff --git a/Ragon.Server/Sources/Room/RagonRoom.cs b/Ragon.Server/Sources/Room/RagonRoom.cs index e0ab00c..a76b1eb 100644 --- a/Ragon.Server/Sources/Room/RagonRoom.cs +++ b/Ragon.Server/Sources/Room/RagonRoom.cs @@ -25,15 +25,15 @@ namespace Ragon.Server.Room; public class RagonRoom : IRagonRoom, IRagonAction { public string Id { get; private set; } - public string Map { get; private set; } + public string Scene { get; private set; } public int PlayerMax { get; private set; } public int PlayerMin { get; private set; } public int PlayerCount => WaitPlayersList.Count; - + public RagonRoomPlayer Owner { get; private set; } public RagonBuffer Writer { get; } public IRoomPlugin Plugin { get; private set; } - + public Dictionary Players { get; private set; } public List WaitPlayersList { get; private set; } public List ReadyPlayersList { get; private set; } @@ -45,11 +45,11 @@ public class RagonRoom : IRagonRoom, IRagonAction public List EntityList { get; private set; } private readonly HashSet _entitiesDirtySet; - + public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin) { Id = roomId; - Map = info.Map; + Scene = info.Scene; PlayerMax = info.Max; PlayerMin = info.Min; Plugin = roomPlugin; @@ -182,7 +182,7 @@ public class RagonRoom : IRagonRoom, IRagonAction public void UpdateMap(string sceneName) { - Map = sceneName; + Scene = sceneName; DynamicEntitiesList.Clear(); StaticEntitiesList.Clear(); @@ -218,9 +218,7 @@ public class RagonRoom : IRagonRoom, IRagonAction public IRagonEntity? GetEntityById(ushort id) { - return Entities.TryGetValue(id, out var entity) ? - entity : - null; + return Entities.TryGetValue(id, out var entity) ? entity : null; } public IRagonEntity[] GetEntitiesOfPlayer(RagonRoomPlayer player) diff --git a/Ragon.Server/Sources/Room/RagonRoomInformation.cs b/Ragon.Server/Sources/Room/RagonRoomInformation.cs index 1ef8376..4435cce 100644 --- a/Ragon.Server/Sources/Room/RagonRoomInformation.cs +++ b/Ragon.Server/Sources/Room/RagonRoomInformation.cs @@ -18,7 +18,7 @@ namespace Ragon.Server; public ref struct RoomInformation { - public string Map; + public string Scene; public int Min; public int Max; } \ No newline at end of file