feat: room properties ready, player properties wip
This commit is contained in:
@@ -41,6 +41,7 @@ public sealed class AuthorizationOperation: BaseOperation
|
||||
_webhook = webhook;
|
||||
_observer = observer;
|
||||
_writer = writer;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
|
||||
+4
-6
@@ -5,11 +5,11 @@ using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler
|
||||
{
|
||||
public class PlayerDataOperation : BaseOperation
|
||||
public class PlayerPropertiesOperation : BaseOperation
|
||||
{
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public PlayerDataOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
public PlayerPropertiesOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -20,10 +20,8 @@ namespace Ragon.Server.Handler
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var playerDataLen = Reader.ReadUShort();
|
||||
var playerData = Reader.ReadBytes(playerDataLen);
|
||||
|
||||
|
||||
var playerData = Reader.ReadBytes(Reader.Capacity);
|
||||
context.UserData.Data = playerData;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
|
||||
@@ -27,11 +28,22 @@ public sealed class RoomDataOperation : BaseOperation
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var playerDataLen = Reader.ReadUShort();
|
||||
var playerData = Reader.ReadBytes(playerDataLen);
|
||||
|
||||
var player = context.RoomPlayer;
|
||||
var room = context.Room;
|
||||
if (room != null)
|
||||
room.UserData.Data = playerData;
|
||||
|
||||
var data = Reader.RawData;
|
||||
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);
|
||||
|
||||
Array.Copy(data, 1, sendData, headerSize, dataSize);
|
||||
|
||||
room.Broadcast(sendData, channel);
|
||||
}
|
||||
}
|
||||
+15
-18
@@ -17,33 +17,30 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.IO;
|
||||
using Ragon.Server.Lobby;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class RoomRawDataOperation : BaseOperation
|
||||
public sealed class RoomPropertiesOperation : BaseOperation
|
||||
{
|
||||
public RoomRawDataOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public RoomPropertiesOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Handle(RagonContext context, NetworkChannel channel)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
|
||||
{
|
||||
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
|
||||
return;
|
||||
}
|
||||
|
||||
var roomData = Reader.ReadBytes(Reader.Capacity);
|
||||
|
||||
var room = context.Room;
|
||||
|
||||
var data = Reader.RawData;
|
||||
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);
|
||||
|
||||
Array.Copy(data, 1, sendData, headerSize, dataSize);
|
||||
|
||||
room.Broadcast(sendData, channel);
|
||||
if (room != null)
|
||||
room.UserData.Data = roomData;
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,7 @@ public class RagonContext
|
||||
public RagonLobbyPlayer? LobbyPlayer { get; private set; }
|
||||
public RagonRoom? Room { get; private set; }
|
||||
public RagonRoomPlayer? RoomPlayer { get; private set; }
|
||||
|
||||
public RagonData UserData { get; private set; }
|
||||
|
||||
public RagonScheduler Scheduler { get; private set; }
|
||||
|
||||
public RagonContext(
|
||||
|
||||
@@ -74,7 +74,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
var contextObserver = new RagonContextObserver(_contextsByPlayerId);
|
||||
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomList, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendUserData, 0.2f));
|
||||
_scheduler.Run(new RagonActionTimer(SendPlayerProperties, 1.0f));
|
||||
_scheduler.Run(new RagonActionTimer(SendRoomProperties, 1.0f));
|
||||
|
||||
_serverPlugin.OnAttached(this);
|
||||
|
||||
@@ -94,9 +95,9 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_handlers[(byte)RagonOperation.TRANSFER_ENTITY_OWNERSHIP] = new EntityOwnershipOperation(_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 RoomRawDataOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.ROOM_DATA_UPDATED] = new RoomDataOperation(_reader, _writer);
|
||||
_handlers[(byte)RagonOperation.PLAYER_DATA_UPDATED] = new PlayerDataOperation(_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);
|
||||
|
||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||
}
|
||||
@@ -247,19 +248,39 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
}
|
||||
}
|
||||
|
||||
public void SendUserData()
|
||||
public void SendPlayerProperties()
|
||||
{
|
||||
foreach (var (_, value) in _contextsByPlayerId)
|
||||
{
|
||||
if (value.UserData.IsDirty)
|
||||
{
|
||||
_writer.Clear();
|
||||
_writer.WriteOperation(RagonOperation.PLAYER_DATA_UPDATED);
|
||||
_writer.WriteOperation(RagonOperation.PLAYER_PROPERTIES_UPDATED);
|
||||
_writer.WriteUShort(value.Connection.Id);
|
||||
_writer.WriteBytes(value.UserData.Data);
|
||||
|
||||
var sendData = _writer.ToArray();
|
||||
_server.Broadcast(sendData, NetworkChannel.RELIABLE);
|
||||
|
||||
value.UserData.IsDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SendRoomProperties()
|
||||
{
|
||||
foreach (var room in _lobby.Rooms)
|
||||
{
|
||||
if (room.UserData.IsDirty)
|
||||
{
|
||||
_writer.Clear();
|
||||
_writer.WriteOperation(RagonOperation.ROOM_PROPERTIES_UPDATED);
|
||||
_writer.WriteBytes(room.UserData.Data);
|
||||
|
||||
var sendData = _writer.ToArray();
|
||||
_server.Broadcast(sendData, NetworkChannel.RELIABLE);
|
||||
|
||||
room.UserData.IsDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
||||
|
||||
_entitiesDirtySet = new HashSet<RagonEntity>();
|
||||
|
||||
UserData = new RagonData(Array.Empty<byte>());
|
||||
Writer = new RagonBuffer();
|
||||
}
|
||||
|
||||
@@ -110,20 +111,6 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
||||
foreach (var roomPlayer in ReadyPlayersList)
|
||||
roomPlayer.Connection.Unreliable.Send(sendData);
|
||||
}
|
||||
|
||||
if (UserData.IsDirty)
|
||||
{
|
||||
Writer.Clear();
|
||||
Writer.WriteOperation(RagonOperation.ROOM_DATA_UPDATED);
|
||||
Writer.WriteUShort((ushort)UserData.Data.Length);
|
||||
Writer.WriteBytes(UserData.Data);
|
||||
|
||||
var sendData = Writer.ToArray();
|
||||
foreach (var roomPlayer in ReadyPlayersList)
|
||||
roomPlayer.Connection.Reliable.Send(sendData);
|
||||
|
||||
UserData.IsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void AttachPlayer(RagonRoomPlayer player)
|
||||
|
||||
Reference in New Issue
Block a user