diff --git a/Ragon.Client/Sources/Entity/RagonEntity.cs b/Ragon.Client/Sources/Entity/RagonEntity.cs index 8029625..03621d2 100644 --- a/Ragon.Client/Sources/Entity/RagonEntity.cs +++ b/Ragon.Client/Sources/Entity/RagonEntity.cs @@ -226,7 +226,7 @@ namespace Ragon.Client var prevOwner = Owner; Owner = player; - HasAuthority = player.PeerId == _client.Room.Local.PeerId; + HasAuthority = player.IsLocal; OwnershipChanged?.Invoke(prevOwner, player); } diff --git a/Ragon.Client/Sources/Handler/OwnershipEntityHandler.cs b/Ragon.Client/Sources/Handler/EntityOwnershipHandler.cs similarity index 83% rename from Ragon.Client/Sources/Handler/OwnershipEntityHandler.cs rename to Ragon.Client/Sources/Handler/EntityOwnershipHandler.cs index 5edb74a..6713819 100644 --- a/Ragon.Client/Sources/Handler/OwnershipEntityHandler.cs +++ b/Ragon.Client/Sources/Handler/EntityOwnershipHandler.cs @@ -19,13 +19,13 @@ using Ragon.Protocol; namespace Ragon.Client; -internal class OwnershipEntityHandler: Handler +internal class EntityOwnershipHandler: Handler { private readonly RagonListenerList _listenerList; private readonly RagonPlayerCache _playerCache; private readonly RagonEntityCache _entityCache; - public OwnershipEntityHandler( + public EntityOwnershipHandler( RagonListenerList listenerList, RagonPlayerCache playerCache, RagonEntityCache entityCache) @@ -37,13 +37,16 @@ internal class OwnershipEntityHandler: Handler public void Handle(RagonBuffer buffer) { - var newOwnerId = buffer.ReadString(); - var player = _playerCache.GetPlayerById(newOwnerId); + var newOwnerId = buffer.ReadUShort(); var entities = buffer.ReadUShort(); + + var player = _playerCache.GetPlayerByPeer(newOwnerId); for (var i = 0; i < entities; i++) { var entityId = buffer.ReadUShort(); _entityCache.OnOwnershipChanged(player, entityId); + + RagonLog.Trace("Entity changed owner: " + entityId); } } } \ No newline at end of file diff --git a/Ragon.Client/Sources/Handler/OwnershipRoomHandler.cs b/Ragon.Client/Sources/Handler/OwnershipRoomHandler.cs index 49aca9e..cb35c6f 100644 --- a/Ragon.Client/Sources/Handler/OwnershipRoomHandler.cs +++ b/Ragon.Client/Sources/Handler/OwnershipRoomHandler.cs @@ -37,8 +37,8 @@ internal class OwnershipRoomHandler: Handler public void Handle(RagonBuffer buffer) { - var newOwnerId = buffer.ReadString(); - var player = _playerCache.GetPlayerById(newOwnerId); + var newOwnerId = buffer.ReadUShort(); + var player = _playerCache.GetPlayerByPeer(newOwnerId); _playerCache.OnOwnershipChanged(newOwnerId); _listenerList.OnOwnershipChanged(player); diff --git a/Ragon.Client/Sources/RagonClient.cs b/Ragon.Client/Sources/RagonClient.cs index 63722fe..c7f4afb 100644 --- a/Ragon.Client/Sources/RagonClient.cs +++ b/Ragon.Client/Sources/RagonClient.cs @@ -91,7 +91,7 @@ namespace Ragon.Client _handlers[(byte)RagonOperation.JOIN_FAILED] = new JoinFailedHandler(_listenerList); _handlers[(byte)RagonOperation.LEAVE_ROOM] = new LeaveRoomHandler(this, _listenerList, _entityCache); _handlers[(byte)RagonOperation.OWNERSHIP_ROOM_CHANGED] = new OwnershipRoomHandler(_listenerList, _playerCache, _entityCache); - _handlers[(byte)RagonOperation.OWNERSHIP_ENTITY_CHANGED] = new OwnershipEntityHandler(_listenerList, _playerCache, _entityCache); + _handlers[(byte)RagonOperation.OWNERSHIP_ENTITY_CHANGED] = new EntityOwnershipHandler(_listenerList, _playerCache, _entityCache); _handlers[(byte)RagonOperation.PLAYER_JOINED] = new PlayerJoinHandler(_playerCache, _listenerList); _handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, _listenerList); _handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listenerList); diff --git a/Ragon.Client/Sources/RagonEntityCache.cs b/Ragon.Client/Sources/RagonEntityCache.cs index 4ed30a9..0563c50 100644 --- a/Ragon.Client/Sources/RagonEntityCache.cs +++ b/Ragon.Client/Sources/RagonEntityCache.cs @@ -24,20 +24,20 @@ public sealed class RagonEntityCache private readonly Dictionary _entityMap = new(); private readonly Dictionary _pendingEntities = new(); private readonly Dictionary _sceneEntities = new(); - + private readonly RagonClient _client; private readonly IRagonEntityListener _entityListener; private readonly IRagonSceneCollector _sceneCollector; private readonly RagonPlayerCache _playerCache; private int _localEntitiesCounter = 0; - + public RagonEntityCache( - RagonClient client, - RagonPlayerCache playerCache, + RagonClient client, + RagonPlayerCache playerCache, IRagonEntityListener listener, IRagonSceneCollector sceneCollector - ) + ) { _client = client; _entityListener = listener; @@ -49,24 +49,24 @@ public sealed class RagonEntityCache { return _entityMap[id]; } - + public void Create(RagonEntity entity, IRagonPayload? spawnPayload) { - var attachId = (ushort) (_playerCache.Local.PeerId + _localEntitiesCounter++) ; + var attachId = (ushort)(_playerCache.Local.PeerId + _localEntitiesCounter++); var buffer = _client.Buffer; - + buffer.Clear(); buffer.WriteOperation(RagonOperation.CREATE_ENTITY); buffer.WriteUShort(attachId); buffer.WriteUShort(entity.Type); - buffer.WriteByte((byte) entity.Authority); + buffer.WriteByte((byte)entity.Authority); entity.State.WriteInfo(buffer); - + spawnPayload?.Serialize(buffer); - + _pendingEntities.Add(attachId, entity); - + var sendData = buffer.ToArray(); _client.Reliable.Send(sendData); } @@ -74,16 +74,16 @@ public sealed class RagonEntityCache public void Transfer(RagonEntity entity, RagonPlayer player) { var buffer = _client.Buffer; - + buffer.Clear(); buffer.WriteOperation(RagonOperation.TRANSFER_ENTITY_OWNERSHIP); buffer.WriteUShort(entity.Id); buffer.WriteUShort(player.PeerId); - + var sendData = buffer.ToArray(); _client.Reliable.Send(sendData); } - + public void Destroy(RagonEntity entity, IRagonPayload? destroyPayload) { if (!entity.IsAttached) @@ -91,9 +91,9 @@ public sealed class RagonEntityCache RagonLog.Warn("Can't destroy object, he is not created"); return; } - + var buffer = _client.Buffer; - + buffer.Clear(); buffer.WriteOperation(RagonOperation.REMOVE_ENTITY); buffer.WriteUShort(entity.Id); @@ -107,7 +107,7 @@ public sealed class RagonEntityCache internal void WriteState(RagonBuffer buffer) { var changedEntities = 0u; - + buffer.Clear(); buffer.WriteOperation(RagonOperation.REPLICATE_ENTITY_STATE); @@ -119,34 +119,34 @@ public sealed class RagonEntityCache if (!ent.IsAttached || !ent.Replication || !ent.PropertiesChanged) continue; - + ent.Write(buffer); - + changedEntities++; } if (changedEntities <= 0) return; - + buffer.Write(changedEntities, 16, offset); var data = buffer.ToArray(); _client.Unreliable.Send(data); } - + internal void WriteScene(RagonBuffer buffer) { _sceneEntities.Clear(); - + var entities = _sceneCollector.Collect(); - buffer.WriteUShort((ushort) entities.Length); + buffer.WriteUShort((ushort)entities.Length); foreach (var entity in entities) { buffer.WriteUShort(entity.Type); - buffer.WriteByte((byte) entity.Authority); + buffer.WriteByte((byte)entity.Authority); buffer.WriteUShort(entity.SceneId); - + entity.State.WriteInfo(buffer); - + _sceneEntities.Add(entity.SceneId, entity); } } @@ -154,12 +154,12 @@ public sealed class RagonEntityCache internal void CacheScene() { _sceneEntities.Clear(); - + var entities = _sceneCollector.Collect(); foreach (var entity in entities) _sceneEntities.Add(entity.SceneId, entity); } - + internal void Cleanup() { var payload = new RagonPayload(); @@ -169,7 +169,7 @@ public sealed class RagonEntityCache _entityMap.Clear(); _entityList.Clear(); } - + internal RagonEntity OnCreate(ushort attachId, ushort entityType, ushort sceneId, ushort entityId, bool hasAuthority) { if (sceneId > 0) @@ -177,45 +177,45 @@ public sealed class RagonEntityCache if (_sceneEntities.TryGetValue(sceneId, out var entity)) { _entityMap.Add(entityId, entity); - + if (hasAuthority) _entityList.Add(entity); - + return entity; } } - + if (_pendingEntities.Remove(attachId, out var existsEntity)) { _entityMap.Add(entityId, existsEntity); - + if (hasAuthority) _entityList.Add(existsEntity); - + return existsEntity; } else { var entity = new RagonEntity(entityType, sceneId); - + _entityMap.Add(entityId, entity); - + if (hasAuthority) _entityList.Add(entity); - + _entityListener.OnEntityCreated(entity); return entity; } } - + internal void OnDestroy(ushort entityId, RagonPayload payload) { if (_entityMap.Remove(entityId, out var ragonEntity)) { _entityList.Remove(ragonEntity); - + ragonEntity.Detach(payload); } } @@ -224,7 +224,7 @@ public sealed class RagonEntityCache { if (_entityMap.TryGetValue(entityId, out var entity)) entity.Read(buffer); - else + else RagonLog.Warn($"Entity {entityId} not found!"); } @@ -232,15 +232,24 @@ public sealed class RagonEntityCache { if (_entityMap.TryGetValue(entityId, out var entity)) entity.Event(eventCode, player, buffer); - else + else RagonLog.Warn($"Entity {entityId} not found!"); } internal void OnOwnershipChanged(RagonPlayer player, ushort entityId) { if (_entityMap.TryGetValue(entityId, out var entity)) + { + if (player.IsLocal) + _entityList.Add(entity); + else + _entityList.Remove(entity); + entity.OnOwnershipChanged(player); + } else + { RagonLog.Warn($"Entity {entityId} not found!"); + } } } \ No newline at end of file diff --git a/Ragon.Client/Sources/RagonPlayerCache.cs b/Ragon.Client/Sources/RagonPlayerCache.cs index 2625fc0..bec7bbc 100644 --- a/Ragon.Client/Sources/RagonPlayerCache.cs +++ b/Ragon.Client/Sources/RagonPlayerCache.cs @@ -71,13 +71,15 @@ public sealed class RagonPlayerCache } } - public void OnOwnershipChanged(string playerId) + public void OnOwnershipChanged(ushort playerPeerId) { foreach (var player in _players) { - if (player.Id == playerId) + if (player.PeerId == playerPeerId) + { Owner = player; - player.IsRoomOwner = player.Id == playerId; + Owner.IsRoomOwner = true; + } } } diff --git a/Ragon.Relay/Ragon.Relay.csproj b/Ragon.Relay/Ragon.Relay.csproj index b492477..cf8f643 100644 --- a/Ragon.Relay/Ragon.Relay.csproj +++ b/Ragon.Relay/Ragon.Relay.csproj @@ -24,7 +24,7 @@ - + diff --git a/Ragon.Relay/Sources/Relay.cs b/Ragon.Relay/Sources/Relay.cs index a5d8a55..98edb98 100644 --- a/Ragon.Relay/Sources/Relay.cs +++ b/Ragon.Relay/Sources/Relay.cs @@ -17,7 +17,7 @@ using NLog; using Ragon.Server; using Ragon.Server.ENet; -using Ragon.Server.DotNetWebsockets; +using Ragon.Server.WebSocketServer; using Ragon.Server.IO; using Ragon.Server.Plugin; @@ -30,8 +30,8 @@ public class Relay var logger = LogManager.GetLogger("Ragon.Relay"); logger.Info("Relay Application"); - var configuration = Configuration.Load("relay.config.json"); - var serverType = Configuration.GetServerType(configuration.ServerType); + var configuration = RagonServerConfiguration.Load("relay.config.json"); + var serverType = RagonServerConfiguration.GetServerType(configuration.ServerType); INetworkServer networkServer = new ENetServer(); IServerPlugin plugin = new RelayServerPlugin(); @@ -41,7 +41,7 @@ public class Relay networkServer = new ENetServer(); break; case ServerType.WEBSOCKET: - networkServer = new DotNetWebSocketServer(); + networkServer = new WebSocketServer(); break; } diff --git a/Ragon.Relay/relay.config.json b/Ragon.Relay/relay.config.json index 3e61bde..25fbb5a 100644 --- a/Ragon.Relay/relay.config.json +++ b/Ragon.Relay/relay.config.json @@ -9,6 +9,7 @@ "limitConnections": 4095, "limitPlayersPerRoom": 20, "limitRooms": 200, + "limitBufferedEvents": 50, "webHooks": { "room-created": "http://127.0.0.1:3000/service/create-room", diff --git a/Ragon.Server.DotNetWebSockets/Ragon.Server.DotNetWebSockets.csproj b/Ragon.Server.WebSocketServer/Ragon.Server.WebSocketServer.csproj similarity index 89% rename from Ragon.Server.DotNetWebSockets/Ragon.Server.DotNetWebSockets.csproj rename to Ragon.Server.WebSocketServer/Ragon.Server.WebSocketServer.csproj index 5feec38..0c36bf3 100644 --- a/Ragon.Server.DotNetWebSockets/Ragon.Server.DotNetWebSockets.csproj +++ b/Ragon.Server.WebSocketServer/Ragon.Server.WebSocketServer.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 enable enable Ragon.WebSockets diff --git a/Ragon.Server.DotNetWebSockets/Sources/WebSocketConnection.cs b/Ragon.Server.WebSocketServer/Sources/WebSocketConnection.cs similarity index 97% rename from Ragon.Server.DotNetWebSockets/Sources/WebSocketConnection.cs rename to Ragon.Server.WebSocketServer/Sources/WebSocketConnection.cs index 59182c8..6c02f52 100644 --- a/Ragon.Server.DotNetWebSockets/Sources/WebSocketConnection.cs +++ b/Ragon.Server.WebSocketServer/Sources/WebSocketConnection.cs @@ -18,7 +18,7 @@ using NLog; using System.Net.WebSockets; using Ragon.Server.IO; -namespace Ragon.Server.DotNetWebsockets; +namespace Ragon.Server.WebSocketServer; public sealed class WebSocketConnection : INetworkConnection { diff --git a/Ragon.Server.DotNetWebSockets/Sources/WebSocketReliableChannel.cs b/Ragon.Server.WebSocketServer/Sources/WebSocketReliableChannel.cs similarity index 96% rename from Ragon.Server.DotNetWebSockets/Sources/WebSocketReliableChannel.cs rename to Ragon.Server.WebSocketServer/Sources/WebSocketReliableChannel.cs index b310b73..c00c528 100644 --- a/Ragon.Server.DotNetWebSockets/Sources/WebSocketReliableChannel.cs +++ b/Ragon.Server.WebSocketServer/Sources/WebSocketReliableChannel.cs @@ -17,7 +17,7 @@ using System.Net.WebSockets; using Ragon.Server.IO; -namespace Ragon.Server.DotNetWebsockets; +namespace Ragon.Server.WebSocketServer; public class WebSocketReliableChannel : INetworkChannel { diff --git a/Ragon.Server.DotNetWebSockets/Sources/WebSocketServer.cs b/Ragon.Server.WebSocketServer/Sources/WebSocketServer.cs similarity index 96% rename from Ragon.Server.DotNetWebSockets/Sources/WebSocketServer.cs rename to Ragon.Server.WebSocketServer/Sources/WebSocketServer.cs index 4e94d90..d304238 100644 --- a/Ragon.Server.DotNetWebSockets/Sources/WebSocketServer.cs +++ b/Ragon.Server.WebSocketServer/Sources/WebSocketServer.cs @@ -20,9 +20,9 @@ using NLog; using Ragon.Protocol; using Ragon.Server.IO; -namespace Ragon.Server.DotNetWebsockets; +namespace Ragon.Server.WebSocketServer; -public class DotNetWebSocketServer : INetworkServer +public class WebSocketServer : INetworkServer { public Executor Executor => _executor; @@ -35,7 +35,7 @@ public class DotNetWebSocketServer : INetworkServer private List _activeConnections; private CancellationTokenSource _cancellationTokenSource; - public DotNetWebSocketServer() + public WebSocketServer() { _sequencer = new Stack(); _connections = Array.Empty(); diff --git a/Ragon.Server/Sources/Entity/RagonEntity.cs b/Ragon.Server/Sources/Entity/RagonEntity.cs index ad4e6e4..842d441 100644 --- a/Ragon.Server/Sources/Entity/RagonEntity.cs +++ b/Ragon.Server/Sources/Entity/RagonEntity.cs @@ -20,7 +20,7 @@ using Ragon.Server.Room; namespace Ragon.Server.Entity; -public class RagonEntity: IRagonEntity +public class RagonEntity : IRagonEntity { private static ushort _idGenerator = 100; public ushort Id { get; private set; } @@ -31,24 +31,26 @@ public class RagonEntity: IRagonEntity public RagonAuthority Authority { get; private set; } public RagonPayload Payload { get; private set; } public IRagonEntityState State => _state; - + private readonly List _bufferedEvents; + private readonly int _limitBufferedEvents; private readonly RagonEntityState _state; - + public RagonEntity(RagonEntityParameters parameters) { Id = _idGenerator++; - + StaticId = parameters.StaticId; Type = parameters.Type; AttachId = parameters.AttachId; Authority = parameters.Authority; Payload = new RagonPayload(); - + _state = new RagonEntityState(this); _bufferedEvents = new List(); + _limitBufferedEvents = parameters.BufferedEvents; } - + public void Attach(RagonRoomPlayer owner) { Owner = owner; @@ -56,8 +58,7 @@ public class RagonEntity: IRagonEntity public void Detach() { - - } + } public void RestoreBufferedEvents(RagonRoomPlayer roomPlayer, RagonBuffer writer) { @@ -88,7 +89,7 @@ public class RagonEntity: IRagonEntity buffer.WriteUShort(Type); buffer.WriteUShort(Id); buffer.WriteUShort(Owner.Connection.Id); - + Payload.Write(buffer); var sendData = buffer.ToArray(); @@ -122,7 +123,7 @@ public class RagonEntity: IRagonEntity buffer.WriteUShort(Payload.Size); Payload.Write(buffer); - + _state.Snapshot(buffer); } @@ -163,7 +164,9 @@ public class RagonEntity: IRagonEntity return; } - if (eventMode == RagonReplicationMode.Buffered && targetMode != RagonTarget.Owner) + if (eventMode == RagonReplicationMode.Buffered && + targetMode != RagonTarget.Owner && + _bufferedEvents.Count < _limitBufferedEvents) { _bufferedEvents.Add(evnt); } @@ -221,7 +224,7 @@ public class RagonEntity: IRagonEntity { _state.AddProperty(property); } - + public void WriteState(RagonBuffer writer) { _state.Write(writer); @@ -231,9 +234,9 @@ public class RagonEntity: IRagonEntity { if (Owner.Connection.Id != player.Connection.Id) return false; - + _state.Read(reader); - + return true; } } \ No newline at end of file diff --git a/Ragon.Server/Sources/Entity/RagonEntityParameters.cs b/Ragon.Server/Sources/Entity/RagonEntityParameters.cs index 36bea24..79b23ce 100644 --- a/Ragon.Server/Sources/Entity/RagonEntityParameters.cs +++ b/Ragon.Server/Sources/Entity/RagonEntityParameters.cs @@ -24,4 +24,5 @@ public ref struct RagonEntityParameters public ushort StaticId; public ushort AttachId; public RagonAuthority Authority; + public int BufferedEvents; } \ No newline at end of file diff --git a/Ragon.Server/Sources/Handler/AuthorizationOperation.cs b/Ragon.Server/Sources/Handler/AuthorizationOperation.cs index b76e6ee..c03e795 100644 --- a/Ragon.Server/Sources/Handler/AuthorizationOperation.cs +++ b/Ragon.Server/Sources/Handler/AuthorizationOperation.cs @@ -28,16 +28,14 @@ public sealed class AuthorizationOperation: IRagonOperation private Logger _logger = LogManager.GetCurrentClassLogger(); private readonly RagonWebHookPlugin _ragonWebHook; private readonly RagonContextObserver _contextObserver; - private readonly Configuration _configuration; private readonly RagonBuffer _writer; - public AuthorizationOperation(RagonWebHookPlugin ragonWebHook, + public AuthorizationOperation( + RagonWebHookPlugin ragonWebHook, RagonContextObserver contextObserver, - RagonBuffer writer, - Configuration configuration) + RagonBuffer writer) { _ragonWebHook = ragonWebHook; - _configuration = configuration; _contextObserver = contextObserver; _writer = writer; } @@ -55,12 +53,13 @@ public sealed class AuthorizationOperation: IRagonOperation _logger.Warn("Player already request authorization!"); return; } - + + var configuration = context.Configuration; var key = reader.ReadString(); var name = reader.ReadString(); var payload = reader.ReadString(); - if (key == _configuration.ServerKey) + if (key == configuration.ServerKey) { if (_ragonWebHook.RequestAuthorization(context, name, payload)) return; diff --git a/Ragon.Server/Sources/Handler/EntityCreateOperation.cs b/Ragon.Server/Sources/Handler/EntityCreateOperation.cs index eaf9c88..b3eff0d 100644 --- a/Ragon.Server/Sources/Handler/EntityCreateOperation.cs +++ b/Ragon.Server/Sources/Handler/EntityCreateOperation.cs @@ -38,7 +38,8 @@ public sealed class EntityCreateOperation : IRagonOperation Type = entityType, Authority = eventAuthority, AttachId = attachId, - StaticId = 0 + StaticId = 0, + BufferedEvents = context.Configuration.LimitBufferedEvents, }; var entity = new RagonEntity(entityParameters); diff --git a/Ragon.Server/Sources/Handler/EntityOwnershipOperation.cs b/Ragon.Server/Sources/Handler/EntityOwnershipOperation.cs index 8873e6d..df78d2e 100644 --- a/Ragon.Server/Sources/Handler/EntityOwnershipOperation.cs +++ b/Ragon.Server/Sources/Handler/EntityOwnershipOperation.cs @@ -9,11 +9,11 @@ public sealed class EntityOwnershipOperation : IRagonOperation public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer) { - var player = context.RoomPlayer; + var currentOwner = context.RoomPlayer; var room = context.Room; var entityId = reader.ReadUShort(); - var playerId = reader.ReadUShort(); + var playerPeerId = reader.ReadUShort(); if (!room.Entities.TryGetValue(entityId, out var entity)) { @@ -21,29 +21,33 @@ public sealed class EntityOwnershipOperation : IRagonOperation return; } - if (entity.Owner.Connection.Id != player.Connection.Id) + if (entity.Owner.Connection.Id != currentOwner.Connection.Id) { _logger.Error($"Player not owner of entity with id {entityId}"); return; } - if (!room.Players.TryGetValue(playerId, out var nextOwner)) + if (!room.Players.TryGetValue(playerPeerId, out var nextOwner)) { _logger.Error($"Player not found with id {entityId}"); return; } - writer.Clear(); - writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED); - writer.WriteUShort(nextOwner.Connection.Id); - writer.WriteUShort(1); - writer.WriteUShort(entity.Id); - - player.Entities.Remove(entity); + currentOwner.Entities.Remove(entity); nextOwner.Entities.Add(entity); entity.Attach(nextOwner); _logger.Trace($"Entity {entity.Id} next owner {nextOwner.Connection.Id}"); + + writer.Clear(); + writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED); + writer.WriteUShort(playerPeerId); + writer.WriteUShort(1); + writer.WriteUShort(entity.Id); + + var sendData = writer.ToArray(); + foreach (var player in room.PlayerList) + player.Connection.Reliable.Send(sendData); } } \ No newline at end of file diff --git a/Ragon.Server/Sources/Http/RagonHttpServer.cs b/Ragon.Server/Sources/Http/RagonHttpServer.cs index 4c4b4c8..13525f8 100644 --- a/Ragon.Server/Sources/Http/RagonHttpServer.cs +++ b/Ragon.Server/Sources/Http/RagonHttpServer.cs @@ -91,7 +91,7 @@ public class RagonHttpServer } } - public void Start(Configuration configuration) + public void Start(RagonServerConfiguration configuration) { _cancellationTokenSource = new CancellationTokenSource(); _logger.Info($"Listen at http://0.0.0.0:{configuration.HttpPort}/"); diff --git a/Ragon.Server/Sources/Plugin/Web/RagonWebHookPlugin.cs b/Ragon.Server/Sources/Plugin/Web/RagonWebHookPlugin.cs index 71669ae..5dabada 100644 --- a/Ragon.Server/Sources/Plugin/Web/RagonWebHookPlugin.cs +++ b/Ragon.Server/Sources/Plugin/Web/RagonWebHookPlugin.cs @@ -31,7 +31,7 @@ public class RagonWebHookPlugin private RagonServer _server; private HttpClient _httpClient; - public RagonWebHookPlugin(RagonServer server, Configuration configuration) + public RagonWebHookPlugin(RagonServer server, RagonServerConfiguration configuration) { _webHooks = new Dictionary(configuration.WebHooks); _httpClient = new HttpClient(); diff --git a/Ragon.Server/Sources/RagonContext.cs b/Ragon.Server/Sources/RagonContext.cs index 4aafa22..3cf9e22 100644 --- a/Ragon.Server/Sources/RagonContext.cs +++ b/Ragon.Server/Sources/RagonContext.cs @@ -26,7 +26,7 @@ public class RagonContext public ConnectionStatus ConnectionStatus { get; set; } public INetworkConnection Connection { get; } public IExecutor Executor { get; private set; } - + public RagonServerConfiguration Configuration { get; private set; } public IRagonLobby Lobby { get; private set; } public RagonLobbyPlayer? LobbyPlayer { get; private set; } @@ -37,11 +37,13 @@ public class RagonContext public RagonContext( INetworkConnection connection, + RagonServerConfiguration configuration, IExecutor executor, IRagonLobby lobby, RagonScheduler scheduler) { ConnectionStatus = ConnectionStatus.Unauthorized; + Configuration = configuration; Connection = connection; Executor = executor; Lobby = lobby; diff --git a/Ragon.Server/Sources/RagonServer.cs b/Ragon.Server/Sources/RagonServer.cs index 62682be..f3e40b4 100644 --- a/Ragon.Server/Sources/RagonServer.cs +++ b/Ragon.Server/Sources/RagonServer.cs @@ -36,7 +36,7 @@ public class RagonServer : IRagonServer, INetworkListener private readonly IServerPlugin _serverPlugin; private readonly Thread _dedicatedThread; private readonly Executor _executor; - private readonly Configuration _configuration; + private readonly RagonServerConfiguration _configuration; private readonly RagonWebHookPlugin _webhooks; private readonly RagonHttpServer _httpServer; private readonly RagonBuffer _reader; @@ -50,7 +50,7 @@ public class RagonServer : IRagonServer, INetworkListener public RagonServer( INetworkServer server, IServerPlugin plugin, - Configuration configuration) + RagonServerConfiguration configuration) { _server = server; _executor = _server.Executor; @@ -74,7 +74,7 @@ public class RagonServer : IRagonServer, INetworkListener _serverPlugin.OnAttached(this); _handlers = new IRagonOperation[byte.MaxValue]; - _handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation(_webhooks, contextObserver, _writer, configuration); + _handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation(_webhooks, contextObserver, _writer); _handlers[(byte) RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(plugin, _webhooks); _handlers[(byte) RagonOperation.CREATE_ROOM] = new RoomCreateOperation(plugin, _webhooks); _handlers[(byte) RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_webhooks); @@ -136,7 +136,7 @@ public class RagonServer : IRagonServer, INetworkListener public void OnConnected(INetworkConnection connection) { - var context = new RagonContext(connection, _executor, _lobby, _scheduler); + var context = new RagonContext(connection, _configuration, _executor, _lobby, _scheduler); _logger.Trace($"Connected: {connection.Id}"); _contextsByConnection.Add(connection.Id, context); diff --git a/Ragon.Server/Sources/RagonServerConfiguration.cs b/Ragon.Server/Sources/RagonServerConfiguration.cs index c27a388..c9971bb 100644 --- a/Ragon.Server/Sources/RagonServerConfiguration.cs +++ b/Ragon.Server/Sources/RagonServerConfiguration.cs @@ -31,7 +31,7 @@ public class WebHook } [Serializable] -public struct Configuration +public struct RagonServerConfiguration { public string ServerKey; public string ServerType; @@ -43,6 +43,7 @@ public struct Configuration public int LimitConnections; public int LimitPlayersPerRoom; public int LimitRooms; + public int LimitBufferedEvents; public Dictionary WebHooks; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); @@ -53,12 +54,12 @@ public struct Configuration {"websocket", Server.ServerType.WEBSOCKET} }; - public static Configuration Load(string filePath) + public static RagonServerConfiguration Load(string filePath) { CopyrightInfo(); var data = File.ReadAllText(filePath); - var configuration = JsonConvert.DeserializeObject(data); + var configuration = JsonConvert.DeserializeObject(data); return configuration; } diff --git a/Ragon.sln b/Ragon.sln index 97863a5..80980c2 100644 --- a/Ragon.sln +++ b/Ragon.sln @@ -6,7 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Protocol", "Ragon.Pro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Server", "Ragon.Server\Ragon.Server.csproj", "{F4AA86B9-2486-4B53-BA77-43D958A2FDC3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Server.DotNetWebSockets", "Ragon.Server.DotNetWebSockets\Ragon.Server.DotNetWebSockets.csproj", "{81050343-A9B8-487B-86C8-7A5B7DD9C39B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Server.WebSocketServer", "Ragon.Server.WebSocketServer\Ragon.Server.WebSocketServer.csproj", "{81050343-A9B8-487B-86C8-7A5B7DD9C39B}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ragon.Server.ENet", "Ragon.Server.ENet\Ragon.Server.ENet.csproj", "{DD79AC4F-9E5C-4938-850E-805D537E68D0}" EndProject