♻️ plugin api
This commit is contained in:
@@ -32,7 +32,8 @@ internal class AuthorizeSuccessHandler: Handler
|
|||||||
{
|
{
|
||||||
var playerId = buffer.ReadString();
|
var playerId = buffer.ReadString();
|
||||||
var playerName = buffer.ReadString();
|
var playerName = buffer.ReadString();
|
||||||
|
var playerPayload = buffer.ReadString();
|
||||||
|
|
||||||
_listenerList.OnAuthorizationSuccess(playerId, playerName);
|
_listenerList.OnAuthorizationSuccess(playerId, playerName, playerPayload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -19,11 +19,11 @@ using Ragon.Protocol;
|
|||||||
|
|
||||||
namespace Ragon.Client;
|
namespace Ragon.Client;
|
||||||
|
|
||||||
internal class EntityDestroyHandler: Handler
|
internal class EntityRemoveHandler: Handler
|
||||||
{
|
{
|
||||||
private readonly RagonEntityCache _entityCache;
|
private readonly RagonEntityCache _entityCache;
|
||||||
|
|
||||||
public EntityDestroyHandler(RagonEntityCache entityCache)
|
public EntityRemoveHandler(RagonEntityCache entityCache)
|
||||||
{
|
{
|
||||||
_entityCache = entityCache;
|
_entityCache = entityCache;
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ namespace Ragon.Client
|
|||||||
_handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, _listenerList);
|
_handlers[(byte)RagonOperation.PLAYER_LEAVED] = new PlayerLeftHandler(_entityCache, _playerCache, _listenerList);
|
||||||
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listenerList);
|
_handlers[(byte)RagonOperation.LOAD_SCENE] = new SceneLoadHandler(this, _listenerList);
|
||||||
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateHandler(this, _playerCache, _entityCache);
|
_handlers[(byte)RagonOperation.CREATE_ENTITY] = new EntityCreateHandler(this, _playerCache, _entityCache);
|
||||||
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityDestroyHandler(_entityCache);
|
_handlers[(byte)RagonOperation.REMOVE_ENTITY] = new EntityRemoveHandler(_entityCache);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new StateEntityHandler(_entityCache);
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_STATE] = new StateEntityHandler(_entityCache);
|
||||||
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventHandler(this, _playerCache, _entityCache);
|
_handlers[(byte)RagonOperation.REPLICATE_ENTITY_EVENT] = new EntityEventHandler(this, _playerCache, _entityCache);
|
||||||
_handlers[(byte)RagonOperation.SNAPSHOT] = new SnapshotHandler(this, _listenerList, _entityCache, _playerCache);
|
_handlers[(byte)RagonOperation.SNAPSHOT] = new SnapshotHandler(this, _listenerList, _entityCache, _playerCache);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ namespace Ragon.Client
|
|||||||
_playerLeftListeners.Remove(listener);
|
_playerLeftListeners.Remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAuthorizationSuccess(string playerId, string playerName)
|
public void OnAuthorizationSuccess(string playerId, string playerName, string payload)
|
||||||
{
|
{
|
||||||
foreach (var listener in _authorizationListeners)
|
foreach (var listener in _authorizationListeners)
|
||||||
listener.OnAuthorizationSuccess(_client, playerId, playerName);
|
listener.OnAuthorizationSuccess(_client, playerId, playerName);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using Ragon.Protocol;
|
||||||
|
using Ragon.Server.Room;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
|
public interface IRagonEntity
|
||||||
|
{
|
||||||
|
public ushort Id { get; }
|
||||||
|
public ushort Type { get; }
|
||||||
|
public ushort StaticId { get; }
|
||||||
|
public ushort AttachId { get; }
|
||||||
|
public RagonRoomPlayer Owner { get; }
|
||||||
|
public RagonAuthority Authority { get; }
|
||||||
|
public RagonPayload Payload { get; }
|
||||||
|
public IRagonEntityState State { get; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Ragon.Protocol;
|
||||||
|
|
||||||
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
|
public interface IRagonEntityState
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ using Ragon.Server.Room;
|
|||||||
|
|
||||||
namespace Ragon.Server.Entity;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonEntity
|
public class RagonEntity: IRagonEntity
|
||||||
{
|
{
|
||||||
private static ushort _idGenerator = 100;
|
private static ushort _idGenerator = 100;
|
||||||
public ushort Id { get; private set; }
|
public ushort Id { get; private set; }
|
||||||
@@ -30,8 +30,10 @@ public class RagonEntity
|
|||||||
public RagonRoomPlayer Owner { get; private set; }
|
public RagonRoomPlayer Owner { get; private set; }
|
||||||
public RagonAuthority Authority { get; private set; }
|
public RagonAuthority Authority { get; private set; }
|
||||||
public RagonPayload Payload { get; private set; }
|
public RagonPayload Payload { get; private set; }
|
||||||
public RagonEntityState State { get; private set; }
|
public IRagonEntityState State => _state;
|
||||||
|
|
||||||
private readonly List<RagonEvent> _bufferedEvents;
|
private readonly List<RagonEvent> _bufferedEvents;
|
||||||
|
private readonly RagonEntityState _state;
|
||||||
|
|
||||||
public RagonEntity(RagonEntityParameters parameters)
|
public RagonEntity(RagonEntityParameters parameters)
|
||||||
{
|
{
|
||||||
@@ -41,10 +43,9 @@ public class RagonEntity
|
|||||||
Type = parameters.Type;
|
Type = parameters.Type;
|
||||||
AttachId = parameters.AttachId;
|
AttachId = parameters.AttachId;
|
||||||
Authority = parameters.Authority;
|
Authority = parameters.Authority;
|
||||||
|
|
||||||
State = new RagonEntityState(this);
|
|
||||||
Payload = new RagonPayload();
|
Payload = new RagonPayload();
|
||||||
|
|
||||||
|
_state = new RagonEntityState(this);
|
||||||
_bufferedEvents = new List<RagonEvent>();
|
_bufferedEvents = new List<RagonEvent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +122,8 @@ public class RagonEntity
|
|||||||
|
|
||||||
buffer.WriteUShort(Payload.Size);
|
buffer.WriteUShort(Payload.Size);
|
||||||
Payload.Write(buffer);
|
Payload.Write(buffer);
|
||||||
State.Snapshot(buffer);
|
|
||||||
|
_state.Snapshot(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReplicateEvent(
|
public void ReplicateEvent(
|
||||||
@@ -215,16 +217,23 @@ public class RagonEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(RagonBuffer writer)
|
public void AddProperty(RagonProperty property)
|
||||||
{
|
{
|
||||||
State.Write(writer);
|
_state.AddProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteState(RagonBuffer writer)
|
||||||
|
{
|
||||||
|
_state.Write(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Read(RagonRoomPlayer player, RagonBuffer reader)
|
public bool TryReadState(RagonRoomPlayer player, RagonBuffer reader)
|
||||||
{
|
{
|
||||||
if (Owner.Connection.Id != player.Connection.Id)
|
if (Owner.Connection.Id != player.Connection.Id)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
State.Read(reader);
|
_state.Read(reader);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,14 +19,16 @@ using Ragon.Protocol;
|
|||||||
|
|
||||||
namespace Ragon.Server.Entity;
|
namespace Ragon.Server.Entity;
|
||||||
|
|
||||||
public class RagonEntityState
|
public class RagonEntityState: IRagonEntityState
|
||||||
{
|
{
|
||||||
private List<RagonProperty> _properties;
|
private List<RagonProperty> _properties;
|
||||||
private RagonEntity _entity;
|
private RagonEntity _entity;
|
||||||
|
private RagonBuffer _buffer;
|
||||||
|
|
||||||
public RagonEntityState(RagonEntity entity, int capacity = 10)
|
public RagonEntityState(RagonEntity entity, int capacity = 10)
|
||||||
{
|
{
|
||||||
_entity = entity;
|
_entity = entity;
|
||||||
|
_buffer = new RagonBuffer(8);
|
||||||
_properties = new List<RagonProperty>(capacity);
|
_properties = new List<RagonProperty>(capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +67,8 @@ public class RagonEntityState
|
|||||||
{
|
{
|
||||||
foreach (var property in _properties)
|
foreach (var property in _properties)
|
||||||
{
|
{
|
||||||
var hasPayload = property.IsFixed || !property.IsFixed && property.Size > 0;
|
var hasPayloadOrFixed = property.IsFixed || property is { IsFixed: false, Size: > 0 };
|
||||||
if (hasPayload)
|
if (hasPayloadOrFixed)
|
||||||
{
|
{
|
||||||
buffer.WriteBool(true);
|
buffer.WriteBool(true);
|
||||||
property.Write(buffer);
|
property.Write(buffer);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public sealed class EntityCreateOperation : IRagonOperation
|
|||||||
var propertyType = reader.ReadBool();
|
var propertyType = reader.ReadBool();
|
||||||
var propertySize = reader.ReadUShort();
|
var propertySize = reader.ReadUShort();
|
||||||
|
|
||||||
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reader.Capacity > 0)
|
if (reader.Capacity > 0)
|
||||||
|
|||||||
@@ -32,10 +32,14 @@ public sealed class EntityStateOperation: IRagonOperation
|
|||||||
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
|
for (var entityIndex = 0; entityIndex < entitiesCount; entityIndex++)
|
||||||
{
|
{
|
||||||
var entityId = reader.ReadUShort();
|
var entityId = reader.ReadUShort();
|
||||||
if (room.Entities.TryGetValue(entityId, out var entity))
|
if (room.Entities.TryGetValue(entityId, out var entity) && entity.TryReadState(player, reader))
|
||||||
entity.Read(player, reader);
|
{
|
||||||
|
room.Track(entity);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
_logger.Error($"Entity with Id {entityId} not found, replication interrupted");
|
_logger.Error($"Entity with Id {entityId} not found, replication interrupted");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,13 +25,12 @@ namespace Ragon.Server.Handler;
|
|||||||
public sealed class RoomJoinOperation : IRagonOperation
|
public sealed class RoomJoinOperation : IRagonOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
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;
|
_webHook = plugin;
|
||||||
_ragonWebHookPlugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
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);
|
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
|
||||||
context.SetRoom(existsRoom, player);
|
context.SetRoom(existsRoom, player);
|
||||||
|
|
||||||
if (!_serverPlugin.OnRoomJoin(player, existsRoom))
|
if (!existsRoom.Plugin.OnPlayerJoined(player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
|
_webHook.RoomJoined(context, existsRoom, player);
|
||||||
|
|
||||||
JoinSuccess(context, existsRoom, writer);
|
JoinSuccess(context, existsRoom, writer);
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,10 @@ namespace Ragon.Server.Handler;
|
|||||||
public sealed class RoomLeaveOperation: IRagonOperation
|
public sealed class RoomLeaveOperation: IRagonOperation
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
private readonly IServerPlugin _serverPlugin;
|
private readonly RagonWebHookPlugin _webHook;
|
||||||
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
|
public RoomLeaveOperation(RagonWebHookPlugin plugin)
|
||||||
public RoomLeaveOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
|
|
||||||
{
|
{
|
||||||
_serverPlugin = serverPlugin;
|
_webHook = plugin;
|
||||||
_ragonWebHookPlugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
|
||||||
@@ -39,9 +37,13 @@ public sealed class RoomLeaveOperation: IRagonOperation
|
|||||||
|
|
||||||
if (room != null)
|
if (room != null)
|
||||||
{
|
{
|
||||||
_serverPlugin.OnRoomLeave(roomPlayer, room);
|
var plugin = room.Plugin;
|
||||||
_ragonWebHookPlugin.RoomLeaved(context, room, roomPlayer);
|
|
||||||
context.Room?.DetachPlayer(roomPlayer);
|
plugin.OnPlayerLeaved(roomPlayer);
|
||||||
|
room.DetachPlayer(roomPlayer);
|
||||||
|
|
||||||
|
_webHook.RoomLeaved(context, room, roomPlayer);
|
||||||
|
|
||||||
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
|
_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 propertyType = reader.ReadBool();
|
||||||
var propertySize = reader.ReadUShort();
|
var propertySize = reader.ReadUShort();
|
||||||
entity.State.AddProperty(new RagonProperty(propertySize, propertyType));
|
entity.AddProperty(new RagonProperty(propertySize, propertyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomPlugin = room.Plugin;
|
var roomPlugin = room.Plugin;
|
||||||
|
|||||||
@@ -15,11 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
using Ragon.Server.Lobby;
|
||||||
|
|
||||||
namespace Ragon.Server;
|
namespace Ragon.Server;
|
||||||
|
|
||||||
public interface IRagonServer
|
public interface IRagonServer
|
||||||
{
|
{
|
||||||
RagonContext? ResolveContext(INetworkConnection connection);
|
RagonLobbyPlayer? GetPlayerByConnection(INetworkConnection connection);
|
||||||
RagonContext? ResolveContext(string id);
|
RagonLobbyPlayer? GetPlayerById(string id);
|
||||||
}
|
}
|
||||||
@@ -22,44 +22,44 @@ namespace Ragon.Server.Plugin;
|
|||||||
|
|
||||||
public class BaseRoomPlugin: IRoomPlugin
|
public class BaseRoomPlugin: IRoomPlugin
|
||||||
{
|
{
|
||||||
private IRagonRoom _ragonRoom;
|
public IRagonRoom Room { get; private set; }
|
||||||
|
|
||||||
public RagonRoomPlayer GetPlayerById(string id)
|
|
||||||
{
|
|
||||||
var player = _ragonRoom.GetPlayerById(id);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection)
|
|
||||||
{
|
|
||||||
var player = _ragonRoom.GetPlayerByConnection(connection);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnAttached(IRagonRoom room)
|
public virtual void OnAttached(IRagonRoom room)
|
||||||
{
|
{
|
||||||
_ragonRoom = room;
|
Room = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnDetached()
|
public virtual void OnDetached()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region VIRTUAL
|
|
||||||
|
|
||||||
|
#region VIRTUAL
|
||||||
|
|
||||||
|
public virtual bool OnPlayerJoined(RagonRoomPlayer player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual bool OnPlayerLeaved(RagonRoomPlayer player)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Tick(float dt)
|
public virtual void Tick(float dt)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity)
|
public virtual bool OnEntityCreate(RagonRoomPlayer creator, IRagonEntity entity)
|
||||||
{
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool OnEntityRemove(RagonRoomPlayer remover, RagonEntity entity)
|
public virtual bool OnEntityRemove(RagonRoomPlayer remover, IRagonEntity entity)
|
||||||
{
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,26 +22,14 @@ namespace Ragon.Server.Plugin;
|
|||||||
|
|
||||||
public class BaseServerPlugin: IServerPlugin
|
public class BaseServerPlugin: IServerPlugin
|
||||||
{
|
{
|
||||||
private IRagonServer _ragonServer;
|
public IRagonServer Server { get; protected set; }
|
||||||
|
|
||||||
public RagonLobbyPlayer? GetPlayerById(string id)
|
public virtual void OnAttached(IRagonServer server)
|
||||||
{
|
{
|
||||||
var context = _ragonServer.ResolveContext(id);
|
Server = server;
|
||||||
return context?.LobbyPlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RagonLobbyPlayer? GetPlayerByConnection(INetworkConnection connection)
|
public virtual void OnDetached()
|
||||||
{
|
|
||||||
var context = _ragonServer.ResolveContext(connection);
|
|
||||||
return context?.LobbyPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnAttached(IRagonServer server)
|
|
||||||
{
|
|
||||||
_ragonServer = server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnDetached()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -56,16 +44,6 @@ public class BaseServerPlugin: IServerPlugin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool OnRoomLeave(RagonRoomPlayer player, RagonRoom room)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool OnRoomJoin(RagonRoomPlayer player, RagonRoom room)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool OnCommand(string command, string payload)
|
public virtual bool OnCommand(string command, string payload)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public interface IRoomPlugin
|
|||||||
void Tick(float dt);
|
void Tick(float dt);
|
||||||
void OnAttached(IRagonRoom room);
|
void OnAttached(IRagonRoom room);
|
||||||
void OnDetached();
|
void OnDetached();
|
||||||
bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity);
|
bool OnPlayerJoined(RagonRoomPlayer player);
|
||||||
bool OnEntityRemove(RagonRoomPlayer remover, RagonEntity entity);
|
bool OnPlayerLeaved(RagonRoomPlayer player);
|
||||||
|
bool OnEntityCreate(RagonRoomPlayer player, IRagonEntity entity);
|
||||||
|
bool OnEntityRemove(RagonRoomPlayer player, IRagonEntity entity);
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,6 @@ public interface IServerPlugin
|
|||||||
void OnDetached();
|
void OnDetached();
|
||||||
bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room);
|
bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room);
|
||||||
bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room);
|
bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room);
|
||||||
bool OnRoomLeave(RagonRoomPlayer player, RagonRoom room);
|
|
||||||
bool OnRoomJoin(RagonRoomPlayer player, RagonRoom room);
|
|
||||||
bool OnCommand(string command, string payload);
|
bool OnCommand(string command, string payload);
|
||||||
IRoomPlugin CreateRoomPlugin(RoomInformation information);
|
IRoomPlugin CreateRoomPlugin(RoomInformation information);
|
||||||
}
|
}
|
||||||
@@ -77,8 +77,8 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation(_webhooks, contextObserver, _writer, configuration);
|
_handlers[(byte) RagonOperation.AUTHORIZE] = new AuthorizationOperation(_webhooks, contextObserver, _writer, configuration);
|
||||||
_handlers[(byte) RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(plugin, _webhooks);
|
_handlers[(byte) RagonOperation.JOIN_OR_CREATE_ROOM] = new RoomJoinOrCreateOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.CREATE_ROOM] = new RoomCreateOperation(plugin, _webhooks);
|
_handlers[(byte) RagonOperation.CREATE_ROOM] = new RoomCreateOperation(plugin, _webhooks);
|
||||||
_handlers[(byte) RagonOperation.JOIN_ROOM] = new RoomJoinOperation(plugin, _webhooks);
|
_handlers[(byte) RagonOperation.JOIN_ROOM] = new RoomJoinOperation(_webhooks);
|
||||||
_handlers[(byte) RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(plugin, _webhooks);
|
_handlers[(byte) RagonOperation.LEAVE_ROOM] = new RoomLeaveOperation(_webhooks);
|
||||||
_handlers[(byte) RagonOperation.LOAD_SCENE] = new SceneLoadOperation();
|
_handlers[(byte) RagonOperation.LOAD_SCENE] = new SceneLoadOperation();
|
||||||
_handlers[(byte) RagonOperation.SCENE_LOADED] = new SceneLoadedOperation();
|
_handlers[(byte) RagonOperation.SCENE_LOADED] = new SceneLoadedOperation();
|
||||||
_handlers[(byte) RagonOperation.CREATE_ENTITY] = new EntityCreateOperation();
|
_handlers[(byte) RagonOperation.CREATE_ENTITY] = new EntityCreateOperation();
|
||||||
@@ -198,7 +198,23 @@ public class RagonServer : IRagonServer, INetworkListener
|
|||||||
_logger.Error(ex);
|
_logger.Error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IRagonOperation ResolveOperation(RagonOperation operation) => _handlers[(byte)operation];
|
|
||||||
public RagonContext? ResolveContext(INetworkConnection connection) => _contextsByConnection.TryGetValue(connection.Id, out var context) ? context : null;
|
public IRagonOperation ResolveOperation(RagonOperation operation)
|
||||||
public RagonContext? ResolveContext(string playerId) => _contextsByPlayerId.TryGetValue(playerId, out var context) ? context : null;
|
{
|
||||||
|
return _handlers[(byte)operation];
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonLobbyPlayer? GetPlayerByConnection(INetworkConnection connection)
|
||||||
|
{
|
||||||
|
return _contextsByConnection.TryGetValue(connection.Id, out var context) ?
|
||||||
|
context.LobbyPlayer :
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonLobbyPlayer? GetPlayerById(string playerId)
|
||||||
|
{
|
||||||
|
return _contextsByPlayerId.TryGetValue(playerId, out var context) ?
|
||||||
|
context.LobbyPlayer :
|
||||||
|
null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Ragon.Server.Entity;
|
||||||
using Ragon.Server.IO;
|
using Ragon.Server.IO;
|
||||||
|
|
||||||
namespace Ragon.Server.Room;
|
namespace Ragon.Server.Room;
|
||||||
@@ -22,4 +23,6 @@ public interface IRagonRoom
|
|||||||
{
|
{
|
||||||
RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection);
|
RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection);
|
||||||
RagonRoomPlayer GetPlayerById(string id);
|
RagonRoomPlayer GetPlayerById(string id);
|
||||||
|
IRagonEntity GetEntityById(ushort id);
|
||||||
|
IRagonEntity[] GetEntitiesOfPlayer(RagonRoomPlayer id);
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
|||||||
Writer.WriteUShort(entities);
|
Writer.WriteUShort(entities);
|
||||||
|
|
||||||
foreach (var entity in _entitiesDirtySet)
|
foreach (var entity in _entitiesDirtySet)
|
||||||
entity.Write(Writer);
|
entity.WriteState(Writer);
|
||||||
|
|
||||||
_entitiesDirtySet.Clear();
|
_entitiesDirtySet.Clear();
|
||||||
|
|
||||||
@@ -205,7 +205,26 @@ public class RagonRoom : IRagonRoom, IRagonAction
|
|||||||
foreach (var readyPlayer in ReadyPlayersList)
|
foreach (var readyPlayer in ReadyPlayersList)
|
||||||
readyPlayer.Connection.Reliable.Send(data);
|
readyPlayer.Connection.Reliable.Send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection) => Players[connection.Id];
|
public RagonRoomPlayer GetPlayerByConnection(INetworkConnection connection)
|
||||||
public RagonRoomPlayer GetPlayerById(string id) => PlayerList.First(p => p.Id == id);
|
{
|
||||||
|
return Players[connection.Id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public RagonRoomPlayer? GetPlayerById(string id)
|
||||||
|
{
|
||||||
|
return PlayerList.FirstOrDefault(p => p.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRagonEntity? GetEntityById(ushort id)
|
||||||
|
{
|
||||||
|
return Entities.TryGetValue(id, out var entity) ?
|
||||||
|
entity :
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IRagonEntity[] GetEntitiesOfPlayer(RagonRoomPlayer player)
|
||||||
|
{
|
||||||
|
return EntityList.Where(e => e.Owner.Connection.Id == player.Connection.Id).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user