diff --git a/Ragon.Client/Sources/Handler/AuthorizeSuccessHandler.cs b/Ragon.Client/Sources/Handler/AuthorizeSuccessHandler.cs index 0e1addc..e43bd54 100644 --- a/Ragon.Client/Sources/Handler/AuthorizeSuccessHandler.cs +++ b/Ragon.Client/Sources/Handler/AuthorizeSuccessHandler.cs @@ -38,7 +38,7 @@ internal class AuthorizeSuccessHandler: IHandler var playerName = reader.ReadString(); var playerPayload = reader.ReadString(); - _client.SetStatus(RagonStatus.LOBBY); + _client.UpdateState(RagonState.LOBBY); _listenerList.OnAuthorizationSuccess(playerId, playerName, playerPayload); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs b/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs index e9bd96f..3e77570 100644 --- a/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs +++ b/Ragon.Client/Sources/Handler/JoinSuccessHandler.cs @@ -42,16 +42,15 @@ internal class JoinSuccessHandler : IHandler private readonly RagonListenerList _listenerList; private readonly RagonPlayerCache _playerCache; private readonly RagonClient _client; + private readonly RagonRoom _room; public JoinSuccessHandler( RagonClient client, - RagonListenerList listenerList, - RagonPlayerCache playerCache + RagonRoom room ) { _client = client; - _listenerList = listenerList; - _playerCache = playerCache; + _room = room; } public void Handle(RagonStream reader) @@ -59,17 +58,14 @@ internal class JoinSuccessHandler : IHandler var roomId = reader.ReadString(); var min = reader.ReadUShort(); var max = reader.ReadUShort(); - var sceneName = reader.ReadString(); var localId = reader.ReadString(); var ownerId = reader.ReadString(); + var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max); _playerCache.SetOwnerAndLocal(ownerId, localId); - - var roomInfo = new RoomParameters(roomId, localId, ownerId, min, max); - var room = new RagonRoom(_client, _playerCache, roomInfo); + _room.Reset(roomInfo); + _room.UserData.Read(reader); - room.UserData.Read(reader); - var playersCount = reader.ReadUShort(); RagonLog.Trace("Players: " + playersCount); for (var i = 0; i < playersCount; i++) @@ -79,15 +75,14 @@ internal class JoinSuccessHandler : IHandler var playerName = reader.ReadString(); var player = _playerCache.AddPlayer(playerPeerId, playerId, playerName); - + player.UserData.Read(reader); RagonLog.Trace($"Player {playerPeerId} - {playerId} - {playerName}"); } - - _client.AssignRoom(room); - _client.SetStatus(RagonStatus.ROOM); - + + _client.UpdateState(RagonState.ROOM); + _listenerList.OnJoined(); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/LeaveRoomHandler.cs b/Ragon.Client/Sources/Handler/LeaveRoomHandler.cs index eec119c..b088e87 100644 --- a/Ragon.Client/Sources/Handler/LeaveRoomHandler.cs +++ b/Ragon.Client/Sources/Handler/LeaveRoomHandler.cs @@ -35,6 +35,7 @@ internal class LeaveRoomHandler : IHandler public void Handle(RagonStream reader) { _listenerList.OnLeft(); - _client.Room.Cleanup(); + + _client.Room.Clear(); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/RoomDataHandler.cs b/Ragon.Client/Sources/Handler/RoomDataHandler.cs deleted file mode 100644 index a025197..0000000 --- a/Ragon.Client/Sources/Handler/RoomDataHandler.cs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2023-2024 Eduard Kargin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -using Ragon.Protocol; - -namespace Ragon.Client; - -internal class RoomDataHandler: IHandler -{ - private readonly RagonListenerList _listeners; - private readonly RagonPlayerCache _playerCache; - - public RoomDataHandler( - RagonPlayerCache playerCache, - RagonListenerList listeners) - { - _playerCache = playerCache; - _listeners = listeners; - } - - public void Handle(RagonStream reader) - { - var rawData = reader.ReadBinary(reader.Lenght); - var peerId = (ushort)(rawData[1] + (rawData[2] << 8)); - - RagonPlayer player = null; - if (peerId != 10000) - { - player = _playerCache.GetPlayerByPeer(peerId); - if (player == null) - { - RagonLog.Error($"Player with peerId:{peerId} not found"); - - _playerCache.Dump(); - return; - } - } - - var headerSize = 3; - var payload = new byte[rawData.Length - headerSize]; - - Array.Copy(rawData, headerSize, payload, 0, payload.Length); - - _listeners.OnData(player, payload); - } -} \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/RoomEventHandler.cs b/Ragon.Client/Sources/Handler/RoomEventHandler.cs index b51591f..19e93d7 100644 --- a/Ragon.Client/Sources/Handler/RoomEventHandler.cs +++ b/Ragon.Client/Sources/Handler/RoomEventHandler.cs @@ -36,13 +36,13 @@ public class RoomEventHandler : IHandler { var eventCode = buffer.ReadUShort(); var peerId = buffer.ReadUShort(); - var executionMode = (RagonReplicationMode)buffer.ReadByte(); + var executionMode = (RagonReplicationMode) buffer.ReadByte(); var player = _playerCache.GetPlayerByPeer(peerId); if (player == null) { RagonLog.Error($"Player with peerId:{peerId} not found as owner of event with code:{eventCode}"); - + _playerCache.Dump(); return; } diff --git a/Ragon.Client/Sources/Handler/TimestampHandler.cs b/Ragon.Client/Sources/Handler/TimestampHandler.cs index 11ee79f..a1e9b9e 100644 --- a/Ragon.Client/Sources/Handler/TimestampHandler.cs +++ b/Ragon.Client/Sources/Handler/TimestampHandler.cs @@ -16,6 +16,6 @@ public class TimestampHandler: IHandler var timestamp1 = (uint)buffer.ReadInt(); var value = new DoubleToUInt { Int0 = timestamp0, Int1 = timestamp1 }; - _client.SetTimestamp(value.Double); + _client.UpdateTimestamp(value.Double); } } \ No newline at end of file diff --git a/Ragon.Client/Sources/IRagonEvent.cs b/Ragon.Client/Sources/IRagonEvent.cs index 9d10e72..66d51e9 100644 --- a/Ragon.Client/Sources/IRagonEvent.cs +++ b/Ragon.Client/Sources/IRagonEvent.cs @@ -20,6 +20,5 @@ namespace Ragon.Client { public interface IRagonEvent: IRagonSerializable { - } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Listener/IRagonListener.cs b/Ragon.Client/Sources/Listener/IRagonListener.cs index 252234e..a13cf2c 100644 --- a/Ragon.Client/Sources/Listener/IRagonListener.cs +++ b/Ragon.Client/Sources/Listener/IRagonListener.cs @@ -22,7 +22,6 @@ namespace Ragon.Client IRagonFailedListener, IRagonJoinListener, IRagonLeftListener, - IRagonSceneListener, IRagonOwnershipChangedListener, IRagonPlayerJoinListener, IRagonPlayerLeftListener, diff --git a/Ragon.Client/Sources/Listener/IRagonSceneListener.cs b/Ragon.Client/Sources/Listener/IRagonSceneListener.cs deleted file mode 100644 index 513feb3..0000000 --- a/Ragon.Client/Sources/Listener/IRagonSceneListener.cs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2023-2024 Eduard Kargin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Ragon.Client; - -public interface IRagonSceneListener -{ - 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 deleted file mode 100644 index 3ae6040..0000000 --- a/Ragon.Client/Sources/Listener/IRagonSceneRequestListener.cs +++ /dev/null @@ -1,6 +0,0 @@ -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 59832af..ec0fa51 100644 --- a/Ragon.Client/Sources/RagonClient.cs +++ b/Ragon.Client/Sources/RagonClient.cs @@ -31,7 +31,7 @@ namespace Ragon.Client private RagonListenerList _listeners; private RagonPlayerCache _playerCache; private RagonEventCache _eventCache; - private RagonStatus _status; + private RagonState _state; private double _serverTimestamp; private float _replicationRate = 0; @@ -39,7 +39,7 @@ namespace Ragon.Client public double ServerTimestamp => _serverTimestamp; public IRagonConnection Connection => _connection; - public RagonStatus Status => _status; + public RagonState State => _state; public RagonSession Session => _session; public RagonEventCache Event => _eventCache; public NetworkStatistics Statistics => _stats; @@ -64,22 +64,18 @@ namespace Ragon.Client _replicationTime = 0; _eventCache = new RagonEventCache(); - _stats = new NetworkStatistics(); - _status = RagonStatus.DISCONNECTED; - } - - - public void Connect(string address, ushort port, string protocol) - { _writeBuffer = new RagonStream(); _readBuffer = new RagonStream(); _playerCache = new RagonPlayerCache(); _session = new RagonSession(this, _writeBuffer); - + _room = new RagonRoom(this, _playerCache); + _stats = new NetworkStatistics(); + _state = RagonState.DISCONNECTED; + _handlers = new IHandler[byte.MaxValue]; _handlers[(byte)RagonOperation.AUTHORIZED_SUCCESS] = new AuthorizeSuccessHandler(this, _listeners); _handlers[(byte)RagonOperation.AUTHORIZED_FAILED] = new AuthorizeFailedHandler(_listeners); - _handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, _listeners, _playerCache); + _handlers[(byte)RagonOperation.JOIN_SUCCESS] = new JoinSuccessHandler(this, _room); _handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(_listeners); _handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, _listeners); _handlers[(byte)RagonOperation.OWNERSHIP_ROOM_CHANGED] = new OwnershipRoomHandler(_listeners, _playerCache); @@ -87,19 +83,22 @@ namespace Ragon.Client _handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_playerCache, _listeners); _handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventHandler(this, _playerCache); _handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampHandler(this); - _handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataHandler(_playerCache, _listeners); _handlers[(byte)RagonOperation.ROOM_LIST_UPDATED] = new RoomListHandler(_session, _listeners); _handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataHandler(this, _listeners); _handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataHandler(_playerCache, _listeners); - + } + + public void Connect(string address, ushort port, string protocol) + { var protocolRaw = RagonVersion.Parse(protocol); _connection.Connect(address, port, protocolRaw); } public void Disconnect() { - _status = RagonStatus.DISCONNECTED; - _room?.Cleanup(); + _state = RagonState.DISCONNECTED; + _room.Clear(); + _connection.Disconnect(); OnDisconnected(RagonDisconnect.MANUAL); @@ -107,14 +106,13 @@ namespace Ragon.Client public void Update(float dt) { - if (_status != RagonStatus.DISCONNECTED) + if (_state != RagonState.DISCONNECTED) { _replicationTime += dt; if (_replicationTime >= _replicationRate) { _replicationTime = 0; - // _entityCache.WriteState(_writeBuffer); - + SendTimestamp(); SendRoomUserData(); SendPlayerUserData(); @@ -129,9 +127,9 @@ namespace Ragon.Client public void Dispose() { - if (_status != RagonStatus.DISCONNECTED) + if (_state != RagonState.DISCONNECTED) { - _status = RagonStatus.DISCONNECTED; + _state = RagonState.DISCONNECTED; _connection.Disconnect(); } @@ -147,7 +145,6 @@ namespace Ragon.Client public void AddListener(IRagonOwnershipChangedListener listener) => _listeners.Add(listener); public void AddListener(IRagonPlayerJoinListener listener) => _listeners.Add(listener); public void AddListener(IRagonPlayerLeftListener listener) => _listeners.Add(listener); - public void AddListener(IRagonDataListener listener) => _listeners.Add(listener); public void AddListener(IRagonRoomListListener listener) => _listeners.Add(listener); public void AddListener(IRagonPlayerUserDataListener listener) => _listeners.Add(listener); public void AddListener(IRagonRoomUserDataListener listener) => _listeners.Add(listener); @@ -160,7 +157,6 @@ namespace Ragon.Client public void RemoveListener(IRagonOwnershipChangedListener listener) => _listeners.Remove(listener); public void RemoveListener(IRagonPlayerJoinListener listener) => _listeners.Remove(listener); public void RemoveListener(IRagonPlayerLeftListener listener) => _listeners.Remove(listener); - public void RemoveListener(IRagonDataListener listener) => _listeners.Remove(listener); public void RemoveListener(IRagonRoomListListener listener) => _listeners.Remove(listener); public void RemoveListener(IRagonRoomUserDataListener listener) => _listeners.Remove(listener); public void RemoveListener(IRagonPlayerUserDataListener listener) => _listeners.Remove(listener); @@ -168,19 +164,13 @@ namespace Ragon.Client #endregion #region INTERNAL - - internal void AssignRoom(RagonRoom room) + + internal void UpdateState(RagonState state) { - _room?.Dispose(); - _room = room; + _state = state; } - internal void SetStatus(RagonStatus status) - { - _status = status; - } - - internal void SetTimestamp(double time) + internal void UpdateTimestamp(double time) { _serverTimestamp = time; } @@ -240,7 +230,7 @@ namespace Ragon.Client RagonLog.Trace("Connected"); _listeners.OnConnected(); - _status = RagonStatus.CONNECTED; + _state = RagonState.CONNECTED; } private void OnDisconnected(RagonDisconnect reason) @@ -248,7 +238,7 @@ namespace Ragon.Client RagonLog.Trace($"Disconnected: {reason}"); _listeners.OnDisconnected(reason); - _status = RagonStatus.DISCONNECTED; + _state = RagonState.DISCONNECTED; } private void OnData(byte[] data) diff --git a/Ragon.Client/Sources/RagonListenerList.cs b/Ragon.Client/Sources/RagonListenerList.cs index 566d3b0..471eb8d 100644 --- a/Ragon.Client/Sources/RagonListenerList.cs +++ b/Ragon.Client/Sources/RagonListenerList.cs @@ -29,7 +29,6 @@ namespace Ragon.Client private readonly List _ownershipChangedListeners = new(); private readonly List _playerJoinListeners = new(); private readonly List _playerLeftListeners = new(); - private readonly List _dataListeners = new(); private readonly List _roomListListeners = new(); private readonly List _roomUserDataListeners = new(); private readonly List _playerUserDataListeners = new(); @@ -79,11 +78,6 @@ namespace Ragon.Client _delayedActions.Clear(); } - public void Add(IRagonDataListener dataListener) - { - _dataListeners.Add(dataListener); - } - public void Add(IRagonAuthorizationListener listener) { _authorizationListeners.Add(listener); @@ -139,11 +133,6 @@ namespace Ragon.Client _playerUserDataListeners.Add(listener); } - public void Remove(IRagonDataListener listener) - { - _delayedActions.Add(() => _dataListeners.Remove(listener)); - } - public void Remove(IRagonAuthorizationListener listener) { _delayedActions.Add(() => _authorizationListeners.Remove(listener)); @@ -259,12 +248,6 @@ namespace Ragon.Client listener.OnDisconnected(_client, disconnect); } - public void OnData(RagonPlayer player, byte[] data) - { - foreach (var listener in _dataListeners) - listener.OnData(_client, player, data); - } - public void OnRoomList(RagonRoomInformation[] roomInfos) { foreach (var listListener in _roomListListeners) diff --git a/Ragon.Client/Sources/RagonRoom.cs b/Ragon.Client/Sources/RagonRoom.cs index 86e831c..9424dfd 100644 --- a/Ragon.Client/Sources/RagonRoom.cs +++ b/Ragon.Client/Sources/RagonRoom.cs @@ -18,7 +18,7 @@ using Ragon.Protocol; namespace Ragon.Client { - public class RagonRoom : IDisposable + public class RagonRoom { private class EventSubscription : IDisposable { @@ -51,13 +51,12 @@ namespace Ragon.Client private readonly RagonClient _client; private readonly RagonPlayerCache _playerCache; - private readonly RoomParameters _parameters; - private readonly RagonUserData _userData; + private RoomParameters _parameters; + private RagonUserData _userData; public string Id => _parameters.RoomId; public int MinPlayers => _parameters.Min; public int MaxPlayers => _parameters.Max; - public string Scene => "none"; public IReadOnlyList Players => _playerCache.Players; public RagonPlayer Local => _playerCache.Local; @@ -69,27 +68,23 @@ namespace Ragon.Client private readonly Dictionary>> _localListeners = new(); private readonly Dictionary>> _listeners = new(); - - public RagonRoom(RagonClient client, - RagonPlayerCache playerCache, - RoomParameters parameters) + + public RagonRoom(RagonClient client, RagonPlayerCache playerCache) { _client = client; - _parameters = parameters; _playerCache = playerCache; - _userData = new RagonUserData(); + } - internal void Cleanup() + public void Reset(RoomParameters parameters) { + Clear(); + + _userData = new RagonUserData(); + _parameters = parameters; _playerCache.Cleanup(); } - - internal void Update(string sceneName) - { - // _scene.Update(sceneName); - } - + internal void HandleEvent(ushort eventCode, RagonPlayer caller, RagonStream buffer) { if (_events.TryGetValue(eventCode, out var evnt)) @@ -108,7 +103,7 @@ namespace Ragon.Client var t = new TEvent(); var eventCode = _client.Event.GetEventCode(t); var action = (RagonPlayer player, IRagonEvent eventData) => callback.Invoke(player, (TEvent)eventData); - + if (!_listeners.TryGetValue(eventCode, out var callbacks)) { callbacks = new List>(); @@ -194,22 +189,8 @@ namespace Ragon.Client _client.Reliable.Send(sendData); } - public void ReplicateData(byte[] data, bool reliable) + public void Clear() { - var sendData = new byte[data.Length + 1]; - sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA; - Array.Copy(data, 0, sendData, 1, data.Length); - - if (reliable) - _client.Reliable.Send(sendData); - else - _client.Unreliable.Send(sendData); - } - - public void Dispose() - { - Cleanup(); - _events.Clear(); _listeners.Clear(); _localListeners.Clear(); diff --git a/Ragon.Client/Sources/RagonSession.cs b/Ragon.Client/Sources/RagonSession.cs index 9c61168..f194bfb 100644 --- a/Ragon.Client/Sources/RagonSession.cs +++ b/Ragon.Client/Sources/RagonSession.cs @@ -21,20 +21,21 @@ namespace Ragon.Client public class RagonSession { private readonly RagonClient _client; - private readonly RagonStream _buffer; + private readonly RagonStream _buffer; + public RagonSession(RagonClient client, RagonStream buffer) { _client = client; _buffer = buffer; } - public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers) + public void CreateOrJoin(string sessionName, int minPlayers, int maxPlayers) { - var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}; + var parameters = new RagonRoomParameters() { Min = minPlayers, Max = maxPlayers }; CreateOrJoin(parameters); } - + public void CreateOrJoin(RagonRoomParameters parameters) { _buffer.Clear(); @@ -46,16 +47,16 @@ namespace Ragon.Client _client.Reliable.Send(sendData); } - public void Create(string sceneName, int minPlayers, int maxPlayers) + public void Create(string sessionName, int minPlayers, int maxPlayers) { - Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}); + Create(null, new RagonRoomParameters() { Min = minPlayers, Max = maxPlayers }); } - public void Create(string roomId, string sceneName, int minPlayers, int maxPlayers) + public void Create(string roomId, string sessionName, int minPlayers, int maxPlayers) { - Create(roomId, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers}); + Create(roomId, new RagonRoomParameters() { Min = minPlayers, Max = maxPlayers }); } - + public void Create(string roomId, RagonRoomParameters parameters) { _buffer.Clear(); @@ -76,14 +77,14 @@ namespace Ragon.Client var sendData = _buffer.ToArray(); _client.Reliable.Send(sendData); } - - public void Leave() + + public void Leave() { - var sendData = new[] {(byte) RagonOperation.LEAVE_ROOM}; + var sendData = new[] { (byte)RagonOperation.LEAVE_ROOM }; _client.Reliable.Send(sendData); } - public void Join(string roomId) + public void Join(string roomId) { _buffer.Clear(); _buffer.WriteOperation(RagonOperation.JOIN_ROOM); @@ -93,7 +94,7 @@ namespace Ragon.Client _client.Reliable.Send(sendData); } - public void AuthorizeWithKey(string key, string playerName, string payload = "") + public void AuthorizeWithKey(string key, string playerName, string payload = "") { _buffer.Clear(); _buffer.WriteOperation(RagonOperation.AUTHORIZE); @@ -104,6 +105,5 @@ namespace Ragon.Client var sendData = _buffer.ToArray(); _client.Reliable.Send(sendData); } - } } \ No newline at end of file diff --git a/Ragon.Client/Sources/RagonStatus.cs b/Ragon.Client/Sources/RagonState.cs similarity index 96% rename from Ragon.Client/Sources/RagonStatus.cs rename to Ragon.Client/Sources/RagonState.cs index a6b63e7..45dca0f 100644 --- a/Ragon.Client/Sources/RagonStatus.cs +++ b/Ragon.Client/Sources/RagonState.cs @@ -16,7 +16,7 @@ namespace Ragon.Client { - public enum RagonStatus + public enum RagonState { DISCONNECTED, CONNECTED, diff --git a/Ragon.Protocol/Sources/RagonOperation.cs b/Ragon.Protocol/Sources/RagonOperation.cs index 1477ae6..4916f57 100644 --- a/Ragon.Protocol/Sources/RagonOperation.cs +++ b/Ragon.Protocol/Sources/RagonOperation.cs @@ -17,7 +17,7 @@ namespace Ragon.Protocol { - public enum RagonOperation: byte + public enum RagonOperation : byte { AUTHORIZE = 1, AUTHORIZED_SUCCESS = 2, @@ -26,23 +26,13 @@ namespace Ragon.Protocol CREATE_ROOM = 5, JOIN_ROOM = 6, LEAVE_ROOM = 7, - OWNERSHIP_ENTITY_CHANGED = 8, - OWNERSHIP_ROOM_CHANGED= 9, + OWNERSHIP_ROOM_CHANGED = 9, JOIN_SUCCESS = 10, JOIN_FAILED = 11, - LOAD_SCENE = 12, - SCENE_LOADED = 13, PLAYER_JOINED = 14, PLAYER_LEAVED = 15, - CREATE_ENTITY = 16, - REMOVE_ENTITY = 17, - SNAPSHOT = 18, - REPLICATE_ENTITY_STATE = 19, - REPLICATE_ENTITY_EVENT = 20, - REPLICATE_RAW_DATA = 21, REPLICATE_ROOM_EVENT = 22, TRANSFER_ROOM_OWNERSHIP = 23, - TRANSFER_ENTITY_OWNERSHIP = 24, TIMESTAMP_SYNCHRONIZATION = 25, ROOM_LIST_UPDATED = 26, PLAYER_DATA_UPDATED = 27, diff --git a/Ragon.Protocol/Sources/RagonRoomParameters.cs b/Ragon.Protocol/Sources/RagonRoomParameters.cs index 614d2d2..346b2dc 100644 --- a/Ragon.Protocol/Sources/RagonRoomParameters.cs +++ b/Ragon.Protocol/Sources/RagonRoomParameters.cs @@ -19,20 +19,17 @@ namespace Ragon.Protocol { public class RagonRoomParameters { - public string Scene { get; set; } public int Min { get; set; } public int Max { get; set; } public void Serialize(RagonStream buffer) { - buffer.WriteString(Scene); buffer.WriteInt(Min); buffer.WriteInt(Max); } public void Deserialize(RagonStream buffer) { - Scene = buffer.ReadString(); Min = buffer.ReadInt(); Max = buffer.ReadInt(); } diff --git a/Ragon.Relay/Ragon.Relay.csproj b/Ragon.Relay/Ragon.Relay.csproj index 657fbb5..10cea2a 100644 --- a/Ragon.Relay/Ragon.Relay.csproj +++ b/Ragon.Relay/Ragon.Relay.csproj @@ -28,6 +28,8 @@ + + diff --git a/Ragon.Relay/Sources/Plugin/RelayRoomPlugin.cs b/Ragon.Relay/Sources/Plugin/RelayRoomPlugin.cs index e258712..cf4ca1a 100644 --- a/Ragon.Relay/Sources/Plugin/RelayRoomPlugin.cs +++ b/Ragon.Relay/Sources/Plugin/RelayRoomPlugin.cs @@ -9,10 +9,11 @@ public class RelayRoomPlugin: BaseRoomPlugin { } - public void OnAttached() { Console.WriteLine("Room attached"); + + } public void OnDetached() diff --git a/Ragon.Relay/Sources/Plugin/RelayServerPlugin.cs b/Ragon.Relay/Sources/Plugin/RelayServerPlugin.cs index 93a7ac8..03b3b1a 100644 --- a/Ragon.Relay/Sources/Plugin/RelayServerPlugin.cs +++ b/Ragon.Relay/Sources/Plugin/RelayServerPlugin.cs @@ -1,10 +1,35 @@ using Ragon.Server; +using Ragon.Server.Lobby; using Ragon.Server.Plugin; +using Ragon.Server.Time; namespace Ragon.Relay { public class RelayServerPlugin : BaseServerPlugin { + private RelayConfiguration _relayConfiguration; + private RagonScheduler _scheduler; + private RagonConnectionRegistry _connectionRegistry; + private IRagonLobby _lobby; + private Reporter _reporter; + + public RelayServerPlugin(RelayConfiguration config) + { + _relayConfiguration = config; + } + + public override void OnAttached(IRagonServer server) + { + base.OnAttached(server); + + _lobby = server.Lobby; + _connectionRegistry = server.ConnectionRegistry; + _scheduler = server.Scheduler; + _reporter = new Reporter(_relayConfiguration, server, "127.0.0.1", 5000); + + server.Scheduler.Run(new RagonActionTimer(() => _reporter.Done(), 1, -1)); + } + public override bool OnCommand(string command, string payload) { return true; diff --git a/Ragon.Relay/Sources/Reporter/Client.cs b/Ragon.Relay/Sources/Reporter/Client.cs new file mode 100644 index 0000000..565e9b4 --- /dev/null +++ b/Ragon.Relay/Sources/Reporter/Client.cs @@ -0,0 +1,44 @@ +using System; +using System.Net; +using System.Net.Sockets; +using Ragon.Server.Logging; + +namespace Ragon.Relay; + +public class Client +{ + private readonly UdpClient _udpClient; + private readonly IPEndPoint _endpoint; + private readonly IRagonLogger _logger; + + public Client(string host, int port) + { + _logger = LoggerManager.GetLogger("Client"); + _udpClient = new UdpClient(); + _endpoint = new IPEndPoint(IPAddress.Parse(host), port); + } + + public void Send(byte[] data) + { + try + { + _udpClient.BeginSend(data, data.Length, _endpoint, SendCallback, null); + } + catch (Exception ex) + { + _logger.Error(ex.Message); + } + } + + private void SendCallback(IAsyncResult ar) + { + try + { + _udpClient.EndSend(ar); + } + catch (Exception ex) + { + _logger.Error(ex.Message); + } + } +} \ No newline at end of file diff --git a/Ragon.Relay/Sources/Reporter/Protocol.cs b/Ragon.Relay/Sources/Reporter/Protocol.cs new file mode 100644 index 0000000..ff8043d --- /dev/null +++ b/Ragon.Relay/Sources/Reporter/Protocol.cs @@ -0,0 +1,1072 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: protocol.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Ragon.Relay { + + /// Holder for reflection information generated from protocol.proto + public static partial class ProtocolReflection { + + #region Descriptor + /// File descriptor for protocol.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static ProtocolReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Cg5wcm90b2NvbC5wcm90byJNCgREYXRhEg8KB1JlbGF5SUQYASABKAkSHwoK", + "U3RhdGlzdGljcxgCIAEoCzILLlN0YXRpc3RpY3MSEwoEUm9vbRgDIAEoCzIF", + "LlJvb20iXgoKU3RhdGlzdGljcxITCgtDb25uZWN0aW9ucxgBIAEoAxIYChBD", + "b25uZWN0aW9uc0xpbWl0GAIgASgDEg0KBVJvb21zGAMgASgDEhIKClJvb21z", + "TGltaXQYBCABKAMiFAoGUGxheWVyEgoKAklkGAEgASgJIiwKBFJvb20SCgoC", + "SWQYASABKAkSGAoHUGxheWVycxgCIAMoCzIHLlBsYXllckIUWgQuL3BiqgIL", + "UmFnb24uUmVsYXliBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Ragon.Relay.Data), global::Ragon.Relay.Data.Parser, new[]{ "RelayID", "Statistics", "Room" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Ragon.Relay.Statistics), global::Ragon.Relay.Statistics.Parser, new[]{ "Connections", "ConnectionsLimit", "Rooms", "RoomsLimit" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Ragon.Relay.Player), global::Ragon.Relay.Player.Parser, new[]{ "Id" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Ragon.Relay.Room), global::Ragon.Relay.Room.Parser, new[]{ "Id", "Players" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] + public sealed partial class Data : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Data()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Ragon.Relay.ProtocolReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Data() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Data(Data other) : this() { + relayID_ = other.relayID_; + statistics_ = other.statistics_ != null ? other.statistics_.Clone() : null; + room_ = other.room_ != null ? other.room_.Clone() : null; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Data Clone() { + return new Data(this); + } + + /// Field number for the "RelayID" field. + public const int RelayIDFieldNumber = 1; + private string relayID_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string RelayID { + get { return relayID_; } + set { + relayID_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "Statistics" field. + public const int StatisticsFieldNumber = 2; + private global::Ragon.Relay.Statistics statistics_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public global::Ragon.Relay.Statistics Statistics { + get { return statistics_; } + set { + statistics_ = value; + } + } + + /// Field number for the "Room" field. + public const int RoomFieldNumber = 3; + private global::Ragon.Relay.Room room_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public global::Ragon.Relay.Room Room { + get { return room_; } + set { + room_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as Data); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(Data other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (RelayID != other.RelayID) return false; + if (!object.Equals(Statistics, other.Statistics)) return false; + if (!object.Equals(Room, other.Room)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (RelayID.Length != 0) hash ^= RelayID.GetHashCode(); + if (statistics_ != null) hash ^= Statistics.GetHashCode(); + if (room_ != null) hash ^= Room.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (RelayID.Length != 0) { + output.WriteRawTag(10); + output.WriteString(RelayID); + } + if (statistics_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Statistics); + } + if (room_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Room); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (RelayID.Length != 0) { + output.WriteRawTag(10); + output.WriteString(RelayID); + } + if (statistics_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Statistics); + } + if (room_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Room); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (RelayID.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(RelayID); + } + if (statistics_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Statistics); + } + if (room_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Room); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(Data other) { + if (other == null) { + return; + } + if (other.RelayID.Length != 0) { + RelayID = other.RelayID; + } + if (other.statistics_ != null) { + if (statistics_ == null) { + Statistics = new global::Ragon.Relay.Statistics(); + } + Statistics.MergeFrom(other.Statistics); + } + if (other.room_ != null) { + if (room_ == null) { + Room = new global::Ragon.Relay.Room(); + } + Room.MergeFrom(other.Room); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + RelayID = input.ReadString(); + break; + } + case 18: { + if (statistics_ == null) { + Statistics = new global::Ragon.Relay.Statistics(); + } + input.ReadMessage(Statistics); + break; + } + case 26: { + if (room_ == null) { + Room = new global::Ragon.Relay.Room(); + } + input.ReadMessage(Room); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + RelayID = input.ReadString(); + break; + } + case 18: { + if (statistics_ == null) { + Statistics = new global::Ragon.Relay.Statistics(); + } + input.ReadMessage(Statistics); + break; + } + case 26: { + if (room_ == null) { + Room = new global::Ragon.Relay.Room(); + } + input.ReadMessage(Room); + break; + } + } + } + } + #endif + + } + + [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] + public sealed partial class Statistics : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Statistics()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Ragon.Relay.ProtocolReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Statistics() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Statistics(Statistics other) : this() { + connections_ = other.connections_; + connectionsLimit_ = other.connectionsLimit_; + rooms_ = other.rooms_; + roomsLimit_ = other.roomsLimit_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Statistics Clone() { + return new Statistics(this); + } + + /// Field number for the "Connections" field. + public const int ConnectionsFieldNumber = 1; + private long connections_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Connections { + get { return connections_; } + set { + connections_ = value; + } + } + + /// Field number for the "ConnectionsLimit" field. + public const int ConnectionsLimitFieldNumber = 2; + private long connectionsLimit_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long ConnectionsLimit { + get { return connectionsLimit_; } + set { + connectionsLimit_ = value; + } + } + + /// Field number for the "Rooms" field. + public const int RoomsFieldNumber = 3; + private long rooms_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Rooms { + get { return rooms_; } + set { + rooms_ = value; + } + } + + /// Field number for the "RoomsLimit" field. + public const int RoomsLimitFieldNumber = 4; + private long roomsLimit_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long RoomsLimit { + get { return roomsLimit_; } + set { + roomsLimit_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as Statistics); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(Statistics other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Connections != other.Connections) return false; + if (ConnectionsLimit != other.ConnectionsLimit) return false; + if (Rooms != other.Rooms) return false; + if (RoomsLimit != other.RoomsLimit) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Connections != 0L) hash ^= Connections.GetHashCode(); + if (ConnectionsLimit != 0L) hash ^= ConnectionsLimit.GetHashCode(); + if (Rooms != 0L) hash ^= Rooms.GetHashCode(); + if (RoomsLimit != 0L) hash ^= RoomsLimit.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Connections != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Connections); + } + if (ConnectionsLimit != 0L) { + output.WriteRawTag(16); + output.WriteInt64(ConnectionsLimit); + } + if (Rooms != 0L) { + output.WriteRawTag(24); + output.WriteInt64(Rooms); + } + if (RoomsLimit != 0L) { + output.WriteRawTag(32); + output.WriteInt64(RoomsLimit); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Connections != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Connections); + } + if (ConnectionsLimit != 0L) { + output.WriteRawTag(16); + output.WriteInt64(ConnectionsLimit); + } + if (Rooms != 0L) { + output.WriteRawTag(24); + output.WriteInt64(Rooms); + } + if (RoomsLimit != 0L) { + output.WriteRawTag(32); + output.WriteInt64(RoomsLimit); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Connections != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Connections); + } + if (ConnectionsLimit != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ConnectionsLimit); + } + if (Rooms != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Rooms); + } + if (RoomsLimit != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(RoomsLimit); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(Statistics other) { + if (other == null) { + return; + } + if (other.Connections != 0L) { + Connections = other.Connections; + } + if (other.ConnectionsLimit != 0L) { + ConnectionsLimit = other.ConnectionsLimit; + } + if (other.Rooms != 0L) { + Rooms = other.Rooms; + } + if (other.RoomsLimit != 0L) { + RoomsLimit = other.RoomsLimit; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Connections = input.ReadInt64(); + break; + } + case 16: { + ConnectionsLimit = input.ReadInt64(); + break; + } + case 24: { + Rooms = input.ReadInt64(); + break; + } + case 32: { + RoomsLimit = input.ReadInt64(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Connections = input.ReadInt64(); + break; + } + case 16: { + ConnectionsLimit = input.ReadInt64(); + break; + } + case 24: { + Rooms = input.ReadInt64(); + break; + } + case 32: { + RoomsLimit = input.ReadInt64(); + break; + } + } + } + } + #endif + + } + + [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] + public sealed partial class Player : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Player()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Ragon.Relay.ProtocolReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Player() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Player(Player other) : this() { + id_ = other.id_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Player Clone() { + return new Player(this); + } + + /// Field number for the "Id" field. + public const int IdFieldNumber = 1; + private string id_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Id { + get { return id_; } + set { + id_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as Player); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(Player other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Id != other.Id) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Id.Length != 0) hash ^= Id.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Id.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Id); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(Player other) { + if (other == null) { + return; + } + if (other.Id.Length != 0) { + Id = other.Id; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Id = input.ReadString(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Id = input.ReadString(); + break; + } + } + } + } + #endif + + } + + [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] + public sealed partial class Room : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Room()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Ragon.Relay.ProtocolReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Room() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Room(Room other) : this() { + id_ = other.id_; + players_ = other.players_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public Room Clone() { + return new Room(this); + } + + /// Field number for the "Id" field. + public const int IdFieldNumber = 1; + private string id_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Id { + get { return id_; } + set { + id_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "Players" field. + public const int PlayersFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_players_codec + = pb::FieldCodec.ForMessage(18, global::Ragon.Relay.Player.Parser); + private readonly pbc::RepeatedField players_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField Players { + get { return players_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as Room); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(Room other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Id != other.Id) return false; + if(!players_.Equals(other.players_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Id.Length != 0) hash ^= Id.GetHashCode(); + hash ^= players_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } + players_.WriteTo(output, _repeated_players_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } + players_.WriteTo(ref output, _repeated_players_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Id.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Id); + } + size += players_.CalculateSize(_repeated_players_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(Room other) { + if (other == null) { + return; + } + if (other.Id.Length != 0) { + Id = other.Id; + } + players_.Add(other.players_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Id = input.ReadString(); + break; + } + case 18: { + players_.AddEntriesFrom(input, _repeated_players_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + if ((tag & 7) == 4) { + // Abort on any end group tag. + return; + } + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Id = input.ReadString(); + break; + } + case 18: { + players_.AddEntriesFrom(ref input, _repeated_players_codec); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Ragon.Relay/Sources/Reporter/Reporter.cs b/Ragon.Relay/Sources/Reporter/Reporter.cs new file mode 100644 index 0000000..bea854c --- /dev/null +++ b/Ragon.Relay/Sources/Reporter/Reporter.cs @@ -0,0 +1,56 @@ +using Google.Protobuf; +using Google.Protobuf.Collections; +using Ragon.Server; + +namespace Ragon.Relay; + +public class Reporter +{ + private readonly Client _client; + private readonly IRagonServer _server; + private readonly RelayConfiguration _configuration; + + public Reporter( + RelayConfiguration relayConfiguration, + IRagonServer server, + string host, + int port + ) + { + _client = new Client(host, port); + _server = server; + _configuration = relayConfiguration; + } + + public void Done() + { + for (var i = 0; i < 10; i++) + { + var message = new Data(); + message.Statistics = new Statistics() + { + Connections = _server.ConnectionRegistry.Contexts.Count, + ConnectionsLimit = _configuration.LimitConnections, + Rooms = _server.Lobby.Rooms.Count, + RoomsLimit = _configuration.LimitRooms, + }; + + var room = new Room() + { + Id = $"Room ID {i}", + }; + + for (var j = 0; j < 10; j++) + { + room.Players.Add(new Player() + { + Id = $"Player ID {i}", + }); + } + + message.Room = room; + + _client.Send(message.ToByteArray()); + } + } +} \ No newline at end of file diff --git a/Ragon.Relay/Sources/Transport/WebSocket/WebSocketServer.cs b/Ragon.Relay/Sources/Transport/WebSocket/WebSocketServer.cs index da71407..c89b431 100644 --- a/Ragon.Relay/Sources/Transport/WebSocket/WebSocketServer.cs +++ b/Ragon.Relay/Sources/Transport/WebSocket/WebSocketServer.cs @@ -158,13 +158,11 @@ public class WebSocketServer : INetworkServer _sequencer.Push(0); _connections = new WebSocketConnection[configuration.LimitConnections]; - + _httpListener = new HttpListener(); _httpListener.Prefixes.Add($"http://{configuration.Address}:{configuration.Port}/"); _httpListener.Start(); - // _executor.Run(() => StartAccept(_cancellationTokenSource.Token)); - var protocolDecoded = RagonVersion.Parse(configuration.Protocol); _logger.Info($"Listen at http://{configuration.Address}:{configuration.Port}/"); _logger.Info($"Protocol: {protocolDecoded}"); diff --git a/Ragon.Server/Sources/Event/RagonEvent.cs b/Ragon.Server/Sources/Event/RagonEvent.cs index f3bbca1..c7c0a79 100644 --- a/Ragon.Server/Sources/Event/RagonEvent.cs +++ b/Ragon.Server/Sources/Event/RagonEvent.cs @@ -39,8 +39,8 @@ public class RagonEvent public void Read(RagonStream buffer) { - // _size = buffer.Capacity; - // buffer.ReadArray(_data, _size); + // _size = buffer.Capacity; + // buffer.ReadArray(_data, _size); } public void Write(RagonStream buffer) diff --git a/Ragon.Server/Sources/Handler/RoomCreateOperation.cs b/Ragon.Server/Sources/Handler/RoomCreateOperation.cs index 28f417e..31e5591 100644 --- a/Ragon.Server/Sources/Handler/RoomCreateOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomCreateOperation.cs @@ -76,11 +76,10 @@ namespace Ragon.Server.Handler var information = new RoomInformation() { - Scene = _roomParameters.Scene, Max = _roomParameters.Max, Min = _roomParameters.Min, }; - + if (information.Max > _configuration.LimitPlayersPerRoom) information.Max = _configuration.LimitPlayersPerRoom; @@ -97,8 +96,7 @@ namespace Ragon.Server.Handler context.Lobby.Persist(room); context.SetRoom(room, roomPlayer); - _logger.Trace( - $"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}"); + _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id}"); JoinSuccess(roomPlayer, room, Writer); @@ -114,7 +112,6 @@ namespace Ragon.Server.Handler writer.WriteString(room.Id); writer.WriteUShort((ushort)room.PlayerMin); writer.WriteUShort((ushort)room.PlayerMax); - writer.WriteString(room.Scene); writer.WriteString(player.Id); writer.WriteString(room.Owner.Id); diff --git a/Ragon.Server/Sources/Handler/RoomDataOperation.cs b/Ragon.Server/Sources/Handler/RoomDataOperation.cs deleted file mode 100644 index 970a5a0..0000000 --- a/Ragon.Server/Sources/Handler/RoomDataOperation.cs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2023-2024 Eduard Kargin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Ragon.Protocol; -using Ragon.Server.IO; - -namespace Ragon.Server.Handler; - -public sealed class RoomDataOperation : BaseOperation -{ - public RoomDataOperation(RagonStream reader, RagonStream writer) : base(reader, writer) - { - } - - public override void Handle(RagonContext context, NetworkChannel channel) - { - var player = context.RoomPlayer; - var room = context.Room; - - - var data = Reader.ReadBinary(Reader.Lenght); - var dataSize = data.Length - 1; - var headerSize = 3; - var size = headerSize + dataSize; - var sendData = new byte[size]; - var peerId = player.Connection.Id; - - sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA; - sendData[1] = (byte)peerId; - sendData[2] = (byte)(peerId >> 8); - - var pluginData = new byte[dataSize]; - Array.Copy(data, 1, pluginData, 0, dataSize); - room.Plugin.OnData(player, pluginData); - - Array.Copy(data, 1, sendData, headerSize, dataSize); - room.Broadcast(sendData, room.ReadyPlayersList, NetworkChannel.RELIABLE); - } -} \ No newline at end of file diff --git a/Ragon.Server/Sources/Handler/RoomJoinOperation.cs b/Ragon.Server/Sources/Handler/RoomJoinOperation.cs index 48b6b42..f0b2e3b 100644 --- a/Ragon.Server/Sources/Handler/RoomJoinOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomJoinOperation.cs @@ -61,7 +61,6 @@ public sealed class RoomJoinOperation : BaseOperation writer.WriteString(room.Id); writer.WriteUShort((ushort)room.PlayerMin); writer.WriteUShort((ushort)room.PlayerMax); - writer.WriteString(room.Scene); writer.WriteString(context.RoomPlayer.Id); writer.WriteString(room.Owner.Id); diff --git a/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs b/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs index e213760..50ed357 100644 --- a/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomJoinOrCreateOperation.cs @@ -30,11 +30,11 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation private readonly RagonRoomParameters _roomParameters = new(); private readonly IServerPlugin _serverPlugin; private readonly RagonServerConfiguration _configuration; - + public RoomJoinOrCreateOperation( RagonStream reader, RagonStream writer, - IServerPlugin serverPlugin, + IServerPlugin serverPlugin, RagonServerConfiguration configuration ) : base(reader, writer) { @@ -52,52 +52,35 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation var roomId = Guid.NewGuid().ToString(); var lobbyPlayer = context.LobbyPlayer; - + _roomParameters.Deserialize(Reader); - - if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom)) + + var information = new RoomInformation() { - var player = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name); + Max = _roomParameters.Max, + Min = _roomParameters.Min, + }; - context.SetRoom(existsRoom, player); + if (information.Max > _configuration.LimitPlayersPerRoom) + information.Max = _configuration.LimitPlayersPerRoom; - JoinSuccess(player, existsRoom, Writer); + var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name); + var roomPlugin = _serverPlugin.CreateRoomPlugin(information); + var room = new RagonRoom(roomId, information, roomPlugin); - existsRoom.RestoreBufferedEvents(player); + _serverPlugin.OnRoomCreate(lobbyPlayer, room); - existsRoom.Plugin.OnPlayerJoined(player); - } - else - { - var information = new RoomInformation() - { - Scene = _roomParameters.Scene, - Max = _roomParameters.Max, - Min = _roomParameters.Min, - }; + room.Plugin.OnAttached(room); - if (information.Max > _configuration.LimitPlayersPerRoom) - information.Max = _configuration.LimitPlayersPerRoom; + context.Lobby.Persist(room); + context.Scheduler.Run(room); + context.SetRoom(room, roomPlayer); - var roomPlayer = new RagonRoomPlayer(context, lobbyPlayer.Id, lobbyPlayer.Name); - var roomPlugin = _serverPlugin.CreateRoomPlugin(information); - var room = new RagonRoom(roomId, information, roomPlugin); + _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id}"); - _serverPlugin.OnRoomCreate(lobbyPlayer, room); + JoinSuccess(roomPlayer, room, Writer); - room.Plugin.OnAttached(room); - - context.Lobby.Persist(room); - context.Scheduler.Run(room); - context.SetRoom(room, roomPlayer); - - _logger.Trace( - $"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}"); - - JoinSuccess(roomPlayer, room, Writer); - - room.Plugin.OnPlayerJoined(roomPlayer); - } + room.Plugin.OnPlayerJoined(roomPlayer); } private void JoinSuccess(RagonRoomPlayer player, RagonRoom room, RagonStream writer) @@ -107,7 +90,6 @@ public sealed class RoomJoinOrCreateOperation : BaseOperation writer.WriteString(room.Id); writer.WriteUShort((ushort)room.PlayerMin); writer.WriteUShort((ushort)room.PlayerMax); - writer.WriteString(room.Scene); writer.WriteString(player.Id); writer.WriteString(room.Owner.Id); diff --git a/Ragon.Server/Sources/Handler/RoomLeaveOperation.cs b/Ragon.Server/Sources/Handler/RoomLeaveOperation.cs index 0b2cbab..991cbab 100644 --- a/Ragon.Server/Sources/Handler/RoomLeaveOperation.cs +++ b/Ragon.Server/Sources/Handler/RoomLeaveOperation.cs @@ -26,7 +26,7 @@ public sealed class RoomLeaveOperation: BaseOperation public RoomLeaveOperation(RagonStream reader, RagonStream writer): base(reader, writer) { - + } public override void Handle(RagonContext context, NetworkChannel channel) diff --git a/Ragon.Server/Sources/IRagonContextObserver.cs b/Ragon.Server/Sources/IRagonContextObserver.cs index 99f87d8..bf28bd8 100644 --- a/Ragon.Server/Sources/IRagonContextObserver.cs +++ b/Ragon.Server/Sources/IRagonContextObserver.cs @@ -18,14 +18,15 @@ namespace Ragon.Server; public class RagonContextObserver { - private Dictionary _contexts; - public RagonContextObserver(Dictionary contexts) + private readonly RagonConnectionRegistry _registry; + + public RagonContextObserver(RagonConnectionRegistry registry) { - _contexts = contexts; + _registry = registry; } - public void OnAuthorized(RagonContext context) + public void OnAuthorized(RagonContext context) { - _contexts.Add(context.LobbyPlayer.Id, context); + _registry.Add(context.LobbyPlayer.Id, context); } } \ No newline at end of file diff --git a/Ragon.Server/Sources/IRagonServer.cs b/Ragon.Server/Sources/IRagonServer.cs index 3e54335..76fd3a4 100644 --- a/Ragon.Server/Sources/IRagonServer.cs +++ b/Ragon.Server/Sources/IRagonServer.cs @@ -16,14 +16,15 @@ using Ragon.Protocol; using Ragon.Server.Handler; -using Ragon.Server.IO; using Ragon.Server.Lobby; +using Ragon.Server.Time; namespace Ragon.Server; public interface IRagonServer { BaseOperation ResolveHandler(RagonOperation operation); - public RagonContext? GetContextByConnectionId(ushort peerId); - public RagonContext? GetContextById(string playerId); + public RagonConnectionRegistry ConnectionRegistry { get; } + public RagonScheduler Scheduler { get; } + public IRagonLobby Lobby { get; } } \ No newline at end of file diff --git a/Ragon.Server/Sources/Lobby/IRagonLobby.cs b/Ragon.Server/Sources/Lobby/IRagonLobby.cs index de2d55c..349e2fa 100644 --- a/Ragon.Server/Sources/Lobby/IRagonLobby.cs +++ b/Ragon.Server/Sources/Lobby/IRagonLobby.cs @@ -23,7 +23,6 @@ public interface IRagonLobby { public IReadOnlyList Rooms { get; } public bool FindRoomById(string roomId, [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/RagonLobbyDispatcher.cs b/Ragon.Server/Sources/Lobby/RagonLobbyDispatcher.cs index 115bf13..4630a02 100644 --- a/Ragon.Server/Sources/Lobby/RagonLobbyDispatcher.cs +++ b/Ragon.Server/Sources/Lobby/RagonLobbyDispatcher.cs @@ -24,7 +24,6 @@ public class RagonLobbyDispatcher var room = rooms[i]; writer.WriteString(room.Id); - writer.WriteString(room.Scene); writer.WriteUShort((ushort)room.PlayerMax); writer.WriteUShort((ushort)room.PlayerMin); writer.WriteUShort((ushort)room.PlayerCount); diff --git a/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs b/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs index 6446a95..7025fe9 100644 --- a/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs +++ b/Ragon.Server/Sources/Lobby/RagonLobbyInMemory.cs @@ -49,35 +49,7 @@ public class LobbyInMemory : IRagonLobby room = default; return false; } - - public bool FindRoomByScene(string sceneName, [MaybeNullWhen(false)] out RagonRoom room) - { - foreach (var existsRoom in _rooms) - { - if (existsRoom.Scene == sceneName) - { - if (existsRoom.PlayerCount >= existsRoom.PlayerMax) - { - _logger.Warning($"Room with scene {sceneName} fulfilled"); - - room = default; - return false; - } - - room = existsRoom; - return true; - } - } - - room = default; - return false; - } - - public bool FindRoomByProperties(Dictionary props) - { - return true; - } - + public void Persist(RagonRoom room) { room.Attach(); @@ -86,7 +58,7 @@ public class LobbyInMemory : IRagonLobby _logger.Trace($"New room: {room.Id}"); foreach (var r in _rooms) - _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count}"); + _logger.Trace($"Room: {r.Id} ID: {r.Id} Players: {r.Players.Count}"); } public bool RemoveIfEmpty(RagonRoom room) @@ -103,7 +75,7 @@ public class LobbyInMemory : IRagonLobby } foreach (var r in _rooms) - _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count}"); + _logger.Trace($"Room: {r.Id} ID: {r.Id} Players: {r.Players.Count}"); return result; } diff --git a/Ragon.Server/Sources/Plugin/BaseServerPlugin.cs b/Ragon.Server/Sources/Plugin/BaseServerPlugin.cs index 3511e90..72c6a72 100644 --- a/Ragon.Server/Sources/Plugin/BaseServerPlugin.cs +++ b/Ragon.Server/Sources/Plugin/BaseServerPlugin.cs @@ -16,7 +16,6 @@ using Ragon.Protocol; using Ragon.Server.Handler; -using Ragon.Server.IO; using Ragon.Server.Lobby; using Ragon.Server.Room; @@ -42,7 +41,7 @@ namespace Ragon.Server.Plugin public void Approve(string id, string name, string payload) { - var ctx = _server.GetContextByConnectionId(PeerID); + var ctx = _server.ConnectionRegistry.GetContextByConnectionId(PeerID); if (ctx == null) return; @@ -52,7 +51,7 @@ namespace Ragon.Server.Plugin public void Reject() { - var ctx = _server.GetContextByConnectionId(PeerID); + var ctx = _server.ConnectionRegistry.GetContextByConnectionId(PeerID); if (ctx == null) return; @@ -80,7 +79,9 @@ namespace Ragon.Server.Plugin { public IRagonServer Server { get; protected set; } - public virtual void OnAttached(IRagonServer server) + public virtual void OnAttached( + IRagonServer server + ) { Server = server; } diff --git a/Ragon.Server/Sources/Plugin/IServerPlugin.cs b/Ragon.Server/Sources/Plugin/IServerPlugin.cs index 7b4ae89..bb28d7a 100644 --- a/Ragon.Server/Sources/Plugin/IServerPlugin.cs +++ b/Ragon.Server/Sources/Plugin/IServerPlugin.cs @@ -16,6 +16,7 @@ using Ragon.Server.Lobby; using Ragon.Server.Room; +using Ragon.Server.Time; namespace Ragon.Server.Plugin { diff --git a/Ragon.Server/Sources/RagonConnectionRegistry.cs b/Ragon.Server/Sources/RagonConnectionRegistry.cs new file mode 100644 index 0000000..db0444e --- /dev/null +++ b/Ragon.Server/Sources/RagonConnectionRegistry.cs @@ -0,0 +1,60 @@ +namespace Ragon.Server; + +public class RagonConnectionRegistry +{ + private readonly Dictionary _contextsByConnection = new(); + private readonly Dictionary _contextsByPlayerId = new(); + private readonly List _contexts = new(); + private readonly List _playerContexts = new(); + + public void Add(string playerId, RagonContext context) + { + _contextsByPlayerId.Add(playerId, context); + _playerContexts.Add(context); + } + + public void Add(ushort connectionId, RagonContext context) + { + _contextsByConnection.Add(connectionId, context); + _contexts.Add(context); + } + + + public bool Remove(ushort connectionId, out RagonContext o) + { + if (_contextsByConnection.Remove(connectionId, out var context)) + { + _contexts.Remove(context); + o = context; + + return true; + } + + o = null; + + return false; + } + + public bool Remove(string playerId) + { + if (_contextsByPlayerId.Remove(playerId, out var context)) + { + _playerContexts.Remove(context); + + return true; + } + + return false; + } + + public bool TryGetValue(ushort connectionId, out RagonContext o) + { + return _contextsByConnection.TryGetValue(connectionId, out o); + } + + public IReadOnlyList Contexts => _contexts; + public IReadOnlyList PlayerContexts => _playerContexts; + + public RagonContext? GetContextByConnectionId(ushort peerId) => _contextsByConnection.GetValueOrDefault(peerId); + public RagonContext? GetContextById(string playerId) => _contextsByPlayerId.GetValueOrDefault(playerId); +} \ No newline at end of file diff --git a/Ragon.Server/Sources/RagonServer.cs b/Ragon.Server/Sources/RagonServer.cs index 1c66c64..70364fc 100644 --- a/Ragon.Server/Sources/RagonServer.cs +++ b/Ragon.Server/Sources/RagonServer.cs @@ -38,8 +38,7 @@ public class RagonServer : IRagonServer, INetworkListener private readonly RagonStream _reader; private readonly RagonStream _writer; private readonly RagonScheduler _scheduler; - private readonly Dictionary _contextsByConnection; - private readonly Dictionary _contextsByPlayerId; + private readonly RagonConnectionRegistry _connectionRegistry; private readonly Stopwatch _timer; private readonly RagonLobbyDispatcher _lobbySerializer; private readonly long _tickRate = 0; @@ -55,8 +54,7 @@ public class RagonServer : IRagonServer, INetworkListener _server = server; _configuration = configuration; _serverPlugin = plugin; - _contextsByConnection = new Dictionary(); - _contextsByPlayerId = new Dictionary(); + _connectionRegistry = new RagonConnectionRegistry(); _lobby = new LobbyInMemory(); _lobbySerializer = new RagonLobbyDispatcher(_lobby); _scheduler = new RagonScheduler(); @@ -65,13 +63,11 @@ public class RagonServer : IRagonServer, INetworkListener _tickRate = 1000 / _configuration.ServerTickRate; _timer = new Stopwatch(); - var contextObserver = new RagonContextObserver(_contextsByPlayerId); + var contextObserver = new RagonContextObserver(_connectionRegistry); _scheduler.Run(new RagonActionTimer(SendRoomList, 2.0f)); _scheduler.Run(new RagonActionTimer(SendPlayerUserData, 0.1f)); _scheduler.Run(new RagonActionTimer(SendRoomUserData, 0.1f)); - _serverPlugin.OnAttached(this); - _handlers = new BaseOperation[byte.MaxValue]; _handlers[(byte)RagonOperation.AUTHORIZE] = new AuthorizationOperation(_reader, _writer, this, _serverPlugin, contextObserver, configuration); _handlers[(byte)RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(_reader, _writer, plugin, _configuration); @@ -80,7 +76,6 @@ public class RagonServer : IRagonServer, INetworkListener _handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer); _handlers[(byte)RagonOperation.TIMESTAMP_SYNCHRONIZATION] = new TimestampSyncOperation(_reader, _writer); _handlers[(byte)RagonOperation.REPLICATE_ROOM_EVENT] = new RoomEventOperation(_reader, _writer); - _handlers[(byte)RagonOperation.REPLICATE_RAW_DATA] = new RoomDataOperation(_reader, _writer); _handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataOperation(_reader, _writer, _configuration.LimitUserDataSize); _handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserDataSize); } @@ -133,12 +128,12 @@ public class RagonServer : IRagonServer, INetworkListener var context = new RagonContext(connection, _lobby, _scheduler, _configuration.LimitBufferedEvents); _logger.Trace($"Connected: {connection.Id}"); - _contextsByConnection.Add(connection.Id, context); + _connectionRegistry.Add(connection.Id, context); } public void OnDisconnected(INetworkConnection connection) { - if (_contextsByConnection.Remove(connection.Id, out var context)) + if (_connectionRegistry.Remove(connection.Id, out var context)) { var room = context.Room; if (room != null) @@ -149,7 +144,7 @@ public class RagonServer : IRagonServer, INetworkListener } if (context.ConnectionStatus == ConnectionStatus.Authorized) - _contextsByPlayerId.Remove(context.LobbyPlayer.Id); + _connectionRegistry.Remove(context.LobbyPlayer.Id); _logger.Trace($"Disconnected: {connection.Id}"); } @@ -161,7 +156,7 @@ public class RagonServer : IRagonServer, INetworkListener public void OnTimeout(INetworkConnection connection) { - if (_contextsByConnection.Remove(connection.Id, out var context) && context.ConnectionStatus == ConnectionStatus.Authorized) + if (_connectionRegistry.Remove(connection.Id, out var context) && context.ConnectionStatus == ConnectionStatus.Authorized) { var room = context.Room; if (room != null) @@ -171,7 +166,7 @@ public class RagonServer : IRagonServer, INetworkListener } if (context.ConnectionStatus == ConnectionStatus.Authorized) - _contextsByPlayerId.Remove(context.LobbyPlayer.Id); + _connectionRegistry.Remove(context.LobbyPlayer.Id); _logger.Trace($"Timeout: {connection.Id}|{context.LobbyPlayer.Name}|{context.LobbyPlayer.Id}"); } @@ -185,7 +180,7 @@ public class RagonServer : IRagonServer, INetworkListener { try { - if (_contextsByConnection.TryGetValue(connection.Id, out var context)) + if (_connectionRegistry.TryGetValue(connection.Id, out var context)) { _writer.Clear(); _reader.Clear(); @@ -223,24 +218,24 @@ public class RagonServer : IRagonServer, INetworkListener _lobbySerializer.Write(_writer); var sendData = _writer.ToArray(); - foreach (var (_, value) in _contextsByPlayerId) + foreach (var ctx in _connectionRegistry.Contexts) { - if (value.Room == null) // If only in lobby, then send room list data - value.Connection.Reliable.Send(sendData); + if (ctx.Room == null) // If only in lobby, then send room list data + ctx.Connection.Reliable.Send(sendData); } } public void SendPlayerUserData() { - foreach (var (_, value) in _contextsByPlayerId) + foreach (var playerContext in _connectionRegistry.PlayerContexts) { - if (value.UserData.IsDirty) + if (playerContext.UserData.IsDirty) { _writer.Clear(); _writer.WriteOperation(RagonOperation.PLAYER_DATA_UPDATED); - _writer.WriteUShort(value.Connection.Id); + _writer.WriteUShort(playerContext.Connection.Id); - value.UserData.Write(_writer); + playerContext.UserData.Write(_writer); var sendData = _writer.ToArray(); _server.Broadcast(sendData, NetworkChannel.RELIABLE); @@ -264,22 +259,18 @@ public class RagonServer : IRagonServer, INetworkListener } } } - + public BaseOperation ResolveHandler(RagonOperation operation) { return _handlers[(byte)operation]; } - - public RagonContext? GetContextByConnectionId(ushort peerId) - { - return _contextsByConnection.TryGetValue(peerId, out var context) ? context : null; - } - public RagonContext? GetContextById(string playerId) - { - return _contextsByPlayerId.TryGetValue(playerId, out var context) ? context : null; - } + public RagonConnectionRegistry ConnectionRegistry => _connectionRegistry; + public RagonScheduler Scheduler => _scheduler; + + public IRagonLobby Lobby => _lobby; + private void CopyrightInfo() { _logger.Info($"Server Version: {ServerVersion}"); diff --git a/Ragon.Server/Sources/Room/IRagonRoom.cs b/Ragon.Server/Sources/Room/IRagonRoom.cs index dcd29b6..9adddeb 100644 --- a/Ragon.Server/Sources/Room/IRagonRoom.cs +++ b/Ragon.Server/Sources/Room/IRagonRoom.cs @@ -22,17 +22,12 @@ namespace Ragon.Server.Room; public interface IRagonRoom { public string Id { get; } - public string Scene { get; } public int PlayerMin { get; } public int PlayerMax { get; } public int PlayerCount { get; } public RagonData UserData { get; } - - public void ReplicateData(byte[] data, NetworkChannel channel); - public void ReplicateData(byte[] data, List player, NetworkChannel channel); - public void ReplicateData(RagonRoomPlayer invoker, byte[] data, List receivers, - NetworkChannel channel = NetworkChannel.RELIABLE); RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection); RagonRoomPlayer GetPlayerById(string id); + IReadOnlyList GetPlayers(); } \ No newline at end of file diff --git a/Ragon.Server/Sources/Room/RagonRoom.cs b/Ragon.Server/Sources/Room/RagonRoom.cs index 363db1e..582d76b 100644 --- a/Ragon.Server/Sources/Room/RagonRoom.cs +++ b/Ragon.Server/Sources/Room/RagonRoom.cs @@ -26,10 +26,10 @@ namespace Ragon.Server.Room; public class RagonRoom : IRagonRoom, IRagonAction { public string Id { 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 IReadOnlyList GetPlayers() => PlayerList; public bool IsDone { get; private set; } @@ -49,7 +49,6 @@ public class RagonRoom : IRagonRoom, IRagonAction public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin) { Id = roomId; - Scene = info.Scene; PlayerMax = info.Max; PlayerMin = info.Min; Plugin = roomPlugin; @@ -66,8 +65,6 @@ public class RagonRoom : IRagonRoom, IRagonAction Writer = new RagonStream(); } - - public void RestoreBufferedEvents(RagonRoomPlayer roomPlayer) { foreach (var evnt in _bufferedEvents) @@ -163,47 +160,7 @@ public class RagonRoom : IRagonRoom, IRagonAction } } } - public void ReplicateData(byte[] data, NetworkChannel channel) - { - ReplicateData(data, ReadyPlayersList, channel); - } - - public void ReplicateData(byte[] data, List receivers, - NetworkChannel channel = NetworkChannel.RELIABLE) - { - var dataSize = data.Length; - var headerSize = 3; - var size = headerSize + dataSize; - var sendData = new byte[size]; - var peerId = 10000; // Server Peer - - sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA; - sendData[1] = (byte)peerId; - sendData[2] = (byte)(peerId >> 8); - - Array.Copy(data, 0, sendData, headerSize, dataSize); - - Broadcast(sendData, receivers, channel); - } - public void ReplicateData(RagonRoomPlayer invoker, byte[] data, List receivers, - NetworkChannel channel = NetworkChannel.RELIABLE) - { - var dataSize = data.Length; - var headerSize = 3; - var size = headerSize + dataSize; - var sendData = new byte[size]; - var peerId = invoker.Connection.Id; - - sendData[0] = (byte)RagonOperation.REPLICATE_RAW_DATA; - sendData[1] = (byte)peerId; - sendData[2] = (byte)(peerId >> 8); - - Array.Copy(data, 0, sendData, headerSize, dataSize); - - Broadcast(sendData, receivers, channel); - } - public void Tick(float dt) { @@ -247,16 +204,6 @@ public class RagonRoom : IRagonRoom, IRagonAction ReadyPlayersList = PlayerList.Where(p => p.IsLoaded).ToList(); } - public void UpdateMap(string sceneName) - { - Scene = sceneName; - - foreach (var player in PlayerList) - player.UnsetReady(); - - UpdateReadyPlayerList(); - } - public void Broadcast(byte[] data, NetworkChannel channel = NetworkChannel.RELIABLE) { if (channel == NetworkChannel.RELIABLE) diff --git a/Ragon.Server/Sources/Room/RagonRoomInformation.cs b/Ragon.Server/Sources/Room/RagonRoomInformation.cs index dcc37e4..f76e188 100644 --- a/Ragon.Server/Sources/Room/RagonRoomInformation.cs +++ b/Ragon.Server/Sources/Room/RagonRoomInformation.cs @@ -18,7 +18,6 @@ namespace Ragon.Server; public ref struct RoomInformation { - public string Scene; public int Min; public int Max; public int BufferedEventsLimit; diff --git a/Ragon.Server/Sources/Time/IRagonAction.cs b/Ragon.Server/Sources/Scheduler/IRagonAction.cs similarity index 100% rename from Ragon.Server/Sources/Time/IRagonAction.cs rename to Ragon.Server/Sources/Scheduler/IRagonAction.cs diff --git a/Ragon.Server/Sources/Time/RagonActionExecutor.cs b/Ragon.Server/Sources/Scheduler/RagonActionExecutor.cs similarity index 100% rename from Ragon.Server/Sources/Time/RagonActionExecutor.cs rename to Ragon.Server/Sources/Scheduler/RagonActionExecutor.cs diff --git a/Ragon.Server/Sources/Time/RagonActionTimer.cs b/Ragon.Server/Sources/Scheduler/RagonActionTimer.cs similarity index 100% rename from Ragon.Server/Sources/Time/RagonActionTimer.cs rename to Ragon.Server/Sources/Scheduler/RagonActionTimer.cs