diff options
| author | Michael <[email protected]> | 2017-02-12 10:51:53 -0500 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-02-12 10:51:53 -0500 |
| commit | 110438929c855aec8fe1a4cc0b01ccad7ee3807d (patch) | |
| tree | af23414c9a456fccdfb476937160e7ab4254c1d0 /ShiftOS.Server/SaveManager.cs | |
| parent | 88e84f74e1c352b5e24b088ba31cff9eb39964fb (diff) | |
| download | shiftos_thereturn-110438929c855aec8fe1a4cc0b01ccad7ee3807d.tar.gz shiftos_thereturn-110438929c855aec8fe1a4cc0b01ccad7ee3807d.tar.bz2 shiftos_thereturn-110438929c855aec8fe1a4cc0b01ccad7ee3807d.zip | |
More MUD refactoring (I'm almost done!)
Diffstat (limited to 'ShiftOS.Server/SaveManager.cs')
| -rw-r--r-- | ShiftOS.Server/SaveManager.cs | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/ShiftOS.Server/SaveManager.cs b/ShiftOS.Server/SaveManager.cs index 4bca36d..505abe6 100644 --- a/ShiftOS.Server/SaveManager.cs +++ b/ShiftOS.Server/SaveManager.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using ShiftOS.Objects; using System.IO; using Newtonsoft.Json; +using NetSockets; +using static ShiftOS.Server.Program; namespace ShiftOS.Server { @@ -32,6 +34,139 @@ namespace ShiftOS.Server } + [MudRequest("mud_login")] + public static void UserLogin(string guid, object contents) + { + var args = contents as Dictionary<string, object>; + if (args["username"] != null && args["password"] != null) + { + foreach (var savefile in Directory.GetFiles("saves")) + { + try + { + var save = JsonConvert.DeserializeObject<Save>(ReadEncFile(savefile)); + + + if (save.Username == args["username"].ToString() && save.Password == args["password"].ToString()) + { + + Program.server.DispatchTo(new Guid(msg.GUID), new NetObject("mud_savefile", new ServerMessage + { + Name = "mud_savefile", + GUID = "server", + Contents = JsonConvert.SerializeObject(save) + })); + return; + } + } + catch { } + } + Program.server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_login_denied", + GUID = "server" + })); + } + else + { + Program.server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_login_denied", + GUID = "server" + })); + } + + } + + [MudRequest("mud_checkuserexists")] + public static void CheckUserExists(string guid, object contents) + { + var args = contents as Dictionary<string, object>; + if (args["username"] != null && args["password"] != null) + { + foreach (var savefile in Directory.GetFiles("saves")) + { + try + { + var save = JsonConvert.DeserializeObject<Save>(ReadEncFile(savefile)); + + + if (save.Username == args["username"].ToString() && save.Password == args["password"].ToString()) + { + server.DispatchTo(new Guid(msg.GUID), new NetObject("mud_savefile", new ServerMessage + { + Name = "mud_found", + GUID = "server", + })); + return; + } + } + catch { } + } + server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_notfound", + GUID = "server" + })); + } + else + { + server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_notfound", + GUID = "server" + })); + } + + } + + [MudRequest("mud_save")] + public static void SaveGame(string guid, object contents) + { + var sav = JsonConvert.DeserializeObject<Save>(contents as string); + + WriteEncFile("saves/" + sav.Username + ".save", JsonConvert.SerializeObject(sav, Formatting.Indented)); + + Program.server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage + { + Name = "mud_saved", + GUID = "server" + })); + + } + + [MudRequest("usr_givecp")] + public static void GiveCodepoints(string guid, object contents) + { + var args = contents as Dictionary<string, object>; + if (args["username"] != null && args["amount"] != null) + { + string userName = args["username"] as string; + int cpAmount = (int)args["amount"]; + + if (Directory.Exists("saves")) + { + foreach (var saveFile in Directory.GetFiles("saves")) + { + var saveFileContents = JsonConvert.DeserializeObject<Save>(ReadEncFile(saveFile)); + if (saveFileContents.Username == userName) + { + saveFileContents.Codepoints += amount; + WriteEncFile(saveFile, JsonConvert.SerializeObject(saveFileContents, Formatting.Indented)); + Program.ClientDispatcher.Broadcast("update_your_cp", new + { + username = userName, + amount = cpAmount + }); + + return; + } + } + } + } + + } + [MudRequest("usr_takecp")] public static void TakeCodepoints(string guid, object contents) { |
