forked from SoDOff-Project/sodoff-mmo
27 lines
1.3 KiB
C#
27 lines
1.3 KiB
C#
using System;
|
|
using System.Net.Http.Json;
|
|
using sodoffmmo.Attributes;
|
|
using sodoffmmo.Core;
|
|
|
|
namespace sodoffmmo.Management.Commands;
|
|
|
|
[ManagementCommand("ban", Role.Moderator)]
|
|
class BanCommand : IManagementCommand
|
|
{
|
|
public void Handle(Client client, string[] arguments)
|
|
{
|
|
if(arguments.Length < 2) { client.Send(Utils.BuildServerSideMessage($"Expected 3 Args, Got {arguments.Length + 1}", "Server")); return; }
|
|
|
|
if (arguments[0] == "help") client.Send(Utils.BuildServerSideMessage($"::ban - This bans a user who is in-room. First argument is the id of the user in-room. Room user lists start at 0.", "Server"));
|
|
var clientToBan = client.Room!.Clients.ToArray()[int.Parse(arguments[0])].PlayerData.Uid;
|
|
if (clientToBan == null) { client.Send(Utils.BuildServerSideMessage($"User Could Not Be Found", "Server")); return; }
|
|
|
|
// send an http request to the api set in appsettings
|
|
ApiWebService apiWebService = new();
|
|
var response = apiWebService.BanUser(client, clientToBan, arguments[1], arguments[2]);
|
|
|
|
if (response != null) { client.Send(Utils.BuildServerSideMessage("User Banned Successfully", "Server")); return; }
|
|
else { client.Send(Utils.BuildServerSideMessage("Empty Response", "Server")); }
|
|
}
|
|
}
|