aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Server')
-rw-r--r--ShiftOS.Server/ChatBackend.cs69
-rw-r--r--ShiftOS.Server/ShopBackend.cs19
2 files changed, 76 insertions, 12 deletions
diff --git a/ShiftOS.Server/ChatBackend.cs b/ShiftOS.Server/ChatBackend.cs
index 242ae16..ba1c48e 100644
--- a/ShiftOS.Server/ChatBackend.cs
+++ b/ShiftOS.Server/ChatBackend.cs
@@ -1,4 +1,4 @@
-/*
+/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
@@ -73,12 +73,14 @@ namespace ShiftOS.Server
{
if (s.Author.Id != client.CurrentUser.Id)
{
+ var msg = new ChatMessage(s.Author.Username, "discord_" + s.Channel.Name, (s as SocketUserMessage).Resolve(0), chatID);
server.DispatchAll(new NetObject("chat_msgreceived", new ServerMessage
{
Name = "chat_msgreceived",
GUID = "server",
- Contents = JsonConvert.SerializeObject(new ChatMessage(s.Author.Username, "discord_" + s.Channel.Name, (s as SocketUserMessage).Resolve(0), chatID))
+ Contents = JsonConvert.SerializeObject(msg)
}));
+ Log(chatID, $"[{msg.Username}@{msg.SystemName}] {msg.Message}");
}
}
}
@@ -94,10 +96,11 @@ namespace ShiftOS.Server
var dChan = client.GetChannel(Convert.ToUInt64(chat.DiscordChannelID)) as ISocketMessageChannel;
//Relay the message to Discord.
dChan.SendMessageAsync($"**[{msg.Username}@{msg.SystemName}]** `<mud/{msg.Channel}>` {msg.Message}");
+ //Relay it back to all MUD clients.
+ RelayMessage(g, msg);
+ Log(chatID, $"[{msg.Username}@{msg.SystemName}] {msg.Message}");
}
- //Relay it back to all MUD clients.
- RelayMessage(g, msg);
}
};
Reinitialized += () =>
@@ -115,6 +118,8 @@ namespace ShiftOS.Server
{
//Just relay it.
RelayMessage(g, msg);
+ //...Then log it.
+ Log(chatID, $"[{msg.Username}@{msg.SystemName}] {msg.Message}");
}
};
Reinitialized += () => { chatKilled = true; };
@@ -157,6 +162,62 @@ namespace ShiftOS.Server
MessageReceived?.Invoke(guid, new ChatMessage(msg["Username"], msg["SystemName"], msg["Message"], msg["Channel"]));
}
+
+ [MudRequest("chat_getlog", typeof(ChatLogRequest))]
+ public static void GetChatlog(string guid, ChatLogRequest req)
+ {
+ if (!Directory.Exists("chatlogs"))
+ Directory.CreateDirectory("chatlogs");
+
+ if(File.Exists("chatlogs/" + req.Channel + ".log"))
+ {
+ string[] log = File.ReadAllLines("chatlogs/" + req.Channel + ".log");
+ string seg = "";
+
+ if(req.Backtrack == 0 || log.Length < req.Backtrack)
+ {
+ //send all of it.
+ foreach(var ln in log)
+ {
+ seg += ln + Environment.NewLine;
+ }
+ }
+ else
+ {
+ //send only a specific chunk.
+ for(int i = log.Length - 1; i >= log.Length - req.Backtrack; i--)
+ {
+ seg += log[i] + Environment.NewLine;
+ }
+ }
+
+ try
+ {
+ server.DispatchTo(new Guid(guid), new NetObject("always watching, always listening, my eyes are everywhere, you cannot escape me", new ServerMessage
+ {
+ Name = "chatlog",
+ Contents = seg,
+ GUID = "server"
+ }));
+ }
+ catch { }
+ }
+ }
+
+
+ public static void Log(string channel, string line)
+ {
+ if (!Directory.Exists("chatlogs"))
+ Directory.CreateDirectory("chatlogs");
+
+ List<string> lines = new List<string>();
+ if (File.Exists("chatlogs/" + channel + ".log"))
+ lines = new List<string>(File.ReadAllLines("chatlogs/" + channel + ".log"));
+
+ lines.Add(line);
+ File.WriteAllLines("chatlogs/" + channel + ".log", lines.ToArray());
+
+ }
}
}
diff --git a/ShiftOS.Server/ShopBackend.cs b/ShiftOS.Server/ShopBackend.cs
index 12f69ce..baf1e7a 100644
--- a/ShiftOS.Server/ShopBackend.cs
+++ b/ShiftOS.Server/ShopBackend.cs
@@ -1,4 +1,4 @@
-/*
+/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
@@ -185,15 +185,18 @@ namespace ShiftOS.Server
if (File.Exists("shops.json"))
foreach (var shop in JsonConvert.DeserializeObject<List<Shop>>(File.ReadAllText("shops.json")))
{
- if (shop.Owner == shopOwner)
+ if (shop != null)
{
- server.DispatchTo(new Guid(guid), new NetObject("ruecuodaL", new ServerMessage
+ if (shop.Owner == shopOwner)
{
- Name = "user_shop",
- GUID = "server",
- Contents = JsonConvert.SerializeObject(shop)
- }));
- return;
+ server.DispatchTo(new Guid(guid), new NetObject("ruecuodaL", new ServerMessage
+ {
+ Name = "user_shop",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(shop)
+ }));
+ return;
+ }
}
}