diff --git a/MxWs/JSON/IndexGen.cs b/MxWs/JSON/IndexGen.cs index e03326f..ac28747 100644 --- a/MxWs/JSON/IndexGen.cs +++ b/MxWs/JSON/IndexGen.cs @@ -48,7 +48,7 @@ namespace MxWs.JSON int itemid = 0; foreach (var e in ind) { - RootObject j = JsonConvert.DeserializeObject(File.ReadAllText(string.Format("index_{0}.json",e))); + RootObject j = JsonConvert.DeserializeObject(File.ReadAllText(string.Format("json/index_{0}.json",e))); if(j.Misc.Count > 0) { foreach (var d in j.Misc) diff --git a/MxWs/JSON/SpecialGen.cs b/MxWs/JSON/SpecialGen.cs new file mode 100644 index 0000000..fdb9701 --- /dev/null +++ b/MxWs/JSON/SpecialGen.cs @@ -0,0 +1,92 @@ +using MySql.Data.MySqlClient; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MxWs.JSON +{ + public class Special + { + public List special { get; set; } + } + + public class SpecialObject + { + public List Data { get; set; } + } + + class SpecialGen + { + internal static void GenSpecial(string dumpid, string special) + { + string did = string.Format("dumpid='{0}'", dumpid); + StringBuilder sb = new StringBuilder("INSERT INTO ah_special_data (dumpid,itemid,specialid,value) VALUES "); + List Rows = new List(); + List ind = new List(); + + Special ji = JsonConvert.DeserializeObject(File.ReadAllText(special)); + + foreach (var i in ji.special) + { + ind.Add(i); + } + + string duid = Server.dumpID; + int sid = 1; + int itemid = 0; + foreach (var e in ind) + { + SpecialObject j = JsonConvert.DeserializeObject(File.ReadAllText(string.Format("json/special_{0}.json", e))); + + if (j.Data.Count > 0) + { + foreach (var d in j.Data) + { + itemid = Convert.ToInt32(d); + Rows.Add(string.Format("('{0}','{1}','{2}','{3}')", duid, itemid, sid, GetItemValue(itemid))); + } + } + sid = sid + 1; + } + sb.Append(string.Join(",", Rows)); + sb.Append(";"); + InsertIndex(sb.ToString()); + } + + public static int GetItemValue(int id) + { + string d = Server.dumpID; + //string d = "nB3qJHOVPH"; + int v = 0; + + string stm = string.Format("SELECT * FROM ah_items WHERE dumpid='{0}' AND itemid='{1}'", d, id); + MySqlConnection mc = Utilities.DB.ItemDB(); + MySqlCommand cmd = new MySqlCommand(stm, mc); + mc.Open(); + + MySqlDataReader result = cmd.ExecuteReader(); + + if (result.Read()) + { + v = Convert.ToInt32(result["minimum"]); + } + + mc.Close(); + return v; + } + + private static void InsertIndex(string cmd) + { + MySqlConnection mc = Utilities.DB.ItemDB(); + MySqlCommand command = mc.CreateCommand(); + command.CommandText = cmd; + mc.Open(); + command.ExecuteNonQuery(); + mc.Close(); + } + } +} diff --git a/MxWs/MxWs.csproj b/MxWs/MxWs.csproj index ecfa7b3..a1ad753 100644 --- a/MxWs/MxWs.csproj +++ b/MxWs/MxWs.csproj @@ -64,6 +64,7 @@ + diff --git a/MxWs/Server.cs b/MxWs/Server.cs index 43dfab0..4ebe864 100644 --- a/MxWs/Server.cs +++ b/MxWs/Server.cs @@ -19,10 +19,12 @@ namespace MxWs public static bool debug = false; public static bool serverLoop = true; public static bool indexBool = false; + public static bool specialBool = false; public static string st = "init"; public static string dumpID = ""; public static string indexString = ""; + public static string specialString = ""; // Settings Variables // Values are set by ReadSettings() during "init" state. @@ -62,6 +64,14 @@ namespace MxWs int ini = Array.IndexOf(args, "--index"); indexString = args[ini + 1]; + } + // Special Arg Logic + if (args.Contains("--special")) + { + specialBool = true; + int ini = Array.IndexOf(args, "--special"); + specialString = args[ini + 1]; + } // SkipDump Arg Logic if (args.Contains("--skipdump")) @@ -123,6 +133,18 @@ namespace MxWs case "gen_index": Utilities.MSG.CMW("Generating the index table...", true, 1); JSON.IndexGen.GenIndex(dumpID, indexString); + if (specialBool) + { + st = "gen_special"; + } + else + { + st = "clean"; + } + break; + case "gen_special": + Utilities.MSG.CMW("Generating the special table...", true, 1); + JSON.SpecialGen.GenSpecial(dumpID, specialString); st = "clean"; break; case "clean":