diff --git a/MCGalaxy/Database/Backends/SQLiteBackend.cs b/MCGalaxy/Database/Backends/SQLiteBackend.cs index 8e9f9f9ea..336c08069 100644 --- a/MCGalaxy/Database/Backends/SQLiteBackend.cs +++ b/MCGalaxy/Database/Backends/SQLiteBackend.cs @@ -364,17 +364,18 @@ namespace MCGalaxy.SQL return data; } - public unsafe static string FromUTF8(IntPtr ptr, int len) { + public static string FromUTF8(IntPtr ptr, int len) { if (ptr == IntPtr.Zero) return ""; - byte* mem = (byte*)ptr; if (len < 0) { len = 0; - while (mem[len] != 0) { len++; } + while (Marshal.ReadByte(ptr, len) != 0) { len++; } } if (len == 0) return ""; - return utf8.GetString(mem, len); + byte[] data = new byte[len]; + Marshal.Copy(ptr, data, 0, len); + return utf8.GetString(data, 0, len); } public static DateTime ToDateTime(string text) { diff --git a/MCGalaxy/Modules/Relay/Discord/DiscordBot.cs b/MCGalaxy/Modules/Relay/Discord/DiscordBot.cs index e80ae67ac..0e94bf437 100644 --- a/MCGalaxy/Modules/Relay/Discord/DiscordBot.cs +++ b/MCGalaxy/Modules/Relay/Discord/DiscordBot.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using MCGalaxy.Config; +using MCGalaxy.Events; using MCGalaxy.Events.PlayerEvents; using MCGalaxy.Games; using MCGalaxy.Tasks; @@ -27,6 +28,23 @@ using MCGalaxy.Util; namespace MCGalaxy.Modules.Relay.Discord { + public delegate void OnSendingWhoEmbed(DiscordBot bot, RelayUser user, ref ChannelSendEmbed embed); + /// Called when sending an embed response to a .who message from Discord + public sealed class OnSendingWhoEmbedEvent : IEvent + { + public static void Call(DiscordBot bot, RelayUser user, ref ChannelSendEmbed embed) { + IEvent[] items = handlers.Items; + for (int i = 0; i < items.Length; i++) + { + try { + items[i].method(bot, user, ref embed); + } catch (Exception ex) { + LogHandlerException(ex, items[i]); + } + } + } + } + sealed class DiscordUser : RelayUser { public string ReferencedUser; @@ -511,7 +529,9 @@ namespace MCGalaxy.Modules.Relay.Discord ConvertMessage(FormatPlayers(p, e)) ); } + AddGameStatus(embed); + OnSendingWhoEmbedEvent.Call(this, p.User, ref embed); Send(embed); } diff --git a/MCGalaxy/Modules/Relay/RelayBot.cs b/MCGalaxy/Modules/Relay/RelayBot.cs index 10bb66323..6b04366b8 100644 --- a/MCGalaxy/Modules/Relay/RelayBot.cs +++ b/MCGalaxy/Modules/Relay/RelayBot.cs @@ -522,7 +522,8 @@ namespace MCGalaxy.Modules.Relay return Group.DefaultRank; } - protected sealed class RelayPlayer : Player { + protected sealed class RelayPlayer : Player + { public readonly string ChannelID; public readonly RelayUser User; public readonly RelayBot Bot;