Advertisement
Guest User

Untitled

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