feat: improved server plugin api
This commit is contained in:
@@ -3,28 +3,30 @@ using Newtonsoft.Json;
|
||||
using Ragon.Server;
|
||||
using Ragon.Server.Plugin;
|
||||
|
||||
namespace Ragon.Relay;
|
||||
|
||||
public class RelayServerPlugin: BaseServerPlugin
|
||||
namespace Ragon.Relay
|
||||
{
|
||||
public override bool OnCommand(string command, string payload)
|
||||
{
|
||||
Console.WriteLine(command);
|
||||
if (command == "kick-player")
|
||||
{
|
||||
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
|
||||
var player = Server.GetPlayerById(commandPayload.Id);
|
||||
if (player != null)
|
||||
player.Connection.Close();
|
||||
else
|
||||
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||
public class RelayServerPlugin : BaseServerPlugin
|
||||
{
|
||||
return new RelayRoomPlugin();
|
||||
public override bool OnCommand(string command, string payload)
|
||||
{
|
||||
Console.WriteLine(command);
|
||||
if (command == "kick-player")
|
||||
{
|
||||
var commandPayload = JsonConvert.DeserializeObject<KickPlayerCommand>(payload);
|
||||
var player = Server.GetContextById(commandPayload.Id);
|
||||
if (player != null)
|
||||
player.Connection.Close();
|
||||
else
|
||||
Console.WriteLine($"Player not found with Id {commandPayload.Id}");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IRoomPlugin CreateRoomPlugin(RoomInformation information)
|
||||
{
|
||||
return new RelayRoomPlugin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ namespace Ragon.Relay
|
||||
|
||||
INetworkServer networkServer = new ENetServer();
|
||||
IServerPlugin plugin = new RelayServerPlugin();
|
||||
|
||||
switch (serverType)
|
||||
{
|
||||
case ServerType.ENET:
|
||||
@@ -63,6 +64,7 @@ namespace Ragon.Relay
|
||||
ServerKey = configuration.ServerKey,
|
||||
ServerTickRate = configuration.ServerTickRate,
|
||||
};
|
||||
|
||||
var relay = new RagonServer(networkServer, plugin, serverConfiguration);
|
||||
relay.Start();
|
||||
while (relay.IsRunning)
|
||||
|
||||
@@ -15,6 +15,5 @@ namespace Ragon.Relay
|
||||
public int LimitRooms;
|
||||
public int LimitBufferedEvents;
|
||||
public int LimitUserData;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user