Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.40 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using ElmistRo.Network;
  6. using ElmistRo.Database;
  7. using ElmistRo.Network.Sockets;
  8. using ElmistRo.Network.AuthPackets;
  9. using ElmistRo.Game.ConquerStructures.Society;
  10. using ElmistRo.Game;
  11. using System.Collections.Generic;
  12. using System.Runtime.InteropServices;
  13. using System.Threading;
  14. using ElmistRo.Interfaces;
  15. using System.Text;
  16. using ElmistRo.Network.GamePackets;
  17. using ElmistRo.Client;
  18. using ElmistRo.Game.Features.Tournaments;
  19.  
  20. namespace ElmistRo
  21. {
  22. class Program
  23. {
  24. public static void WriteLine(string Line)
  25. {
  26. try
  27. {
  28. Console.WriteLine(Line);
  29. }
  30. catch { }
  31. }
  32. public static bool CpuUsageTimer = true;
  33. public static MemoryCompressor MCompressor = new MemoryCompressor();
  34. public static int CpuUse = 0;
  35. public static string DBName = "";
  36. public static string DBUser = "";
  37. public static string DBPass = "";
  38. public static Encoding Encoding = Encoding.GetEncoding("iso-8859-1");
  39. [DllImport("user32.dll")]
  40. public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  41. [DllImport("user32.dll")]
  42. public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  43. public static int PlayerCap = 800;
  44. public static ServerSocket AuthServer;
  45. public static ServerSocket GameServer;
  46. public static Counter EntityUID;
  47. public static long WeatherType = 0L;
  48. public static string GameIP;
  49. public static bool ClanTeam = false;
  50. public static bool IsBetweenTwoPoints(ushort x, ushort y, ushort startx, ushort starty, ushort endx, ushort endy)
  51. {
  52. return (((x >= startx) && (y >= starty)) && ((x <= endx) && (y <= endy)));
  53. }
  54. public static DayOfWeek Today;
  55. public static ushort GamePort;
  56. public static ushort AuthPort;
  57. //public static LookOut LookOut;
  58. public static DateTime StartDate;
  59. public static uint ScreenColor = 0;
  60. public static DateTime RestartDate = DateTime.Now.AddHours(24);
  61. public static World World;
  62. public static Client.GameClient[] GamePool = new Client.GameClient[0];
  63. public static VariableVault Vars;
  64. public static long MaxOn = 0;
  65. public static int RandomSeed = 0;
  66. private static Native.ConsoleEventHandler ElmistRoHandler;
  67. private static bool ElmistRoConsole_CloseEvent(CtrlType sig)
  68. {
  69. try
  70. {
  71. Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
  72. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
  73. ElmistRo.Database.JiangHu.SaveJiangHu();
  74. //Database.StatueTable.Save();
  75. var count = Kernel.GamePool.Count;
  76. foreach (var client in Program.GamePool)
  77. {
  78. client.Quests.Save();
  79. InnerPowerTable.Save();
  80. DailyQuest.Save(client);
  81. StorageTable.Save(client);
  82. CloudSaintsTable.Save(client);;
  83. client.Disconnect();
  84. }
  85. GameServer.Disable();
  86. AuthServer.Disable();
  87. if (GuildWar.IsWar)
  88. GuildWar.End();
  89. if (PoleTwin.IsWar)
  90. PoleTwin.End();
  91. if (PolePhoenix.IsWar)
  92. PolePhoenix.End();
  93. if (PoleApe.IsWar)
  94. PoleApe.End();
  95. if (PoleBird.IsWar)
  96. PoleBird.End();
  97. EntityVariableTable.Save(0, Program.Vars);
  98. new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration")
  99. .Set("ItemUID", ConquerItem.ItemUID.Now)
  100. .Where("Server", Constants.ServerName)
  101. .Execute();
  102. Console.WriteLine("Saved {" + count + "} characters successfully.");
  103. Thread.Sleep(20000);
  104. return true;
  105. }
  106. catch (Exception P)
  107. {
  108. Console.WriteLine(P);
  109. return false;
  110. }
  111. }
  112. #region Attack[Conntrol]
  113. public static double double_25 = 0.0;
  114. public static double double_26 = 0.0;
  115. public static double double_27 = 0.0;
  116. public static double double_28 = 0.0;
  117. public static int int_2 = 0;
  118. public static int int_3 = 0;
  119. public static int int_4 = 0;
  120. #endregion
  121. static void Main(string[] args)
  122. {
  123. /////////////////////////////Cpu//////////////////////////////
  124. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  125. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  126. /////////////////////////////Cpu//////////////////////////////
  127. Time64 Start = Time64.Now;
  128. RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2));
  129. Kernel.Random = new FastRandom(RandomSeed);
  130. StartDate = DateTime.Now;
  131. Console.Title = " > "+Constants.ServerName+"|OnlinE < "; Console.BackgroundColor = ConsoleColor.Red;
  132. Console.ForegroundColor = ConsoleColor.Red;
  133. IntPtr hWnd = FindWindow(null, Console.Title);
  134. Console.WriteLine("-- This SourcE Has BeeN Edited By ElmistRo. --");
  135. Console.WriteLine("------- Thank You For Allah With Help -------");
  136. Console.WriteLine("----- Copyright (c) ElmistRo|OnlinE . -----");
  137. Console.BackgroundColor = ConsoleColor.Black;
  138. Console.ForegroundColor = ConsoleColor.White;
  139. Console.WriteLine("Load server configuration! !");
  140. string ConfigFileName = "configuration.ini";
  141. IniFile IniFile = new IniFile(ConfigFileName);
  142. GameIP = IniFile.ReadString("configuration", "IP");
  143. GamePort = IniFile.ReadUInt16("configuration", "GamePort");
  144. AuthPort = IniFile.ReadUInt16("configuration", "AuthPort");
  145. Constants.ServerName = IniFile.ReadString("configuration", "ServerName");
  146. ElmistRo.Database.JiangHu.LoadJiangHu();
  147. ElmistRo.Database.JiangHu.LoadStatus();
  148. Database.DataHolder.CreateConnection();
  149. EntityUID = new Counter(0);
  150. /////////////////////////////Cpu//////////////////////////////
  151. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  152. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  153. /////////////////////////////Cpu//////////////////////////////
  154. using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
  155. {
  156. cmd.Select("configuration").Where("Server", Constants.ServerName);
  157. using (MySqlReader r = new MySqlReader(cmd))
  158. {
  159. if (r.Read())
  160. {
  161. EntityUID = new Counter(r.ReadUInt32("EntityID"));
  162. Game.ConquerStructures.Society.Guild.GuildCounter = new ElmistRo.Counter(r.ReadUInt32("GuildID"));
  163. ElmistRo.Network.GamePackets.Union.Union.UnionCounter = new Counter(r.ReadUInt32("UnionID"));
  164. Kernel.ServerKingdom = r.ReadUInt32("ServerKingdom");
  165. Network.GamePackets.ConquerItem.ItemUID = new ElmistRo.Counter(r.ReadUInt32("ItemUID"));
  166. Constants.ExtraExperienceRate = r.ReadUInt32("ExperienceRate");
  167. Constants.ExtraSpellRate = r.ReadUInt32("ProficiencyExperienceRate");
  168. Constants.ExtraProficiencyRate = r.ReadUInt32("SpellExperienceRate");
  169. Constants.MoneyDropRate = r.ReadUInt32("MoneyDropRate");
  170. Constants.MoneyDropMultiple = r.ReadUInt32("MoneyDropMultiple");
  171. Constants.ConquerPointsDropRate = r.ReadUInt32("ConquerPointsDropRate");
  172. Constants.ConquerPointsDropMultiple = r.ReadUInt32("ConquerPointsDropMultiple");
  173. Constants.ItemDropRate = r.ReadUInt32("ItemDropRate");
  174. Constants.ItemDropQualityRates = r.ReadString("ItemDropQualityString").Split('~');
  175. Constants.WebAccExt = r.ReadString("AccountWebExt");
  176. Constants.WebVoteExt = r.ReadString("VoteWebExt");
  177. Constants.WebDonateExt = r.ReadString("DonateWebExt");
  178. Constants.ServerWebsite = r.ReadString("ServerWebsite");
  179. PlayerCap = r.ReadInt32("PlayerCap");
  180. Database.EntityVariableTable.Load(0, out Vars);
  181. }
  182. }
  183. }
  184. /////////////////////////////Cpu//////////////////////////////
  185. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  186. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  187. /////////////////////////////Cpu//////////////////////////////
  188. if (GameIP == "192.168.1.5")
  189. {
  190. Console.WriteLine("Login Success!");
  191. }
  192. else
  193. {
  194. Environment.Exit(0);
  195. }
  196. if (EntityUID.Now == 0)
  197. {
  198. Console.Clear();
  199. Console.WriteLine("Database error. Please check your MySQL. Server will now close.");
  200. Console.ReadLine();
  201. return;
  202. }
  203.  
  204. {
  205. /////////////////////////////Cpu//////////////////////////////
  206. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  207. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  208. /////////////////////////////Cpu//////////////////////////////
  209. Console.WriteLine("Initializing database.");
  210. World = new World();
  211. World.Init();
  212. Console.WriteLine("Checking LastItem UID.");
  213. ElmistRo.Soul.SoulProtection.Load();
  214. Database.PerfectionTable.Load();
  215. QuestInfo.Load();
  216. Console.WriteLine("Checking SoulProtection Load.");
  217. Console.WriteLine("Checking Perfection Load.");
  218. WayofHeroes.Load();
  219. Database.ConquerItemTable.ClearNulledItems();
  220. /////////////////////////////Cpu//////////////////////////////
  221. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  222. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  223. /////////////////////////////Cpu//////////////////////////////
  224. PlayersVot.LoadPlayersVots();
  225. Database.ConquerItemInformation.Load();
  226. Database.NameChange.UpdateNames();
  227. Database.DataHolder.ReadStats();
  228. Database.MonsterInformation.Load();
  229. Database.IPBan.Load();
  230. /////////////////////////////Cpu//////////////////////////////
  231. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  232. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  233. /////////////////////////////Cpu//////////////////////////////
  234. //Messagess.Load();
  235. Database.HelpDesk.Load();
  236. //Database.GameUpdatess.Load();
  237. Database.SpellTable.Load();
  238. Database.ShopFile.Load();
  239. Database.HonorShop.Load();
  240. // Database.StatueTable.Load();
  241. Database.RacePointShop.Load();
  242. /////////////////////////////Cpu//////////////////////////////
  243. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  244. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  245. /////////////////////////////Cpu//////////////////////////////
  246. Database.ChampionShop.Load();
  247. Database.EShopFile.Load();
  248. Database.EShopV2File.Load();
  249. Database.MapsTable.Load();
  250. Database.NobilityTable.Load();
  251. Database.ArenaTable.Load();
  252. Database.TeamArenaTable.Load();
  253. /////////////////////////////Cpu//////////////////////////////
  254. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  255. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  256. /////////////////////////////Cpu//////////////////////////////
  257. Database.ChampionTable.Load();
  258. Database.GuildTable.Load();
  259. ElmistRo.Network.GamePackets.Union.UnionTable.Load();
  260. Database.LotteryTable.Load();
  261. Database.SignInTable.Load();
  262. Console.WriteLine("ClanArena Table Loaded.");
  263. Database.DROP_SOULS.LoadDrops();
  264. Database.ChiTable.LoadAllChi();
  265. Console.WriteLine("Chi Table Loaded.");
  266. Console.WriteLine("ClanArena Table Loaded.");
  267. Database.PoketTables.LoadTables();
  268. /////////////////////////////Cpu//////////////////////////////
  269. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  270. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  271. /////////////////////////////Cpu//////////////////////////////
  272. Kernel.QuizShow = new Game.ConquerStructures.QuizShow();
  273. Refinery.Load();
  274. BruteForceProtection.CreatePoll();
  275. Map.CreateTimerFactories();
  276. Database.DMaps.Load();
  277. ClanWar.Create();
  278. InnerPowerTable.LoadDBInformation();
  279. InnerPowerTable.Load();
  280. Game.Screen.CreateTimerFactories();
  281. StorageManager.Load();
  282. Database.storageItem.Load();
  283. WarDrobe.Load();
  284. /////////////////////////////Cpu//////////////////////////////
  285. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  286. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  287. /////////////////////////////Cpu//////////////////////////////
  288. GamePool = new Client.GameClient[0];
  289. new Game.Map(1002, Database.DMaps.MapPaths[1002]);
  290. new Game.Map(1038, Database.DMaps.MapPaths[1038]);
  291. new Game.Map(2071, Database.DMaps.MapPaths[2071]);
  292. new Map(2078, DMaps.MapPaths[1000]);
  293. Game.GuildWar.Initiate();
  294. //Game.SuperGuildWar.Initiate();
  295. // Game.PoleTwin.Initiate();
  296. //Game.DecPole.DecPoleIni();
  297. ///Game.PolePhoenix.Initiate();
  298. // Game.PoleApe.Initiate();
  299. // Game.PoleBird.Initiate();
  300. new Game.Map(CrossServer.mapid, Database.DMaps.MapPaths[CrossServer.mapid]);
  301. Game.CrossServer.Initiate();
  302. new Game.Map(1509, Database.DMaps.MapPaths[1509]);
  303. new Game.Map(10002, 2021, Database.DMaps.MapPaths[2021]);
  304. new Game.Map(8883, 1004, Database.DMaps.MapPaths[1004]);
  305. Constants.PKFreeMaps.Add(8883);
  306. Constants.PKFreeMaps.Add(CrossServer.mapid);
  307. /////////////////////////////Cpu//////////////////////////////
  308. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  309. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  310. /////////////////////////////Cpu//////////////////////////////
  311. Game.ClanWar2.Initiate();
  312. Game.EliteGuildWar.EliteGwint();
  313. Console.WriteLine("Elite Guild war initializated.");
  314. Console.WriteLine("Guild war initializated.");
  315. Console.WriteLine("PoleTwin War initilizated.");
  316. Console.WriteLine("PolePhoenix War initilizated.");
  317. Console.WriteLine("PoleApe War initilizated.");
  318. Console.WriteLine("PoleBird War initilizated.");
  319. Console.WriteLine("Loading Game Clans.");
  320. Clan.LoadClans();
  321. House.LoadHouses();
  322. Console.WriteLine("House Table Loaded.");
  323. Database.ReincarnationTable.Load();
  324. new MsgUserAbilityScore().GetRankingList();
  325. new MsgEquipRefineRank().UpdateRanking();
  326. //PrestigeRank.LoadRanking();
  327. Console.WriteLine("Reincarnate Table Loaded.");
  328. Console.WriteLine("Flower Table Loaded.");
  329. Console.WriteLine("JiangHu Hu Loaded Successfully");
  330. Console.WriteLine("Computing npc dialogues!");
  331. {
  332. ElmistRo.Client.GameClient gc = new ElmistRo.Client.GameClient(new ClientWrapper());
  333. gc.Account = new AccountTable("NONE");
  334. gc.Socket.Alive = false;
  335. gc.Entity = new Entity(EntityFlag.Player, false) { Name = "NONE" };
  336. Npcs.GetDialog(new NpcRequest(), gc, true);
  337. }
  338. /////////////////////////////Cpu//////////////////////////////
  339. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  340. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  341. /////////////////////////////Cpu//////////////////////////////
  342. Console.WriteLine("Computing npc's succeeded.");
  343. Database.StaticShop.LoadStatitcStalls();
  344. Console.WriteLine("Loading Booths");
  345. Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
  346. World.CreateTournaments();
  347. Game.Features.Tournaments.TeamElitePk.TeamTournament.Create();
  348. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Create();
  349. Console.WriteLine("TeamPk Loaded Successfully");
  350. Console.WriteLine("SkillTeam Loaded Successfully");
  351. ElmistRoHandler += ElmistRoConsole_CloseEvent;
  352. Native.SetConsoleCtrlHandler(ElmistRoHandler, true);
  353. /////////////////////////////Cpu//////////////////////////////
  354. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  355. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  356. /////////////////////////////Cpu//////////////////////////////
  357. new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Execute();
  358. Console.WriteLine("Initializing sockets.");
  359.  
  360. AuthServer = new ServerSocket();
  361. AuthServer.OnClientConnect += AuthServer_OnClientConnect;
  362. AuthServer.OnClientReceive += AuthServer_OnClientReceive;
  363. AuthServer.OnClientDisconnect += AuthServer_OnClientDisconnect;
  364. AuthServer.Enable(AuthPort, "0.0.0.0");
  365. /////////////////////////////Cpu//////////////////////////////
  366. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  367. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  368. /////////////////////////////Cpu//////////////////////////////
  369. GameServer = new ServerSocket();
  370. GameServer.OnClientConnect += GameServer_OnClientConnect;
  371. GameServer.OnClientReceive += GameServer_OnClientReceive;
  372. GameServer.OnClientDisconnect += GameServer_OnClientDisconnect;
  373. GameServer.Enable(GamePort, "0.0.0.0");
  374. /////////////////////////////Cpu//////////////////////////////
  375. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  376. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  377. /////////////////////////////Cpu//////////////////////////////
  378. Console.WriteLine("Auth server online.");
  379. Console.WriteLine("Game server online.");
  380. Console.WriteLine("-------------------------------------");
  381. Console.WriteLine("Server loaded in " + (Time64.Now - Start) + " milliseconds.");
  382. /////////////////////////////Cpu//////////////////////////////
  383. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  384. Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
  385. /////////////////////////////Cpu//////////////////////////////
  386. GC.Collect();
  387. WorkConsole();
  388. {
  389. }
  390. }
  391. }
  392. #region Exceptions & Logs
  393. public static void AddCpsWin(string text)
  394. {
  395. try
  396. {
  397. text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
  398. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  399. Path = "gmlogs\\AddWinCps\\",
  400. NewPath = System.IO.Path.Combine(Path, folderN);
  401. if (!File.Exists(NewPath + folderN))
  402. {
  403. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  404. }
  405. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  406. {
  407. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  408. {
  409. fs.Close();
  410. }
  411. }
  412. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  413. {
  414. file.WriteLine(text);
  415. file.Close();
  416. }
  417.  
  418. }
  419. catch (Exception ex) { Console.WriteLine(ex); }
  420. }
  421. public static void AddVendorLog(String vendor, string buying, string moneyamount, ConquerItem Item)
  422. {
  423. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  424. Path = "gmlogs\\VendorLogs\\",
  425. NewPath = System.IO.Path.Combine(Path, folderN);
  426. if (!File.Exists(NewPath + folderN))
  427. {
  428. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  429. }
  430. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  431. {
  432. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  433. {
  434. fs.Close();
  435. }
  436. }
  437.  
  438. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  439. {
  440. file.WriteLine("------------------------------------------------------------------------------------");
  441. file.WriteLine("{0} HAS BOUGHT AN ITEM : {2} FROM {1} SHOP - for {3}", vendor, buying, Item.ToLog(), moneyamount);
  442. file.WriteLine("------------------------------------------------------------------------------------");
  443. }
  444. }
  445. public static void AddGMCommand(string gm, string commandStr)
  446. {
  447. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  448. Path = "gmlogs\\GMCommandsLog\\",
  449. NewPath = System.IO.Path.Combine(Path, folderN);
  450. if (!File.Exists(NewPath + folderN))
  451. {
  452. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  453. }
  454. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  455. {
  456. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  457. {
  458. fs.Close();
  459. }
  460. }
  461.  
  462. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  463. {
  464. file.WriteLine(gm + commandStr);
  465. }
  466. }
  467. public static void AddDropLog(String Name, ConquerItem Item)
  468. {
  469. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  470. Path = "gmlogs\\droplogs\\",
  471. NewPath = System.IO.Path.Combine(Path, folderN);
  472. if (!File.Exists(NewPath + folderN))
  473. {
  474. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  475. }
  476. string path = NewPath + "\\" + DateTime.Now.Day + ".txt";
  477. if (!File.Exists(path)) File.AppendAllText(path, "");
  478.  
  479. string text = "------------------------------------------------------------------------------------"
  480. + Environment.NewLine + string.Format("Player {0} HAS DROPPED AN ITEM : {1} -", Name, Item.ToLog())
  481. + Environment.NewLine + "------------------------------------------------------------------------------------";
  482. File.AppendAllText(path, text);
  483. }
  484. public static void AddTradeLog(ElmistRo.Game.ConquerStructures.Trade first, String firstN, ElmistRo.Game.ConquerStructures.Trade second, String secondN)
  485. {
  486. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  487. Path = "gmlogs\\tradelogs\\",
  488. NewPath = System.IO.Path.Combine(Path, folderN);
  489. if (!File.Exists(NewPath + folderN))
  490. {
  491. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  492. }
  493. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  494. {
  495. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  496. {
  497. fs.Close();
  498. }
  499. }
  500.  
  501. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  502. {
  503. file.WriteLine("************************************************************************************");
  504. file.WriteLine("First Person TradeLog ( {0} ) -", firstN);
  505. file.WriteLine("Gold Traded: " + first.Money);
  506. file.WriteLine("Conquer Points Traded: " + first.ConquerPoints);
  507.  
  508. for (int i = 0; i < first.Items.Count; i++)
  509. {
  510. file.WriteLine("------------------------------------------------------------------------------------");
  511. file.WriteLine("Item : " + first.Items[i].ToLog());
  512. file.WriteLine("------------------------------------------------------------------------------------");
  513. }
  514. file.WriteLine("Second Person TradeLog ( {0} ) -", secondN);
  515. file.WriteLine("Gold Traded: " + second.Money);
  516. file.WriteLine("Conquer Points Traded: " + second.ConquerPoints);
  517.  
  518. for (int i = 0; i < second.Items.Count; i++)
  519. {
  520. file.WriteLine("------------------------------------------------------------------------------------");
  521. file.WriteLine("Item : " + second.Items[i].ToLog());
  522. file.WriteLine("------------------------------------------------------------------------------------");
  523. }
  524. file.WriteLine("************************************************************************************");
  525. }
  526. }
  527. public static void AddWarLog(string War, string CPs, string name)
  528. {
  529. String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
  530. Path = "gmlogs\\Warlogs\\",
  531. NewPath = System.IO.Path.Combine(Path, folderN);
  532. if (!File.Exists(NewPath + folderN))
  533. {
  534. System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
  535. }
  536. if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  537. {
  538. using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
  539. {
  540. fs.Close();
  541. }
  542. }
  543.  
  544. using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
  545. {
  546. file.WriteLine(name + " got " + CPs + " CPs from the [" + War + "] as prize at " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second);
  547. }
  548. }
  549. public static void BuyFromShop(string text)
  550. {
  551. string path2 = (string)(object)DateTime.Now.Year + (object)"-" + (string)(object)DateTime.Now.Month;
  552. string path1 = "gmlogs\\ShopBuy\\";
  553. string str = Path.Combine(path1, path2);
  554. if (!File.Exists(str + path2))
  555. Directory.CreateDirectory(Path.Combine(path1, path2));
  556. if (!File.Exists(string.Concat(new object[4]
  557. {
  558. (object) str,
  559. (object) "\\",
  560. (object) DateTime.Now.Day,
  561. (object) ".txt"
  562. })))
  563. {
  564. using (FileStream fileStream = File.Create(string.Concat(new object[4]
  565. {
  566. (object) str,
  567. (object) "\\",
  568. (object) DateTime.Now.Day,
  569. (object) ".txt"
  570. })))
  571. fileStream.Close();
  572. }
  573. using (StreamWriter streamWriter = new StreamWriter(string.Concat(new object[4]
  574. {
  575. (object) str,
  576. (object) "\\",
  577. (object) DateTime.Now.Day,
  578. (object) ".txt"
  579. }), true))
  580. streamWriter.WriteLine(text);
  581. }
  582. static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  583. {
  584. SaveException(e.Exception);
  585. }
  586.  
  587. public static void SaveException(Exception e, bool dont = false)
  588. {
  589. if (e.Message.Contains("String reference not set")) return;
  590. if (!dont)
  591. Console.WriteLine(e);
  592. if ((e.TargetSite.Name != "ThrowInvalidOperationException") && !e.Message.Contains("String reference not set"))
  593. {
  594. ElmistRo.Console.WriteLine(e);
  595. DateTime now = DateTime.Now;
  596. string str = string.Concat(new object[] { now.Month, "-", now.Day, "//" });
  597. if (!Directory.Exists(Application.StartupPath + @"database\exceptions\"))
  598. {
  599. Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\");
  600. }
  601. if (!Directory.Exists(Application.StartupPath + @"\database\exceptions\" + str))
  602. {
  603. Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\" + str);
  604. }
  605. if (!Directory.Exists(Application.StartupPath + @"\database\exceptions\" + str + e.TargetSite.Name))
  606. {
  607. Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\" + str + e.TargetSite.Name);
  608. }
  609. File.WriteAllLines((Application.StartupPath + @"\database\exceptions\" + str + e.TargetSite.Name + @"\") + (now.Hour + "-" + now.Minute) + ".txt", new List<string> { "----Exception message----", e.Message, "----End of exception message----\r\n", "----Stack trace----", e.StackTrace, "----End of stack trace----\r\n" }.ToArray());
  610. }
  611. }
  612. #endregion
  613.  
  614. private static void WorkConsole()
  615. {
  616. while (true)
  617. {
  618. try
  619. {
  620. CommandsAI(Console.ReadLine());
  621. }
  622. catch (Exception e) { Console.WriteLine(e); }
  623. }
  624. }
  625. public static DateTime LastRandomReset = DateTime.Now;
  626. public static Network.GamePackets.BlackSpotPacket BlackSpotPacket = new Network.GamePackets.BlackSpotPacket();
  627. public static bool MyPC = true;
  628. public static void CommandsAI(string command)
  629. {
  630. if (command == null)
  631. return;
  632. string[] data = command.Split(' ');
  633. switch (data[0])
  634. {
  635. case "@cp":
  636. {
  637. Controlpanel cp = new Controlpanel();
  638. cp.ShowDialog();
  639. break;
  640. }
  641. case "@teampk":
  642. {
  643. Game.Features.Tournaments.TeamElitePk.TeamTournament.Open();
  644. foreach (var clien in Kernel.GamePool.Values)
  645. {
  646. if (clien.Team == null)
  647. clien.Team = new Game.ConquerStructures.Team();
  648. Game.Features.Tournaments.TeamElitePk.TeamTournament.Join(clien, 3);
  649. }
  650. break;
  651. }
  652. case "@steampk":
  653. {
  654. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Open();
  655. foreach (var clien in Kernel.GamePool.Values)
  656. {
  657. if (clien.Team == null)
  658. clien.Team = new Game.ConquerStructures.Team();
  659. Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Join(clien, 3);
  660. }
  661. break;
  662. }
  663. case "@lc":
  664. {
  665. LevelControl lc = new LevelControl();
  666. lc.ShowDialog();
  667. break;
  668. }
  669. case "@hema":
  670. {
  671. ElmistRo.Console.WriteLine("Server will restart after 10 minutes.");
  672. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 5 minute, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  673. System.Threading.Thread.Sleep(30000);
  674. Kernel.SendWorldMessage(new ElmistRo.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, 0x7db), Program.GamePool);
  675. System.Threading.Thread.Sleep(30000);
  676. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 4 minute, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  677. System.Threading.Thread.Sleep(30000);
  678. Kernel.SendWorldMessage(new ElmistRo.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, 0x7db), Program.GamePool);
  679. System.Threading.Thread.Sleep(30000);
  680. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 3 minute, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  681. System.Threading.Thread.Sleep(30000);
  682. Kernel.SendWorldMessage(new ElmistRo.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, 0x7db), Program.GamePool);
  683. System.Threading.Thread.Sleep(30000);
  684. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 2 minute, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  685. System.Threading.Thread.Sleep(30000);
  686. Kernel.SendWorldMessage(new ElmistRo.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, 0x7db), Program.GamePool);
  687. System.Threading.Thread.Sleep(30000);
  688. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 1 minute, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  689. System.Threading.Thread.Sleep(30000);
  690. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The server will be brought down for maintenance in 30 second, Please exit the game now.", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  691. ElmistRo.Console.WriteLine("Server will exit after 1 minute.");
  692. CommandsAI("@save");
  693. System.Threading.Thread.Sleep(0x7530);
  694. Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The Server restarted, Please log in after 2 minutes! ", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
  695. try
  696. {
  697. CommandsAI("@restart");
  698. }
  699. catch
  700. {
  701. ElmistRo.Console.WriteLine("Server cannot exit");
  702. }
  703. break;
  704. }
  705. case "@flushbans":
  706. {
  707. Database.IPBan.Load();
  708. break;
  709. }
  710. case "@alivetime":
  711. {
  712. DateTime now = DateTime.Now;
  713. TimeSpan t2 = new TimeSpan(StartDate.ToBinary());
  714. TimeSpan t1 = new TimeSpan(now.ToBinary());
  715. Console.WriteLine("The server has been online " + (int)(t1.TotalHours - t2.TotalHours) + " hours, " + (int)((t1.TotalMinutes - t2.TotalMinutes) % 60) + " minutes.");
  716. break;
  717. }
  718. case "@online":
  719. {
  720. Console.WriteLine("Online players count: " + Kernel.GamePool.Count);
  721. string line = "";
  722. foreach (Client.GameClient pClient in Program.GamePool)
  723. line += pClient.Entity.Name + ",";
  724. if (line != "")
  725. {
  726. line = line.Remove(line.Length - 1);
  727. Console.WriteLine("Players: " + line);
  728. }
  729. break;
  730. }
  731.  
  732. case "@memoryusage":
  733. {
  734. var proc = System.Diagnostics.Process.GetCurrentProcess();
  735. Console.WriteLine("Thread count: " + proc.Threads.Count);
  736. Console.WriteLine("Memory set(MB): " + ((double)((double)proc.WorkingSet64 / 1024)) / 1024);
  737. proc.Close();
  738. break;
  739. }
  740. case "@save":
  741. {
  742. ElmistRo.Database.JiangHu.SaveJiangHu();
  743. using (var conn = Database.DataHolder.MySqlConnection)
  744. {
  745. conn.Open();
  746. foreach (Client.GameClient client in Program.GamePool)
  747. {
  748. client.Quests.Save();
  749. InnerPowerTable.Save();
  750. client.Account.Save();
  751. Database.EntityTable.SaveEntity(client, conn);
  752. DailyQuest.Save(client);
  753. Database.DailyQuestTable.Save(client);
  754. Database.StorageTable.Save(client);
  755. Database.ActivenessTable.Save(client);
  756. TeamElitePk.TeamTournament.Save();
  757. TeamElitePk.SkillTeamTournament.Save();
  758. Database.SkillTable.SaveProficiencies(client, conn);
  759. CloudSaintsTable.Save(client);
  760. Database.SkillTable.SaveSpells(client, conn);
  761. Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, conn);
  762. Database.TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
  763. Database.ChampionTable.SaveStatistics(client.ChampionStats, conn);
  764. }
  765. }
  766. ClanWar.Save();
  767. //Database.StatueTable.Save();
  768. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  769. new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ServerKingdom", Kernel.ServerKingdom).Where("Server", Constants.ServerName).Execute();
  770. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("UnionID", ElmistRo.Network.GamePackets.Union.Union.UnionCounter.Now).Execute();
  771. Console.WriteLine("Saving Done.");
  772. }
  773. break;
  774. case "@skill":
  775. TeamElitePk.SkillTeamTournament.Open();
  776. using (IEnumerator<GameClient> enumerator = Kernel.GamePool.Values.GetEnumerator())
  777. {
  778. while (enumerator.MoveNext())
  779. {
  780. GameClient current = enumerator.Current;
  781. if (current.Team == null)
  782. current.Team = new ElmistRo.Game.ConquerStructures.Team();
  783. TeamElitePk.SkillTeamTournament.Join(current, (byte)3);
  784. }
  785. break;
  786. }
  787. case "@team":
  788. TeamElitePk.TeamTournament.Open();
  789. using (IEnumerator<GameClient> enumerator = Kernel.GamePool.Values.GetEnumerator())
  790. {
  791. while (enumerator.MoveNext())
  792. {
  793. GameClient current = enumerator.Current;
  794. if (current.Team == null)
  795. current.Team = new ElmistRo.Game.ConquerStructures.Team();
  796. TeamElitePk.TeamTournament.Join(current, (byte)3);
  797. }
  798. break;
  799. }
  800. case "@playercap":
  801. {
  802. try
  803. {
  804. PlayerCap = int.Parse(data[1]);
  805. }
  806. catch
  807. {
  808.  
  809. }
  810. break;
  811. }
  812.  
  813. case "@exit":
  814. {
  815. Database.JiangHu.SaveJiangHu();
  816. CommandsAI("@save");
  817. using (var conn = Database.DataHolder.MySqlConnection)
  818. {
  819. conn.Open();
  820. foreach (Client.GameClient client in Program.GamePool)
  821. {
  822. client.Quests.Save();
  823. Database.EntityTable.SaveEntity(client, conn);
  824. DailyQuest.Save(client);
  825. StorageTable.Save(client);
  826. Database.SkillTable.SaveProficiencies(client, conn);
  827. Database.SkillTable.SaveSpells(client, conn);
  828. Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, conn);
  829. Database.TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
  830. Database.ChampionTable.SaveStatistics(client.ChampionStats, conn);
  831. }
  832.  
  833. }
  834. ClanWar.Save();
  835. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  836. Database.EntityVariableTable.Save(0, Vars);
  837. GameServer.Disable();
  838. AuthServer.Disable();
  839.  
  840. var WC = Program.GamePool.ToArray();
  841. foreach (Client.GameClient client in WC)
  842. client.Disconnect();
  843.  
  844. if (GuildWar.IsWar)
  845. GuildWar.End();
  846. if (PoleTwin.IsWar)
  847. PoleTwin.End();
  848. if (PolePhoenix.IsWar)
  849. PolePhoenix.End();
  850. if (PoleApe.IsWar)
  851. PoleApe.End();
  852. if (PoleBird.IsWar)
  853. PoleBird.End();
  854. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  855.  
  856. Environment.Exit(0);
  857. }
  858. break;
  859. case "@dc":
  860. {
  861. CommandsAI("@save");
  862. CommandsAI("@exit");
  863. }
  864. break;
  865. case "@showips":
  866. {
  867. bool f = !AuthServer.PrintoutIPs;
  868. AuthServer.PrintoutIPs = GameServer.PrintoutIPs = f;
  869. Console.WriteLine(string.Format("Showing forcing IPs? {0}", f));
  870. break;
  871. }
  872. case "@pressure":
  873. {
  874. Console.WriteLine("Genr: " + World.GenericThreadPool.ToString());
  875. Console.WriteLine("Send: " + World.SendPool.ToString());
  876. Console.WriteLine("Recv: " + World.ReceivePool.ToString());
  877. break;
  878. }
  879. case "@load":
  880. {
  881. using (var conn = Database.DataHolder.MySqlConnection)
  882. {
  883. conn.Open();
  884. foreach (Client.GameClient client in Program.GamePool)
  885. {
  886. client.Account.Save();
  887.  
  888. Database.SkillTable.LoadProficiencies(client, conn);
  889. Database.SkillTable.LoadSpells(client, conn);
  890. }
  891. }
  892. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  893. }
  894. break;
  895. case "@restart":
  896. {
  897. CommandsAI("@save");
  898. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  899.  
  900. GameServer.Disable();
  901. AuthServer.Disable();
  902.  
  903. var WC = Program.GamePool.ToArray();
  904. foreach (Client.GameClient client in WC)
  905. client.Disconnect();
  906.  
  907. if (GuildWar.IsWar)
  908. GuildWar.End();
  909. if (PoleTwin.IsWar)
  910. PoleTwin.End();
  911. if (PolePhoenix.IsWar)
  912. PolePhoenix.End();
  913. if (PoleApe.IsWar)
  914. PoleApe.End();
  915. if (PoleBird.IsWar)
  916. PoleBird.End();
  917. ClanWar.Save();
  918. new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
  919.  
  920. Application.Restart();
  921. Environment.Exit(0);
  922. }
  923. break;
  924. case "@account":
  925. {
  926. Database.AccountTable account = new AccountTable(data[1]);
  927. account.Password = data[2];
  928. account.State = AccountTable.AccountState.Player;
  929. account.Save();
  930. }
  931. break;
  932. case "@process":
  933. {
  934. HandleClipboardPacket(command);
  935. break;
  936. }
  937. }
  938. }
  939.  
  940. public static void HandleClipboardPacket(string cmd)
  941. {
  942. string[] pData = cmd.Split(' ');
  943. long off = 0, type = 0, val = 0;
  944. if (pData.Length > 1)
  945. {
  946. string[] oData = pData[1].Split(':');
  947. if (oData.Length == 3)
  948. {
  949. off = long.Parse(oData[0]);
  950. type = long.Parse(oData[1]);
  951. if (oData[2] == "u")
  952. val = 1337;
  953. else
  954. val = long.Parse(oData[2]);
  955. }
  956. }
  957. string Data = OSClipboard.GetText();
  958. string[] num = Data.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  959. byte[] packet = new byte[num.Length + 8];
  960. for (int i = 0; i < num.Length; i++)
  961. packet[i] = byte.Parse(num[i], System.Globalization.NumberStyles.HexNumber);
  962. Writer.WriteUInt16((ushort)(packet.Length - 8), 0, packet);
  963. if (off != 0)
  964. {
  965. switch (type)
  966. {
  967. case 1:
  968. {
  969. packet[(int)off] = (byte)val;
  970. break;
  971. }
  972. case 2:
  973. {
  974. Writer.WriteUInt16((ushort)val, (int)off, packet);
  975. break;
  976. }
  977. case 4:
  978. {
  979. Writer.WriteUInt32((uint)val, (int)off, packet);
  980. break;
  981. }
  982. case 8:
  983. {
  984. Writer.WriteUInt64((ulong)val, (int)off, packet);
  985. break;
  986. }
  987. }
  988. }
  989. foreach (var client in Program.GamePool)
  990. {
  991. if (val == 1337 && type == 4)
  992. Writer.WriteUInt32(client.Entity.UID, (int)off, packet);
  993. client.Send(packet);
  994. }
  995. }
  996. static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
  997. {
  998. if (obj.Connector == null)
  999. {
  1000. obj.Disconnect();
  1001. return;
  1002. }
  1003.  
  1004. Client.GameClient Client = obj.Connector as Client.GameClient;
  1005.  
  1006. if (Client.Exchange)
  1007. {
  1008. Client.Exchange = false;
  1009. Client.Action = 1;
  1010. var crypto = new Network.Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
  1011. byte[] otherData = new byte[length];
  1012. Array.Copy(buffer, otherData, length);
  1013. crypto.Decrypt(otherData, length);
  1014.  
  1015. bool extra = false;
  1016. int pos = 0;
  1017. if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
  1018. {
  1019. pos = length - 140;
  1020. Client.Cryptography.Decrypt(buffer, length);
  1021. }
  1022. else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet
  1023. {
  1024. pos = length - 176;
  1025. extra = true;
  1026. Client.Cryptography.Decrypt(buffer, length - 36);
  1027. }
  1028. int len = BitConverter.ToInt32(buffer, pos); pos += 4;
  1029. if (len != 128)
  1030. {
  1031. Client.Disconnect();
  1032. return;
  1033. }
  1034. byte[] pubKey = new byte[128];
  1035. for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
  1036.  
  1037. string PubKey = System.Text.Encoding.Default.GetString(pubKey);
  1038. Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
  1039.  
  1040. if (extra)
  1041. {
  1042. byte[] data = new byte[36];
  1043. Buffer.BlockCopy(buffer, length - 36, data, 0, 36);
  1044. processData(data, 36, Client);
  1045. }
  1046. }
  1047. else
  1048. {
  1049. processData(buffer, length, Client);
  1050. }
  1051. }
  1052.  
  1053. //private static void processData(byte[] buffer, int length, Client.GameClient Client)
  1054. //{
  1055. // Client.Cryptography.Decrypt(buffer, length);
  1056. // Client.Queue.Enqueue(buffer, length);
  1057. // if (Client.Queue.CurrentLength > 1224)
  1058. // {
  1059. // Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
  1060. // Client.Disconnect();
  1061. // return;
  1062. // }
  1063. // while (Client.Queue.CanDequeue())
  1064. // {
  1065. // byte[] data = Client.Queue.Dequeue();
  1066. // if(data != null)
  1067. // if (Client != null)
  1068. // Network.PacketHandler.HandlePacket(data, Client);
  1069. // }
  1070. //}
  1071. private static void processData(byte[] buffer, int length, Client.GameClient Client)
  1072. {
  1073. Client.Cryptography.Decrypt(buffer, length);
  1074. Client.Queue.Enqueue(buffer, length);
  1075. if (Client.Queue.CurrentLength > 1224)
  1076. {
  1077. Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
  1078. Client.Disconnect();
  1079. return;
  1080. }
  1081. while (Client.Queue.CanDequeue())
  1082. {
  1083. byte[] data = Client.Queue.Dequeue();
  1084. Network.PacketHandler.HandlePacket(data, Client);
  1085. }
  1086. }
  1087.  
  1088. static void GameServer_OnClientConnect(ClientWrapper obj)
  1089. {
  1090. Client.GameClient client = new Client.GameClient(obj);
  1091. client.Send(client.DHKeyExchange.CreateServerKeyPacket());
  1092. obj.Connector = client;
  1093. }
  1094. static void GameServer_OnClientDisconnect(ClientWrapper obj)
  1095. {
  1096. if (obj.Connector != null)
  1097. (obj.Connector as Client.GameClient).Disconnect();
  1098. else
  1099. obj.Disconnect();
  1100. }
  1101.  
  1102. static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
  1103. {
  1104. var player = arg3.Connector as Client.AuthClient;
  1105. AuthClient authClient = arg3.Connector as AuthClient;
  1106. player.Cryptographer.Decrypt(buffer, length);
  1107. player.Queue.Enqueue(buffer, length);
  1108. while (player.Queue.CanDequeue())
  1109. {
  1110. byte[] packet = player.Queue.Dequeue();
  1111.  
  1112. ushort len = BitConverter.ToUInt16(packet, 0);
  1113. ushort id = BitConverter.ToUInt16(packet, 2);
  1114.  
  1115. if (len == 312)
  1116. {
  1117. player.Info = new Authentication();
  1118. player.Info.Deserialize(packet);
  1119. player.Account = new AccountTable(player.Info.Username);
  1120. msvcrt.msvcrt.srand(player.PasswordSeed);
  1121. if (!BruteForceProtection.AcceptJoin(arg3.IP))
  1122. {
  1123. Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" }));
  1124. arg3.Disconnect();
  1125. break;
  1126. }
  1127. Forward Fw = new Forward();
  1128. if (player.Account.Password == player.Info.Password && player.Account.exists)
  1129. {
  1130. Fw.Type = Forward.ForwardType.Ready;
  1131. }
  1132. else
  1133. {
  1134. BruteForceProtection.ClientRegistred(arg3.IP);
  1135. Fw.Type = Forward.ForwardType.InvalidInfo;
  1136. }
  1137. if (IPBan.IsBanned(arg3.IP))
  1138. {
  1139. Fw.Type = Forward.ForwardType.Banned;
  1140. player.Send(Fw);
  1141. return;
  1142. }
  1143. if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready)
  1144. {
  1145. Fw.Identifier = player.Account.GenerateKey();
  1146. Kernel.AwaitingPool[Fw.Identifier] = player.Account;
  1147. Fw.IP = GameIP;
  1148. Fw.Port = GamePort;
  1149. }
  1150. player.Send(Fw);
  1151. }
  1152. }
  1153. }
  1154.  
  1155. static void AuthServer_OnClientDisconnect(ClientWrapper obj)
  1156. {
  1157. obj.Disconnect();
  1158. }
  1159.  
  1160. static void AuthServer_OnClientConnect(ClientWrapper obj)
  1161. {
  1162. Client.AuthClient authState;
  1163. obj.Connector = (authState = new Client.AuthClient(obj));
  1164. authState.Cryptographer = new Network.Cryptography.AuthCryptography();
  1165. Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
  1166. pcs.Seed = Kernel.Random.Next();
  1167. authState.PasswordSeed = pcs.Seed;
  1168. authState.Send(pcs);
  1169. }
  1170.  
  1171. internal static Client.GameClient FindClient(string name)
  1172. {
  1173. return GamePool.FirstOrDefault(p => p.Entity.LoweredName == name);
  1174. }
  1175. }
  1176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement