Advertisement
Guest User

Untitled

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