feat: player propeties
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler
|
||||
{
|
||||
public class PlayerPropertiesOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PlayerPropertiesOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||
{
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var playerData = Reader.ReadBytes(Reader.Capacity);
|
||||
context.UserData.Data = playerData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler
|
||||
{
|
||||
public class PlayerUserDataOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly int _userDataLimit;
|
||||
|
||||
public PlayerUserDataOperation(
|
||||
RagonBuffer reader,
|
||||
RagonBuffer writer,
|
||||
int userDataLimit
|
||||
) : base(reader, writer)
|
||||
{
|
||||
_userDataLimit = userDataLimit;
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||
{
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var playerUserData = Reader.ReadBytes(Reader.Capacity);
|
||||
if (playerUserData.Length > _userDataLimit)
|
||||
{
|
||||
_logger.Warn($"Player {context.Connection.Id} exceeded user data limit");
|
||||
return;
|
||||
}
|
||||
|
||||
context.UserData.Data = playerUserData;
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-6
@@ -21,12 +21,18 @@ using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class RoomPropertiesOperation : BaseOperation
|
||||
public sealed class RoomUserDataOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RoomPropertiesOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
private readonly int _userDataLimit;
|
||||
|
||||
public RoomUserDataOperation(
|
||||
RagonBuffer reader,
|
||||
RagonBuffer writer,
|
||||
int userDataLimit
|
||||
) : base(reader, writer)
|
||||
{
|
||||
_userDataLimit = userDataLimit;
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
@@ -36,11 +42,16 @@ public sealed class RoomPropertiesOperation : BaseOperation
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var roomData = Reader.ReadBytes(Reader.Capacity);
|
||||
|
||||
var roomUserData = Reader.ReadBytes(Reader.Capacity);
|
||||
if (roomUserData.Length > _userDataLimit)
|
||||
{
|
||||
_logger.Warn("Room user data is too big");
|
||||
return;
|
||||
}
|
||||
|
||||
var room = context.Room;
|
||||
if (room != null)
|
||||
room.UserData.Data = roomData;
|
||||
room.UserData.Data = roomUserData;
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
|
||||
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomList, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendPlayerProperties, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomProperties, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendPlayerUserData, 0.2f));
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomUserData, 0.2f));
|
||||
|
||||
_serverPlugin.OnAttached(this);
|
||||
|
||||
@@ -96,8 +96,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_PROPERTIES_UPDATED] = new RoomPropertiesOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.PLAYER_PROPERTIES_UPDATED] = new PlayerPropertiesOperation(_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);
|
||||
|
||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||
}
|
||||
@@ -248,14 +248,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
}
|
||||
}
|
||||
|
||||
public void SendPlayerProperties()
|
||||
public void SendPlayerUserData()
|
||||
{
|
||||
foreach (var (_, value) in _contextsByPlayerId)
|
||||
{
|
||||
if (value.UserData.IsDirty)
|
||||
{
|
||||
_writer.Clear();
|
||||
_writer.WriteOperation(RagonOperation.PLAYER_PROPERTIES_UPDATED);
|
||||
_writer.WriteOperation(RagonOperation.PLAYER_DATA_UPDATED);
|
||||
_writer.WriteUShort(value.Connection.Id);
|
||||
_writer.WriteBytes(value.UserData.Data);
|
||||
|
||||
@@ -267,14 +267,14 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
}
|
||||
}
|
||||
|
||||
public void SendRoomProperties()
|
||||
public void SendRoomUserData()
|
||||
{
|
||||
foreach (var room in _lobby.Rooms)
|
||||
{
|
||||
if (room.UserData.IsDirty)
|
||||
{
|
||||
_writer.Clear();
|
||||
_writer.WriteOperation(RagonOperation.ROOM_PROPERTIES_UPDATED);
|
||||
_writer.WriteOperation(RagonOperation.ROOM_DATA_UPDATED);
|
||||
_writer.WriteBytes(room.UserData.Data);
|
||||
|
||||
var sendData = _writer.ToArray();
|
||||
|
||||
@@ -39,6 +39,7 @@ public struct RagonServerConfiguration
|
||||
public int LimitPlayersPerRoom;
|
||||
public int LimitRooms;
|
||||
public int LimitBufferedEvents;
|
||||
public int LimitUserData;
|
||||
public Dictionary<string, string> WebHooks;
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
Reference in New Issue
Block a user