http-commands

This commit is contained in:
2023-04-13 20:42:05 +04:00
parent 24c9aa2043
commit e1a9ad476c
31 changed files with 428 additions and 104 deletions
@@ -26,17 +26,19 @@ namespace Ragon.Server.Handler;
public sealed class AuthorizationOperation: IRagonOperation
{
private Logger _logger = LogManager.GetCurrentClassLogger();
private readonly WebHookPlugin _webHook;
private readonly RagonWebHookPlugin _ragonWebHook;
private readonly RagonContextObserver _contextObserver;
private readonly Configuration _configuration;
private readonly RagonBuffer _writer;
public AuthorizationOperation(
WebHookPlugin webHook,
public AuthorizationOperation(RagonWebHookPlugin ragonWebHook,
RagonContextObserver contextObserver,
RagonBuffer writer,
Configuration configuration)
{
_webHook = webHook;
_ragonWebHook = ragonWebHook;
_configuration = configuration;
_contextObserver = contextObserver;
_writer = writer;
}
@@ -60,10 +62,10 @@ public sealed class AuthorizationOperation: IRagonOperation
if (key == _configuration.ServerKey)
{
if (_webHook.RequestAuthorization(context, name, payload))
if (_ragonWebHook.RequestAuthorization(context, name, payload))
return;
var lobbyPlayer = new RagonLobbyPlayer(Guid.NewGuid().ToString(), name, payload);
var lobbyPlayer = new RagonLobbyPlayer(context.Connection, Guid.NewGuid().ToString(), name, payload);
context.SetPlayer(lobbyPlayer);
Approve(context);
@@ -77,7 +79,9 @@ public sealed class AuthorizationOperation: IRagonOperation
public void Approve(RagonContext context)
{
context.ConnectionStatus = ConnectionStatus.Authorized;
_contextObserver.OnAuthorized(context);
var playerId = context.LobbyPlayer.Id;
var playerName = context.LobbyPlayer.Name;
var playerPayload = context.LobbyPlayer.Payload;
@@ -28,12 +28,12 @@ public sealed class RoomCreateOperation: IRagonOperation
private readonly RagonRoomParameters _roomParameters = new();
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly WebHookPlugin _webHookPlugin;
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomCreateOperation(IServerPlugin serverPlugin, WebHookPlugin webHook)
public RoomCreateOperation(IServerPlugin serverPlugin, RagonWebHookPlugin ragonWebHook)
{
_serverPlugin = serverPlugin;
_webHookPlugin = webHook;
_ragonWebHookPlugin = ragonWebHook;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
@@ -79,11 +79,13 @@ public sealed class RoomCreateOperation: IRagonOperation
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);
_webHookPlugin.RoomCreated(context, room);
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}");
@@ -26,12 +26,12 @@ public sealed class RoomJoinOperation : IRagonOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly WebHookPlugin _webHookPlugin;
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomJoinOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
public RoomJoinOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
{
_serverPlugin = serverPlugin;
_webHookPlugin = plugin;
_ragonWebHookPlugin = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
@@ -53,7 +53,7 @@ public sealed class RoomJoinOperation : IRagonOperation
if (!_serverPlugin.OnRoomJoin(player, existsRoom))
return;
_webHookPlugin.RoomJoined(context, existsRoom, player);
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
JoinSuccess(context, existsRoom, writer);
@@ -28,12 +28,12 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
private readonly RagonRoomParameters _roomParameters = new();
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly WebHookPlugin _webHookPlugin;
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomJoinOrCreateOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
public RoomJoinOrCreateOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
{
_serverPlugin = serverPlugin;
_webHookPlugin = plugin;
_ragonWebHookPlugin = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
@@ -54,7 +54,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
context.SetRoom(existsRoom, player);
_webHookPlugin.RoomJoined(context, existsRoom, player);
_ragonWebHookPlugin.RoomJoined(context, existsRoom, player);
JoinSuccess(player, existsRoom, writer);
}
@@ -71,7 +71,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
var roomPlugin = _serverPlugin.CreateRoomPlugin(information);
var room = new RagonRoom(roomId, information, roomPlugin);
_webHookPlugin.RoomCreated(context, room);
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
context.Lobby.Persist(room);
context.Scheduler.Run(room);
@@ -25,11 +25,11 @@ public sealed class RoomLeaveOperation: IRagonOperation
{
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly WebHookPlugin _webHookPlugin;
public RoomLeaveOperation(IServerPlugin serverPlugin, WebHookPlugin plugin)
private readonly RagonWebHookPlugin _ragonWebHookPlugin;
public RoomLeaveOperation(IServerPlugin serverPlugin, RagonWebHookPlugin plugin)
{
_serverPlugin = serverPlugin;
_webHookPlugin = plugin;
_ragonWebHookPlugin = plugin;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
@@ -40,7 +40,7 @@ public sealed class RoomLeaveOperation: IRagonOperation
if (room != null)
{
_serverPlugin.OnRoomLeave(roomPlayer, room);
_webHookPlugin.RoomLeaved(context, room, roomPlayer);
_ragonWebHookPlugin.RoomLeaved(context, room, roomPlayer);
context.Room?.DetachPlayer(roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} leaved from {room.Id}");
}