aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ShiftOS.Objects/Objects.cs4
-rw-r--r--ShiftOS.Objects/Save.cs2
-rw-r--r--ShiftOS.Server/ChatBackend.cs43
-rw-r--r--ShiftOS.Server/Program.cs4
-rw-r--r--ShiftOS.Server/SaveManager.cs8
5 files changed, 59 insertions, 2 deletions
diff --git a/ShiftOS.Objects/Objects.cs b/ShiftOS.Objects/Objects.cs
index 17f40ea..c4cd67c 100644
--- a/ShiftOS.Objects/Objects.cs
+++ b/ShiftOS.Objects/Objects.cs
@@ -96,6 +96,10 @@ namespace ShiftOS.Objects
//Don't describe this one. We want it to be hidden from the admin panel's chat editor.
public string ID { get; set; }
+ [FriendlyName("Requires Patreon?")]
+ [FriendlyDescription("If checked, this chat will only be shown in the MUD Control Centre if the user's save is marked as a Patreon supporter.")]
+ public bool RequiresPatreon { get; set; }
+
[FriendlyName("Chat topic")]
[FriendlyDescription("A more in-depth version of your chat name. Describe what your chat's about in a sentence.")]
public string Topic { get; set; }
diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs
index 23c1d0f..35bfdc2 100644
--- a/ShiftOS.Objects/Save.cs
+++ b/ShiftOS.Objects/Save.cs
@@ -45,6 +45,8 @@ namespace ShiftOS.Objects
public int MinorVersion { get; set; }
public int Revision { get; set; }
+ public bool IsPatreon { get; set; }
+
public string Password { get; set; }
public bool PasswordHashed { get; set; }
public string SystemName { get; set; }
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)
{
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs
index 04d7b2e..3ef9715 100644
--- a/ShiftOS.Server/Program.cs
+++ b/ShiftOS.Server/Program.cs
@@ -185,6 +185,10 @@ namespace ShiftOS.Server
Console.WriteLine("Save not found.");
}
}
+ else if(cmd.ToLower().StartsWith("broadcast "))
+ {
+ ChatBackend.Broadcast(cmd.Remove(0, 10));
+ }
else if (cmd == "purge_all_bad_saves")
{
foreach(var f in Directory.GetFiles("saves"))
diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs
index cef8b37..e986ecd 100644
--- a/ShiftOS.Server/SaveManager.cs
+++ b/ShiftOS.Server/SaveManager.cs
@@ -1,4 +1,4 @@
-/*
+/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
@@ -73,6 +73,12 @@ namespace ShiftOS.Server
if (save.Username == args["username"].ToString() && save.Password == args["password"].ToString())
{
+ if(save.ID == new Guid())
+ {
+ save.ID = Guid.NewGuid();
+ WriteEncFile(savefile, JsonConvert.SerializeObject(save));
+ }
+
Program.server.DispatchTo(new Guid(guid), new NetObject("mud_savefile", new ServerMessage
{