🚧 pass-through raw data, refactoring

This commit is contained in:
2023-10-07 19:30:52 +03:00
parent 8788cb0fcf
commit e1a3ea45e2
29 changed files with 434 additions and 219 deletions
@@ -22,24 +22,25 @@ using Ragon.Server.Plugin.Web;
namespace Ragon.Server.Handler;
public sealed class AuthorizationOperation: IRagonOperation
public sealed class AuthorizationOperation: BaseOperation
{
private Logger _logger = LogManager.GetCurrentClassLogger();
private readonly RagonWebHookPlugin _ragonWebHook;
private readonly RagonContextObserver _contextObserver;
private readonly RagonWebHookPlugin _webhook;
private readonly RagonContextObserver _observer;
private readonly RagonBuffer _writer;
public AuthorizationOperation(
RagonWebHookPlugin ragonWebHook,
RagonContextObserver contextObserver,
RagonBuffer writer)
RagonBuffer reader,
RagonBuffer writer,
RagonWebHookPlugin webhook,
RagonContextObserver observer): base(reader, writer)
{
_ragonWebHook = ragonWebHook;
_contextObserver = contextObserver;
_webhook = webhook;
_observer = observer;
_writer = writer;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
if (context.ConnectionStatus == ConnectionStatus.Authorized)
{
@@ -54,13 +55,13 @@ public sealed class AuthorizationOperation: IRagonOperation
}
var configuration = context.Configuration;
var key = reader.ReadString();
var name = reader.ReadString();
var payload = reader.ReadString();
var key = Reader.ReadString();
var name = Reader.ReadString();
var payload = Reader.ReadString();
if (key == configuration.ServerKey)
{
if (_ragonWebHook.RequestAuthorization(context, name, payload))
if (_webhook.RequestAuthorization(context, name, payload))
return;
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, Guid.NewGuid().ToString(), name, payload);
@@ -78,7 +79,7 @@ public sealed class AuthorizationOperation: IRagonOperation
{
context.ConnectionStatus = ConnectionStatus.Authorized;
_contextObserver.OnAuthorized(context);
_observer.OnAuthorized(context);
var playerId = context.LobbyPlayer.Id;
var playerName = context.LobbyPlayer.Name;
@@ -108,4 +109,6 @@ public sealed class AuthorizationOperation: IRagonOperation
_logger.Trace($"Connection {context.Connection.Id}");
}
}
@@ -18,7 +18,16 @@ using Ragon.Protocol;
namespace Ragon.Server.Handler;
public interface IRagonOperation
public abstract class BaseOperation
{
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer);
protected readonly RagonBuffer Reader;
protected readonly RagonBuffer Writer;
public BaseOperation(RagonBuffer reader, RagonBuffer writer)
{
Reader = reader;
Writer = writer;
}
public abstract void Handle(RagonContext context, byte[] data);
}
@@ -20,18 +20,22 @@ using Ragon.Server.Entity;
namespace Ragon.Server.Handler;
public sealed class EntityCreateOperation : IRagonOperation
public sealed class EntityCreateOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public EntityCreateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
var player = context.RoomPlayer;
var room = context.Room;
var attachId = reader.ReadUShort();
var entityType = reader.ReadUShort();
var eventAuthority = (RagonAuthority) reader.ReadByte();
var propertiesCount = reader.ReadUShort();
var attachId = Reader.ReadUShort();
var entityType = Reader.ReadUShort();
var eventAuthority = (RagonAuthority) Reader.ReadByte();
var propertiesCount = Reader.ReadUShort();
var entityParameters = new RagonEntityParameters()
{
@@ -45,14 +49,14 @@ public sealed class EntityCreateOperation : IRagonOperation
var entity = new RagonEntity(entityParameters);
for (var i = 0; i < propertiesCount; i++)
{
var propertyType = reader.ReadBool();
var propertySize = reader.ReadUShort();
var propertyType = Reader.ReadBool();
var propertySize = Reader.ReadUShort();
entity.AddProperty(new RagonProperty(propertySize, propertyType));
}
if (reader.Capacity > 0)
entity.Payload.Read(reader);
if (Reader.Capacity > 0)
entity.Payload.Read(Reader);
var plugin = room.Plugin;
if (!plugin.OnEntityCreate(player, entity))
@@ -66,4 +70,6 @@ public sealed class EntityCreateOperation : IRagonOperation
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} created entity {entity.Id}:{entity.Type}");
}
}
@@ -20,15 +20,19 @@ using Ragon.Server.Event;
namespace Ragon.Server.Handler;
public sealed class EntityEventOperation : IRagonOperation
public sealed class EntityEventOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public EntityEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
var player = context.RoomPlayer;
var room = context.Room;
var entityId = reader.ReadUShort();
var entityId = Reader.ReadUShort();
if (!room.Entities.TryGetValue(entityId, out var ent))
{
@@ -36,16 +40,16 @@ public sealed class EntityEventOperation : IRagonOperation
return;
}
var eventId = reader.ReadUShort();
var eventMode = (RagonReplicationMode)reader.ReadByte();
var targetMode = (RagonTarget)reader.ReadByte();
var eventId = Reader.ReadUShort();
var eventMode = (RagonReplicationMode)Reader.ReadByte();
var targetMode = (RagonTarget)Reader.ReadByte();
var targetPlayerPeerId = (ushort)0;
if (targetMode == RagonTarget.Player)
targetPlayerPeerId = reader.ReadUShort();
targetPlayerPeerId = Reader.ReadUShort();
var @event = new RagonEvent(player, eventId);
@event.Read(reader);
@event.Read(Reader);
if (targetMode == RagonTarget.Player && room.Players.TryGetValue(targetPlayerPeerId, out var targetPlayer))
{
@@ -3,17 +3,21 @@ using Ragon.Protocol;
namespace Ragon.Server.Handler;
public sealed class EntityOwnershipOperation : IRagonOperation
public sealed class EntityOwnershipOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public EntityOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
var currentOwner = context.RoomPlayer;
var room = context.Room;
var entityId = reader.ReadUShort();
var playerPeerId = reader.ReadUShort();
var entityId = Reader.ReadUShort();
var playerPeerId = Reader.ReadUShort();
if (!room.Entities.TryGetValue(entityId, out var entity))
{
@@ -40,13 +44,13 @@ public sealed class EntityOwnershipOperation : IRagonOperation
_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);
Writer.Clear();
Writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED);
Writer.WriteUShort(playerPeerId);
Writer.WriteUShort(1);
Writer.WriteUShort(entity.Id);
var sendData = writer.ToArray();
var sendData = Writer.ToArray();
foreach (var player in room.PlayerList)
player.Connection.Reliable.Send(sendData);
}
@@ -20,20 +20,24 @@ using Ragon.Server.Entity;
namespace Ragon.Server.Handler;
public sealed class EntityDestroyOperation: IRagonOperation
public sealed class EntityDestroyOperation: BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public EntityDestroyOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
var player = context.RoomPlayer;
var room = context.Room;
var entityId = reader.ReadUShort();
var entityId = Reader.ReadUShort();
if (room.Entities.TryGetValue(entityId, out var entity))
{
var payload = new RagonPayload();
payload.Read(reader);
payload.Read(Reader);
room.DetachEntity(entity);
player.DetachEntity(entity);
@@ -19,20 +19,24 @@ using Ragon.Protocol;
namespace Ragon.Server.Handler;
public sealed class EntityStateOperation: IRagonOperation
public sealed class EntityStateOperation: BaseOperation
{
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public EntityStateOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
var room = context.Room;
var player = context.RoomPlayer;
var entitiesCount = reader.ReadUShort();
var entitiesCount = Reader.ReadUShort();
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
{
var entityId = reader.ReadUShort();
if (room.Entities.TryGetValue(entityId, out var entity) && entity.TryReadState(player, reader))
var entityId = Reader.ReadUShort();
if (room.Entities.TryGetValue(entityId, out var entity) && entity.TryReadState(player, Reader))
{
room.Track(entity);
}
@@ -23,20 +23,20 @@ using Ragon.Server.Room;
namespace Ragon.Server.Handler;
public sealed class RoomCreateOperation: IRagonOperation
public sealed class RoomCreateOperation : BaseOperation
{
private readonly RagonRoomParameters _roomParameters = new();
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomCreateOperation(IServerPlugin serverPlugin, RagonWebHookPlugin ragonWebHook)
public RoomCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin, RagonWebHookPlugin ragonWebHook) : base(reader, writer)
{
_serverPlugin = serverPlugin;
_ragonWebHookPlugin = ragonWebHook;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
{
@@ -44,56 +44,56 @@ public sealed class RoomCreateOperation: IRagonOperation
return;
}
var custom = reader.ReadBool();
var custom = Reader.ReadBool();
var roomId = Guid.NewGuid().ToString();
if (custom)
{
roomId = reader.ReadString();
roomId = Reader.ReadString();
if (context.Lobby.FindRoomById(roomId, out _))
{
writer.Clear();
writer.WriteOperation(RagonOperation.JOIN_FAILED);
writer.WriteString($"Room with id {roomId} already exists");
var sendData = writer.ToArray();
{
Writer.Clear();
Writer.WriteOperation(RagonOperation.JOIN_FAILED);
Writer.WriteString($"Room with id {roomId} already exists");
var sendData = Writer.ToArray();
context.Connection.Reliable.Send(sendData);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} join failed to room {roomId}, room already exist");
return;
return;
}
}
_roomParameters.Deserialize(reader);
_roomParameters.Deserialize(Reader);
var information = new RoomInformation()
{
Scene = _roomParameters.Scene,
Max = _roomParameters.Max,
Min = _roomParameters.Min,
Scene = _roomParameters.Scene,
Max = _roomParameters.Max,
Min = _roomParameters.Min,
};
var lobbyPlayer = context.LobbyPlayer;
var roomPlayer = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
var room = new RagonRoom(roomId, information, roomPlugin);
roomPlayer.OnAttached(room);
context.Scheduler.Run(room);
context.Lobby.Persist(room);
context.SetRoom(room, roomPlayer);
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
JoinSuccess(roomPlayer, room, writer);
JoinSuccess(roomPlayer, room, Writer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
}
private void JoinSuccess(RagonRoomPlayer player, RagonRoom room, RagonBuffer writer)
{
writer.Clear();
@@ -101,8 +101,8 @@ public sealed class RoomCreateOperation: IRagonOperation
writer.WriteString(room.Id);
writer.WriteString(player.Id);
writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteUShort((ushort)room.PlayerMin);
writer.WriteUShort((ushort)room.PlayerMax);
writer.WriteString(room.Scene);
var sendData = writer.ToArray();
@@ -0,0 +1,47 @@
/*
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
*
* 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 NLog;
using Ragon.Protocol;
namespace Ragon.Server.Handler;
public sealed class RoomDataOperation : BaseOperation
{
public RoomDataOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
var player = context.RoomPlayer;
var room = context.Room;
Writer.Clear();
Writer.WriteOperation(RagonOperation.REPLICATE_RAW_DATA);
Writer.WriteUShort(player.Connection.Id);
var playerData = Writer.ToArray();
var payloadData = data;
var size = playerData.Length + payloadData.Length;
var sendData = new byte[size];
Array.Copy(playerData, 0, sendData, 0, playerData.Length);
Array.Copy(payloadData, 0, sendData, playerData.Length, payloadData.Length);
room.Broadcast(sendData);
}
}
@@ -0,0 +1,44 @@
using Ragon.Protocol;
using Ragon.Server.Event;
namespace Ragon.Server.Handler;
public class RoomEventOperation : BaseOperation
{
public RoomEventOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
var room = context.Room;
var player = context.RoomPlayer;
var eventId = Reader.ReadUShort();
var replicationMode = (RagonReplicationMode)Reader.ReadByte();
var targetMode = (RagonTarget)Reader.ReadByte();
var targetPlayerPeerId = (ushort)0;
if (targetMode == RagonTarget.Player)
targetPlayerPeerId = Reader.ReadUShort();
var @event = new RagonEvent(player, eventId);
@event.Read(Reader);
Writer.Clear();
Writer.WriteUShort(eventId);
Writer.WriteUShort(player.Connection.Id);
Writer.WriteUShort((ushort) replicationMode);
var sendData = Writer.ToArray();
if (targetMode == RagonTarget.Player && room.Players.TryGetValue(targetPlayerPeerId, out var targetPlayer))
{
targetPlayer.Connection.Reliable.Send(sendData);
return;
}
foreach (var roomPlayer in room.ReadyPlayersList)
roomPlayer.Connection.Reliable.Send(sendData);
}
}
@@ -22,40 +22,40 @@ using Ragon.Server.Room;
namespace Ragon.Server.Handler;
public sealed class RoomJoinOperation : IRagonOperation
public sealed class RoomJoinOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly RagonWebHookPlugin _webHook;
public RoomJoinOperation(RagonWebHookPlugin plugin)
public RoomJoinOperation(RagonBuffer reader, RagonBuffer writer, RagonWebHookPlugin plugin) : base(reader, writer)
{
_webHook = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
var roomId = reader.ReadString();
var roomId = Reader.ReadString();
var lobbyPlayer = context.LobbyPlayer;
if (!context.Lobby.FindRoomById(roomId, out var existsRoom))
{
JoinFailed(context, writer);
JoinFailed(context, Writer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} failed to join room {roomId}");
return;
}
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
context.SetRoom(existsRoom, player);
if (!existsRoom.Plugin.OnPlayerJoined(player))
return;
_webHook.RoomJoined(context, existsRoom, player);
JoinSuccess(context, existsRoom, writer);
JoinSuccess(context, existsRoom, Writer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to {existsRoom.Id}");
}
@@ -66,8 +66,8 @@ public sealed class RoomJoinOperation : IRagonOperation
writer.WriteString(room.Id);
writer.WriteString(context.RoomPlayer.Id);
writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteUShort((ushort)room.PlayerMin);
writer.WriteUShort((ushort)room.PlayerMax);
writer.WriteString(room.Scene);
var sendData = writer.ToArray();
@@ -23,20 +23,20 @@ using Ragon.Server.Room;
namespace Ragon.Server.Handler;
public sealed class RoomJoinOrCreateOperation : IRagonOperation
public sealed class RoomJoinOrCreateOperation : BaseOperation
{
private readonly RagonRoomParameters _roomParameters = new();
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomJoinOrCreateOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
public RoomJoinOrCreateOperation(RagonBuffer reader, RagonBuffer writer, IServerPlugin serverPlugin, RagonWebHookPlugin plugin): base(reader, writer)
{
_serverPlugin = serverPlugin;
_ragonWebHookPlugin = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
{
@@ -47,7 +47,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
var roomId = Guid.NewGuid().ToString();
var lobbyPlayer = context.LobbyPlayer;
_roomParameters.Deserialize(reader);
_roomParameters.Deserialize(Reader);
if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
{
@@ -56,7 +56,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
JoinSuccess(player, existsRoom, writer);
JoinSuccess(player, existsRoom, Writer);
}
else
{
@@ -79,7 +79,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
JoinSuccess(roomPlayer, room, writer);
JoinSuccess(roomPlayer, room, Writer);
}
}
@@ -21,16 +21,17 @@ using Ragon.Server.Plugin.Web;
namespace Ragon.Server.Handler;
public sealed class RoomLeaveOperation: IRagonOperation
public sealed class RoomLeaveOperation: BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly RagonWebHookPlugin _webHook;
public RoomLeaveOperation(RagonWebHookPlugin plugin)
public RoomLeaveOperation(RagonBuffer reader, RagonBuffer writer, RagonWebHookPlugin plugin): base(reader, writer)
{
_webHook = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
var room = context.Room;
var roomPlayer = context.RoomPlayer;
@@ -4,11 +4,16 @@ using Ragon.Server.Entity;
namespace Ragon.Server.Handler;
public sealed class RoomOwnershipOperation : IRagonOperation
public sealed class RoomOwnershipOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public RoomOwnershipOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
}
public override void Handle(RagonContext context, byte[] data)
{
}
}
@@ -20,16 +20,18 @@ using Ragon.Protocol;
namespace Ragon.Server.Handler;
public class SceneLoadOperation: IRagonOperation
public class SceneLoadOperation: BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public SceneLoadOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer) {}
public override void Handle(RagonContext context, byte[] data)
{
var roomOwner = context.Room.Owner;
var currentPlayer = context.RoomPlayer;
var room = context.Room;
var sceneName = reader.ReadString();
var sceneName = Reader.ReadString();
if (roomOwner.Connection.Id != currentPlayer.Connection.Id)
{
@@ -39,11 +41,11 @@ public class SceneLoadOperation: IRagonOperation
room.UpdateMap(sceneName);
writer.Clear();
writer.WriteOperation(RagonOperation.LOAD_SCENE);
writer.WriteString(sceneName);
Writer.Clear();
Writer.WriteOperation(RagonOperation.LOAD_SCENE);
Writer.WriteString(sceneName);
var sendData = writer.ToArray();
var sendData = Writer.ToArray();
foreach (var player in room.PlayerList)
player.Connection.Reliable.Send(sendData);
}
@@ -22,16 +22,16 @@ using Ragon.Server.Room;
namespace Ragon.Server.Handler;
public sealed class SceneLoadedOperation : IRagonOperation
public sealed class SceneLoadedOperation : BaseOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
public SceneLoadedOperation()
public SceneLoadedOperation(RagonBuffer reader, RagonBuffer writer): base(reader, writer)
{
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public override void Handle(RagonContext context, byte[] data)
{
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
return;
@@ -42,13 +42,13 @@ public sealed class SceneLoadedOperation : IRagonOperation
if (player == owner)
{
var statics = reader.ReadUShort();
var statics = Reader.ReadUShort();
for (var staticIndex = 0; staticIndex < statics; staticIndex++)
{
var entityType = reader.ReadUShort();
var eventAuthority = (RagonAuthority)reader.ReadByte();
var staticId = reader.ReadUShort();
var propertiesCount = reader.ReadUShort();
var entityType = Reader.ReadUShort();
var eventAuthority = (RagonAuthority)Reader.ReadByte();
var staticId = Reader.ReadUShort();
var propertiesCount = Reader.ReadUShort();
var entityParameters = new RagonEntityParameters()
{
@@ -62,8 +62,8 @@ public sealed class SceneLoadedOperation : IRagonOperation
var entity = new RagonEntity(entityParameters);
for (var propertyIndex = 0; propertyIndex < propertiesCount; propertyIndex++)
{
var propertyType = reader.ReadBool();
var propertySize = reader.ReadUShort();
var propertyType = Reader.ReadBool();
var propertySize = Reader.ReadUShort();
entity.AddProperty(new RagonProperty(propertySize, propertyType));
}
@@ -86,14 +86,14 @@ public sealed class SceneLoadedOperation : IRagonOperation
foreach (var roomPlayer in room.WaitPlayersList)
{
DispatchPlayerJoinExcludePlayer(room, roomPlayer, writer);
DispatchPlayerJoinExcludePlayer(room, roomPlayer, Writer);
roomPlayer.SetReady();
}
room.UpdateReadyPlayerList();
DispatchSnapshot(room, room.WaitPlayersList, writer);
DispatchSnapshot(room, room.WaitPlayersList, Writer);
room.WaitPlayersList.Clear();
}
@@ -101,14 +101,14 @@ public sealed class SceneLoadedOperation : IRagonOperation
{
player.SetReady();
DispatchPlayerJoinExcludePlayer(room, player, writer);
DispatchPlayerJoinExcludePlayer(room, player, Writer);
room.UpdateReadyPlayerList();
DispatchSnapshot(room, new List<RagonRoomPlayer>() { player }, writer);
DispatchSnapshot(room, new List<RagonRoomPlayer>() { player }, Writer);
foreach (var entity in room.EntityList)
entity.RestoreBufferedEvents(player, writer);
entity.RestoreBufferedEvents(player, Writer);
}
else
{
@@ -2,12 +2,16 @@ using Ragon.Protocol;
namespace Ragon.Server.Handler;
public class TimestampSyncOperation: IRagonOperation
public class TimestampSyncOperation: BaseOperation
{
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
public TimestampSyncOperation(RagonBuffer reader, RagonBuffer writer) : base(reader, writer)
{
var timestamp0 = reader.Read(32);
var timestamp1 = reader.Read(32);
}
public override void Handle(RagonContext context, byte[] data)
{
var timestamp0 = Reader.Read(32);
var timestamp1 = Reader.Read(32);
var value = new DoubleToUInt() { Int0 = timestamp0, Int1 = timestamp1 };
context.RoomPlayer?.SetTimestamp(value.Double);