aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Server/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Server/Program.cs')
-rw-r--r--ShiftOS.Server/Program.cs384
1 files changed, 0 insertions, 384 deletions
diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs
index cb896cd..46d5ab3 100644
--- a/ShiftOS.Server/Program.cs
+++ b/ShiftOS.Server/Program.cs
@@ -328,390 +328,6 @@ namespace ShiftOS.Server
}
ClientDispatcher.DispatchTo("Error", msg.GUID, new MudRequestHandlerNotFoundException());
-
-
- switch (msg.Name)
- {
-
- case "get_memos_for_user":
- 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(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 "download_start":
- if (!msg.Contents.StartsWith("shiftnet/"))
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = (File.Exists("badrequest.md") == true) ? File.ReadAllText("badrequest.md") : @"# Bad request.
-
-You have sent a bad request to the multi-user domain. Please try again."
- }));
- return;
- }
-
- if (File.Exists(msg.Contents))
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("download", new ServerMessage
- {
- Name = "download_meta",
- GUID = "server",
- Contents = JsonConvert.SerializeObject(File.ReadAllBytes(msg.Contents))
- }));
- }
- else
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = (File.Exists("notfound.md") == true) ? File.ReadAllText("notfound.md") : @"# Not found.
-
-The page you requested at was not found on this multi-user domain."
- }));
-
- }
- break;
- case "shiftnet_get":
- string surl = args["url"] as string;
- while (surl.EndsWith("/"))
- {
- surl = surl.Remove(surl.Length - 1, 1);
- }
- if (!surl.StartsWith("shiftnet/"))
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = (File.Exists("badrequest.md") == true) ? File.ReadAllText("badrequest.md") : @"# Bad request.
-
-You have sent a bad request to the multi-user domain. Please try again."
- }));
-
- return;
- }
-
- if (File.Exists(surl))
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = File.ReadAllText(surl)
- }));
- }
- else if (File.Exists(surl + "/home.rnp"))
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = File.ReadAllText(surl + "/home.rnp")
- }));
-
- }
- else
- {
- server.DispatchTo(new Guid(msg.GUID), new NetObject("shiftnet_got", new ServerMessage
- {
- Name = "shiftnet_file",
- GUID = "server",
- Contents = (File.Exists("notfound.md") == true) ? File.ReadAllText("notfound.md") : @"# Not found.
-
-The page you requested at was not found on this multi-user domain."
- }));
-
- }
- break;
- 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 "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 usrname = msg.Contents;
- string guid = msg.GUID;
- server.DispatchAll(new NetObject("are_you_this_guy", new ServerMessage
- {
- Name = "getguid_fromserver",
- GUID = guid,
- Contents = usrname,
- }));
- 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;
- }
}
catch(Exception ex)
{