improvements

This commit is contained in:
Michael VanOverbeek 2017-03-06 17:01:16 +00:00
parent 909873af65
commit 9e30864a10
5 changed files with 59 additions and 2 deletions

View file

@ -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; }

View file

@ -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; }

View file

@ -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)
{

View file

@ -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"))

View file

@ -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
{