forked from SoDOff-Project/sodoff-mmo
implement `BanCommand
`
This commit is contained in:
parent
783d02d4b2
commit
86b9d39266
34
src/Management/Commands/BanCommand.cs
Normal file
34
src/Management/Commands/BanCommand.cs
Normal file
@ -0,0 +1,34 @@
|
||||
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; }
|
||||
|
||||
// send an http request to the api set in appsettings
|
||||
HttpClient httpClient = new();
|
||||
var content = new FormUrlEncodedContent(
|
||||
new Dictionary<string, string> {
|
||||
{ "token", client.PlayerData.UNToken },
|
||||
{ "userId", arguments[0] },
|
||||
{ "banType", arguments[1] },
|
||||
{ "days", arguments[2] }
|
||||
}
|
||||
);
|
||||
|
||||
httpClient.Timeout = new TimeSpan(0, 0, 3);
|
||||
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/AddBanToVikingByGuid", content).Result;
|
||||
string? responseString = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
if (response.StatusCode != System.Net.HttpStatusCode.OK && responseString != null) { client.Send(Utils.BuildServerSideMessage(responseString, "Server")); return; }
|
||||
else if (responseString != null) { client.Send(Utils.BuildServerSideMessage("User Banned Successfully", "Server")); return; }
|
||||
else { client.Send(Utils.BuildServerSideMessage("Empty Response", "Server")); }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user