♻️ plugin api
This commit is contained in:
@@ -47,7 +47,7 @@ public sealed class EntityCreateOperation : IRagonOperation
|
||||
var propertyType = reader.ReadBool();
|
||||
var propertySize = reader.ReadUShort();
|
||||
|
||||
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
}
|
||||
|
||||
if (reader.Capacity > 0)
|
||||
|
||||
@@ -32,10 +32,14 @@ public sealed class EntityStateOperation: IRagonOperation
|
||||
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
|
||||
{
|
||||
var entityId = reader.ReadUShort();
|
||||
if (room.Entities.TryGetValue(entityId, out var entity))
|
||||
entity.Read(player, reader);
|
||||
if (room.Entities.TryGetValue(entityId, out var entity) && entity.TryReadState(player, reader))
|
||||
{
|
||||
room.Track(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error($"Entity with Id {entityId} not found, replication interrupted");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,12 @@ namespace Ragon.Server.Handler;
|
||||
public sealed class RoomJoinOperation : IRagonOperation
|
||||
{
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IServerPlugin _serverPlugin;
|
||||
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
|
||||
|
||||
private readonly RagonWebHookPlugin _webHook;
|
||||
|
||||
public RoomJoinOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
|
||||
public RoomJoinOperation(RagonWebHookPlugin plugin)
|
||||
{
|
||||
_serverPlugin = serverPlugin;
|
||||
_ragonWebHookPlugin = plugin;
|
||||
_webHook = plugin;
|
||||
}
|
||||
|
||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||
@@ -50,10 +49,10 @@ public sealed class RoomJoinOperation : IRagonOperation
|
||||
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||
context.SetRoom(existsRoom, player);
|
||||
|
||||
if (!_serverPlugin.OnRoomJoin(player, existsRoom))
|
||||
if (!existsRoom.Plugin.OnPlayerJoined(player))
|
||||
return;
|
||||
|
||||
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
|
||||
_webHook.RoomJoined(context, existsRoom, player);
|
||||
|
||||
JoinSuccess(context, existsRoom, writer);
|
||||
|
||||
|
||||
@@ -24,12 +24,10 @@ namespace Ragon.Server.Handler;
|
||||
public sealed class RoomLeaveOperation: IRagonOperation
|
||||
{
|
||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IServerPlugin _serverPlugin;
|
||||
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
|
||||
public RoomLeaveOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
|
||||
private readonly RagonWebHookPlugin _webHook;
|
||||
public RoomLeaveOperation(RagonWebHookPlugin plugin)
|
||||
{
|
||||
_serverPlugin = serverPlugin;
|
||||
_ragonWebHookPlugin = plugin;
|
||||
_webHook = plugin;
|
||||
}
|
||||
|
||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||
@@ -39,9 +37,13 @@ public sealed class RoomLeaveOperation: IRagonOperation
|
||||
|
||||
if (room != null)
|
||||
{
|
||||
_serverPlugin.OnRoomLeave(roomPlayer, room);
|
||||
_ragonWebHookPlugin.RoomLeaved(context, room, roomPlayer);
|
||||
context.Room?.DetachPlayer(roomPlayer);
|
||||
var plugin = room.Plugin;
|
||||
|
||||
plugin.OnPlayerLeaved(roomPlayer);
|
||||
room.DetachPlayer(roomPlayer);
|
||||
|
||||
_webHook.RoomLeaved(context, room, roomPlayer);
|
||||
|
||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public sealed class SceneLoadedOperation : IRagonOperation
|
||||
{
|
||||
var propertyType = reader.ReadBool();
|
||||
var propertySize = reader.ReadUShort();
|
||||
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||
}
|
||||
|
||||
var roomPlugin = room.Plugin;
|
||||
|
||||
Reference in New Issue
Block a user