🚧 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
@@ -19,7 +19,6 @@ using Ragon.Server;
using Ragon.Server.ENet;
using Ragon.Server.DotNetWebsockets;
namespace Ragon.Relay;
public class Relay
@@ -32,21 +31,19 @@ public class Relay
var configuration = Configuration.Load("relay.config.json");
var serverType = Configuration.GetServerType(configuration.ServerType);
INetworkServer server = null;
INetworkServer networkServer = new ENetServer();
IServerPlugin plugin = new RelayServerPlugin();
switch (serverType)
{
case ServerType.ENET:
server = new ENetServer();
networkServer = new ENetServer();
break;
case ServerType.WEBSOCKET:
server = new DotNetWebSocketServer();
break;
default:
server = new ENetServer();
networkServer = new DotNetWebSocketServer();
break;
}
var relay = new RagonServer(server, configuration);
var relay = new RagonServer(networkServer, plugin, configuration);
logger.Info("Started");
relay.Start();
}
+34
View File
@@ -0,0 +1,34 @@
using System;
using Ragon.Server;
namespace Ragon.Relay;
public class RelayRoomPlugin: IRoomPlugin
{
public void Tick(float dt)
{
}
public void OnAttached()
{
Console.WriteLine("Room attached");
}
public void OnDetached()
{
Console.WriteLine("Room detached");
}
public bool OnEntityCreate(RagonRoomPlayer creator, RagonEntity entity)
{
Console.WriteLine($"Entity created: {entity.Id}");
return true;
}
public bool OnEntityRemove(RagonRoomPlayer destroyer, RagonEntity entity)
{
Console.WriteLine($"Entity destroyed: {entity.Id}");
return true;
}
}
+39
View File
@@ -0,0 +1,39 @@
using System;
using System.Net.Http;
using Ragon.Server;
namespace Ragon.Relay;
public class RelayServerPlugin: IServerPlugin
{
private HttpClient httpClient;
public IRoomPlugin CreateRoomPlugin(RoomInformation information)
{
return new RelayRoomPlugin();
}
public RelayServerPlugin()
{
httpClient = new HttpClient();
}
public bool OnRoomCreate(RagonLobbyPlayer player, RagonRoom room)
{
return true;
}
public bool OnRoomRemove(RagonLobbyPlayer player, RagonRoom room)
{
return true;
}
public bool OnRoomLeave(RagonRoomPlayer player, RagonRoom room)
{
return true;
}
public bool OnRoomJoin(RagonRoomPlayer player, RagonRoom room)
{
return true;
}
}
+8 -1
View File
@@ -6,5 +6,12 @@
"port": 5000,
"limitConnections": 4095,
"limitPlayersPerRoom": 20,
"limitRooms": 200
"limitRooms": 200,
"webHooks":
{
"room-created": "http://127.0.0.1:3000/service/create-room",
"room-removed": "http://127.0.0.1:3000/service/remove-room",
"room-joined": "http://127.0.0.1:3000/service/join-room",
"room-leaved": "http://127.0.0.1:3000/service/leave-room"
}
}