Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Windows.Forms;
- using ElmistRo.Network;
- using ElmistRo.Database;
- using ElmistRo.Network.Sockets;
- using ElmistRo.Network.AuthPackets;
- using ElmistRo.Game.ConquerStructures.Society;
- using ElmistRo.Game;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Threading;
- using ElmistRo.Interfaces;
- using System.Text;
- using ElmistRo.Network.GamePackets;
- using ElmistRo.Client;
- using ElmistRo.Game.Features.Tournaments;
- namespace ElmistRo
- {
- class Program
- {
- public static void WriteLine(string Line)
- {
- try
- {
- Console.WriteLine(Line);
- }
- catch { }
- }
- public static bool CpuUsageTimer = true;
- public static MemoryCompressor MCompressor = new MemoryCompressor();
- public static int CpuUse = 0;
- public static string DBName = "";
- public static string DBUser = "";
- public static string DBPass = "";
- public static Encoding Encoding = Encoding.GetEncoding("iso-8859-1");
- [DllImport("user32.dll")]
- public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
- [DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- public static int PlayerCap = 800;
- public static ServerSocket AuthServer;
- public static ServerSocket GameServer;
- public static Counter EntityUID;
- public static long WeatherType = 0L;
- public static string GameIP;
- public static bool ClanTeam = false;
- public static bool IsBetweenTwoPoints(ushort x, ushort y, ushort startx, ushort starty, ushort endx, ushort endy)
- {
- return (((x >= startx) && (y >= starty)) && ((x <= endx) && (y <= endy)));
- }
- public static DayOfWeek Today;
- public static ushort GamePort;
- public static ushort AuthPort;
- //public static LookOut LookOut;
- public static DateTime StartDate;
- public static uint ScreenColor = 0;
- public static DateTime RestartDate = DateTime.Now.AddHours(24);
- public static World World;
- public static Client.GameClient[] GamePool = new Client.GameClient[0];
- public static VariableVault Vars;
- public static long MaxOn = 0;
- public static int RandomSeed = 0;
- private static Native.ConsoleEventHandler ElmistRoHandler;
- private static bool ElmistRoConsole_CloseEvent(CtrlType sig)
- {
- try
- {
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
- ElmistRo.Database.JiangHu.SaveJiangHu();
- //Database.StatueTable.Save();
- var count = Kernel.GamePool.Count;
- foreach (var client in Program.GamePool)
- {
- client.Quests.Save();
- InnerPowerTable.Save();
- DailyQuest.Save(client);
- StorageTable.Save(client);
- CloudSaintsTable.Save(client);;
- client.Disconnect();
- }
- GameServer.Disable();
- AuthServer.Disable();
- if (GuildWar.IsWar)
- GuildWar.End();
- if (PoleTwin.IsWar)
- PoleTwin.End();
- if (PolePhoenix.IsWar)
- PolePhoenix.End();
- if (PoleApe.IsWar)
- PoleApe.End();
- if (PoleBird.IsWar)
- PoleBird.End();
- EntityVariableTable.Save(0, Program.Vars);
- new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration")
- .Set("ItemUID", ConquerItem.ItemUID.Now)
- .Where("Server", Constants.ServerName)
- .Execute();
- Console.WriteLine("Saved {" + count + "} characters successfully.");
- Thread.Sleep(20000);
- return true;
- }
- catch (Exception P)
- {
- Console.WriteLine(P);
- return false;
- }
- }
- #region Attack[Conntrol]
- public static double double_25 = 0.0;
- public static double double_26 = 0.0;
- public static double double_27 = 0.0;
- public static double double_28 = 0.0;
- public static int int_2 = 0;
- public static int int_3 = 0;
- public static int int_4 = 0;
- #endregion
- static void Main(string[] args)
- {
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Time64 Start = Time64.Now;
- RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2));
- Kernel.Random = new FastRandom(RandomSeed);
- StartDate = DateTime.Now;
- Console.Title = " > "+Constants.ServerName+"|OnlinE < "; Console.BackgroundColor = ConsoleColor.Red;
- Console.ForegroundColor = ConsoleColor.Red;
- IntPtr hWnd = FindWindow(null, Console.Title);
- Console.WriteLine("-- This SourcE Has BeeN Edited By ElmistRo. --");
- Console.WriteLine("------- Thank You For Allah With Help -------");
- Console.WriteLine("----- Copyright (c) ElmistRo|OnlinE . -----");
- Console.BackgroundColor = ConsoleColor.Black;
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Load server configuration! !");
- string ConfigFileName = "configuration.ini";
- IniFile IniFile = new IniFile(ConfigFileName);
- GameIP = IniFile.ReadString("configuration", "IP");
- GamePort = IniFile.ReadUInt16("configuration", "GamePort");
- AuthPort = IniFile.ReadUInt16("configuration", "AuthPort");
- Constants.ServerName = IniFile.ReadString("configuration", "ServerName");
- ElmistRo.Database.JiangHu.LoadJiangHu();
- ElmistRo.Database.JiangHu.LoadStatus();
- Database.DataHolder.CreateConnection();
- EntityUID = new Counter(0);
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("configuration").Where("Server", Constants.ServerName);
- using (MySqlReader r = new MySqlReader(cmd))
- {
- if (r.Read())
- {
- EntityUID = new Counter(r.ReadUInt32("EntityID"));
- Game.ConquerStructures.Society.Guild.GuildCounter = new ElmistRo.Counter(r.ReadUInt32("GuildID"));
- ElmistRo.Network.GamePackets.Union.Union.UnionCounter = new Counter(r.ReadUInt32("UnionID"));
- Kernel.ServerKingdom = r.ReadUInt32("ServerKingdom");
- Network.GamePackets.ConquerItem.ItemUID = new ElmistRo.Counter(r.ReadUInt32("ItemUID"));
- Constants.ExtraExperienceRate = r.ReadUInt32("ExperienceRate");
- Constants.ExtraSpellRate = r.ReadUInt32("ProficiencyExperienceRate");
- Constants.ExtraProficiencyRate = r.ReadUInt32("SpellExperienceRate");
- Constants.MoneyDropRate = r.ReadUInt32("MoneyDropRate");
- Constants.MoneyDropMultiple = r.ReadUInt32("MoneyDropMultiple");
- Constants.ConquerPointsDropRate = r.ReadUInt32("ConquerPointsDropRate");
- Constants.ConquerPointsDropMultiple = r.ReadUInt32("ConquerPointsDropMultiple");
- Constants.ItemDropRate = r.ReadUInt32("ItemDropRate");
- Constants.ItemDropQualityRates = r.ReadString("ItemDropQualityString").Split('~');
- Constants.WebAccExt = r.ReadString("AccountWebExt");
- Constants.WebVoteExt = r.ReadString("VoteWebExt");
- Constants.WebDonateExt = r.ReadString("DonateWebExt");
- Constants.ServerWebsite = r.ReadString("ServerWebsite");
- PlayerCap = r.ReadInt32("PlayerCap");
- Database.EntityVariableTable.Load(0, out Vars);
- }
- }
- }
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- if (GameIP == "192.168.1.5")
- {
- Console.WriteLine("Login Success!");
- }
- else
- {
- Environment.Exit(0);
- }
- if (EntityUID.Now == 0)
- {
- Console.Clear();
- Console.WriteLine("Database error. Please check your MySQL. Server will now close.");
- Console.ReadLine();
- return;
- }
- {
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Console.WriteLine("Initializing database.");
- World = new World();
- World.Init();
- Console.WriteLine("Checking LastItem UID.");
- ElmistRo.Soul.SoulProtection.Load();
- Database.PerfectionTable.Load();
- QuestInfo.Load();
- Console.WriteLine("Checking SoulProtection Load.");
- Console.WriteLine("Checking Perfection Load.");
- WayofHeroes.Load();
- Database.ConquerItemTable.ClearNulledItems();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- PlayersVot.LoadPlayersVots();
- Database.ConquerItemInformation.Load();
- Database.NameChange.UpdateNames();
- Database.DataHolder.ReadStats();
- Database.MonsterInformation.Load();
- Database.IPBan.Load();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- //Messagess.Load();
- Database.HelpDesk.Load();
- //Database.GameUpdatess.Load();
- Database.SpellTable.Load();
- Database.ShopFile.Load();
- Database.HonorShop.Load();
- // Database.StatueTable.Load();
- Database.RacePointShop.Load();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Database.ChampionShop.Load();
- Database.EShopFile.Load();
- Database.EShopV2File.Load();
- Database.MapsTable.Load();
- Database.NobilityTable.Load();
- Database.ArenaTable.Load();
- Database.TeamArenaTable.Load();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Database.ChampionTable.Load();
- Database.GuildTable.Load();
- ElmistRo.Network.GamePackets.Union.UnionTable.Load();
- Database.LotteryTable.Load();
- Database.SignInTable.Load();
- Console.WriteLine("ClanArena Table Loaded.");
- Database.DROP_SOULS.LoadDrops();
- Database.ChiTable.LoadAllChi();
- Console.WriteLine("Chi Table Loaded.");
- Console.WriteLine("ClanArena Table Loaded.");
- Database.PoketTables.LoadTables();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Kernel.QuizShow = new Game.ConquerStructures.QuizShow();
- Refinery.Load();
- BruteForceProtection.CreatePoll();
- Map.CreateTimerFactories();
- Database.DMaps.Load();
- ClanWar.Create();
- InnerPowerTable.LoadDBInformation();
- InnerPowerTable.Load();
- Game.Screen.CreateTimerFactories();
- StorageManager.Load();
- Database.storageItem.Load();
- WarDrobe.Load();
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- GamePool = new Client.GameClient[0];
- new Game.Map(1002, Database.DMaps.MapPaths[1002]);
- new Game.Map(1038, Database.DMaps.MapPaths[1038]);
- new Game.Map(2071, Database.DMaps.MapPaths[2071]);
- new Map(2078, DMaps.MapPaths[1000]);
- Game.GuildWar.Initiate();
- //Game.SuperGuildWar.Initiate();
- // Game.PoleTwin.Initiate();
- //Game.DecPole.DecPoleIni();
- ///Game.PolePhoenix.Initiate();
- // Game.PoleApe.Initiate();
- // Game.PoleBird.Initiate();
- new Game.Map(CrossServer.mapid, Database.DMaps.MapPaths[CrossServer.mapid]);
- Game.CrossServer.Initiate();
- new Game.Map(1509, Database.DMaps.MapPaths[1509]);
- new Game.Map(10002, 2021, Database.DMaps.MapPaths[2021]);
- new Game.Map(8883, 1004, Database.DMaps.MapPaths[1004]);
- Constants.PKFreeMaps.Add(8883);
- Constants.PKFreeMaps.Add(CrossServer.mapid);
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Game.ClanWar2.Initiate();
- Game.EliteGuildWar.EliteGwint();
- Console.WriteLine("Elite Guild war initializated.");
- Console.WriteLine("Guild war initializated.");
- Console.WriteLine("PoleTwin War initilizated.");
- Console.WriteLine("PolePhoenix War initilizated.");
- Console.WriteLine("PoleApe War initilizated.");
- Console.WriteLine("PoleBird War initilizated.");
- Console.WriteLine("Loading Game Clans.");
- Clan.LoadClans();
- House.LoadHouses();
- Console.WriteLine("House Table Loaded.");
- Database.ReincarnationTable.Load();
- new MsgUserAbilityScore().GetRankingList();
- new MsgEquipRefineRank().UpdateRanking();
- //PrestigeRank.LoadRanking();
- Console.WriteLine("Reincarnate Table Loaded.");
- Console.WriteLine("Flower Table Loaded.");
- Console.WriteLine("JiangHu Hu Loaded Successfully");
- Console.WriteLine("Computing npc dialogues!");
- {
- ElmistRo.Client.GameClient gc = new ElmistRo.Client.GameClient(new ClientWrapper());
- gc.Account = new AccountTable("NONE");
- gc.Socket.Alive = false;
- gc.Entity = new Entity(EntityFlag.Player, false) { Name = "NONE" };
- Npcs.GetDialog(new NpcRequest(), gc, true);
- }
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Console.WriteLine("Computing npc's succeeded.");
- Database.StaticShop.LoadStatitcStalls();
- Console.WriteLine("Loading Booths");
- Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
- World.CreateTournaments();
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Create();
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Create();
- Console.WriteLine("TeamPk Loaded Successfully");
- Console.WriteLine("SkillTeam Loaded Successfully");
- ElmistRoHandler += ElmistRoConsole_CloseEvent;
- Native.SetConsoleCtrlHandler(ElmistRoHandler, true);
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Execute();
- Console.WriteLine("Initializing sockets.");
- AuthServer = new ServerSocket();
- AuthServer.OnClientConnect += AuthServer_OnClientConnect;
- AuthServer.OnClientReceive += AuthServer_OnClientReceive;
- AuthServer.OnClientDisconnect += AuthServer_OnClientDisconnect;
- AuthServer.Enable(AuthPort, "0.0.0.0");
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- GameServer = new ServerSocket();
- GameServer.OnClientConnect += GameServer_OnClientConnect;
- GameServer.OnClientReceive += GameServer_OnClientReceive;
- GameServer.OnClientDisconnect += GameServer_OnClientDisconnect;
- GameServer.Enable(GamePort, "0.0.0.0");
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- Console.WriteLine("Auth server online.");
- Console.WriteLine("Game server online.");
- Console.WriteLine("-------------------------------------");
- Console.WriteLine("Server loaded in " + (Time64.Now - Start) + " milliseconds.");
- /////////////////////////////Cpu//////////////////////////////
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- Program.MCompressor.Optimize(); Program.MCompressor.Optimize();
- /////////////////////////////Cpu//////////////////////////////
- GC.Collect();
- WorkConsole();
- {
- }
- }
- }
- #region Exceptions & Logs
- public static void AddCpsWin(string text)
- {
- try
- {
- text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\AddWinCps\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- fs.Close();
- }
- }
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
- {
- file.WriteLine(text);
- file.Close();
- }
- }
- catch (Exception ex) { Console.WriteLine(ex); }
- }
- public static void AddVendorLog(String vendor, string buying, string moneyamount, ConquerItem Item)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\VendorLogs\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- fs.Close();
- }
- }
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
- {
- file.WriteLine("------------------------------------------------------------------------------------");
- file.WriteLine("{0} HAS BOUGHT AN ITEM : {2} FROM {1} SHOP - for {3}", vendor, buying, Item.ToLog(), moneyamount);
- file.WriteLine("------------------------------------------------------------------------------------");
- }
- }
- public static void AddGMCommand(string gm, string commandStr)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\GMCommandsLog\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- fs.Close();
- }
- }
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
- {
- file.WriteLine(gm + commandStr);
- }
- }
- public static void AddDropLog(String Name, ConquerItem Item)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\droplogs\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- string path = NewPath + "\\" + DateTime.Now.Day + ".txt";
- if (!File.Exists(path)) File.AppendAllText(path, "");
- string text = "------------------------------------------------------------------------------------"
- + Environment.NewLine + string.Format("Player {0} HAS DROPPED AN ITEM : {1} -", Name, Item.ToLog())
- + Environment.NewLine + "------------------------------------------------------------------------------------";
- File.AppendAllText(path, text);
- }
- public static void AddTradeLog(ElmistRo.Game.ConquerStructures.Trade first, String firstN, ElmistRo.Game.ConquerStructures.Trade second, String secondN)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\tradelogs\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- fs.Close();
- }
- }
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
- {
- file.WriteLine("************************************************************************************");
- file.WriteLine("First Person TradeLog ( {0} ) -", firstN);
- file.WriteLine("Gold Traded: " + first.Money);
- file.WriteLine("Conquer Points Traded: " + first.ConquerPoints);
- for (int i = 0; i < first.Items.Count; i++)
- {
- file.WriteLine("------------------------------------------------------------------------------------");
- file.WriteLine("Item : " + first.Items[i].ToLog());
- file.WriteLine("------------------------------------------------------------------------------------");
- }
- file.WriteLine("Second Person TradeLog ( {0} ) -", secondN);
- file.WriteLine("Gold Traded: " + second.Money);
- file.WriteLine("Conquer Points Traded: " + second.ConquerPoints);
- for (int i = 0; i < second.Items.Count; i++)
- {
- file.WriteLine("------------------------------------------------------------------------------------");
- file.WriteLine("Item : " + second.Items[i].ToLog());
- file.WriteLine("------------------------------------------------------------------------------------");
- }
- file.WriteLine("************************************************************************************");
- }
- }
- public static void AddWarLog(string War, string CPs, string name)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\Warlogs\\",
- NewPath = System.IO.Path.Combine(Path, folderN);
- if (!File.Exists(NewPath + folderN))
- {
- System.IO.Directory.CreateDirectory(System.IO.Path.Combine(Path, folderN));
- }
- if (!File.Exists(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- using (System.IO.FileStream fs = System.IO.File.Create(NewPath + "\\" + DateTime.Now.Day + ".txt"))
- {
- fs.Close();
- }
- }
- using (System.IO.StreamWriter file = new System.IO.StreamWriter(NewPath + "\\" + DateTime.Now.Day + ".txt", true))
- {
- file.WriteLine(name + " got " + CPs + " CPs from the [" + War + "] as prize at " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second);
- }
- }
- public static void BuyFromShop(string text)
- {
- string path2 = (string)(object)DateTime.Now.Year + (object)"-" + (string)(object)DateTime.Now.Month;
- string path1 = "gmlogs\\ShopBuy\\";
- string str = Path.Combine(path1, path2);
- if (!File.Exists(str + path2))
- Directory.CreateDirectory(Path.Combine(path1, path2));
- if (!File.Exists(string.Concat(new object[4]
- {
- (object) str,
- (object) "\\",
- (object) DateTime.Now.Day,
- (object) ".txt"
- })))
- {
- using (FileStream fileStream = File.Create(string.Concat(new object[4]
- {
- (object) str,
- (object) "\\",
- (object) DateTime.Now.Day,
- (object) ".txt"
- })))
- fileStream.Close();
- }
- using (StreamWriter streamWriter = new StreamWriter(string.Concat(new object[4]
- {
- (object) str,
- (object) "\\",
- (object) DateTime.Now.Day,
- (object) ".txt"
- }), true))
- streamWriter.WriteLine(text);
- }
- static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- SaveException(e.Exception);
- }
- public static void SaveException(Exception e, bool dont = false)
- {
- if (e.Message.Contains("String reference not set")) return;
- if (!dont)
- Console.WriteLine(e);
- if ((e.TargetSite.Name != "ThrowInvalidOperationException") && !e.Message.Contains("String reference not set"))
- {
- ElmistRo.Console.WriteLine(e);
- DateTime now = DateTime.Now;
- string str = string.Concat(new object[] { now.Month, "-", now.Day, "//" });
- if (!Directory.Exists(Application.StartupPath + @"database\exceptions\"))
- {
- Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\");
- }
- if (!Directory.Exists(Application.StartupPath + @"\database\exceptions\" + str))
- {
- Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\" + str);
- }
- if (!Directory.Exists(Application.StartupPath + @"\database\exceptions\" + str + e.TargetSite.Name))
- {
- Directory.CreateDirectory(Application.StartupPath + @"\database\exceptions\" + str + e.TargetSite.Name);
- }
- 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());
- }
- }
- #endregion
- private static void WorkConsole()
- {
- while (true)
- {
- try
- {
- CommandsAI(Console.ReadLine());
- }
- catch (Exception e) { Console.WriteLine(e); }
- }
- }
- public static DateTime LastRandomReset = DateTime.Now;
- public static Network.GamePackets.BlackSpotPacket BlackSpotPacket = new Network.GamePackets.BlackSpotPacket();
- public static bool MyPC = true;
- public static void CommandsAI(string command)
- {
- if (command == null)
- return;
- string[] data = command.Split(' ');
- switch (data[0])
- {
- case "@cp":
- {
- Controlpanel cp = new Controlpanel();
- cp.ShowDialog();
- break;
- }
- case "@teampk":
- {
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Open();
- foreach (var clien in Kernel.GamePool.Values)
- {
- if (clien.Team == null)
- clien.Team = new Game.ConquerStructures.Team();
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Join(clien, 3);
- }
- break;
- }
- case "@steampk":
- {
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Open();
- foreach (var clien in Kernel.GamePool.Values)
- {
- if (clien.Team == null)
- clien.Team = new Game.ConquerStructures.Team();
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Join(clien, 3);
- }
- break;
- }
- case "@lc":
- {
- LevelControl lc = new LevelControl();
- lc.ShowDialog();
- break;
- }
- case "@hema":
- {
- ElmistRo.Console.WriteLine("Server will restart after 10 minutes.");
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- ElmistRo.Console.WriteLine("Server will exit after 1 minute.");
- CommandsAI("@save");
- System.Threading.Thread.Sleep(0x7530);
- Kernel.SendWorldMessage(new ElmistRo.Network.GamePackets.Message("The Server restarted, Please log in after 2 minutes! ", System.Drawing.Color.Orange, 0x7db), Program.GamePool);
- try
- {
- CommandsAI("@restart");
- }
- catch
- {
- ElmistRo.Console.WriteLine("Server cannot exit");
- }
- break;
- }
- case "@flushbans":
- {
- Database.IPBan.Load();
- break;
- }
- case "@alivetime":
- {
- DateTime now = DateTime.Now;
- TimeSpan t2 = new TimeSpan(StartDate.ToBinary());
- TimeSpan t1 = new TimeSpan(now.ToBinary());
- Console.WriteLine("The server has been online " + (int)(t1.TotalHours - t2.TotalHours) + " hours, " + (int)((t1.TotalMinutes - t2.TotalMinutes) % 60) + " minutes.");
- break;
- }
- case "@online":
- {
- Console.WriteLine("Online players count: " + Kernel.GamePool.Count);
- string line = "";
- foreach (Client.GameClient pClient in Program.GamePool)
- line += pClient.Entity.Name + ",";
- if (line != "")
- {
- line = line.Remove(line.Length - 1);
- Console.WriteLine("Players: " + line);
- }
- break;
- }
- case "@memoryusage":
- {
- var proc = System.Diagnostics.Process.GetCurrentProcess();
- Console.WriteLine("Thread count: " + proc.Threads.Count);
- Console.WriteLine("Memory set(MB): " + ((double)((double)proc.WorkingSet64 / 1024)) / 1024);
- proc.Close();
- break;
- }
- case "@save":
- {
- ElmistRo.Database.JiangHu.SaveJiangHu();
- using (var conn = Database.DataHolder.MySqlConnection)
- {
- conn.Open();
- foreach (Client.GameClient client in Program.GamePool)
- {
- client.Quests.Save();
- InnerPowerTable.Save();
- client.Account.Save();
- Database.EntityTable.SaveEntity(client, conn);
- DailyQuest.Save(client);
- Database.DailyQuestTable.Save(client);
- Database.StorageTable.Save(client);
- Database.ActivenessTable.Save(client);
- TeamElitePk.TeamTournament.Save();
- TeamElitePk.SkillTeamTournament.Save();
- Database.SkillTable.SaveProficiencies(client, conn);
- CloudSaintsTable.Save(client);
- Database.SkillTable.SaveSpells(client, conn);
- Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, conn);
- Database.TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
- Database.ChampionTable.SaveStatistics(client.ChampionStats, conn);
- }
- }
- ClanWar.Save();
- //Database.StatueTable.Save();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ServerKingdom", Kernel.ServerKingdom).Where("Server", Constants.ServerName).Execute();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("UnionID", ElmistRo.Network.GamePackets.Union.Union.UnionCounter.Now).Execute();
- Console.WriteLine("Saving Done.");
- }
- break;
- case "@skill":
- TeamElitePk.SkillTeamTournament.Open();
- using (IEnumerator<GameClient> enumerator = Kernel.GamePool.Values.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- GameClient current = enumerator.Current;
- if (current.Team == null)
- current.Team = new ElmistRo.Game.ConquerStructures.Team();
- TeamElitePk.SkillTeamTournament.Join(current, (byte)3);
- }
- break;
- }
- case "@team":
- TeamElitePk.TeamTournament.Open();
- using (IEnumerator<GameClient> enumerator = Kernel.GamePool.Values.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- GameClient current = enumerator.Current;
- if (current.Team == null)
- current.Team = new ElmistRo.Game.ConquerStructures.Team();
- TeamElitePk.TeamTournament.Join(current, (byte)3);
- }
- break;
- }
- case "@playercap":
- {
- try
- {
- PlayerCap = int.Parse(data[1]);
- }
- catch
- {
- }
- break;
- }
- case "@exit":
- {
- Database.JiangHu.SaveJiangHu();
- CommandsAI("@save");
- using (var conn = Database.DataHolder.MySqlConnection)
- {
- conn.Open();
- foreach (Client.GameClient client in Program.GamePool)
- {
- client.Quests.Save();
- Database.EntityTable.SaveEntity(client, conn);
- DailyQuest.Save(client);
- StorageTable.Save(client);
- Database.SkillTable.SaveProficiencies(client, conn);
- Database.SkillTable.SaveSpells(client, conn);
- Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, conn);
- Database.TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
- Database.ChampionTable.SaveStatistics(client.ChampionStats, conn);
- }
- }
- ClanWar.Save();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- Database.EntityVariableTable.Save(0, Vars);
- GameServer.Disable();
- AuthServer.Disable();
- var WC = Program.GamePool.ToArray();
- foreach (Client.GameClient client in WC)
- client.Disconnect();
- if (GuildWar.IsWar)
- GuildWar.End();
- if (PoleTwin.IsWar)
- PoleTwin.End();
- if (PolePhoenix.IsWar)
- PolePhoenix.End();
- if (PoleApe.IsWar)
- PoleApe.End();
- if (PoleBird.IsWar)
- PoleBird.End();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- Environment.Exit(0);
- }
- break;
- case "@dc":
- {
- CommandsAI("@save");
- CommandsAI("@exit");
- }
- break;
- case "@showips":
- {
- bool f = !AuthServer.PrintoutIPs;
- AuthServer.PrintoutIPs = GameServer.PrintoutIPs = f;
- Console.WriteLine(string.Format("Showing forcing IPs? {0}", f));
- break;
- }
- case "@pressure":
- {
- Console.WriteLine("Genr: " + World.GenericThreadPool.ToString());
- Console.WriteLine("Send: " + World.SendPool.ToString());
- Console.WriteLine("Recv: " + World.ReceivePool.ToString());
- break;
- }
- case "@load":
- {
- using (var conn = Database.DataHolder.MySqlConnection)
- {
- conn.Open();
- foreach (Client.GameClient client in Program.GamePool)
- {
- client.Account.Save();
- Database.SkillTable.LoadProficiencies(client, conn);
- Database.SkillTable.LoadSpells(client, conn);
- }
- }
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- }
- break;
- case "@restart":
- {
- CommandsAI("@save");
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- GameServer.Disable();
- AuthServer.Disable();
- var WC = Program.GamePool.ToArray();
- foreach (Client.GameClient client in WC)
- client.Disconnect();
- if (GuildWar.IsWar)
- GuildWar.End();
- if (PoleTwin.IsWar)
- PoleTwin.End();
- if (PolePhoenix.IsWar)
- PolePhoenix.End();
- if (PoleApe.IsWar)
- PoleApe.End();
- if (PoleBird.IsWar)
- PoleBird.End();
- ClanWar.Save();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where("Server", Constants.ServerName).Execute();
- Application.Restart();
- Environment.Exit(0);
- }
- break;
- case "@account":
- {
- Database.AccountTable account = new AccountTable(data[1]);
- account.Password = data[2];
- account.State = AccountTable.AccountState.Player;
- account.Save();
- }
- break;
- case "@process":
- {
- HandleClipboardPacket(command);
- break;
- }
- }
- }
- public static void HandleClipboardPacket(string cmd)
- {
- string[] pData = cmd.Split(' ');
- long off = 0, type = 0, val = 0;
- if (pData.Length > 1)
- {
- string[] oData = pData[1].Split(':');
- if (oData.Length == 3)
- {
- off = long.Parse(oData[0]);
- type = long.Parse(oData[1]);
- if (oData[2] == "u")
- val = 1337;
- else
- val = long.Parse(oData[2]);
- }
- }
- string Data = OSClipboard.GetText();
- string[] num = Data.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- byte[] packet = new byte[num.Length + 8];
- for (int i = 0; i < num.Length; i++)
- packet[i] = byte.Parse(num[i], System.Globalization.NumberStyles.HexNumber);
- Writer.WriteUInt16((ushort)(packet.Length - 8), 0, packet);
- if (off != 0)
- {
- switch (type)
- {
- case 1:
- {
- packet[(int)off] = (byte)val;
- break;
- }
- case 2:
- {
- Writer.WriteUInt16((ushort)val, (int)off, packet);
- break;
- }
- case 4:
- {
- Writer.WriteUInt32((uint)val, (int)off, packet);
- break;
- }
- case 8:
- {
- Writer.WriteUInt64((ulong)val, (int)off, packet);
- break;
- }
- }
- }
- foreach (var client in Program.GamePool)
- {
- if (val == 1337 && type == 4)
- Writer.WriteUInt32(client.Entity.UID, (int)off, packet);
- client.Send(packet);
- }
- }
- static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
- {
- if (obj.Connector == null)
- {
- obj.Disconnect();
- return;
- }
- Client.GameClient Client = obj.Connector as Client.GameClient;
- if (Client.Exchange)
- {
- Client.Exchange = false;
- Client.Action = 1;
- var crypto = new Network.Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
- byte[] otherData = new byte[length];
- Array.Copy(buffer, otherData, length);
- crypto.Decrypt(otherData, length);
- bool extra = false;
- int pos = 0;
- if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
- {
- pos = length - 140;
- Client.Cryptography.Decrypt(buffer, length);
- }
- else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet
- {
- pos = length - 176;
- extra = true;
- Client.Cryptography.Decrypt(buffer, length - 36);
- }
- int len = BitConverter.ToInt32(buffer, pos); pos += 4;
- if (len != 128)
- {
- Client.Disconnect();
- return;
- }
- byte[] pubKey = new byte[128];
- for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
- string PubKey = System.Text.Encoding.Default.GetString(pubKey);
- Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
- if (extra)
- {
- byte[] data = new byte[36];
- Buffer.BlockCopy(buffer, length - 36, data, 0, 36);
- processData(data, 36, Client);
- }
- }
- else
- {
- processData(buffer, length, Client);
- }
- }
- //private static void processData(byte[] buffer, int length, Client.GameClient Client)
- //{
- // Client.Cryptography.Decrypt(buffer, length);
- // Client.Queue.Enqueue(buffer, length);
- // if (Client.Queue.CurrentLength > 1224)
- // {
- // Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
- // Client.Disconnect();
- // return;
- // }
- // while (Client.Queue.CanDequeue())
- // {
- // byte[] data = Client.Queue.Dequeue();
- // if(data != null)
- // if (Client != null)
- // Network.PacketHandler.HandlePacket(data, Client);
- // }
- //}
- private static void processData(byte[] buffer, int length, Client.GameClient Client)
- {
- Client.Cryptography.Decrypt(buffer, length);
- Client.Queue.Enqueue(buffer, length);
- if (Client.Queue.CurrentLength > 1224)
- {
- Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
- Client.Disconnect();
- return;
- }
- while (Client.Queue.CanDequeue())
- {
- byte[] data = Client.Queue.Dequeue();
- Network.PacketHandler.HandlePacket(data, Client);
- }
- }
- static void GameServer_OnClientConnect(ClientWrapper obj)
- {
- Client.GameClient client = new Client.GameClient(obj);
- client.Send(client.DHKeyExchange.CreateServerKeyPacket());
- obj.Connector = client;
- }
- static void GameServer_OnClientDisconnect(ClientWrapper obj)
- {
- if (obj.Connector != null)
- (obj.Connector as Client.GameClient).Disconnect();
- else
- obj.Disconnect();
- }
- static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
- {
- var player = arg3.Connector as Client.AuthClient;
- AuthClient authClient = arg3.Connector as AuthClient;
- player.Cryptographer.Decrypt(buffer, length);
- player.Queue.Enqueue(buffer, length);
- while (player.Queue.CanDequeue())
- {
- byte[] packet = player.Queue.Dequeue();
- ushort len = BitConverter.ToUInt16(packet, 0);
- ushort id = BitConverter.ToUInt16(packet, 2);
- if (len == 312)
- {
- player.Info = new Authentication();
- player.Info.Deserialize(packet);
- player.Account = new AccountTable(player.Info.Username);
- msvcrt.msvcrt.srand(player.PasswordSeed);
- if (!BruteForceProtection.AcceptJoin(arg3.IP))
- {
- Console.WriteLine(string.Concat(new string[] { "Client > ", player.Info.Username, "was blocked address", arg3.IP, "!" }));
- arg3.Disconnect();
- break;
- }
- Forward Fw = new Forward();
- if (player.Account.Password == player.Info.Password && player.Account.exists)
- {
- Fw.Type = Forward.ForwardType.Ready;
- }
- else
- {
- BruteForceProtection.ClientRegistred(arg3.IP);
- Fw.Type = Forward.ForwardType.InvalidInfo;
- }
- if (IPBan.IsBanned(arg3.IP))
- {
- Fw.Type = Forward.ForwardType.Banned;
- player.Send(Fw);
- return;
- }
- if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready)
- {
- Fw.Identifier = player.Account.GenerateKey();
- Kernel.AwaitingPool[Fw.Identifier] = player.Account;
- Fw.IP = GameIP;
- Fw.Port = GamePort;
- }
- player.Send(Fw);
- }
- }
- }
- static void AuthServer_OnClientDisconnect(ClientWrapper obj)
- {
- obj.Disconnect();
- }
- static void AuthServer_OnClientConnect(ClientWrapper obj)
- {
- Client.AuthClient authState;
- obj.Connector = (authState = new Client.AuthClient(obj));
- authState.Cryptographer = new Network.Cryptography.AuthCryptography();
- Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
- pcs.Seed = Kernel.Random.Next();
- authState.PasswordSeed = pcs.Seed;
- authState.Send(pcs);
- }
- internal static Client.GameClient FindClient(string name)
- {
- return GamePool.FirstOrDefault(p => p.Entity.LoweredName == name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement