aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-01-08 09:57:10 -0500
committerMichael <[email protected]>2017-01-08 09:57:10 -0500
commitf30dcf5ef41d54c588d7b42c48be8d941abba72e (patch)
tree7705f99b965673b1c034ac2b1c56e65072c827df /ShiftOS.Server
parent69dfad54724d4176dfce238a8d7e73970e6eef24 (diff)
downloadshiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.gz
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.tar.bz2
shiftos_thereturn-f30dcf5ef41d54c588d7b42c48be8d941abba72e.zip
Initial upload
Diffstat (limited to 'ShiftOS.Server')
-rw-r--r--ShiftOS.Server/App.config6
-rw-r--r--ShiftOS.Server/Program.cs964
-rw-r--r--ShiftOS.Server/Properties/AssemblyInfo.cs36
-rw-r--r--ShiftOS.Server/Properties/Resources.Designer.cs97
-rw-r--r--ShiftOS.Server/Properties/Resources.resx127
-rw-r--r--ShiftOS.Server/Resources/Home.txt31
-rw-r--r--ShiftOS.Server/Resources/NotFound.txt9
-rw-r--r--ShiftOS.Server/ShiftOS.Server.csproj108
-rw-r--r--ShiftOS.Server/WebAdmin.cs91
-rw-r--r--ShiftOS.Server/packages.config8
10 files changed, 1477 insertions, 0 deletions
diff --git a/ShiftOS.Server/App.config b/ShiftOS.Server/App.config
new file mode 100644
index 0000000..88fa402
--- /dev/null
+++ b/ShiftOS.Server/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
+ </startup>
+</configuration> \ No newline at end of file
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs
new file mode 100644
index 0000000..768ed08
--- /dev/null
+++ b/ShiftOS.Server/Program.cs
@@ -0,0 +1,964 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ShiftOS.Objects;
+using NetSockets;
+using System.IO;
+using Newtonsoft.Json;
+using System.Net;
+using System.Net.Sockets;
+using Nancy.Hosting.Self;
+using Nancy;
+using Nancy.Authentication.Basic;
+using Nancy.Security;
+using Nancy.TinyIoc;
+using Nancy.Bootstrapper;
+
+namespace ShiftOS.Server
+{
+ public interface IUserMapper
+ {
+ /// <summary>
+ /// Get the real username from an identifier
+ /// </summary>
+ /// <param name="identifier">User identifier</param>
+ /// <param name="context">The current NancyFx context</param>
+ /// <returns>Matching populated IUserIdentity object, or empty</returns>
+ IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context);
+ }
+
+ public class MUDUserValidator : IUserValidator
+ {
+ public IUserIdentity Validate(string username, string password)
+ {
+ if(username == Program.AdminUsername && password == Program.AdminPassword)
+ {
+ return null;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ public class MUDUserIdentity : IUserIdentity
+ {
+ public IEnumerable<string> Claims
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ public string UserName
+ {
+ get
+ {
+ return uname;
+ }
+ }
+
+ public string uname = "";
+
+ public MUDUserIdentity(string username)
+ {
+ uname = username;
+ }
+ }
+
+ public class AuthenticationBootstrapper : DefaultNancyBootstrapper
+ {
+ protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
+ {
+ base.ApplicationStartup(container, pipelines);
+
+ pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
+ container.Resolve<MUDUserValidator>(),
+ "MUD", UserPromptBehaviour.NonAjax));
+ }
+ }
+
+ public class Program
+ {
+ public static string AdminUsername = "admin";
+ public static string AdminPassword = "admin";
+
+
+
+ public static NetObjectServer server;
+
+ public delegate void StringEventHandler(string str);
+
+ public static event StringEventHandler ServerStarted;
+
+ public static void SaveChats()
+ {
+ List<Channel> saved = new List<Channel>();
+ foreach(var chat in chats)
+ {
+ saved.Add(new Channel
+ {
+ ID = chat.ID,
+ Name = chat.Name,
+ MaxUsers = chat.MaxUsers,
+ Topic = chat.Topic,
+ Users = new List<Save>()
+ });
+ }
+ File.WriteAllText("chats.json", JsonConvert.SerializeObject(saved));
+ }
+
+ public static void LoadChats()
+ {
+ chats = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Channel>>(File.ReadAllText("chats.json"));
+ }
+
+ public static void Main(string[] args)
+ {
+ if (!Directory.Exists("saves"))
+ {
+ Directory.CreateDirectory("saves");
+ }
+
+ if(!File.Exists("chats.json"))
+ {
+ SaveChats();
+ }
+ else
+ {
+ LoadChats();
+ }
+
+ if(!Directory.Exists("scripts"))
+ {
+ Console.WriteLine("Creating scripts directory...");
+ Directory.CreateDirectory("scripts");
+ Console.WriteLine("NOTE: This MUD is not just gonna generate scripts for you. You're going to need to write them. YOU are DevX.");
+ }
+
+ Console.WriteLine("Starting server...");
+ server = new NetObjectServer();
+
+ server.OnStarted += (o, a) =>
+ {
+ Console.WriteLine($"Server started on address {server.Address}, port {server.Port}.");
+ ServerStarted?.Invoke(server.Address.MapToIPv4().ToString());
+ };
+
+ server.OnStopped += (o, a) =>
+ {
+ Console.WriteLine("WARNING! Server stopped.");
+ };
+
+ server.OnError += (o, a) =>
+ {
+ Console.WriteLine("ERROR: " + a.Exception.Message);
+ };
+
+ server.OnClientAccepted += (o, a) =>
+ {
+ Console.WriteLine("Client connected.");
+ server.DispatchTo(a.Guid, new NetObject("welcome", new ServerMessage { Name = "Welcome", Contents = a.Guid.ToString(), GUID = "Server" }));
+ };
+
+ server.OnReceived += (o, a) =>
+ {
+ var obj = a.Data.Object;
+
+ var msg = obj as ServerMessage;
+
+ if(msg != null)
+ {
+ Interpret(msg);
+ }
+ };
+
+ IPAddress defaultAddress = null;
+
+ var host = Dns.GetHostEntry(Dns.GetHostName());
+ foreach (var ip in host.AddressList)
+ {
+ if (ip.AddressFamily == AddressFamily.InterNetwork)
+ {
+ defaultAddress = ip;
+ }
+ }
+
+ try
+ {
+ server.Start(defaultAddress, 13370);
+ }
+ catch
+ {
+ Console.WriteLine("So we tried to bind the server to your IP address automatically, but your operating system or the .NET environment you are in (possibly Mono on Linux) is preventing us from doing so. We'll try to bind to the loopback IP address (127.0.0.1) and if that doesn't work, the multi-user domain software may not be compatible with this OS or .NET environment.");
+ server.Stop();
+ server.Start(IPAddress.Loopback, 13370);
+
+ }
+
+ var hConf = new HostConfiguration();
+ hConf.UrlReservations.CreateAutomatically = true;
+
+ var nancy = new NancyHost(hConf, new Uri("http://localhost:13371/"));
+
+ server.OnStopped += (o, a) =>
+ {
+ nancy.Stop();
+ };
+
+ nancy.Start();
+ }
+
+ public static bool UserInChat(Channel chan, Save user)
+ {
+ foreach(var usr in chan.Users)
+ {
+ if(usr.Username == user.Username)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+ public static void Interpret(ServerMessage msg)
+ {
+ Dictionary<string, object> args = null;
+
+ try
+ {
+ Console.WriteLine($@"Message received from {msg.GUID}: {msg.Name}
+
+Contents:
+{msg.Contents}");
+
+ if (!string.IsNullOrWhiteSpace(msg.Contents))
+ {
+ try
+ {
+ //It's gotta be JSON.
+ if (msg.Contents.StartsWith("{"))
+ {
+ args = JsonConvert.DeserializeObject<Dictionary<string, object>>(msg.Contents);
+ }
+ }
+ catch
+ {
+ //Damnit, we were wrong.
+ args = null;
+ }
+ }
+
+ switch (msg.Name)
+ {
+ case "mud_login":
+ if (args["username"] != null && args["password"] != null)
+ {
+ foreach(var savefile in Directory.GetFiles("saves"))
+ {
+ try
+ {
+ var save = JsonConvert.DeserializeObject<Save>(File.ReadAllText(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_savefile",
+ GUID = "server",
+ Contents = File.ReadAllText(savefile)
+ }));
+ return;
+ }
+ }
+ catch { }
+ }
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage
+ {
+ Name = "mud_login_denied",
+ GUID = "server"
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage
+ {
+ Name = "mud_login_denied",
+ GUID = "server"
+ }));
+ }
+ break;
+ case "legion_create":
+ List<Legion> legions = new List<Legion>();
+ if (File.Exists("legions.json"))
+ legions = JsonConvert.DeserializeObject<List<Legion>>(File.ReadAllText("legions.json"));
+
+ var l = JsonConvert.DeserializeObject<Legion>(msg.Contents);
+
+ legions.Add(l);
+
+ File.WriteAllText("legions.json", JsonConvert.SerializeObject(legions, Formatting.Indented));
+ break;
+ case "legion_get_all":
+ List<Legion> allLegions = new List<Legion>();
+
+ if (File.Exists("legions.json"))
+ allLegions = JsonConvert.DeserializeObject<List<Legion>>(File.ReadAllText("legions.json"));
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("alllegions", new ServerMessage
+ {
+ Name = "legion_all",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(allLegions)
+ }));
+ break;
+ case "legion_get_users":
+ var lgn = JsonConvert.DeserializeObject<Legion>(msg.Contents);
+
+ List<string> userIDs = new List<string>();
+
+ foreach (var savfile in Directory.GetFiles("saves"))
+ {
+ try
+ {
+ var savefilecontents = JsonConvert.DeserializeObject<Save>(File.ReadAllText(savfile));
+ if (savefilecontents.CurrentLegions.Contains(lgn.ShortName))
+ {
+ userIDs.Add($"{savefilecontents.Username}@{savefilecontents.SystemName}");
+ }
+ }
+ catch { }
+ }
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("userlist", new ServerMessage
+ {
+ Name = "legion_users_found",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(userIDs)
+ }));
+ break;
+ case "user_get_legion":
+ var userSave = JsonConvert.DeserializeObject<Save>(msg.Contents);
+
+ if (File.Exists("legions.json"))
+ {
+ var legionList = JsonConvert.DeserializeObject<List<Legion>>(File.ReadAllText("legions.json"));
+ foreach (var legion in legionList)
+ {
+ if (userSave.CurrentLegions.Contains(legion.ShortName))
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("reply", new ServerMessage
+ {
+ Name = "user_legion",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(legion)
+ }));
+ return;
+ }
+ }
+ }
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("fuck", new ServerMessage
+ {
+ Name = "user_not_found_in_legion",
+ GUID = "server"
+ }));
+
+ break;
+ case "mud_save":
+ var sav = JsonConvert.DeserializeObject<Save>(msg.Contents);
+ File.WriteAllText("saves/" + sav.Username + ".save", JsonConvert.SerializeObject(sav, Formatting.Indented));
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("auth_failed", new ServerMessage
+ {
+ Name = "mud_saved",
+ GUID = "server"
+ }));
+
+ break;
+ case "mud_checkuserexists":
+ if (args["username"] != null && args["password"] != null)
+ {
+ foreach (var savefile in Directory.GetFiles("saves"))
+ {
+ try
+ {
+ var save = JsonConvert.DeserializeObject<Save>(File.ReadAllText(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"
+ }));
+ }
+ break;
+ break;
+ case "pong_gethighscores":
+ if (File.Exists("pong_highscores.json"))
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("pongstuff", new ServerMessage
+ {
+ Name = "pong_highscores",
+ GUID = "server",
+ Contents = File.ReadAllText("pong_highscores.json")
+ }));
+ }
+ break;
+ case "get_memos_for_user":
+ if(args["username"] != null)
+ {
+ string usrname = 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 == usrname)
+ {
+ mmos.Add(mmo);
+ }
+ }
+ }
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mud_memos", new ServerMessage
+ {
+ Name = "mud_usermemos",
+ GUID = "server",
+ Contents = JsonConvert.SerializeObject(mmos)
+ }));
+ }
+ break;
+ case "mud_post_memo":
+ MUDMemo memo = JsonConvert.DeserializeObject<MUDMemo>(msg.Contents);
+ 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));
+
+
+ break;
+ case "pong_sethighscore":
+ var hs = new List<PongHighscore>();
+ if (File.Exists("pong_highscores.json"))
+ hs = JsonConvert.DeserializeObject<List<PongHighscore>>(File.ReadAllText("ponghighscores.json"));
+
+ var newHS = JsonConvert.DeserializeObject<PongHighscore>(msg.Contents);
+ for (int i = 0; i <= hs.Count; i++)
+ {
+ try
+ {
+ if (hs[i].UserName == newHS.UserName)
+ {
+ if (newHS.HighestLevel > hs[i].HighestLevel)
+ hs[i].HighestLevel = newHS.HighestLevel;
+ if (newHS.HighestCodepoints > hs[i].HighestCodepoints)
+ hs[i].HighestCodepoints = newHS.HighestCodepoints;
+ File.WriteAllText("pong_highscores.json", JsonConvert.SerializeObject(hs));
+ return;
+
+ }
+ }
+ catch
+ {
+
+ }
+ }
+ hs.Add(newHS);
+ File.WriteAllText("pong_highscores.json", JsonConvert.SerializeObject(hs));
+ return;
+ case "getvirusdb":
+ if (!File.Exists("virus.db"))
+ File.WriteAllText("virus.db", "{}");
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("vdb", new ServerMessage
+ {
+ Name = "virusdb",
+ GUID = "server",
+ Contents = File.ReadAllText("virus.db")
+ }));
+ break;
+ case "getvirus":
+ Dictionary<string, string> virusDB = new Dictionary<string, string>();
+
+ if (File.Exists("virus.db"))
+ virusDB = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("virus.db"));
+
+ foreach (var kv in virusDB)
+ {
+ if (kv.Key == msg.Contents)
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("response", new ServerMessage
+ {
+ Name = "mud_virus",
+ GUID = "server",
+ Contents = kv.Value,
+ }));
+ return;
+ }
+ }
+
+
+ break;
+ case "mud_scanvirus":
+ Dictionary<string, string> _virusDB = new Dictionary<string, string>();
+
+ bool addIfNotFound = true;
+
+ if (msg.Contents.Contains("||scanonly"))
+ addIfNotFound = false;
+
+ msg.Contents = msg.Contents.Replace("||scanonly", "");
+
+ if(File.Exists("virus.db"))
+ _virusDB = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText("virus.db"));
+
+ foreach(var kv in _virusDB)
+ {
+ if(kv.Value == msg.Contents)
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("response", new ServerMessage
+ {
+ Name = "mud_virus_signature",
+ GUID = "server",
+ Contents = kv.Key,
+ }));
+ return;
+ }
+ }
+
+ if (addIfNotFound == true)
+ {
+ string newguid = Guid.NewGuid().ToString();
+ _virusDB.Add(newguid, msg.Contents);
+ File.WriteAllText("virus.db", JsonConvert.SerializeObject(_virusDB, Formatting.Indented));
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("response", new ServerMessage
+ {
+ Name = "mud_virus_signature",
+ GUID = "server",
+ Contents = newguid,
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("response", new ServerMessage
+ {
+ Name = "mud_virus_signature",
+ GUID = "server",
+ Contents = "unknown",
+ }));
+ }
+ return;
+
+ case "chat_join":
+ if (args.ContainsKey("id"))
+ {
+ var cuser = new Save();
+ if (args.ContainsKey("user"))
+ {
+ cuser = JsonConvert.DeserializeObject<Save>(JsonConvert.SerializeObject(args["user"]));
+
+
+ }
+ int index = -1;
+ string chat_id = args["id"] as string;
+ foreach(var chat in chats)
+ {
+ if(chat.ID == chat_id)
+ {
+ if(chat.Users.Count < chat.MaxUsers || chat.MaxUsers == 0)
+ {
+ //user can join chat.
+ if(cuser != null)
+ {
+ index = chats.IndexOf(chat);
+ }
+ }
+ }
+ }
+ if(index > -1)
+ {
+ chats[index].Users.Add(cuser);
+ server.DispatchAll(new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chat_id}: {cuser.Username} {{CHAT_HAS_JOINED}}"
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chat_id}: {{CHAT_NOT_FOUND_OR_TOO_MANY_MEMBERS}}"
+ }));
+ }
+ }
+ break;
+ case "chat":
+ if (args.ContainsKey("id"))
+ {
+ var cuser = new Save();
+ if (args.ContainsKey("user"))
+ {
+ cuser = JsonConvert.DeserializeObject<Save>(JsonConvert.SerializeObject(args["user"]));
+
+
+ }
+ string message = "";
+ if (args.ContainsKey("msg"))
+ message = args["msg"] as string;
+
+ int index = -1;
+ string chat_id = args["id"] as string;
+ foreach (var chat in chats)
+ {
+ if (chat.ID == chat_id)
+ {
+ if (cuser != null && !string.IsNullOrWhiteSpace(message) && UserInChat(chat, cuser))
+ {
+ index = chats.IndexOf(chat);
+ }
+ }
+ }
+ if (index > -1)
+ {
+ server.DispatchAll(new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chat_id}/{cuser.Username}: {message}"
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chats[index].ID}: {{CHAT_NOT_FOUND_OR_NOT_IN_CHAT}}"
+ }));
+ }
+ }
+
+ break;
+ case "chat_leave":
+ if (args.ContainsKey("id"))
+ {
+ var cuser = new Save();
+ if (args.ContainsKey("user"))
+ {
+ cuser = JsonConvert.DeserializeObject<Save>(JsonConvert.SerializeObject(args["user"]));
+
+
+ }
+ int index = -1;
+ string chat_id = args["id"] as string;
+ foreach (var chat in chats)
+ {
+ if (chat.ID == chat_id)
+ {
+ if (cuser != null && UserInChat(chat, cuser))
+ {
+ index = chats.IndexOf(chat);
+ }
+ }
+ }
+ if (index > -1)
+ {
+ server.DispatchAll(new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chats[index].ID}: {cuser.Username} {{HAS_LEFT_CHAT}}"
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{chat_id}: {{CHAT_NOT_FOUND_OR_NOT_IN_CHAT}}"
+ }));
+ }
+ }
+ break;
+ case "chat_create":
+ string id = "";
+ string topic = "";
+ string name = "";
+ int max_users = 0;
+
+ if (args.ContainsKey("id"))
+ id = args["id"] as string;
+ if (args.ContainsKey("topic"))
+ name = args["topic"] as string;
+ if (args.ContainsKey("name"))
+ topic = args["name"] as string;
+ if (args.ContainsKey("max_users"))
+ max_users = Convert.ToInt32(args["max_users"].ToString());
+
+ bool id_taken = false;
+
+ foreach(var chat in chats)
+ {
+ if (chat.ID == id)
+ id_taken = true;
+ }
+
+ if (id_taken == false)
+ {
+ chats.Add(new Channel
+ {
+ ID = id,
+ Name = name,
+ Topic = topic,
+ MaxUsers = max_users,
+ Users = new List<Save>()
+ });
+ SaveChats();
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{id}: {{SUCCESSFULLY_CREATED_CHAT}}"
+ }));
+ }
+ else
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("broadcast", new ServerMessage
+ {
+ Name = "cbroadcast",
+ GUID = "server",
+ Contents = $"{id}: {{ID_TAKEN}}"
+ }));
+ }
+
+ break;
+ case "broadcast":
+ string text = msg.Contents;
+ if (!string.IsNullOrWhiteSpace(text))
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("runme", new ServerMessage
+ {
+ Name = "broadcast",
+ GUID = "Server",
+ Contents = text
+
+ }));
+ }
+ break;
+ case "lua_up":
+ string lua = msg.Contents;
+ string firstLine = lua.Split(new[] { Environment.NewLine }, StringSplitOptions.None)[0];
+ firstLine = firstLine.Remove(0, 3); //delete the comment
+ string[] a = firstLine.Split('.');
+ if(!Directory.Exists("scripts/" + a[0]))
+ {
+ Directory.CreateDirectory($"scripts/{a[0]}");
+ }
+ File.WriteAllText($"scripts/{a[0]}/{a[1]}.lua", lua);
+ break;
+ case "mudhack_init":
+ if (MUDHackPasswords.ContainsKey(msg.GUID))
+ MUDHackPasswords.Remove(msg.GUID);
+
+ MUDHackPasswords.Add(msg.GUID, GenerateRandomPassword());
+
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mudhack_init", new ServerMessage
+ {
+ Name = "mudhack_init",
+ GUID = "SERVER",
+ Contents = MUDHackPasswords[msg.GUID],
+ }));
+
+ break;
+ case "mudhack_verify":
+ if (!MUDHackPasswords.ContainsKey(msg.GUID))
+ {
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mudhack_init", new ServerMessage
+ {
+ Name = "server_error",
+ GUID = "SERVER",
+ Contents = "{SRV_HACK_NOT_INITIATED}",
+ }));
+ return;
+ }
+
+ string pass = "";
+ if (args.ContainsKey("pass"))
+ pass = args["pass"] as string;
+
+ if(pass == MUDHackPasswords[msg.GUID])
+ {
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mudhack_init", new ServerMessage
+ {
+ Name = "mudhack_granted",
+ GUID = "SERVER",
+ }));
+
+ }
+ else
+ {
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mudhack_init", new ServerMessage
+ {
+ Name = "mudhack_denied",
+ GUID = "SERVER",
+ }));
+ }
+ break;
+ case "mudhack_killpass":
+ if (MUDHackPasswords.ContainsKey(msg.GUID))
+ MUDHackPasswords.Remove(msg.GUID);
+ break;
+ case "mudhack_getallusers":
+ List<OnlineUser> users = new List<OnlineUser>();
+
+ foreach (var chat in chats)
+ {
+ foreach(var usr in chat.Users)
+ {
+ var ousr = new OnlineUser();
+ ousr.Username = usr.Username;
+ ousr.OnlineChat = chat.ID;
+ users.Add(ousr);
+ }
+ }
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("mudhack_users", new ServerMessage
+ {
+ Name = "mudhack_users",
+ GUID = "SERVER",
+ Contents = JsonConvert.SerializeObject(users),
+ }));
+ break;
+ case "getguid_reply":
+ msg.GUID = "server";
+ //The message's GUID was manipulated by the client to send to another client.
+ //So we can just bounce back the message to the other client.
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("bounce", msg));
+ break;
+ case "getguid_send":
+ string username = msg.Contents;
+ string guid = msg.GUID;
+ server.DispatchAll(new NetObject("are_you_this_guy", new ServerMessage
+ {
+ Name = "getguid_fromserver",
+ GUID = guid,
+ Contents = username,
+ }));
+ break;
+ case "script":
+ string user = "";
+ string script = "";
+ string sArgs = "";
+
+ if (!args.ContainsKey("user"))
+ throw new Exception("No 'user' arg specified in message to server");
+
+ if (!args.ContainsKey("script"))
+ throw new Exception("No 'script' arg specified in message to server");
+
+ if (!args.ContainsKey("args"))
+ throw new Exception("No 'args' arg specified in message to server");
+
+ user = args["user"] as string;
+ script = args["script"] as string;
+ sArgs = args["args"] as string;
+
+ if(File.Exists($"scripts/{user}/{script}.lua"))
+ {
+ var script_arguments = JsonConvert.DeserializeObject<Dictionary<string, object>>(sArgs);
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("runme", new ServerMessage {
+ Name="run",
+ GUID="Server",
+ Contents = $@"{{
+ script:""{File.ReadAllText($"scripts/{user}/{script}.lua").Replace("\"", "\\\"")}"",
+ args:""{sArgs}""
+}}"
+ }));
+ }
+ else
+ {
+ throw new Exception($"{user}.{script}: Script not found.");
+ }
+ break;
+ default:
+ throw new Exception($"Server couldn't decipher this message:\n\n{JsonConvert.SerializeObject(msg)}");
+ }
+ }
+ catch(Exception ex)
+ {
+ Console.WriteLine("An error occurred with that one.");
+ Console.WriteLine(ex);
+
+ server.DispatchTo(new Guid(msg.GUID), new NetObject("error", new ServerMessage { Name = "Error", GUID = "Server", Contents = JsonConvert.SerializeObject(ex) }));
+ }
+ }
+
+ public static string GenerateRandomPassword()
+ {
+ return Guid.NewGuid().ToString();
+ }
+
+ public static Dictionary<string, string> MUDHackPasswords = new Dictionary<string, string>();
+
+ public static void Stop()
+ {
+ try
+ {
+ if (server.IsOnline)
+ {
+ try
+ {
+ server.Stop();
+ }
+ catch
+ {
+
+ }
+ }
+ server = null;
+ }
+ catch { }
+ }
+
+ public static List<Channel> chats = new List<Channel>();
+ }
+}
diff --git a/ShiftOS.Server/Properties/AssemblyInfo.cs b/ShiftOS.Server/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..631aa86
--- /dev/null
+++ b/ShiftOS.Server/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ShiftOS.Server")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ShiftOS.Server")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("226c63b4-e60d-4949-b4e7-7a2ddbb96776")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/ShiftOS.Server/Properties/Resources.Designer.cs b/ShiftOS.Server/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..4ceddac
--- /dev/null
+++ b/ShiftOS.Server/Properties/Resources.Designer.cs
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace ShiftOS.Server.Properties {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShiftOS.Server.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to &lt;html&gt;
+ /// &lt;head&gt;
+ /// &lt;title&gt;ShiftOS Multi-User Domain &amp;bull; Admin Panel&lt;/title&gt;
+ /// &lt;/head&gt;
+ /// &lt;body&gt;
+ /// &lt;h1&gt;Welcome.&lt;/h1&gt;
+ /// &lt;p&gt;There&apos;s nothing here, but hey, it works!&lt;/p&gt;
+ /// &lt;/body&gt;
+ ///&lt;/html&gt;.
+ /// </summary>
+ internal static string Home {
+ get {
+ return ResourceManager.GetString("Home", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to &lt;html&gt;
+ /// &lt;head&gt;
+ /// &lt;title&gt;Multi-User Domain &amp;bull; Administration Panel - Page not found.&lt;/title&gt;
+ /// &lt;/head&gt;
+ /// &lt;body&gt;
+ /// &lt;h1&gt;This page wasn&apos;t found.&lt;/h1&gt;
+ /// &lt;p&gt;We couldn&apos;t find this page...&lt;/p&gt;
+ /// &lt;/body&gt;
+ ///&lt;/html&gt;.
+ /// </summary>
+ internal static string NotFound {
+ get {
+ return ResourceManager.GetString("NotFound", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/ShiftOS.Server/Properties/Resources.resx b/ShiftOS.Server/Properties/Resources.resx
new file mode 100644
index 0000000..cd10c06
--- /dev/null
+++ b/ShiftOS.Server/Properties/Resources.resx
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <data name="Home" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\Home.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+ <data name="NotFound" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\NotFound.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
+ </data>
+</root> \ No newline at end of file
diff --git a/ShiftOS.Server/Resources/Home.txt b/ShiftOS.Server/Resources/Home.txt
new file mode 100644
index 0000000..41c8995
--- /dev/null
+++ b/ShiftOS.Server/Resources/Home.txt
@@ -0,0 +1,31 @@
+<html>
+ <head>
+ <title>ShiftOS Multi-User Domain &bull; Admin Panel</title>
+
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
+
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
+
+ </head>
+ <body>
+ <nav class="navbar navbar-inverse navbar-fixed-top">
+ <div class="container">
+ <a class="navbar-brand" href="/">MUD Admin Panel</a>
+
+ <ul class="nav navbar-nav">
+ <li><a href="/chats">Chat manager</a></li>
+ <li><a href="/status" class="active">System status</a></li>
+ </ul>
+ </div>
+ </nav>
+
+ <div class="container">
+
+ {BODY}
+
+ <footer>
+ <p>MUD server on {IP_ADDR}:{PORT}</p>
+ </footer>
+ </div>
+ </body>
+</html> \ No newline at end of file
diff --git a/ShiftOS.Server/Resources/NotFound.txt b/ShiftOS.Server/Resources/NotFound.txt
new file mode 100644
index 0000000..cd65829
--- /dev/null
+++ b/ShiftOS.Server/Resources/NotFound.txt
@@ -0,0 +1,9 @@
+<html>
+ <head>
+ <title>Multi-User Domain &bull; Administration Panel - Page not found.</title>
+ </head>
+ <body>
+ <h1>This page wasn't found.</h1>
+ <p>We couldn't find this page...</p>
+ </body>
+</html> \ No newline at end of file
diff --git a/ShiftOS.Server/ShiftOS.Server.csproj b/ShiftOS.Server/ShiftOS.Server.csproj
new file mode 100644
index 0000000..8db678e
--- /dev/null
+++ b/ShiftOS.Server/ShiftOS.Server.csproj
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{226C63B4-E60D-4949-B4E7-7A2DDBB96776}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ShiftOS.Server</RootNamespace>
+ <AssemblyName>ShiftOS.Server</AssemblyName>
+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="DynamicLua, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\DynamicLua.1.1.2.0\lib\net40-Client\DynamicLua.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Nancy, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Nancy.1.4.1\lib\net40\Nancy.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Nancy.Authentication.Basic, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Nancy.Authentication.Basic.1.4.1\lib\net40\Nancy.Authentication.Basic.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="Nancy.Hosting.Self, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="NetSockets">
+ <HintPath>..\Libraries\NetSockets.dll</HintPath>
+ </Reference>
+ <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="WebAdmin.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ShiftOS.Objects\ShiftOS.Objects.csproj">
+ <Project>{a069089a-8962-4607-b2b2-4cf4a371066e}</Project>
+ <Name>ShiftOS.Objects</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\NotFound.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\Home.txt" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/ShiftOS.Server/WebAdmin.cs b/ShiftOS.Server/WebAdmin.cs
new file mode 100644
index 0000000..cf21181
--- /dev/null
+++ b/ShiftOS.Server/WebAdmin.cs
@@ -0,0 +1,91 @@
+using Nancy;
+using Nancy.Security;
+using NetSockets;
+using Newtonsoft.Json;
+using ShiftOS.Objects;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Server
+{
+ public class WebAdmin : NancyModule
+ {
+ private Guid thisGuid { get; set; }
+
+ public WebAdmin()
+ {
+ this.RequiresAuthentication();
+
+
+ client = new NetObjectClient();
+
+ client.OnReceived += (o, a) =>
+ {
+ var msg = a.Data.Object as ServerMessage;
+ if (msg.Name == "Welcome")
+ {
+ thisGuid = new Guid(msg.Contents);
+ }
+ };
+
+ client.Connect(Program.server.Address.MapToIPv4().ToString(), 13370);
+
+ string template = Properties.Resources.Home;
+
+ Get["/"] = _ => { return GetPage(template, "index.html"); };
+ Get["/{page}"] = parameters =>
+ {
+ return GetPage(template, parameters.page);
+ };
+ }
+
+ public NetObjectClient client = new NetObjectClient();
+
+ public string GetPage(string template, string page)
+ {
+ string pageContents = File.ReadAllText("adm/" + page);
+
+ string page_text = template.Replace("{BODY}", pageContents);
+
+ page_text = page_text.Replace("{IP_ADDR}", client.RemoteHost.ToString());
+ page_text = page_text.Replace("{PORT}", client.RemotePort.ToString());
+
+ return page_text;
+ }
+
+ public string GrabResource(string page)
+ {
+ var type = this.GetType();
+ foreach(var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ foreach(var attr in property.GetCustomAttributes(false))
+ {
+ if(attr is PageAttribute)
+ {
+ if(page == (attr as PageAttribute).Name)
+ {
+ return property.GetGetMethod().Invoke(this, null) as string;
+ }
+ }
+ }
+ }
+
+ return Properties.Resources.NotFound;
+ }
+ }
+
+ public class PageAttribute :Attribute
+ {
+ public PageAttribute(string name)
+ {
+ Name = name;
+ }
+
+ public string Name { get; set; }
+ }
+}
diff --git a/ShiftOS.Server/packages.config b/ShiftOS.Server/packages.config
new file mode 100644
index 0000000..3e07118
--- /dev/null
+++ b/ShiftOS.Server/packages.config
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="DynamicLua" version="1.1.2.0" targetFramework="net452" />
+ <package id="Nancy" version="1.4.1" targetFramework="net452" />
+ <package id="Nancy.Authentication.Basic" version="1.4.1" targetFramework="net452" />
+ <package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net452" />
+ <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
+</packages> \ No newline at end of file