Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,227 @@
#region Header
// Vorspire _,-'/-'/ DiscordBot.cs
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2017 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # The MIT License (MIT) #
#endregion
#region References
using System;
using System.Linq;
using Server;
using Server.Misc;
using VitaNex.Collections;
using VitaNex.IO;
using VitaNex.Modules.AutoPvP;
using VitaNex.Text;
using VitaNex.Web;
#endregion
namespace VitaNex.Modules.Discord
{
public static partial class DiscordBot
{
public const AccessLevel Access = AccessLevel.Administrator;
private static readonly string[] _SaveMessages;
private static string _LastMessage;
private static readonly DictionaryPool<string, object> _Pool;
public static DiscordBotOptions CMOptions { get; private set; }
/*
private static void OnWorldBroadcast(WorldBroadcastEventArgs e)
{
if (CMOptions.HandleBroadcast)
{
SendMessage(e.Text);
}
}
*/
private static void OnServerShutdown(ShutdownEventArgs e)
{
if (CMOptions.HandleStatus)
{
SendMessage("Status: Offline");
}
}
private static void OnServerCrashed(CrashedEventArgs e)
{
if (CMOptions.HandleStatus)
{
SendMessage("Status: Offline (Back Soon!)");
}
}
private static void OnServerStarted()
{
if (CMOptions.HandleStatus)
{
SendMessage("Status: Online");
}
}
private static void OnNotifyBroadcast(string message)
{
if (CMOptions.HandleNotify)
{
SendMessage(message);
}
}
private static void OnBattleWorldBroadcast(PvPBattle b, string text)
{
if (CMOptions.HandleBattles)
{
SendMessage(text);
}
}
public static void SendMessage(string message)
{
SendMessage(message, true);
}
public static void SendMessage(string message, bool filtered)
{
if (!CMOptions.ModuleEnabled || String.IsNullOrWhiteSpace(message))
{
return;
}
var uri = GetWebhookUri();
if (uri.Contains("NULL"))
{
return;
}
message = message.StripHtmlBreaks(true).StripHtml(false);
if (filtered)
{
if (CMOptions.FilterSaves && _SaveMessages.Any(o => Insensitive.Contains(message, o)))
{
return;
}
if (CMOptions.FilterRepeat && _LastMessage == message)
{
return;
}
}
_LastMessage = message;
var d = _Pool.Acquire();
d["content"] = message;
d["username"] = ServerList.ServerName;
d["file"] = null;
d["embeds"] = null;
WebAPI.BeginRequest(
uri,
d,
(req, o) =>
{
req.Method = "POST";
req.ContentType = FileMime.Lookup("json");
req.SetContent(Json.Encode(o));
_Pool.Free(o);
},
null);
}
public static string GetWebhookUri()
{
return GetWebhookUri(CMOptions.ModuleDebug);
}
public static string GetWebhookUri(bool debug)
{
return GetWebhook(debug).ToString();
}
public static Uri GetWebhook(bool debug)
{
var id = debug ? CMOptions.WebhookDebugID : CMOptions.WebhookID;
var key = debug ? CMOptions.WebhookDebugKey : CMOptions.WebhookKey;
if (String.IsNullOrWhiteSpace(id))
{
id = "NULL";
}
if (String.IsNullOrWhiteSpace(key))
{
key = "NULL";
}
return new Uri("https://discordapp.com/api/webhooks/" + id + "/" + key);
}
public static bool SetWebhook(string uri, bool debug)
{
try
{
return SetWebhook(new Uri(uri), debug);
}
catch
{
return false;
}
}
public static bool SetWebhook(Uri u, bool debug)
{
try
{
var s = u.ToString();
var i = s.IndexOf("discordapp.com/api/webhooks/", StringComparison.OrdinalIgnoreCase);
if (i < 0 || i >= s.Length - 28)
{
return false;
}
s = s.Substring(i + 28);
i = s.IndexOf('/');
if (i <= 0 || i >= s.Length - 1)
{
return false;
}
if (debug)
{
CMOptions.WebhookDebugID = s.Substring(0, i);
CMOptions.WebhookDebugKey = s.Substring(i + 1);
}
else
{
CMOptions.WebhookID = s.Substring(0, i);
CMOptions.WebhookKey = s.Substring(i + 1);
}
return true;
}
catch
{
return false;
}
}
}
}

View File

