wip
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class EntityOwnershipOperation : IRagonOperation
|
||||
{
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||
{
|
||||
var player = context.RoomPlayer;
|
||||
var room = context.Room;
|
||||
|
||||
var entityId = reader.ReadUShort();
|
||||
var playerId = reader.ReadUShort();
|
||||
|
||||
if (!room.Entities.TryGetValue(entityId, out var entity))
|
||||
{
|
||||
_logger.Error($"Entity not found with id {entityId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.Owner.Connection.Id != player.Connection.Id)
|
||||
{
|
||||
_logger.Error($"Player not owner of entity with id {entityId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!room.Players.TryGetValue(playerId, 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);
|
||||
nextOwner.Entities.Add(entity);
|
||||
|
||||
entity.Attach(nextOwner);
|
||||
|
||||
_logger.Trace($"Entity {entity.Id} next owner {nextOwner.Connection.Id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using NLog;
|
||||
using Ragon.Protocol;
|
||||
using Ragon.Server.Entity;
|
||||
|
||||
namespace Ragon.Server.Handler;
|
||||
|
||||
public sealed class RoomOwnershipOperation : IRagonOperation
|
||||
{
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
||||
_handlers[(byte) RagonOperation.REMOVE_ENTITY] = new EntityDestroyOperation();
|
||||
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventOperation();
|
||||
_handlers[(byte) RagonOperation.REPLICATE_ENTITY_STATE] = new EntityStateOperation();
|
||||
_handlers[(byte) RagonOperation.TRANSFER_ROOM_OWNERSHIP] = new EntityOwnershipOperation();
|
||||
_handlers[(byte) RagonOperation.TRANSFER_ENTITY_OWNERSHIP] = new EntityOwnershipOperation();
|
||||
|
||||
_logger.Trace($"Server Tick Rate: {_configuration.ServerTickRate}");
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
||||
var entitiesToUpdate = roomPlayer.Entities.StaticList;
|
||||
|
||||
Writer.Clear();
|
||||
Writer.WriteOperation(RagonOperation.OWNERSHIP_CHANGED);
|
||||
Writer.WriteOperation(RagonOperation.OWNERSHIP_ENTITY_CHANGED);
|
||||
Writer.WriteString(Owner.Id);
|
||||
Writer.WriteUShort((ushort)entitiesToUpdate.Count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user