Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ☺ Created by MyThs
- // ☺ Copyright © 2010 - 2016 TQ Digital
- // ☺ MyThs - Project
- using System;
- using System.IO;
- using System.Linq;
- using System.Text;
- using COServer.Game;
- using COServer.Network;
- using COServer.Database;
- using System.Windows.Forms;
- using COServer.Network.Sockets;
- using System.Collections.Generic;
- using COServer.Network.AuthPackets;
- using MsgServer.Network.GamePackets.Union;
- using COServer.Network.GamePackets;
- using System.Runtime.InteropServices;
- using COserver;
- namespace COServer
- {
- public unsafe class Server
- {
- public static MemoryCompressor MCompressor = new MemoryCompressor();
- public static int CpuUse = 0;
- public static bool CpuUsageTimer = true;
- public static bool Ready = false;
- public static int MaxOn = 0;
- public static void UpdateConsoleTitle()
- {
- if (Kernel.GamePool.Count > Server.MaxOn)
- Server.MaxOn = Kernel.GamePool.Count;
- if (Kernel.GamePool.Count != 0)
- {
- Console.Title = "MyThs-Co[Hard] Online Players: [ " + Kernel.GamePool.Count + " ] Max Online: [ " + Server.MaxOn + " ]MyThs";
- }
- else if (Kernel.GamePool.Count == 0)
- {
- Console.Title = "MyThs-Co[Hard] No Online Players Now!! But Max Online: [ " + Server.MaxOn + " ]<<<";
- }
- }
- #region Poker
- public static void easteregg(string text)
- {
- try
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\PetApet\\",
- 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 AddpokerAllinCps(string text)
- {
- try
- {
- text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\AddpokerAllinCps\\",
- 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 AddpokerCps(string text)
- {
- try
- {
- text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\AddpokerCps\\",
- 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); }
- }
- #endregion
- public static void RemoveCps(string text)
- {
- try
- {
- text = "[" + DateTime.Now.ToString("HH:mm:ss") + "]" + text;
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month,
- Path = "gmlogs\\RemoveCps\\",
- 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 int PacketsReceived = 0, PacketsSent = 0;
- #region Definitions
- public static int PlayerCap = 0;
- public static int MaxPlayers = 0;
- public static ServerSocket[] AuthServer;
- public static ServerSocket GameServer;
- public static Counter EntityUID;
- public static string GameIP;
- public static DayOfWeek Today;
- public static ushort GamePort;
- public static List<ushort> AuthPort;
- public static DateTime StartDate;
- public static Thread Thread;
- public static VariableVault Vars;
- public static bool ALEXPC = false;
- public static bool uniquepk = false;
- public static int RandomSeed = 0;
- public static Encoding Encoding = ASCIIEncoding.Default;
- public static DateTime LastRandomReset = DateTime.Now;
- public static Client.GameState[] GamePool = new Client.GameState[0];
- public static Client.GameState[] Values = new Client.GameState[0];
- #endregion
- #region ConsoleHandler
- #region Closing Events
- [DllImport("Kernel32")]
- private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
- private delegate bool EventHandler(CtrlType sig);
- static EventHandler _handler;
- enum CtrlType
- {
- CTRL_C_EVENT = 0,
- CTRL_BREAK_EVENT = 1,
- CTRL_CLOSE_EVENT = 2,
- CTRL_LOGOFF_EVENT = 5,
- CTRL_SHUTDOWN_EVENT = 6
- }
- private static bool Handler(CtrlType sig)
- {
- if (MessageBox.Show("Are you sure you want to Exit ?", "MyThs", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- Console.WriteLine("Saving Before Exiting.......");
- return !Save();
- }
- return true;
- }
- #endregion
- public static bool Save()
- {
- try
- {
- AuctionBase.Save();
- Database.InnerPowerTable.Save();
- FamilyTournament.Save();
- FlowersTable.SaveFlowers();
- KongFuTable.SaveKongFu();
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
- foreach (var client in Server.GamePool)
- {
- EntityTable.SaveEntity(client);
- SkillTable.SaveProficiencies(client);
- Database.MailboxTable.Save(client);
- Database.ArenaTable.SaveArenaStatistics(client.ArenaStatistic, client.CP);
- // ArenaTable.SaveArenaStatistics(client.ArenaStatistic);
- Database.ActivenessTable.Save(client);
- TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic);
- NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
- using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("configuration");
- using (MySqlReader r = new MySqlReader(cmd))
- {
- if (r.Read())
- {
- 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();
- if (r.ReadByte("LastDailySignReset") != DateTime.Now.Month) MsgSignIn.Reset();
- }
- }
- }
- using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration"))
- cmd.Set("LastDailySignReset", DateTime.Now.Month).Execute();
- //if (restart)
- // {
- // Application.Restart();
- //Environment.Exit(0);
- // }
- //Environment.Exit(0);
- }
- Console.WriteLine("Saving Cmd Done.");
- new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- return false;
- }
- return true;
- }
- #endregion
- #region GameServer|AuthServer
- static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
- {
- if (obj.Connector == null)
- {
- obj.Disconnect();
- return;
- }
- Client.GameState Client = obj.Connector as Client.GameState;
- 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;
- try
- {
- 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);
- }
- }
- catch { }
- 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.GameState 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();
- PacketHandler.Process(data, Client);
- }
- }
- static void GameServer_OnClientConnect(ClientWrapper obj)
- {
- Client.GameState client = new Client.GameState(obj);
- client.Send(client.DHKeyExchange.CreateServerKeyPacket());
- obj.Connector = client;
- }
- static void GameServer_OnClientDisconnect(ClientWrapper obj)
- {
- if (obj.Connector != null)
- (obj.Connector as Client.GameState).Disconnect();
- else
- obj.Disconnect();
- }
- static void AuthServer_OnClientReceive(byte[] buffer, int length, ClientWrapper arg3)
- {
- var player = arg3.Connector as Client.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 (!LoginBruteForce.AcceptJoin(arg3.IP))
- {
- Console.WriteLine("Client -> ", player.Info.Username, " was bloked Adrres ", arg3.IP, "!");
- arg3.Disconnect();
- break;
- }
- Database.ServerInfo Server = null;
- Forward Fw = new Forward();
- if (ServerData.Servers.TryGetValue("MyThs", out Server))
- {
- if (!player.Account.exists)
- {
- Fw.Type = Forward.ForwardType.WrongAccount;
- player.Send(Fw);
- }
- if (player.Account.Password == player.Info.Password && player.Account.exists)
- {
- Fw.Type = Forward.ForwardType.Ready;
- }
- else
- {
- LoginBruteForce.ClientRegistred(arg3.IP);
- Fw.Type = Forward.ForwardType.InvalidInfo;
- }
- if (IPBan.IsBanned(arg3.IP) || player.Account.Banned)
- {
- Fw.Type = Forward.ForwardType.Banned;
- player.Send(Fw);
- return;
- }
- if (Fw.Type == Network.AuthPackets.Forward.ForwardType.Ready)
- {
- Client.GameState aClient;
- if (Kernel.GamePool.TryGetValue(Fw.Identifier, out aClient))
- {
- Fw.Type = Forward.ForwardType.InvalidInfo;
- aClient.Disconnect();
- player.Send(Fw);
- return;
- }
- 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.GameState FindClient(string name)
- {
- return GamePool.FirstOrDefault(p => p.Player.LoweredName == name);
- }
- #endregion
- #region SaveException|Commands
- private static void WorkConsole()
- {
- while (true)
- {
- try
- {
- CommandsAI(Console.ReadLine());
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- }
- public static void CommandsAI(string command)
- {
- if (command == null) return;
- string[] data = command.Split(' ');
- switch (data[0])
- {
- case "@ban":
- {
- 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 "@steam":
- {
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Open();
- foreach (var clien in Kernel.GamePool.Values)
- {
- if (clien.Team == null)
- clien.Team = new Game.ConquerStructures.Team(clien);
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Join(clien, 3);
- }
- break;
- }
- case "@Spellc":
- {
- new Custom.GUI.SpellControl().ShowDialog();
- break;
- }
- case "@addnpc":
- {
- new NpcCreator().ShowDialog();
- break;
- }
- case "@team":
- {
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Open();
- foreach (var clien in Kernel.GamePool.Values)
- {
- if (clien.Team == null)
- clien.Team = new Game.ConquerStructures.Team(clien);
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Join(clien, 3);
- }
- break;
- }
- case "@online":
- {
- Console.WriteLine("Online players count: " + Kernel.GamePool.Count);
- string line = "";
- foreach (Client.GameState pClient in Server.GamePool)
- line += pClient.Player.Name + ",";
- if (line != "")
- {
- line = line.Remove(line.Length - 1);
- Console.WriteLine("Players: " + line);
- }
- break;
- }
- case "@memo":
- {
- 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 "@restart":
- {
- GameServer.Disable();
- for (int i = 0; i < AuthServer.Length; i++)
- {
- AuthServer[i].Disable();
- }
- Save();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- Database.EntityVariableTable.Save(0, Vars);
- var wc = GamePool.ToArray();
- foreach (Client.GameState client in wc)
- client.Disconnect();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- Application.Exit();
- Environment.Exit(0);
- break;
- }
- case "@exit":
- {
- GameServer.Disable();
- for (int i = 0; i < AuthServer.Length; i++)
- {
- AuthServer[i].Disable();
- }
- Save();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- Database.EntityVariableTable.Save(0, Vars);
- var wc = GamePool.ToArray();
- foreach (Client.GameState client in wc)
- client.Disconnect();
- new Database.MySqlCommand(Database.MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- Application.Exit();
- Environment.Exit(0);
- break;
- }
- case "@myths":
- {
- foreach (Client.GameState client in Kernel.GamePool.Values)
- {
- client.Map.FreezeMonsters = true;
- var Clone = client.Map.Entities.Values.ToArray();
- foreach (var mob in Clone)
- if (!mob.Companion)
- {
- client.Map.Floor[mob.X, mob.Y, COServer.Game.MapObjectType.Monster, mob] = true;
- client.Map.Entities.Remove(mob.UID);
- }
- Clone = new Player[0];
- client.Map.EntityUIDCounter.Now = 400000;
- client.Map.LoadMonsters();
- client.Map.FreezeMonsters = false;
- foreach (Client.GameState Client in Kernel.GamePool.Values)
- {
- if (Client.Map.ID == client.Map.ID)
- {
- Client.Player.Teleport(Client.Player.MapID, Client.Player.X, Client.Player.Y);
- }
- }
- }
- break;
- }
- case "@Rest":
- {
- Console.WriteLine("Server will restart after 5 minutes.");
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- System.Threading.Thread.Sleep(30000);
- 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);
- Console.WriteLine("Server will exit after 1 minute.");
- CommandsAI("@save");
- System.Threading.Thread.Sleep(30000);
- Kernel.SendWorldMessage(new COServer.Network.GamePackets.Message("The Server restarted, Please log in after 2 minutes! ", System.Drawing.Color.Orange, 0x7db), Server.GamePool);
- try
- {
- CommandsAI("@restart");
- }
- catch
- {
- Console.WriteLine("Server cannot exit");
- }
- break;
- }
- case "@clear":
- {
- Console.Clear();
- break;
- }
- case "@save":
- {
- AuctionBase.Save();
- Database.InnerPowerTable.Save();
- using (var conn = DataHolder.MySqlConnection)
- {
- conn.Open();
- foreach (Client.GameState client in Server.GamePool)
- {
- FamilyTournament.Save();
- client.Account.Save();
- Database.InnerPowerTable.Save();
- KongFuTable.SaveKongFu();
- FlowersTable.SaveFlowers();
- SkillTable.SaveSpells(client);
- SkillTable.SaveProficiencies(client);
- EntityTable.SaveEntity(client, conn);
- Game.Features.Tournaments.TeamElitePk.TeamTournament.Save();
- Game.Features.Tournaments.TeamElitePk.SkillTeamTournament.Save();
- TeamArenaTable.SaveArenaStatistics(client.TeamArenaStatistic, conn);
- }
- }
- new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("ItemUID", _NextItemID).Execute();
- break;
- }
- case "@a":
- {
- Console.Clear();
- break;
- }
- //case "@showips":
- // {
- // bool f = !AuthServer.PrintoutIPs;
- // AuthServer.PrintoutIPs = GameServer.PrintoutIPs = f;
- // Console.WriteLine(string.Format("Showing forcing IPs? {0}", f));
- // break;
- // }
- case "@a7a88":
- {
- Console.WriteLine("Genr: " + Thread.GenericThreadPool.ToString());
- Console.WriteLine("Send: " + Thread.SendPool.ToString());
- Console.WriteLine("Recv: " + Thread.ReceivePool.ToString());
- break;
- }
- case "@account":
- {
- AccountTable account = new AccountTable(data[1]);
- account.Password = data[2];
- account.State = AccountTable.AccountState.Player;
- account.Save();
- break;
- }
- }
- }
- public static void AddGMCommand(string gm, string commandStr)
- {
- String folderN = DateTime.Now.Year + "-" + DateTime.Now.Month, Path =
- "database\\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 SaveException(Exception e, bool dont = false)
- {
- if (e.TargetSite.Name == "ThrowInvalidOperationException") return;
- if (e.Message.Contains("String reference not set")) return;
- if (!dont)
- Console.WriteLine(e);
- var dt = DateTime.Now;
- string date = dt.Month + "-" + dt.Day + "//";
- if (!Directory.Exists(Application.StartupPath + Constants.UnhandledExceptionsPath))
- Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath);
- if (!Directory.Exists(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date))
- Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date);
- if (!Directory.Exists(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name))
- Directory.CreateDirectory(Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name);
- string fullPath = Application.StartupPath + "\\" + Constants.UnhandledExceptionsPath + date + e.TargetSite.Name + "\\";
- string date2 = dt.Hour + "-" + dt.Minute;
- List<string> Lines = new List<string>();
- Lines.Add("----Exception message----");
- Lines.Add(e.Message);
- Lines.Add("----End of exception message----\r\n");
- Lines.Add("----Stack trace----");
- Lines.Add(e.StackTrace);
- Lines.Add("----End of stack trace----\r\n");
- File.WriteAllLines(fullPath + date2 + ".txt", Lines.ToArray());
- }
- #endregion
- public static uint _NextItemID;
- public static uint NextItemID
- {
- get { return _NextItemID++; }
- }
- public static void NextItemUID()
- {
- Console.WriteLine("Check Last Item UID... ");
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("items"))
- using (var reader = new MySqlReader(cmd))
- {
- while (reader.Read())
- {
- uint UID = reader.ReadUInt32("UID");
- if ((UID > 0) && (UID > _NextItemID))
- {
- _NextItemID = UID;
- }
- }
- }
- }
- static bool restart = false;
- public static void Restart()
- {
- if (!restart)
- {
- restart = true;
- Save();
- }
- }
- public static void LoadServer()
- {
- Time32 Start = Time32.Now;
- RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2));
- Kernel.Random = new FastRandom(RandomSeed);
- StartDate = DateTime.Now;
- ALEXPC = true;
- Console.ForegroundColor = ConsoleColor.Green;
- GameIP = "25.80.137.49";
- GamePort = 5819;
- AuthPort = new List<ushort>() { 9959 };
- DataHolder.CreateConnection("root", "258456", "hard", "localhost");
- using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("configuration");
- using (MySqlReader r = new MySqlReader(cmd))
- {
- if (r.Read())
- {
- EntityUID = new Counter(r.ReadUInt32("EntityID"));
- Union.UnionCounter = new Counter(r.ReadUInt32("UnionID"));
- Kernel.ServerKingdom = r.ReadUInt32("ServerKingdom");
- if (r.ReadByte("LastDailySignReset") != DateTime.Now.Month) MsgSignIn.Reset();
- Game.ConquerStructures.Society.Guild.GuildCounter = new Counter(r.ReadUInt32("GuildID"));
- 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");
- PlayerCap = r.ReadInt32("PlayerCap");
- EntityVariableTable.Load(0, out Vars);
- }
- }
- }
- using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration"))
- cmd.Set("LastDailySignReset", DateTime.Now.Month).Execute();
- if (EntityUID.Now == 0)
- {
- Console.Clear();
- Console.WriteLine("Database error. Please check your MySQL. Server will now close.");
- Console.ReadLine();
- return;
- }
- Thread = new Thread();
- Thread.Init();
- NextItemUID();
- Console.ForegroundColor = ConsoleColor.Magenta;
- FlowersTable.LoadFlowers();
- Console.ForegroundColor = ConsoleColor.Blue;
- ConquerItemTable.ClearNulledItems();
- ConquerItemInformation.Load();
- DataHolder.ReadStats();
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- MonsterInformation.Load();
- IPBan.Load();
- SpellTable.Load();
- ShopFile.Load();
- Console.ForegroundColor = ConsoleColor.DarkGray;
- HonorShop.Load();
- RacePointShop.Load();
- Console.ForegroundColor = ConsoleColor.Gray;
- UnionTable.Load();
- ChampionShop.Load();
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- Database.PerfectionTable.Load();
- EShopFile.Load();
- EShopV2File.Load();
- MapsTable.Load();
- NobilityTable.Load();
- Console.ForegroundColor = ConsoleColor.Yellow;
- ArenaTable.Load();
- TeamArenaTable.Load();
- SignInTable.Load();
- GuildTable.Load();
- ChiTable.LoadAllChi();
- PrizeNpcTable.Load();
- SoulProtection.Load();
- Console.ForegroundColor = ConsoleColor.DarkGray;
- MsgProcessGoal.Load();
- Kernel.QuizShow = new Game.ConquerStructures.QuizShow();
- Refinery.Load();
- Map.CreateTimerFactories();
- DMaps.Load();
- Console.ForegroundColor = ConsoleColor.Yellow;
- Game.Screen.CreateTimerFactories();
- GamePool = new Client.GameState[0];
- new Map(2073, DMaps.MapPaths[1011]);
- new Map(2075, DMaps.MapPaths[1015]);
- new Map(2076, DMaps.MapPaths[1020]);
- new Map(2078, DMaps.MapPaths[1000]);
- new Map(2072, DMaps.MapPaths[1002]);
- new Map(1002, DMaps.MapPaths[1002]);
- new Map(1038, DMaps.MapPaths[1038]);
- new Map(2071, DMaps.MapPaths[2071]);
- new Map(1509, DMaps.MapPaths[1509]);
- new Map(10002, 2021, DMaps.MapPaths[2021]);
- new Map(8883, 1004, DMaps.MapPaths[1004]);
- new Map(3846, DMaps.MapPaths[3846]);
- new Map(1927, DMaps.MapPaths[1927]);
- Constants.PKFreeMaps.Add(8883);
- GuildWar.Initiate();
- Game.ClanWar.Initiate();
- Console.ForegroundColor = ConsoleColor.Cyan;
- MsgFamily.LoadClans();
- Game.EliteGuildWar.EliteGwint();
- LoginBruteForce.CreatePoll();
- ReincarnationTable.Load();
- FurnitureTable.Load();
- Console.ForegroundColor = ConsoleColor.DarkBlue;
- KoBoard.Load();
- AuctionBase.Load();
- ServerData.Load();
- Console.ForegroundColor = ConsoleColor.DarkYellow;
- KongFuTable.LoadStatus();
- KongFuTable.LoadKongFu();
- Database.LotteryTable.Load();
- StorageManager.Load();
- Network.GamePackets.TaskReward.Load();
- Database.InnerPowerTable.LoadDBInformation();
- Console.ForegroundColor = ConsoleColor.DarkGreen;
- Database.InnerPowerTable.Load();
- Database.StorageItem.Load();
- Console.ForegroundColor = ConsoleColor.DarkCyan;
- Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
- Thread.CreateTournaments();
- //_handler += new EventHandler(Handler);
- //SetConsoleCtrlHandler(_handler, true);
- AddingInformationTable.Load();
- // FloorItemTable.Load();
- Console.ForegroundColor = ConsoleColor.DarkBlue;
- Console.WriteLine("Loading Npc information... ");
- {
- Client.GameState gc = new Client.GameState(new ClientWrapper());
- gc.Account = new AccountTable("NONE");
- gc.Socket.Alive = false;
- gc.Player = new Player(PlayerFlag.Player, false) { Name = "NONE" };
- Npcs.GetDialog(new MsgTaskDialog(true), gc, true);
- }
- new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Execute();
- new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("ChatBanned", 0).Execute();
- new MsgEquipRefineRank().UpdateRanking();
- new MsgUserAbilityScore().GetRankingList();
- new MsgRankMemberShow().UpdateBestPlayer();
- AuthServer = new ServerSocket[AuthPort.Count];
- for (int i = 0; i < AuthServer.Length; i++)
- {
- AuthServer[i] = new ServerSocket();
- AuthServer[i].OnClientConnect += AuthServer_OnClientConnect;
- AuthServer[i].OnClientReceive += AuthServer_OnClientReceive;
- AuthServer[i].OnClientDisconnect += AuthServer_OnClientDisconnect;
- AuthServer[i].Enable(AuthPort[i], "0.0.0.0");
- }
- GameServer = new ServerSocket();
- GameServer.OnClientConnect += GameServer_OnClientConnect;
- GameServer.OnClientReceive += GameServer_OnClientReceive;
- GameServer.OnClientDisconnect += GameServer_OnClientDisconnect;
- GameServer.Enable(GamePort, "0.0.0.0");
- AI.CreateTimerFactories();
- Booths.Load();
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("");
- Console.WriteLine("MyThs-Online waiting for new connection...");
- Console.WriteLine("");
- GC.Collect();
- WorkConsole();
- CommandsAI(Console.ReadLine());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement