From c544e4081d53bcd888c8fce459c7e02f8516f5a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Feb 2017 18:32:48 -0500 Subject: Dramatic shop optimizations. --- ShiftOS.Server/Program.cs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'ShiftOS.Server') diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 9ac5702..bdcf10e 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -443,12 +443,46 @@ Contents: Contents = res.ToString() })); + break; + case "shop_getitems": + var shopName = args["shopname"] as string; + Shop tempShop = null; + foreach(var item in JsonConvert.DeserializeObject>(File.ReadAllText("shops.json"))) + { + if(item.Name == shopName) + { + tempShop = item; + } + } + + if(tempShop != null) + foreach(var item in tempShop.Items) + { + server.DispatchTo(new Guid(msg.GUID), new NetObject("item", new ServerMessage + { + Name = "shop_additem", + GUID = "server", + Contents = JsonConvert.SerializeObject(new + { + shop = shopName, + itemdata = item + }) + })); + } + break; case "shop_getall": List shops = new List(); if (File.Exists("shops.json")) shops = JsonConvert.DeserializeObject>(File.ReadAllText("shops.json")); - + //Purge all items in all shops temporarily. + //This is to save on network bandwidth as it will take a long time to send everyone's shops down if we don't purge the stock. + //And with high bandwidth usage, we may end up DOSing our clients when too many people upload too many things. + //Furthermore, this'll make the MUD Control Centre seem faster... + for (int i = 0; i <= shops.Count; i++) + { + shops[i].Items = new List(); + } server.DispatchTo(new Guid(msg.GUID), new NetObject("ladouceur", new ServerMessage { Name = "shop_all", -- cgit v1.2.3