Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.37 KB | None | 0 0
  1. using System;
  2. using MySql.Data.MySqlClient;
  3. using System.Collections.Generic;
  4. using System.IO;
  5.  
  6. /*
  7. * Надо сделать показ статистики
  8. * Console.WriteLine("==========||========================================||);
  9. * Console.WriteLine("Statistics: Templates || Bad templates || table name||);
  10. * Console.WriteLine("==========||========================================||);
  11. * Templates = last array index
  12. * Bad templates = templates with error
  13. * */
  14. namespace MySqlTableCompare
  15. {
  16. public class fTable
  17. {
  18. public UInt32 ID;
  19. public UInt32[] KillCredit;
  20. public UInt32[] ModelID;
  21. public string IconName;
  22. public UInt32 Rank;
  23. public UInt32 Family;
  24. public UInt32 Type;
  25. public UInt32 TypeFlag;
  26. public UInt32 MovementID;
  27. public float HealthMod; //need convert to Float or double
  28. public float ManaMod; //need convert to Float or double
  29. public UInt32 RacialLider;
  30. public UInt32[] QuestItem;
  31.  
  32. public fTable()
  33. {
  34. KillCredit = new UInt32[2];
  35. ModelID = new UInt32[4];
  36. QuestItem = new UInt32[6];
  37. }
  38. };
  39.  
  40. public class sTable
  41. {
  42. public UInt32 ID;
  43. public UInt32[] KillCredit;
  44. public UInt32[] ModelID;
  45. public string IconName;
  46. public UInt32 Rank;
  47. public UInt32 Family;
  48. public UInt32 Type;
  49. public UInt32 TypeFlag;
  50. public UInt32 MovementID;
  51. public float HealthMod; //need convert to Float or double
  52. public float ManaMod; //need convert to Float or double
  53. public UInt32 RacialLider;
  54. public UInt32[] QuestItem;
  55.  
  56. public sTable()
  57. {
  58. KillCredit = new UInt32[2];
  59. ModelID = new UInt32[4];
  60. QuestItem = new UInt32[6];
  61. }
  62. };
  63.  
  64. public static class Program
  65. {
  66. const string connectionInfo = ("host=127.0.0.1;" + "port = '3306';" + "database='world';" + "UserName='root';" + "Password='mangos'");
  67. public static StreamWriter Log = new StreamWriter("sql_log.txt", true);
  68. public static MySqlCommand fcommand;
  69. public static MySqlCommand scommand;
  70. public static MySqlConnection connect = new MySqlConnection(connectionInfo);
  71.  
  72. public static List<fTable> fTables = new List<fTable>();
  73. public static List<sTable> sTables = new List<sTable>();
  74.  
  75. static void Main(string[] args)
  76. {
  77. Console.ForegroundColor = ConsoleColor.Yellow;
  78. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Programm is open!");
  79. ToLog("Programm is open!");
  80.  
  81. if (!TryCon())
  82. return;
  83.  
  84. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Choose variante:");
  85. Console.WriteLine("1 - Get creature_template structure and compare it");
  86. Console.WriteLine("2 - Get gameobject_template structure and compare it");
  87. Console.WriteLine("3 - Get item_template structure and compare it");
  88. Console.WriteLine("4 - Get locale_template structure and compare it");
  89. string variant = Console.ReadLine();
  90.  
  91. switch (variant)
  92. {
  93. case "1":
  94. Console.WriteLine("Get DB struct...");
  95. ToLog("Get DB struct...");
  96. CreatureTemplateStructur();
  97. Console.WriteLine("Done!");
  98. ToLog("Done");
  99. Console.WriteLine("Compare...");
  100. ToLog("Compare...");
  101. CompareCreatureTemplate();
  102. break;
  103. case "2":
  104. case "3":
  105. case "4":
  106. Console.WriteLine("Not finished yet!");
  107. ToLog("Not finished yet");
  108. break;
  109. }
  110. Console.Read();
  111. }
  112.  
  113. public static void ToLog(string text)
  114. {
  115. Log.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + text); Log.Flush();
  116. }
  117.  
  118. public static uint ToUInt32(this object val)
  119. {
  120. uint num;
  121. uint.TryParse(val.ToString(), out num);
  122. return num;
  123. }
  124.  
  125. public static float ToFloat(this object val)
  126. {
  127. float num;
  128. float.TryParse(val.ToString(), out num);
  129. return num;
  130. }
  131.  
  132. public static void CreatureTemplateStructur()
  133. {
  134. connect.Close();
  135. connect.Open();
  136.  
  137. string fSelect = "SELECT * FROM world.creature_template";
  138. string sSelect = "SELECT * FROM world.creature_template1";
  139. fcommand = new MySqlCommand(fSelect, connect);
  140. scommand = new MySqlCommand(sSelect, connect);
  141. fTables.Clear();
  142. sTables.Clear();
  143.  
  144. using (var fDBstructur = fcommand.ExecuteReader())
  145. {
  146. while(fDBstructur.Read())
  147. {
  148. fTable table1 = new fTable();
  149.  
  150. table1.ID = fDBstructur[0].ToUInt32();
  151. table1.KillCredit[0] = fDBstructur[4].ToUInt32(); //kill credit 1,2
  152. table1.KillCredit[1] = fDBstructur[5].ToUInt32();
  153. table1.ModelID[0] = fDBstructur[6].ToUInt32(); //modelid1 id 1-4
  154. table1.ModelID[1] = fDBstructur[7].ToUInt32();
  155. table1.ModelID[2] = fDBstructur[8].ToUInt32();
  156. table1.ModelID[3] = fDBstructur[9].ToUInt32();
  157. table1.IconName = fDBstructur[12].ToString();
  158. table1.Rank = fDBstructur[23].ToUInt32(); //rank
  159. table1.Family = fDBstructur[34].ToUInt32(); //family
  160. table1.Type = fDBstructur[42].ToUInt32(); //type
  161. table1.TypeFlag = fDBstructur[43].ToUInt32();//type flag
  162. table1.MovementID = fDBstructur[66].ToUInt32(); //movement id
  163. table1.HealthMod = fDBstructur[68].ToFloat(); //health mod
  164. table1.ManaMod = fDBstructur[69].ToFloat(); //power(mana) mod
  165. table1.RacialLider = fDBstructur[71].ToUInt32(); //racial leader
  166. table1.QuestItem[0] = fDBstructur[72].ToUInt32(); //quest item 1-6
  167. table1.QuestItem[1] = fDBstructur[73].ToUInt32();
  168. table1.QuestItem[2] = fDBstructur[74].ToUInt32();
  169. table1.QuestItem[3] = fDBstructur[75].ToUInt32();
  170. table1.QuestItem[4] = fDBstructur[76].ToUInt32();
  171. table1.QuestItem[5] = fDBstructur[77].ToUInt32();
  172.  
  173. fTables.Add(table1);
  174. }
  175. }
  176. using (var sDBstructur = scommand.ExecuteReader())
  177. {
  178. while(sDBstructur.Read())
  179. {
  180. sTable table2 = new sTable();
  181.  
  182. table2.ID = sDBstructur[0].ToUInt32();
  183. table2.KillCredit[0] = sDBstructur[4].ToUInt32(); //kill credit 1,2
  184. table2.KillCredit[1] = sDBstructur[5].ToUInt32();
  185. table2.ModelID[0] = sDBstructur[6].ToUInt32(); //modelid1 id 1-4
  186. table2.ModelID[1] = sDBstructur[7].ToUInt32();
  187. table2.ModelID[2] = sDBstructur[8].ToUInt32();
  188. table2.ModelID[3] = sDBstructur[9].ToUInt32();
  189. table2.IconName = sDBstructur[12].ToString();
  190. table2.Rank = sDBstructur[23].ToUInt32(); //rank
  191. table2.Family = sDBstructur[34].ToUInt32(); //family
  192. table2.Type = sDBstructur[42].ToUInt32(); //type
  193. table2.TypeFlag = sDBstructur[43].ToUInt32();//type flag
  194. table2.MovementID = sDBstructur[66].ToUInt32(); //movement id
  195. table2.HealthMod = sDBstructur[68].ToFloat(); //health mod
  196. table2.ManaMod = sDBstructur[69].ToFloat(); //power(mana) mod
  197. table2.RacialLider = sDBstructur[71].ToUInt32(); //racial leader
  198. table2.QuestItem[0] = sDBstructur[72].ToUInt32(); //quest item 1-6
  199. table2.QuestItem[1] = sDBstructur[73].ToUInt32();
  200. table2.QuestItem[2] = sDBstructur[74].ToUInt32();
  201. table2.QuestItem[3] = sDBstructur[75].ToUInt32();
  202. table2.QuestItem[4] = sDBstructur[76].ToUInt32();
  203. table2.QuestItem[5] = sDBstructur[77].ToUInt32();
  204.  
  205. sTables.Add(table2);
  206. }
  207. }
  208. }
  209.  
  210. public static void CompareCreatureTemplate()
  211. {
  212. int m = 0;
  213. int q = 0;
  214. string update = "update creature_template SET";
  215. for (int i = 0; i <= 30000; ++i)
  216. {
  217. if (i > 29000)
  218. {
  219. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Compare complete");
  220. ToLog("Compare complete");
  221. Console.Read();
  222. }
  223.  
  224. if (fTables[i].KillCredit[0] != sTables[i].KillCredit[0])
  225. Console.WriteLine("{0} KillCredit1 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[0], fTables[i].ID);
  226.  
  227. if (fTables[i].KillCredit[1] != sTables[i].KillCredit[1])
  228. Console.WriteLine("{0} KillCredit2 = {1} WHERE entry = {2};", update, sTables[i].KillCredit[1], fTables[i].ID);
  229.  
  230. //model ID
  231. for (m = 0; m < 3; ++m)
  232. {
  233. string ModelID = "modelid1";
  234. switch (m)
  235. {
  236. case 0: ModelID = "modelid1"; break;
  237. case 1: ModelID = "modelid2"; break;
  238. case 2: ModelID = "modelid3"; break;
  239. }
  240. if(fTables[i].ModelID[m] != sTables[i].ModelID[m])
  241. Console.WriteLine("{0} {1} = {2} WHERE entry = {3}", update,ModelID,sTables[i].ModelID[m], fTables[i].ID);
  242. }
  243. if (fTables[i].IconName != sTables[i].IconName)
  244. Console.WriteLine("{0} IconName = '{1}' WHERE entry = {2}", update, sTables[i].IconName, fTables[i].ID);
  245. if (fTables[i].Rank != sTables[i].Rank)
  246. Console.WriteLine("{0} rank = {1} WHERE entry = {2}", update, sTables[i].Rank, fTables[i].ID);
  247. if (fTables[i].Family != sTables[i].Family)
  248. Console.WriteLine("{0} family = {1} WHERE entry = {2}", update, sTables[i].Family, fTables[i].ID);
  249. if (fTables[i].Type != sTables[i].Type)
  250. Console.WriteLine("{0} type = {1} WHERE entry = {2}", update, sTables[i].Type, fTables[i].ID);
  251. if (fTables[i].TypeFlag != sTables[i].TypeFlag)
  252. Console.WriteLine("{0} type_flags = {1} WHERE entry = {2}", update, sTables[i].TypeFlag, fTables[i].ID);
  253. if (fTables[i].MovementID != sTables[i].MovementID)
  254. Console.WriteLine("{0} MovementID = {1} WHERE entry = {2}", update, sTables[i].MovementID, fTables[i].ID);
  255. if (fTables[i].HealthMod != sTables[i].HealthMod)
  256. Console.WriteLine("{0} Health_Mod = {1} WHERE entry = {2}", update, sTables[i].HealthMod, fTables[i].ID);
  257. if (fTables[i].ManaMod != sTables[i].ManaMod)
  258. Console.WriteLine("{0} Mana_Mod = {1} WHERE entry = {2}", update, sTables[i].ManaMod, fTables[i].ID);
  259. if (fTables[i].RacialLider != sTables[i].RacialLider)
  260. Console.WriteLine("{0} RacialLeader = {1} WHERE entry = {2}", update, sTables[i].RacialLider, fTables[i].ID);
  261.  
  262. for (q = 0; q < 6; q++)
  263. {
  264. string QuestItem = "questItem1";
  265. switch (q)
  266. {
  267. case 0: QuestItem = "questItem1"; break;
  268. case 1: QuestItem = "questItem2"; break;
  269. case 2: QuestItem = "questItem3"; break;
  270. case 3: QuestItem = "questItem4"; break;
  271. case 4: QuestItem = "questItem5"; break;
  272. case 5: QuestItem = "questItem6"; break;
  273. }
  274. if (fTables[i].QuestItem[q] != sTables[i].QuestItem[q])
  275. Console.WriteLine("{0} {1} = {2} WHERE entry = {3}", update, QuestItem, sTables[i].QuestItem[q], fTables[i].ID);
  276. }
  277. }
  278. }
  279.  
  280. public static bool TryCon()
  281. {
  282. try
  283. {
  284. MySqlConnection connect = new MySqlConnection(connectionInfo);
  285. connect.Open();
  286. connect.Close();
  287.  
  288. return true;
  289. }
  290. catch
  291. {
  292. Console.ForegroundColor = ConsoleColor.Red;
  293. Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss]") + "Check your MySQL server");
  294. ToLog("MySQL Server is not running");
  295.  
  296. return false;
  297. }
  298. }
  299. }
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement