Advertisement
botters

Untitled

Sep 10th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.52 KB | None | 0 0
  1. // ☺ Created by MyThs
  2. // ☺ Copyright © 2010 - 2016 TQ Digital
  3. // ☺ MyThs - Project
  4.  
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using COServer.Game;
  10. using COServer.Network;
  11. using COServer.Database;
  12. using System.Windows.Forms;
  13. using COServer.Network.Sockets;
  14. using System.Collections.Generic;
  15. using COServer.Network.AuthPackets;
  16. using MsgServer.Network.GamePackets.Union;
  17. using COServer.Network.GamePackets;
  18. using System.Runtime.InteropServices;
  19. using COserver;
  20.  
  21. namespace COServer
  22. {
  23. public unsafe class Server
  24. {
  25. public static MemoryCompressor MCompressor = new MemoryCompressor();
  26. public static int CpuUse = 0;
  27. public static bool CpuUsageTimer = true;
  28. public static bool Ready = false;
  29. public static int MaxOn = 0;
  30. public static void UpdateConsoleTitle()
  31. {
  32. if (Kernel.GamePool.Count > Server.MaxOn)
  33. Server.MaxOn = Kernel.GamePool.Count;
  34. if (Kernel.GamePool.Count != 0)
  35. {
  36. Console.Title = "MyThs-Co[Hard] Online Players: [ " + Kernel.GamePool.Count + " ] Max Online: [ " + Server.MaxOn + " ]MyThs";
  37. }
  38. else if (Kernel.GamePool.Count == 0)
  39. {
  40. Console.Title = "MyThs-Co[Hard] No Online Players Now!! But Max Online: [ " + Server.MaxOn + " ]<<<";
  41. }
  42. }
  43. #region Poker
  44. public static void easteregg(string text)
  45. {
  46. try
  47. {
  48. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  49. Path = "gmlogs\\PetApet\\",
  50. NewPath = System.IO.Path.Combine(Path, folderN);
  51. if (!File.Exists(NewPath + folderN))
  52. {
  53. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  54. }
  55. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  56. {
  57. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  58. {
  59. fs.Close();
  60. }
  61. }
  62. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  63. {
  64. file.WriteLine(text);
  65. file.Close();
  66. }
  67. }
  68.  
  69. catch (Exception ex) { Console.WriteLine(ex); }
  70. }
  71. public static void AddpokerAllinCps(string text)
  72. {
  73. try
  74. {
  75. text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
  76. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  77. Path = "gmlogs\\AddpokerAllinCps\\",
  78. NewPath = System.IO.Path.Combine(Path, folderN);
  79. if (!File.Exists(NewPath + folderN))
  80. {
  81. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  82. }
  83. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  84. {
  85. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  86. {
  87. fs.Close();
  88. }
  89. }
  90. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  91. {
  92. file.WriteLine(text);
  93. file.Close();
  94. }
  95.  
  96. }
  97. catch (Exception ex) { Console.WriteLine(ex); }
  98. }
  99. public static void AddpokerCps(string text)
  100. {
  101. try
  102. {
  103. text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
  104. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  105. Path = "gmlogs\\AddpokerCps\\",
  106. NewPath = System.IO.Path.Combine(Path, folderN);
  107. if (!File.Exists(NewPath + folderN))
  108. {
  109. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  110. }
  111. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  112. {
  113. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  114. {
  115. fs.Close();
  116. }
  117. }
  118. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  119. {
  120. file.WriteLine(text);
  121. file.Close();
  122. }
  123.  
  124. }
  125. catch (Exception ex) { Console.WriteLine(ex); }
  126. }
  127. #endregion
  128. public static void RemoveCps(string text)
  129. {
  130. try
  131. {
  132. text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
  133. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  134. Path = "gmlogs\\RemoveCps\\",
  135. NewPath = System.IO.Path.Combine(Path, folderN);
  136. if (!File.Exists(NewPath + folderN))
  137. {
  138. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  139. }
  140. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  141. {
  142. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  143. {
  144. fs.Close();
  145. }
  146. }
  147. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  148. {
  149. file.WriteLine(text);
  150. file.Close();
  151. }
  152. }
  153. catch (Exception ex) { Console.WriteLine(ex); }
  154. }
  155. public static int PacketsReceived = 0, PacketsSent = 0;
  156. #region Definitions
  157. public static int PlayerCap = 0;
  158. public static int MaxPlayers = 0;
  159. public static ServerSocket[] AuthServer;
  160. public static ServerSocket GameServer;
  161. public static Counter EntityUID;
  162. public static string GameIP;
  163. public static DayOfWeek Today;
  164. public static ushort GamePort;
  165. public static List<ushort> AuthPort;
  166. public static DateTime StartDate;
  167. public static Thread Thread;
  168. public static VariableVault Vars;
  169. public static bool ALEXPC = false;
  170. public static bool uniquepk = false;
  171. public static int RandomSeed = 0;
  172. public static Encoding Encoding = ASCIIEncoding.Default;
  173. public static DateTime LastRandomReset = DateTime.Now;
  174. public static Client.GameState[] GamePool = new Client.GameState[0];
  175. public static Client.GameState[] Values = new Client.GameState[0];
  176. #endregion
  177. #region ConsoleHandler
  178. #region Closing Events
  179. [DllImport("Kernel32")]
  180. private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
  181. private delegate bool EventHandler(CtrlType sig);
  182. static EventHandler _handler;
  183. enum CtrlType
  184. {
  185. CTRL_C_EVENT = 0,
  186. CTRL_BREAK_EVENT = 1,
  187. CTRL_CLOSE_EVENT = 2,
  188. CTRL_LOGOFF_EVENT = 5,
  189. CTRL_SHUTDOWN_EVENT = 6
  190. }
  191. private static bool Handler(CtrlType sig)
  192. {
  193. if (MessageBox.Show("Are you sure you want to Exit ?", "MyThs", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  194. {
  195. Console.WriteLine("Saving Before Exiting.......");
  196. return !Save();
  197. }
  198. return true;
  199. }
  200. #endregion
  201. public static bool Save()
  202. {
  203. try
  204. {
  205. AuctionBase.Save();
  206. Database.InnerPowerTable.Save();
  207. FamilyTournament.Save();
  208. FlowersTable.SaveFlowers();
  209. KongFuTable.SaveKongFu();
  210. Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
  211. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
  212. foreach (var client in Server.GamePool)
  213. {
  214. EntityTable.SaveEntity(client);
  215. SkillTable.SaveProficiencies(client);
  216. Database.MailboxTable.Save(client);
  217. Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, client.CP);
  218. // ArenaTable.SaveArenaStatistics(client.ArenaStatistic);
  219. Database.ActivenessTable.Save(client);
  220. TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic);
  221. NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
  222. using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
  223. {
  224. cmd.Select("configuration");
  225. using (MySqlReader r = new MySqlReader(cmd))
  226. {
  227. if (r.Read())
  228. {
  229. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ServerKingdom", Kernel.ServerKingdom).Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Set("GuildID", Game.ConquerStructures.Society.Guild.GuildCounter.Now).Set("UnionID", Union.UnionCounter.Now).Execute();
  230. if (r.ReadByte("LastDailySignReset") != DateTime.Now.Month) MsgSignIn.Reset();
  231. }
  232. }
  233. }
  234. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration"))
  235. cmd.Set("LastDailySignReset", DateTime.Now.Month).Execute();
  236. //if (restart)
  237. // {
  238. // Application.Restart();
  239. //Environment.Exit(0);
  240. // }
  241. //Environment.Exit(0);
  242. }
  243. Console.WriteLine("Saving Cmd Done.");
  244. new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  245. }
  246. catch (Exception e)
  247. {
  248. Console.WriteLine(e.ToString());
  249. return false;
  250. }
  251. return true;
  252. }
  253. #endregion
  254. #region GameServer|AuthServer
  255. static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
  256. {
  257. if (obj.Connector == null)
  258. {
  259. obj.Disconnect();
  260. return;
  261. }
  262. Client.GameState Client = obj.Connector as Client.GameState;
  263. if (Client.Exchange)
  264. {
  265. Client.Exchange = false;
  266. Client.Action = 1;
  267. var crypto = new Network.Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
  268. byte[] otherData = new byte[length];
  269. Array.Copy(buffer, otherData, length);
  270. crypto.Decrypt(otherData, length);
  271.  
  272.  
  273. bool extra = false;
  274. int pos = 0;
  275. try
  276. {
  277. if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
  278. {
  279. pos = length - 140;
  280. Client.Cryptography.Decrypt(buffer, length);
  281. }
  282. else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet
  283. {
  284. pos = length - 176;
  285. extra = true;
  286. Client.Cryptography.Decrypt(buffer, length - 36);
  287.  
  288. }
  289. }
  290. catch { }
  291. int len = BitConverter.ToInt32(buffer, pos); pos += 4;
  292. if (len != 128)
  293. {
  294. Client.Disconnect();
  295. return;
  296. }
  297. byte[] pubKey = new byte[128];
  298. for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
  299. string PubKey = System.Text.Encoding.Default.GetString(pubKey);
  300. Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
  301. if (extra)
  302. {
  303. byte[] data = new byte[36];
  304. Buffer.BlockCopy(buffer, length - 36, data, 0, 36);
  305. processData(data, 36, Client);
  306. }
  307. }
  308. else
  309. {
  310. processData(buffer, length, Client);
  311. }
  312. }
  313. private static void processData(byte[] buffer, int length, Client.GameState Client)
  314. {
  315. Client.Cryptography.Decrypt(buffer, length);
  316. Client.Queue.Enqueue(buffer, length);
  317. if (Client.Queue.CurrentLength > 1224)
  318. {
  319. Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
  320. Client.Disconnect();
  321. return;
  322. }
  323. while (Client.Queue.CanDequeue())
  324. {
  325. byte[] data = Client.Queue.Dequeue();
  326. PacketHandler.Process(data, Client);
  327. }
  328. }
  329. static void GameServer_OnClientConnect(ClientWrapper obj)
  330. {
  331. Client.GameState client = new Client.GameState(obj);
  332. client.Send(client.DHKeyExchange.CreateServerKeyPacket());
  333. obj.Connector = client;
  334. }
  335. static void GameServer_OnClientDisconnect(ClientWrapper obj)
  336. {
  337. if (obj.Connector != null)
  338. (obj.Connector as Client.GameState).Disconnect();
  339. else
  340. obj.Disconnect();
  341. }
  342. static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
  343. {
  344. var player = arg3.Connector as Client.AuthClient;
  345. player.Cryptographer.Decrypt(buffer, length);
  346. player.Queue.Enqueue(buffer, length);
  347. while (player.Queue.CanDequeue())
  348. {
  349. byte[] packet = player.Queue.Dequeue();
  350. ushort len = BitConverter.ToUInt16(packet, 0);
  351. ushort id = BitConverter.ToUInt16(packet, 2);
  352. if (len == 312)
  353. {
  354. player.Info = new Authentication();
  355. player.Info.Deserialize(packet);
  356. player.Account = new AccountTable(player.Info.Username);
  357. msvcrt.msvcrt.srand(player.PasswordSeed);
  358. if (!LoginBruteForce.AcceptJoin(arg3.IP))
  359. {
  360. Console.WriteLine("Client -> ", player.Info.Username, " was bloked Adrres ", arg3.IP, "!");
  361. arg3.Disconnect();
  362. break;
  363. }
  364. Database.ServerInfo Server = null;
  365. Forward Fw = new Forward();
  366. if (ServerData.Servers.TryGetValue("MyThs", out Server))
  367. {
  368. if (!player.Account.exists)
  369. {
  370. Fw.Type = Forward.ForwardType.WrongAccount;
  371. player.Send(Fw);
  372. }
  373. if (player.Account.Password == player.Info.Password && player.Account.exists)
  374. {
  375. Fw.Type = Forward.ForwardType.Ready;
  376. }
  377. else
  378. {
  379. LoginBruteForce.ClientRegistred(arg3.IP);
  380. Fw.Type = Forward.ForwardType.InvalidInfo;
  381. }
  382. if (IPBan.IsBanned(arg3.IP) || player.Account.Banned)
  383. {
  384. Fw.Type = Forward.ForwardType.Banned;
  385. player.Send(Fw);
  386. return;
  387. }
  388. if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready)
  389. {
  390. Client.GameState aClient;
  391. if (Kernel.GamePool.TryGetValue(Fw.Identifier, out aClient))
  392. {
  393. Fw.Type = Forward.ForwardType.InvalidInfo;
  394. aClient.Disconnect();
  395. player.Send(Fw);
  396. return;
  397. }
  398. Fw.Identifier = player.Account.GenerateKey();
  399. Kernel.AwaitingPool[Fw.Identifier] = player.Account;
  400. Fw.IP = GameIP;
  401. Fw.Port = GamePort;
  402. }
  403. player.Send(Fw);
  404. }
  405. }
  406. }
  407. }
  408. static void AuthServer_OnClientDisconnect(ClientWrapper obj)
  409. {
  410. obj.Disconnect();
  411. }
  412. static void AuthServer_OnClientConnect(ClientWrapper obj)
  413. {
  414. Client.AuthClient authState;
  415. obj.Connector = (authState = new Client.AuthClient(obj));
  416. authState.Cryptographer = new Network.Cryptography.AuthCryptography();
  417. Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
  418. pcs.Seed = Kernel.Random.Next();
  419. authState.PasswordSeed = pcs.Seed;
  420. authState.Send(pcs);
  421. }
  422. internal static Client.GameState FindClient(string name)
  423. {
  424. return GamePool.FirstOrDefault(p => p.Player.LoweredName == name);
  425. }
  426. #endregion
  427. #region SaveException|Commands
  428. private static void WorkConsole()
  429. {
  430. while (true)
  431. {
  432. try
  433. {
  434. CommandsAI(Console.ReadLine());
  435. }
  436. catch (Exception e)
  437. {
  438. Console.WriteLine(e);
  439. }
  440. }
  441. }
  442. public static void CommandsAI(string command)
  443. {
  444. if (command == null) return;
  445. string[] data = command.Split(' ');
  446. switch (data[0])
  447. {
  448. case "@ban":
  449. {
  450. IPBan.Load();
  451. break;
  452. }
  453. case "@alivetime":
  454. {
  455. DateTime now = DateTime.Now;
  456. TimeSpan t2 = new TimeSpan(StartDate.ToBinary());
  457. TimeSpan t1 = new TimeSpan(now.ToBinary());
  458. Console.WriteLine("The server has been online " + (int)(t1.TotalHours - t2.TotalHours) + " hours, " + (int)((t1.TotalMinutes - t2.TotalMinutes) % 60) + " minutes.");
  459. break;
  460. }
  461. case "@steam":
  462. {
  463. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Open();
  464. foreach (var clien in Kernel.GamePool.Values)
  465. {
  466. if (clien.Team == null)
  467. clien.Team = new Game.ConquerStructures.Team(clien);
  468. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Join(clien, 3);
  469. }
  470. break;
  471. }
  472. case "@Spellc":
  473. {
  474. new Custom.GUI.SpellControl().ShowDialog();
  475. break;
  476. }
  477. case "@addnpc":
  478. {
  479. new NpcCreator().ShowDialog();
  480. break;
  481. }
  482. case "@team":
  483. {
  484. Game.Features.Tournaments.TeamElitePk.TeamTournament.Open();
  485. foreach (var clien in Kernel.GamePool.Values)
  486. {
  487. if (clien.Team == null)
  488. clien.Team = new Game.ConquerStructures.Team(clien);
  489. Game.Features.Tournaments.TeamElitePk.TeamTournament.Join(clien, 3);
  490. }
  491. break;
  492. }
  493. case "@online":
  494. {
  495. Console.WriteLine("Online players count: " + Kernel.GamePool.Count);
  496. string line = "";
  497. foreach (Client.GameState pClient in Server.GamePool)
  498. line += pClient.Player.Name + ",";
  499. if (line != "")
  500. {
  501. line = line.Remove(line.Length - 1);
  502. Console.WriteLine("Players: " + line);
  503. }
  504. break;
  505. }
  506. case "@memo":
  507. {
  508. var proc = System.Diagnostics.Process.GetCurrentProcess();
  509. Console.WriteLine("Thread count: " + proc.Threads.Count);
  510. Console.WriteLine("Memory set(MB): " + ((double)((double)proc.WorkingSet64 / 1024)) / 1024);
  511. proc.Close();
  512. break;
  513. }
  514. case "@restart":
  515. {
  516. GameServer.Disable();
  517. for (int i = 0; i < AuthServer.Length; i++)
  518. {
  519. AuthServer[i].Disable();
  520. }
  521. Save();
  522. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  523. Database.EntityVariableTable.Save(0, Vars);
  524.  
  525. var wc = GamePool.ToArray();
  526. foreach (Client.GameState client in wc)
  527. client.Disconnect();
  528. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  529.  
  530. Application.Exit();
  531. Environment.Exit(0);
  532. break;
  533. }
  534. case "@exit":
  535. {
  536. GameServer.Disable();
  537. for (int i = 0; i < AuthServer.Length; i++)
  538. {
  539. AuthServer[i].Disable();
  540. }
  541. Save();
  542. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  543. Database.EntityVariableTable.Save(0, Vars);
  544.  
  545. var wc = GamePool.ToArray();
  546. foreach (Client.GameState client in wc)
  547. client.Disconnect();
  548. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  549.  
  550. Application.Exit();
  551. Environment.Exit(0);
  552. break;
  553. }
  554. case "@myths":
  555. {
  556. foreach (Client.GameState client in Kernel.GamePool.Values)
  557. {
  558. client.Map.FreezeMonsters = true;
  559. var Clone = client.Map.Entities.Values.ToArray();
  560. foreach (var mob in Clone)
  561. if (!mob.Companion)
  562. {
  563. client.Map.Floor[mob.X, mob.Y, COServer.Game.MapObjectType.Monster, mob] = true;
  564. client.Map.Entities.Remove(mob.UID);
  565. }
  566. Clone = new Player[0];
  567. client.Map.EntityUIDCounter.Now = 400000;
  568. client.Map.LoadMonsters();
  569. client.Map.FreezeMonsters = false;
  570. foreach (Client.GameState Client in Kernel.GamePool.Values)
  571. {
  572. if (Client.Map.ID == client.Map.ID)
  573. {
  574. Client.Player.Teleport(Client.Player.MapID, Client.Player.X, Client.Player.Y);
  575. }
  576. }
  577. }
  578. break;
  579. }
  580. case "@Rest":
  581. {
  582. Console.WriteLine("Server will restart after 5 minutes.");
  583. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 5 minute, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  584. System.Threading.Thread.Sleep(30000);
  585. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 4 minute 30 second, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  586. System.Threading.Thread.Sleep(30000);
  587. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 4 minute, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  588. System.Threading.Thread.Sleep(30000);
  589. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 3 minute 30 second, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  590. System.Threading.Thread.Sleep(30000);
  591. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 3 minute, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  592. System.Threading.Thread.Sleep(30000);
  593. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 2 minute 30 second, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  594. System.Threading.Thread.Sleep(30000);
  595. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 2 minute, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  596. System.Threading.Thread.Sleep(30000);
  597. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 1 minute 30 second, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  598. System.Threading.Thread.Sleep(30000);
  599. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 1 minute, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  600. System.Threading.Thread.Sleep(30000);
  601. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The server will be brought down for maintenance in 30 second, Please exit the game now.", System.Drawing.Color.Orange, 2011), Server.GamePool);
  602. Console.WriteLine("Server will exit after 1 minute.");
  603. CommandsAI("@save");
  604. System.Threading.Thread.Sleep(30000);
  605. Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The Server restarted, Please log in after 2 minutes! ", System.Drawing.Color.Orange, 0x7db), Server.GamePool);
  606. try
  607. {
  608. CommandsAI("@restart");
  609. }
  610. catch
  611. {
  612. Console.WriteLine("Server cannot exit");
  613. }
  614. break;
  615. }
  616. case "@clear":
  617. {
  618. Console.Clear();
  619. break;
  620. }
  621. case "@save":
  622. {
  623. AuctionBase.Save();
  624. Database.InnerPowerTable.Save();
  625. using (var conn = DataHolder.MySqlConnection)
  626. {
  627. conn.Open();
  628. foreach (Client.GameState client in Server.GamePool)
  629. {
  630. FamilyTournament.Save();
  631. client.Account.Save();
  632. Database.InnerPowerTable.Save();
  633. KongFuTable.SaveKongFu();
  634. FlowersTable.SaveFlowers();
  635. SkillTable.SaveSpells(client);
  636. SkillTable.SaveProficiencies(client);
  637. EntityTable.SaveEntity(client, conn);
  638. Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
  639. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
  640. TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
  641. }
  642. }
  643. new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
  644. break;
  645. }
  646. case "@a":
  647. {
  648. Console.Clear();
  649. break;
  650. }
  651. //case "@showips":
  652. // {
  653. // bool f = !AuthServer.PrintoutIPs;
  654. // AuthServer.PrintoutIPs = GameServer.PrintoutIPs = f;
  655. // Console.WriteLine(string.Format("Showing forcing IPs? {0}", f));
  656. // break;
  657. // }
  658. case "@a7a88":
  659. {
  660. Console.WriteLine("Genr: " + Thread.GenericThreadPool.ToString());
  661. Console.WriteLine("Send: " + Thread.SendPool.ToString());
  662. Console.WriteLine("Recv: " + Thread.ReceivePool.ToString());
  663. break;
  664. }
  665. case "@account":
  666. {
  667. AccountTable account = new AccountTable(data[1]);
  668. account.Password = data[2];
  669. account.State = AccountTable.AccountState.Player;
  670. account.Save();
  671. break;
  672. }
  673. }
  674. }
  675. public static void AddGMCommand(string gm, string commandStr)
  676. {
  677. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month, Path =
  678. "database\\gmlogs\\GMCommandsLog\\", NewPath = System.IO.Path.Combine(Path, folderN);
  679. if (!File.Exists(NewPath + folderN))
  680. {
  681. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  682. }
  683. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  684. {
  685. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  686. {
  687. fs.Close();
  688. }
  689. }
  690. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  691. {
  692. file.WriteLine(gm + commandStr);
  693. }
  694. }
  695. public static void SaveException(Exception e, bool dont = false)
  696. {
  697. if (e.TargetSite.Name == "ThrowInvalidOperationException") return;
  698. if (e.Message.Contains("String reference not set")) return;
  699. if (!dont)
  700. Console.WriteLine(e);
  701. var dt = DateTime.Now;
  702. string date = dt.Month + "-" + dt.Day + "//";
  703. if (!Directory.Exists(Application.StartupPath + Constants.UnhandledExceptionsPath))
  704. Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath);
  705. if (!Directory.Exists(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date))
  706. Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date);
  707. if (!Directory.Exists(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name))
  708. Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name);
  709. string fullPath = Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name + "\\";
  710. string date2 = dt.Hour + "-" + dt.Minute;
  711. List<string> Lines = new List<string>();
  712. Lines.Add("----Exception message----");
  713. Lines.Add(e.Message);
  714. Lines.Add("----End of exception message----\r\n");
  715. Lines.Add("----Stack trace----");
  716. Lines.Add(e.StackTrace);
  717. Lines.Add("----End of stack trace----\r\n");
  718. File.WriteAllLines(fullPath + date2 + ".txt", Lines.ToArray());
  719. }
  720. #endregion
  721. public static uint _NextItemID;
  722. public static uint NextItemID
  723. {
  724. get { return _NextItemID++; }
  725. }
  726. public static void NextItemUID()
  727. {
  728. Console.WriteLine("Check Last Item UID... ");
  729. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("items"))
  730. using (var reader = new MySqlReader(cmd))
  731. {
  732. while (reader.Read())
  733. {
  734.  
  735. uint UID = reader.ReadUInt32("UID");
  736. if ((UID > 0) && (UID > _NextItemID))
  737. {
  738. _NextItemID = UID;
  739. }
  740. }
  741. }
  742.  
  743. }
  744. static bool restart = false;
  745. public static void Restart()
  746. {
  747. if (!restart)
  748. {
  749. restart = true;
  750. Save();
  751.  
  752.  
  753. }
  754. }
  755. public static void LoadServer()
  756. {
  757. Time32 Start = Time32.Now;
  758. RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2));
  759. Kernel.Random = new FastRandom(RandomSeed);
  760. StartDate = DateTime.Now;
  761. ALEXPC = true;
  762. Console.ForegroundColor = ConsoleColor.Green;
  763. GameIP = "25.80.137.49";
  764. GamePort = 5819;
  765. AuthPort = new List<ushort>() { 9959 };
  766. DataHolder.CreateConnection("root", "258456", "hard", "localhost");
  767. using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
  768. {
  769. cmd.Select("configuration");
  770. using (MySqlReader r = new MySqlReader(cmd))
  771. {
  772. if (r.Read())
  773. {
  774.  
  775. EntityUID = new Counter(r.ReadUInt32("EntityID"));
  776. Union.UnionCounter = new Counter(r.ReadUInt32("UnionID"));
  777. Kernel.ServerKingdom = r.ReadUInt32("ServerKingdom");
  778. if (r.ReadByte("LastDailySignReset") != DateTime.Now.Month) MsgSignIn.Reset();
  779. Game.ConquerStructures.Society.Guild.GuildCounter = new Counter(r.ReadUInt32("GuildID"));
  780. Constants.ExtraExperienceRate = r.ReadUInt32("ExperienceRate");
  781. Constants.ExtraSpellRate = r.ReadUInt32("ProficiencyExperienceRate");
  782. Constants.ExtraProficiencyRate = r.ReadUInt32("SpellExperienceRate");
  783. Constants.MoneyDropRate = r.ReadUInt32("MoneyDropRate");
  784. Constants.MoneyDropMultiple = r.ReadUInt32("MoneyDropMultiple");
  785. PlayerCap = r.ReadInt32("PlayerCap");
  786. EntityVariableTable.Load(0, out Vars);
  787. }
  788. }
  789. }
  790. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration"))
  791. cmd.Set("LastDailySignReset", DateTime.Now.Month).Execute();
  792. if (EntityUID.Now == 0)
  793. {
  794. Console.Clear();
  795. Console.WriteLine("Database error. Please check your MySQL. Server will now close.");
  796. Console.ReadLine();
  797. return;
  798. }
  799. Thread = new Thread();
  800. Thread.Init();
  801. NextItemUID();
  802. Console.ForegroundColor = ConsoleColor.Magenta;
  803. FlowersTable.LoadFlowers();
  804. Console.ForegroundColor = ConsoleColor.Blue;
  805. ConquerItemTable.ClearNulledItems();
  806. ConquerItemInformation.Load();
  807. DataHolder.ReadStats();
  808. Console.ForegroundColor = ConsoleColor.DarkMagenta;
  809. MonsterInformation.Load();
  810. IPBan.Load();
  811. SpellTable.Load();
  812. ShopFile.Load();
  813. Console.ForegroundColor = ConsoleColor.DarkGray;
  814. HonorShop.Load();
  815. RacePointShop.Load();
  816. Console.ForegroundColor = ConsoleColor.Gray;
  817. UnionTable.Load();
  818. ChampionShop.Load();
  819. Console.ForegroundColor = ConsoleColor.DarkMagenta;
  820. Database.PerfectionTable.Load();
  821. EShopFile.Load();
  822. EShopV2File.Load();
  823. MapsTable.Load();
  824. NobilityTable.Load();
  825. Console.ForegroundColor = ConsoleColor.Yellow;
  826. ArenaTable.Load();
  827. TeamArenaTable.Load();
  828. SignInTable.Load();
  829. GuildTable.Load();
  830. ChiTable.LoadAllChi();
  831. PrizeNpcTable.Load();
  832. SoulProtection.Load();
  833. Console.ForegroundColor = ConsoleColor.DarkGray;
  834. MsgProcessGoal.Load();
  835. Kernel.QuizShow = new Game.ConquerStructures.QuizShow();
  836. Refinery.Load();
  837. Map.CreateTimerFactories();
  838. DMaps.Load();
  839. Console.ForegroundColor = ConsoleColor.Yellow;
  840. Game.Screen.CreateTimerFactories();
  841. GamePool = new Client.GameState[0];
  842. new Map(2073, DMaps.MapPaths[1011]);
  843. new Map(2075, DMaps.MapPaths[1015]);
  844. new Map(2076, DMaps.MapPaths[1020]);
  845. new Map(2078, DMaps.MapPaths[1000]);
  846. new Map(2072, DMaps.MapPaths[1002]);
  847. new Map(1002, DMaps.MapPaths[1002]);
  848. new Map(1038, DMaps.MapPaths[1038]);
  849. new Map(2071, DMaps.MapPaths[2071]);
  850. new Map(1509, DMaps.MapPaths[1509]);
  851. new Map(10002, 2021, DMaps.MapPaths[2021]);
  852. new Map(8883, 1004, DMaps.MapPaths[1004]);
  853. new Map(3846, DMaps.MapPaths[3846]);
  854. new Map(1927, DMaps.MapPaths[1927]);
  855. Constants.PKFreeMaps.Add(8883);
  856. GuildWar.Initiate();
  857. Game.ClanWar.Initiate();
  858. Console.ForegroundColor = ConsoleColor.Cyan;
  859. MsgFamily.LoadClans();
  860. Game.EliteGuildWar.EliteGwint();
  861. LoginBruteForce.CreatePoll();
  862. ReincarnationTable.Load();
  863. FurnitureTable.Load();
  864. Console.ForegroundColor = ConsoleColor.DarkBlue;
  865. KoBoard.Load();
  866. AuctionBase.Load();
  867. ServerData.Load();
  868. Console.ForegroundColor = ConsoleColor.DarkYellow;
  869. KongFuTable.LoadStatus();
  870. KongFuTable.LoadKongFu();
  871. Database.LotteryTable.Load();
  872. StorageManager.Load();
  873. Network.GamePackets.TaskReward.Load();
  874. Database.InnerPowerTable.LoadDBInformation();
  875. Console.ForegroundColor = ConsoleColor.DarkGreen;
  876. Database.InnerPowerTable.Load();
  877. Database.StorageItem.Load();
  878. Console.ForegroundColor = ConsoleColor.DarkCyan;
  879. Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
  880. Thread.CreateTournaments();
  881. //_handler += new EventHandler(Handler);
  882. //SetConsoleCtrlHandler(_handler, true);
  883. AddingInformationTable.Load();
  884. // FloorItemTable.Load();
  885. Console.ForegroundColor = ConsoleColor.DarkBlue;
  886. Console.WriteLine("Loading Npc information... ");
  887. {
  888.  
  889. Client.GameState gc = new Client.GameState(new ClientWrapper());
  890. gc.Account = new AccountTable("NONE");
  891. gc.Socket.Alive = false;
  892. gc.Player = new Player(PlayerFlag.Player, false) { Name = "NONE" };
  893. Npcs.GetDialog(new MsgTaskDialog(true), gc, true);
  894. }
  895. new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Execute();
  896. new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("ChatBanned", 0).Execute();
  897. new MsgEquipRefineRank().UpdateRanking();
  898. new MsgUserAbilityScore().GetRankingList();
  899. new MsgRankMemberShow().UpdateBestPlayer();
  900.  
  901. AuthServer = new ServerSocket[AuthPort.Count];
  902. for (int i = 0; i < AuthServer.Length; i++)
  903. {
  904. AuthServer[i] = new ServerSocket();
  905. AuthServer[i].OnClientConnect += AuthServer_OnClientConnect;
  906. AuthServer[i].OnClientReceive += AuthServer_OnClientReceive;
  907. AuthServer[i].OnClientDisconnect += AuthServer_OnClientDisconnect;
  908. AuthServer[i].Enable(AuthPort[i], "0.0.0.0");
  909. }
  910. GameServer = new ServerSocket();
  911. GameServer.OnClientConnect += GameServer_OnClientConnect;
  912. GameServer.OnClientReceive += GameServer_OnClientReceive;
  913. GameServer.OnClientDisconnect += GameServer_OnClientDisconnect;
  914. GameServer.Enable(GamePort, "0.0.0.0");
  915. AI.CreateTimerFactories();
  916. Booths.Load();
  917. Console.ForegroundColor = ConsoleColor.Yellow;
  918. Console.WriteLine("");
  919. Console.WriteLine("MyThs-Online waiting for new connection...");
  920. Console.WriteLine("");
  921. GC.Collect();
  922. WorkConsole();
  923. CommandsAI(Console.ReadLine());
  924. }
  925. }
  926. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement