diff options
| author | Michael <[email protected]> | 2017-02-12 11:21:20 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-12 11:21:20 -0500 |
| commit | 7f8f8b1c483e04abde8e849e8054a5ff4b651051 (patch) | |
| tree | 955e3bca44bc0f51459f9faf1beb1c485cafa18c /ShiftOS.Server/MemoManager.cs | |
| parent | 177c22a24b419144af7a00d5970d04dc1618e0d7 (diff) | |
| download | shiftos_thereturn-7f8f8b1c483e04abde8e849e8054a5ff4b651051.tar.gz shiftos_thereturn-7f8f8b1c483e04abde8e849e8054a5ff4b651051.tar.bz2 shiftos_thereturn-7f8f8b1c483e04abde8e849e8054a5ff4b651051.zip | |
Finish MUD Refactoring
Diffstat (limited to 'ShiftOS.Server/MemoManager.cs')
| -rw-r--r-- | ShiftOS.Server/MemoManager.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ShiftOS.Server/MemoManager.cs b/ShiftOS.Server/MemoManager.cs new file mode 100644 index 0000000..ed0a2e9 --- /dev/null +++ b/ShiftOS.Server/MemoManager.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Objects; +using NetSockets; +using Newtonsoft.Json; +using System.IO; +using static ShiftOS.Server.Program; + +namespace ShiftOS.Server +{ + public static class MemoManager + { + [MudRequest("get_memos_for_user")] + public static void GetMemosForUser(string guid, object contents) + { + var args = contents as Dictionary<string, object>; + if (args["username"] != null) + { + string usrnme = args["username"].ToString(); + + List<MUDMemo> mmos = new List<MUDMemo>(); + + if (File.Exists("memos.json")) + { + foreach (var mmo in JsonConvert.DeserializeObject<MUDMemo[]>(File.ReadAllText("memos.json"))) + { + if (mmo.UserTo == usrnme) + { + mmos.Add(mmo); + } + } + } + + server.DispatchTo(new Guid(guid), new NetObject("mud_memos", new ServerMessage + { + Name = "mud_usermemos", + GUID = "server", + Contents = JsonConvert.SerializeObject(mmos) + })); + } + + } + + [MudRequest("mud_postmemo")] + public static void PostMemo(string guid, object contents) + { + MUDMemo memo = JsonConvert.DeserializeObject<MUDMemo>(contents as string); + List<MUDMemo> memos = new List<MUDMemo>(); + + if (File.Exists("memos.json")) + memos = JsonConvert.DeserializeObject<List<MUDMemo>>(File.ReadAllText("memos.json")); + + memos.Add(memo); + File.WriteAllText("memos.txt", JsonConvert.SerializeObject(memos)); + } + } +} |
