aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server/ChatBackend.cs
diff options
context:
space:
mode:
authorMichael VanOverbeek <[email protected]>2017-03-06 17:01:16 +0000
committerMichael VanOverbeek <[email protected]>2017-03-06 17:01:24 +0000
commit9e30864a106a1a9b5dab0ffd6c333951d3c91dd2 (patch)
tree9896b85dcb4f119d7eea8ace27471b760d6a952a /ShiftOS.Server/ChatBackend.cs
parent909873af65113a5808e509741a3f37f849d425ca (diff)
downloadshiftos_thereturn-9e30864a106a1a9b5dab0ffd6c333951d3c91dd2.tar.gz
shiftos_thereturn-9e30864a106a1a9b5dab0ffd6c333951d3c91dd2.tar.bz2
shiftos_thereturn-9e30864a106a1a9b5dab0ffd6c333951d3c91dd2.zip
improvements
Diffstat (limited to 'ShiftOS.Server/ChatBackend.cs')
-rw-r--r--ShiftOS.Server/ChatBackend.cs43
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)
{