diff options
Diffstat (limited to 'ShiftOS.Server/ChatBackend.cs')
| -rw-r--r-- | ShiftOS.Server/ChatBackend.cs | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/ShiftOS.Server/ChatBackend.cs b/ShiftOS.Server/ChatBackend.cs index ba1c48e..b9fbf25 100644 --- a/ShiftOS.Server/ChatBackend.cs +++ b/ShiftOS.Server/ChatBackend.cs @@ -103,7 +103,21 @@ namespace ShiftOS.Server } } }; - Reinitialized += () => + OnBroadcast += (msg) => + { + if (chatKilled == false) + { + var cMsg = new ChatMessage("sys", "mud", msg, chatID); + RelayMessageToAll(cMsg); + Log(chatID, msg); + //Get the Discord channel for this chat. + var dChan = client.GetChannel(Convert.ToUInt64(chat.DiscordChannelID)) as ISocketMessageChannel; + //Relay the message to Discord. + dChan.SendMessageAsync($"{msg}"); + //Relay it back to all MUD clients. + + } + }; Reinitialized += () => { client.DisconnectAsync(); @@ -122,11 +136,31 @@ namespace ShiftOS.Server Log(chatID, $"[{msg.Username}@{msg.SystemName}] {msg.Message}"); } }; + OnBroadcast += (msg) => + { + if (chatKilled == false) + { + var cMsg = new ChatMessage("sys", "mud", msg, chatID); + RelayMessageToAll(cMsg); + Log(chatID, msg); + } + }; Reinitialized += () => { chatKilled = true; }; } } } + internal static void RelayMessageToAll(ChatMessage msg) + { + server.DispatchAll(new NetObject("chat_msgreceived", new ServerMessage + { + Name = "chat_msgreceived", + GUID = "server", + Contents = JsonConvert.SerializeObject(msg) + })); + + } + internal static void RelayMessage(string guid, ChatMessage msg) { server.DispatchAllExcept(new Guid(guid), new NetObject("chat_msgreceived", new ServerMessage @@ -163,6 +197,13 @@ namespace ShiftOS.Server } + public static event Action<string> OnBroadcast; + + public static void Broadcast(string text) + { + OnBroadcast?.Invoke("[Broadcast] " + text); + } + [MudRequest("chat_getlog", typeof(ChatLogRequest))] public static void GetChatlog(string guid, ChatLogRequest req) { |
