forked from SoDOff-Project/sodoff-mmo
Moderation Commands #1
@ -40,16 +40,8 @@ class ChatMessageHandler : CommandHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send an http request to api to check for 'IndefiniteOpenChatBan' or 'TemporaryOpenChatBan'
|
// send an http request to api to check for 'IndefiniteOpenChatBan' or 'TemporaryOpenChatBan'
|
||||||
HttpClient httpClient = new();
|
ApiWebService apiWebService = new();
|
||||||
var content = new FormUrlEncodedContent(
|
var banType = apiWebService.CheckForUserBan(client);
|
||||||
new Dictionary<string, string> {
|
|
||||||
{ "token", client.PlayerData.UNToken }
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
httpClient.Timeout = new TimeSpan(0, 0, 3);
|
|
||||||
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/CheckForVikingBan", content).Result;
|
|
||||||
UserBanType? banType = response.Content.ReadFromJsonAsync<UserBanType>().Result;
|
|
||||||
|
|
||||||
if (banType != null && (banType == UserBanType.IndefiniteOpenChatBan || banType == UserBanType.TemporaryOpenChatBan))
|
if (banType != null && (banType == UserBanType.IndefiniteOpenChatBan || banType == UserBanType.TemporaryOpenChatBan))
|
||||||
{ client.Send(Utils.ArrNetworkPacket(new string[] { "SMF", "-1", "CB", "1", "Sorry, You've Been Banned From Using Type Chat", "1" }, "SMF")); return; }
|
{ client.Send(Utils.ArrNetworkPacket(new string[] { "SMF", "-1", "CB", "1", "Sorry, You've Been Banned From Using Type Chat", "1" }, "SMF")); return; }
|
||||||
|
38
src/Core/ApiWebService.cs
Normal file
38
src/Core/ApiWebService.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
|
namespace sodoffmmo.Core;
|
||||||
|
|
||||||
|
public class ApiWebService
|
||||||
|
{
|
||||||
|
public UserBanType? CheckForUserBan(Client client)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new();
|
||||||
|
var content = new FormUrlEncodedContent(
|
||||||
|
new Dictionary<string, string> {
|
||||||
|
{ "token", client.PlayerData.UNToken }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
httpClient.Timeout = new TimeSpan(0, 0, 3);
|
||||||
|
|
||||||
|
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/CheckForVikingBan", content).Result;
|
||||||
|
if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content != null) return response.Content.ReadFromJsonAsync<UserBanType>().Result;
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpResponseMessage BanUser(Client client, string userId, string banType, string days)
|
||||||
|
{
|
||||||
|
HttpClient httpClient = new();
|
||||||
|
var content = new FormUrlEncodedContent(
|
||||||
|
new Dictionary<string, string> {
|
||||||
|
{ "token", client.PlayerData.UNToken },
|
||||||
|
{ "userId", userId },
|
||||||
|
{ "banType", banType },
|
||||||
|
{ "days", days }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
httpClient.Timeout = new TimeSpan(0, 0, 3);
|
||||||
|
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/AddBanToVikingByGuid", content).Result;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
@ -13,19 +13,9 @@ class BanCommand : IManagementCommand
|
|||||||
if(arguments.Length < 2) { client.Send(Utils.BuildServerSideMessage($"Expected 3 Args, Got {arguments.Length + 1}", "Server")); return; }
|
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
|
// send an http request to the api set in appsettings
|
||||||
HttpClient httpClient = new();
|
ApiWebService apiWebService = new();
|
||||||
var content = new FormUrlEncodedContent(
|
var response = apiWebService.BanUser(client, arguments[0], arguments[1], arguments[2]);
|
||||||
new Dictionary<string, string> {
|
var responseString = response.Content.ReadAsStringAsync().Result;
|
||||||
{ "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; }
|
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 if (responseString != null) { client.Send(Utils.BuildServerSideMessage("User Banned Successfully", "Server")); return; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user