@@ -0,0 +1,62 @@
#region Header
// Vorspire _,-'/-'/ DiscordBot_Init.cs
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2017 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # The MIT License (MIT) #
#endregion
#region References
using System;
using Server;
using VitaNex.Collections;
#endregion
namespace VitaNex.Modules.Discord
{
[CoreModule("Discord Bot", "1.0.0.0", false, TaskPriority.Lowest)]
public static partial class DiscordBot
{
static DiscordBot()
{
_SaveMessages = new[] {"The world will save in", "The world is saving", "World save complete"};
_Pool = new DictionaryPool<string, object>();
CMOptions = new DiscordBotOptions();
}
private static void CMConfig()
{
EventSink.Shutdown += OnServerShutdown;
EventSink.Crashed += OnServerCrashed;
EventSink.ServerStarted += OnServerStarted;
Notify.Notify.OnBroadcast += OnNotifyBroadcast;
AutoPvP.AutoPvP.OnBattleWorldBroadcast += OnBattleWorldBroadcast;
}
private static void CMInvoke()
{
//EventSink.WorldBroadcast += OnWorldBroadcast;
CommandUtility.Register(
"Discord",
Access,
e =>
{
var message = String.Format("[{0}]: {1}", e.Mobile.RawName, e.ArgString);
SendMessage(message, false);
});
CommandUtility.Register("DiscordAdmin", Access, e => new DiscordBotUI(e.Mobile).Send());
}
}
}

View File

