forked from SoDOff-Project/sodoff-mmo
Compare commits
No commits in common. "a7aae8763eefa895209e8dc9f5861ea0b861b1ef" and "783d02d4b27c908efd8771fa91d6f85ea1a596db" have entirely different histories.
a7aae8763e
...
783d02d4b2
@ -1,6 +1,4 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using sodoffmmo.Attributes;
|
||||
using sodoffmmo.Attributes;
|
||||
using sodoffmmo.Core;
|
||||
using sodoffmmo.Data;
|
||||
using sodoffmmo.Management;
|
||||
@ -39,13 +37,6 @@ class ChatMessageHandler : CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// send an http request to api to check for 'IndefiniteOpenChatBan' or 'TemporaryOpenChatBan'
|
||||
ApiWebService apiWebService = new();
|
||||
var banType = apiWebService.CheckForUserBan(client);
|
||||
|
||||
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.Room.Send(Utils.BuildChatMessage(client.PlayerData.Uid, message, client.PlayerData.DiplayName), client);
|
||||
|
||||
NetworkObject cmd = new();
|
||||
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Net.Http.Json;
|
||||
using sodoffmmo.CommandHandlers;
|
||||
|
||||
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);
|
||||
|
||||
try
|
||||
{
|
||||
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/CheckForVikingBan", content).Result;
|
||||
Log("Moderation/CheckForVikingBan");
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content != null) return response.Content.ReadFromJsonAsync<UserBanType>().Result;
|
||||
else return null;
|
||||
} catch (Exception e) { LogError(e.Message); return null; }
|
||||
}
|
||||
|
||||
public string? 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);
|
||||
|
||||
try
|
||||
{
|
||||
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Moderation/AddBanToVikingByGuid", content).Result;
|
||||
Log("Moderation/AddBanToVikingByGuid");
|
||||
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content != null) return response.Content.ReadAsStringAsync().Result;
|
||||
else return null;
|
||||
} catch (Exception e) { LogError(e.Message); return null; }
|
||||
}
|
||||
|
||||
private void Log(string endpoint) => Console.WriteLine($"Sent API Request To {Configuration.ServerConfiguration.ApiUrl}/{endpoint}");
|
||||
|
||||
private void LogError(string message) => Console.WriteLine($"An Error Has Occured When Sending An API Request - {message}");
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace sodoffmmo.Core;
|
||||
|
||||
public enum UserBanType
|
||||
{
|
||||
NotBanned = 0,
|
||||
IndefiniteOpenChatBan = 1,
|
||||
TemporaryOpenChatBan = 2,
|
||||
IndefiniteAccountBan = 3,
|
||||
TemporaryAccountBan = 4
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
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")); }
|
||||
}
|
||||
}
|
@ -61,9 +61,9 @@
|
||||
"// Authentication Optional": "authentication is required only for moderation activities",
|
||||
"// Authentication RequiredForChat": "authentication is required only for moderation activities and using chat (if chat is enabled)",
|
||||
"// Authentication Required": "authentication is required to connect to mmo",
|
||||
"Authentication": "Required",
|
||||
"Authentication": "Disabled",
|
||||
|
||||
"// ApiUrl": "SoDOff API server URL for authentication calls and other calls",
|
||||
"// ApiUrl": "SoDOff API server URL for authentication calls",
|
||||
"ApiUrl": "http://localhost:5000",
|
||||
|
||||
"// BypassToken": "Token allowed to connect without authentication",
|
||||
|
Loading…
x
Reference in New Issue
Block a user