feat: config for size of property
fix: websocket server now can receive large messages fix: buffer resize on read array
This commit is contained in:
@@ -27,13 +27,13 @@ public class RagonProperty : RagonPayload
|
||||
|
||||
private uint[] _data;
|
||||
|
||||
public RagonProperty(int size, bool isFixed)
|
||||
public RagonProperty(int size, bool isFixed, int limit)
|
||||
{
|
||||
Size = size;
|
||||
IsFixed = isFixed;
|
||||
IsDirty = false;
|
||||
|
||||
_data = new uint[128];
|
||||
|
||||
_data = new uint[limit / 4 + 1];
|
||||
}
|
||||
|
||||
public void Read(RagonBuffer buffer)
|
||||
|
||||
@@ -24,11 +24,14 @@ namespace Ragon.Server.Handler;
|
||||
public sealed class EntityCreateOperation : BaseOperation
|
||||
{
|
||||
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(EntityCreateOperation));
|
||||
|
||||
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
private RagonServerConfiguration _configuration;
|
||||
|
||||
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer, RagonServerConfiguration configuration) :
|
||||
base(reader, writer)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
@@ -53,7 +56,7 @@ public sealed class EntityCreateOperation : BaseOperation
|
||||
var propertyType = Reader.ReadBool();
|
||||
var propertySize = Reader.ReadUShort();
|
||||
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType, _configuration.LimitPropertySize));
|
||||
}
|
||||
|
||||
if (Reader.Capacity > 0)
|
||||
|
||||
@@ -27,9 +27,11 @@ namespace Ragon.Server.Handler
|
||||
public sealed class SceneLoadedOperation : BaseOperation
|
||||
{
|
||||
private readonly IRagonLogger _logger = LoggerManager.GetLogger(nameof(SceneLoadedOperation));
|
||||
|
||||
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
private RagonServerConfiguration _configuration;
|
||||
|
||||
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer, RagonServerConfiguration serverConfiguration) : base(reader, writer)
|
||||
{
|
||||
_configuration = serverConfiguration;
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
@@ -40,6 +42,7 @@ namespace Ragon.Server.Handler
|
||||
var owner = context.Room.Owner;
|
||||
var player = context.RoomPlayer;
|
||||
var room = context.Room;
|
||||
|
||||
if (player.IsLoaded)
|
||||
{
|
||||
_logger.Warning($"Player {player.Name}:{player.Connection.Id} already ready");
|
||||
@@ -70,10 +73,11 @@ namespace Ragon.Server.Handler
|
||||
{
|
||||
var propertyType = Reader.ReadBool();
|
||||
var propertySize = Reader.ReadUShort();
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType, _configuration.LimitPropertySize));
|
||||
}
|
||||
|
||||
var roomPlugin = room.Plugin;
|
||||
|
||||
if (!roomPlugin.OnEntityCreate(player, entity)) continue;
|
||||
|
||||
var playerInfo = $"Player {context.Connection.Id}|{context.LobbyPlayer.Name}";
|
||||
|
||||
@@ -79,8 +79,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_handlers[(byte)RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.SCENE_LOADED] = new SceneLoadedOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.SCENE_LOADED] = new SceneLoadedOperation(_reader, _writer, _configuration);
|
||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateOperation(_reader, _writer, _configuration);
|
||||
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityDestroyOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation(_reader, _writer);
|
||||
@@ -89,8 +89,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_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.LimitUserData);
|
||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserData);
|
||||
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomUserDataOperation(_reader, _writer, _configuration.LimitUserDataSize);
|
||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerUserDataOperation(_reader, _writer, _configuration.LimitUserDataSize);
|
||||
}
|
||||
public void Tick()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,8 @@ public struct RagonServerConfiguration
|
||||
public int LimitPlayersPerRoom;
|
||||
public int LimitRooms;
|
||||
public int LimitBufferedEvents;
|
||||
public int LimitUserData;
|
||||
public int LimitUserDataSize;
|
||||
public int LimitPropertySize;
|
||||
|
||||
private static Dictionary<string, ServerType> _serverTypes = new Dictionary<string, ServerType>()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user