ShiftOS_TheReturn/ShiftOS.Server/MemoManager.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2017-02-12 16:21:20 +00:00
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
{
2017-02-15 21:30:58 +00:00
[MudRequest("get_memos_for_user", typeof(Dictionary<string, object>))]
2017-02-12 16:21:20 +00:00
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)
}));
}
}
2017-02-15 21:30:58 +00:00
[MudRequest("mud_postmemo", typeof(MUDMemo))]
2017-02-12 16:21:20 +00:00
public static void PostMemo(string guid, object contents)
{
2017-02-15 21:30:58 +00:00
MUDMemo memo = contents as MUDMemo;
2017-02-12 16:21:20 +00:00
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));
}
}
}