@@ -0,0 +1,134 @@
#region Header
// Vorspire _,-'/-'/ DiscordBotOptions.cs
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2017 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # The MIT License (MIT) #
#endregion
#region References
using System;
using Server;
#endregion
namespace VitaNex.Modules.Discord
{
public class DiscordBotOptions : CoreModuleOptions
{
[CommandProperty(DiscordBot.Access)]
public string WebhookID { get; set; }
[CommandProperty(DiscordBot.Access)]
public string WebhookKey { get; set; }
[CommandProperty(DiscordBot.Access)]
public string WebhookDebugID { get; set; }
[CommandProperty(DiscordBot.Access)]
public string WebhookDebugKey { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool FilterSaves { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool FilterRepeat { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool HandleBroadcast { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool HandleNotify { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool HandleBattles { get; set; }
[CommandProperty(DiscordBot.Access)]
public bool HandleStatus { get; set; }
public DiscordBotOptions()
: base(typeof(DiscordBot))
{
SetDefaults();
}
public DiscordBotOptions(GenericReader reader)
: base(reader)
{ }
public override void Clear()
{
base.Clear();
SetDefaults();
}
public override void Reset()
{
base.Reset();
SetDefaults();
}
public void SetDefaults()
{
WebhookID = String.Empty;
WebhookKey = String.Empty;
WebhookDebugID = String.Empty;
WebhookDebugKey = String.Empty;
FilterSaves = true;
FilterRepeat = true;
HandleBroadcast = true;
HandleNotify = true;
HandleBattles = true;
HandleStatus = true;
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.SetVersion(0);
writer.Write(WebhookID);
writer.Write(WebhookKey);
writer.Write(WebhookDebugID);
writer.Write(WebhookDebugKey);
writer.Write(FilterSaves);
writer.Write(FilterRepeat);
writer.Write(HandleBroadcast);
writer.Write(HandleNotify);
writer.Write(HandleBattles);
writer.Write(HandleStatus);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
reader.GetVersion();
WebhookID = reader.ReadString();
WebhookKey = reader.ReadString();
WebhookDebugID = reader.ReadString();
WebhookDebugKey = reader.ReadString();
FilterSaves = reader.ReadBool();
FilterRepeat = reader.ReadBool();
HandleBroadcast = reader.ReadBool();
HandleNotify = reader.ReadBool();
HandleBattles = reader.ReadBool();
HandleStatus = reader.ReadBool();
}
}
}

View File

@@ -0,0 +1,285 @@
#region Header
// Vorspire _,-'/-'/ DiscordBotUI.cs
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2017 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # The MIT License (MIT) #
#endregion
#region References
using System;
using System.Drawing;
using Server;
using Server.Commands;
using Server.Gumps;
using VitaNex.SuperGumps;
#endregion
namespace VitaNex.Modules.Discord
{
public class DiscordBotUI : SuperGump
{
public DiscordBotUI(Mobile user)
: base(user)
{ }
protected override void CompileLayout(SuperGumpLayout layout)
{
base.CompileLayout(layout);
const int w = 600, h = 400;
layout.Add("bg", () => AddBackground(0, 0, w, h, SupportsUltimaStore ? 40000 : 9270));
layout.Add(
"title",
() =>
{
var label = "Discord Bot Settings";
label = label.WrapUOHtmlBig();
label = label.WrapUOHtmlCenter();
label = label.WrapUOHtmlColor(Color.Gold, false);
AddHtml(15, 10, w - 30, 40, label, false, false);
});
layout.Add(
"webhook/live",
() =>
{
var label = "Live Webhook";
label = label.WrapUOHtmlRight();
label = label.WrapUOHtmlColor(Color.Gold, false);
const int ww = (w - 30) / 4;
AddHtml(15, 40, ww, 40, label, false, false);
AddImageTiled(15 + (ww + 10), 40, (w - 30) - (ww + 10), 20, 2624);
AddTextEntry(
15 + (ww + 15),
40,
(w - 30) - (ww + 20),
20,
TextHue,
DiscordBot.GetWebhookUri(false),
(e, t) => DiscordBot.SetWebhook(t, false));
});
layout.Add(
"webhook/debug",
() =>
{
var label = "Debug Webhook";
label = label.WrapUOHtmlRight();
label = label.WrapUOHtmlColor(Color.Gold, false);
const int ww = (w - 30) / 4;
AddHtml(15, 60, ww, 40, label, false, false);
AddImageTiled(15 + (ww + 10), 60, (w - 30) - (ww + 10), 20, 2624);
AddTextEntry(
15 + (ww + 15),
60,
(w - 30) - (ww + 20),
20,
TextHue,
DiscordBot.GetWebhookUri(true),
(e, t) => DiscordBot.SetWebhook(t, true));
});
layout.Add(
"options",
() =>
{
var xx = 15;
var yy = 90;
const int ww = (w - 30) / 4;
var col = DiscordBot.CMOptions.FilterSaves ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.FilterSaves = !DiscordBot.CMOptions.FilterSaves;
Refresh(true);
},
"Saves Filter".WrapUOHtmlCenter(),
col,
Color.Black,
Color.Silver,
1);
xx += ww;
col = DiscordBot.CMOptions.FilterRepeat ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.FilterRepeat = !DiscordBot.CMOptions.FilterRepeat;
Refresh(true);
},
"Repeat Filter".WrapUOHtmlCenter(),
col,
Color.Black,
col,
1);
xx = 15;
yy += 35;
col = DiscordBot.CMOptions.HandleBroadcast ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.HandleBroadcast = !DiscordBot.CMOptions.HandleBroadcast;
Refresh(true);
},
"Handle Broadcasts".WrapUOHtmlCenter(),
col,
Color.Black,
Color.Silver,
1);
xx += ww;
col = DiscordBot.CMOptions.HandleNotify ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.HandleNotify = !DiscordBot.CMOptions.HandleNotify;
Refresh(true);
},
"Handle Notifications".WrapUOHtmlCenter(),
col,
Color.Black,
col,
1);
xx += ww;
col = DiscordBot.CMOptions.HandleBattles ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.HandleBattles = !DiscordBot.CMOptions.HandleBattles;
Refresh(true);
},
"Handle PvP Battles".WrapUOHtmlCenter(),
col,
Color.Black,
col,
1);
xx += ww;
col = DiscordBot.CMOptions.HandleStatus ? Color.LawnGreen : Color.OrangeRed;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
DiscordBot.CMOptions.HandleStatus = !DiscordBot.CMOptions.HandleStatus;
Refresh(true);
},
"Handle Server Status".WrapUOHtmlCenter(),
col,
Color.Black,
col,
1);
xx = 15;
yy += 35;
AddHtmlButton(
xx,
yy,
ww,
25,
b =>
{
Refresh();
User.SendGump(new PropertiesGump(User, DiscordBot.CMOptions));
},
"Module Config".WrapUOHtmlCenter(),
Color.Gold,
Color.Black,
Color.Gold,
1);
xx = 0;
yy += 35;
AddBackground(xx, yy, w, h - yy, SupportsUltimaStore ? 40000 : 9270);
xx += 15;
yy += 10;
var label = "Information";
label = label.WrapUOHtmlBig();
label = label.WrapUOHtmlCenter();
label = label.WrapUOHtmlColor(Color.Gold, false);
AddHtml(xx, yy, w - 30, 40, label, false, false);
yy += 35;
label = Information;
label = label.WrapUOHtmlColor(Color.PaleGoldenrod, false);
AddHtml(xx, yy, w - 30, (h - 20) - yy, label, false, true);
});
}
public const string WebhooksUri = "https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks";
public static readonly string Information = //
"Configure Webhooks to use when sending messages to Discord.\n" +
"Discord - Intro to Webhooks".WrapUOHtmlUrl(WebhooksUri) +
"\n\nThe Debug Webhook will be used when the Discord Bot is in Debug Mode, otherwise, the Live Webhook is used.\n" +
"Make sure to use a fully qualified URL when update your Webhook settings.\n\nYou may use the " +
CommandSystem.Prefix + "Discord command to send messages directly to Discord.\n" +
"Messages sent this way will not be subject to filtering.\n\n";
}
}