🚧 plugin system, webhook system

This commit is contained in:
2023-04-09 10:52:18 +04:00
parent f2edc94958
commit bfd6c1b54b
60 changed files with 762 additions and 267 deletions
@@ -16,17 +16,28 @@
using NLog;
using Ragon.Protocol;
using Ragon.Server.Lobby;
using Ragon.Server.Plugin;
using Ragon.Server.Room;
namespace Ragon.Server;
namespace Ragon.Server.Hander;
public sealed class RoomCreateOperation: IRagonOperation
{
private RagonRoomParameters _roomParameters = new();
private Logger _logger = LogManager.GetCurrentClassLogger();
private readonly RagonRoomParameters _roomParameters = new();
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IServerPlugin _serverPlugin;
private readonly WebHookPlugin _webHookPlugin;
public RoomCreateOperation(IServerPlugin serverPlugin, WebHookPlugin webHook)
{
_serverPlugin = serverPlugin;
_webHookPlugin = webHook;
}
public void Handle(RagonContext context, RagonBuffer reader, RagonBuffer writer)
{
if (context.LobbyPlayer.Status == LobbyPlayerStatus.Unauthorized)
if (context.ConnectionStatus == ConnectionStatus.Unauthorized)
{
_logger.Warn($"Player {context.Connection.Id} not authorized for this request");
return;
@@ -62,17 +73,20 @@ public sealed class RoomCreateOperation: IRagonOperation
};
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);
var room = new RagonRoom(roomId, information);
context.Scheduler.Run(room);
context.Lobby.Persist(room);
context.SetRoom(room, roomPlayer);
var player = new RagonRoomPlayer(lobbyPlayer.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
context.SetRoom(room, player);
_webHookPlugin.RoomCreated(context, room);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} {information}");
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}");
JoinSuccess(player, room, writer);
JoinSuccess(roomPlayer, room, writer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} joined to room {room.Id}");
}
@@ -84,9 +98,9 @@ public sealed class RoomCreateOperation: IRagonOperation
writer.WriteString(room.Id);
writer.WriteString(player.Id);
writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.Info.Min);
writer.WriteUShort((ushort) room.Info.Max);
writer.WriteString(room.Info.Map);
writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteString(room.Map);
var sendData = writer.ToArray();
player.Connection.Reliable.Send(sendData);