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 Conquer_Online_Server.Network;
- using Conquer_Online_Server.Database;
- using Conquer_Online_Server.Network.Sockets;
- using Conquer_Online_Server.Network.AuthPackets;
- using Conquer_Online_Server.Game;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using System.Text;
- using Conquer_Online_Server.Network.GamePackets;
- using Conquer_Online_Server.Client;
- using System.Diagnostics;
- using System.Threading.Tasks;
- using System.Threading;
- using Conquer_Online_Server;
- namespace Conquer_Online_Server
- {
- class Program
- {
- #region Statics and Def's
- public static Encoding Encoding = ASCIIEncoding.Default;
- [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 bool cycolne = false;
- public static bool cycolne1 = false;
- public static int PlayerCap = 400;
- public static bool ALEXPC = false;
- public static bool NemesisTyrantSpanwed = false;
- public static long MaxOn = 0;
- public static long MaxPlayers = 0;
- public static ServerSocket AuthServer;
- public static bool CpuUsageTimer = true;
- public static MemoryCompressor MCompressor = new MemoryCompressor();
- public static int CpuUse = 0;
- public static ServerSocket GameServer;
- public static Counter EntityUID;
- public static string GameIP;
- public static bool SpookAlive = false;
- public static DayOfWeek Today;
- public static ushort GamePort;
- public static ushort AuthPort;
- public static DateTime StartDate;
- public static bool reseted = false;
- public static uint ScreenColor = 0;
- public static DateTime RestartDate = DateTime.Now.AddHours(24);
- public static bool restarted = false;
- public static bool WarEnd = false;
- public static bool uniquepk = false;
- public static uint mess = 0;
- public static World World;
- public static Client.GameState[] GamePool = new Client.GameState[0];
- public static Client.GameState[] Values = new Client.GameState[0];
- public static VariableVault Vars;
- public static long WeatherType = 0L;
- public static bool TestingMode = false;
- public static bool AllTest = false;
- public static int RandomSeed = 0;
- #endregion
- public static void Main(string[] args)
- {//uda
- 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;
- Console.Title = "Conquer Online Server Emulator. Start time: " + StartDate.ToString("dd MM yyyy hh:mm");
- Console.BackgroundColor = ConsoleColor.Red;
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("-- This source has been writen by Bagu Alexandru. --");
- Console.WriteLine("-- And Edited by Sheko Hex [Shady Khalifa] --");
- Console.WriteLine("-- Copyright (c) Bagu Alexandru 2008-2016. --");
- Console.WriteLine("-- Source created with the help of all mighty God.--");
- Console.BackgroundColor = ConsoleColor.Black;
- Console.ForegroundColor = ConsoleColor.White;
- string ConfigFileName = "configuration.ini";
- IniFile IniRates = new IniFile("ServerRates.ini");
- IniFile IniFile = new IniFile(ConfigFileName);
- GameIP = IniFile.ReadString("configuration", "IP");
- GamePort = IniFile.ReadUInt16("configuration", "GamePort");
- AuthPort = IniFile.ReadUInt16("configuration", "AuthPort");
- Constants.ServerName = "Zegor";
- string user, pass, db;
- user = IniFile.ReadString("MySql", "Username");
- pass = IniFile.ReadString("MySql", "Password");
- db = IniFile.ReadString("MySql", "Database");
- #region Database Contacting..
- Database.DataHolder.CreateConnection("localhost", user, pass, db);
- EntityUID = new Counter(0);
- using (MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("configuration").Where("Server", Constants.ServerName);
- using (MySqlReader r = new MySqlReader(cmd))
- {
- if (r.Read())
- {
- Network.GamePackets.UnionPacket.UnionCounter =
- new Conquer_Online_Server.Counter(r.ReadUInt32("UnionID"));
- EntityUID = new Counter(r.ReadUInt32("EntityID"));
- Game.ConquerStructures.Society.Guild.GuildCounter = new Conquer_Online_Server.Counter(r.ReadUInt32("GuildID"));
- ConquerItem.ItemUID = new 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");
- Constants.ServerGMPass = r.ReadString("ServerGMPass");
- PlayerCap = r.ReadInt32("PlayerCap");
- Database.EntityVariableTable.Load(0, out Vars);
- }
- }
- }
- if (EntityUID.Now == 0)
- {
- Console.Clear();
- Console.WriteLine("Database error. Please check your MySQL. Server will now close.");
- Console.ReadLine();
- return;
- }
- #endregion
- {
- Console.WriteLine("Loading Server Now.");
- World = new World();
- Database.ConquerItemInformation.Load();
- Database.ConquerItemTable.ClearNulledItems();
- Database.MonsterInformation.Load();
- Database.MapsTable.Load();
- ClientSystem.SoulProtection.Load();
- Map.CreateTimerFactories();
- Database.DMaps.Load();
- InnerPowerTable.LoadDBInformation();
- InnerPowerTable.Load();
- PrizeNpcTable.Load();
- {
- ClientSystem.Reward.Load();
- ClientSystem.QuestInfo.Load();
- Database.helpdesk.LoadRates();
- Database.VipTable.LoadAllVips();
- Database.GameUpdatess.LoadRates();
- Database.SpellTable.Load();
- Database.ShopFile.Load();
- Database.HonorShop.Load();
- Database.RacePointShop.Load();
- Database.ChampionShop.Load();
- Database.EShopFile.Load();
- Database.EShopV2File.Load();
- StorageManager.Load();
- Database.AddingInformationTable.Load();
- Database.LotteryTable.Load();
- Database.vipLottery.Load();
- Database.PoketTables.LoadTables();
- ClientSystem.Roulette.Database.Roulettes.Load();
- ClientSystem.Way2Heroes.Load();
- Database.ConquerItemTable.ClearNulledItems();
- Kernel.QuizShow = new Game.ConquerStructures.QuizShow();
- Refinery.Load();
- Values = new Client.GameState[0];
- Game.ClanWar.Initiate();
- Game.EliteGuildWar.EliteGwint();
- Database.Furniture.Load();
- ClientSystem.House.LoadHouses();
- }
- Flowers.LoadFlowers();
- Database.DataHolder.ReadStats();
- Database.IPBan.Load();
- Database.JiangHu.LoadStatus();
- Database.JiangHu.LoadJiangHu();
- Database.UnionTable.Load();
- Database.NobilityTable.Load();
- Database.ArenaTable.Load();
- Database.TeamArenaTable.Load();
- Database.ChampionTable.Load();
- Database.GuildTable.Load();
- Database.ChiTable.LoadAllChi();
- Clan.LoadClans();
- Game.Screen.CreateTimerFactories();
- Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
- World.CreateTournaments();
- World.Init();
- new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Execute();
- {
- AuthServer = new ServerSocket();
- AuthServer.OnClientConnect += AuthServer_OnClientConnect;
- AuthServer.OnClientReceive += AuthServer_OnClientReceive;
- AuthServer.OnClientDisconnect += AuthServer_OnClientDisconnect;
- AuthServer.Enable(AuthPort, GameIP);
- }
- {
- GameServer = new ServerSocket();
- GameServer.OnClientConnect += GameServer_OnClientConnect;
- GameServer.OnClientReceive += GameServer_OnClientReceive;
- GameServer.OnClientDisconnect += GameServer_OnClientDisconnect;
- GameServer.Enable(GamePort, GameIP);
- Console.WriteLine("Auth server online.");
- Console.WriteLine("Game server online.");
- _handler += new EventHandler(Handler);
- SetConsoleCtrlHandler(_handler, true);
- ClientSystem.Pet.CreateTimerFactories();
- ClientSystem.AI.CreateTimerFactories();
- ClientSystem.ClientSystemMob.CreateTimerFactories();
- var client = new GameState(null);
- client.Entity = new Entity(EntityFlag.Monster, false);
- client.Entity.MapID = 1002;
- Npcs npc = new Npcs(client);
- var req = new NpcRequest();
- req.Deserialize(new byte[28]);
- Npcs.GetDialog(req, client);
- client = null;
- Conquer_Online_Server.ServerSystem.Booths.Load();
- }
- GameState.LoadBoothingAI();
- float Time = (Time32.Now - Start).Value;
- float ServerLoadedTime = Time;
- Console.WriteLine("Server Is Online Now !");
- Console.WriteLine(@"On IP : " + GameIP + ":" + AuthPort);
- Console.WriteLine("Server loaded in " + (ServerLoadedTime) + " ms");
- Console.WriteLine("");
- Program.MCompressor.Optimize();
- GC.Collect();
- WorkConsole();
- }
- }
- 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)
- {
- try
- {
- if (command == null)
- return;
- string[] data = command.Split(' ');
- switch (data[0])
- {
- //No Commands For Now
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- public static void WriteLine(string Line)
- {
- try
- {
- Console.WriteLine(Line);
- }
- catch { }
- }
- 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[] 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.Values)
- {
- 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.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;
- 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.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();
- Network.PacketHandler.HandlePacket(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);
- Forward Fw = new Forward();
- if (player.Account.Password == player.Info.Password && player.Account.exists)
- Fw.Type = Forward.ForwardType.Ready;
- else
- 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.GameState FindClient(string name)
- {
- return Values.FirstOrDefault(p => p.Entity.Name == name);
- }
- internal static void WriteLine(string p, ushort MsgId, short p_2)
- {
- throw new NotImplementedException();
- }
- }
- public class ClientSystem_Times
- {
- public static DateTime now
- {
- get
- {
- return DateTime.Now;
- }
- }
- public class Start
- {
- public static bool KingsTime
- {
- get
- {
- return (now.Hour >= 00 && now.Hour < 24);
- }
- }
- public static bool SkyWar
- {
- get
- {
- return (now.Hour == 1 || now.Hour == 13) && now.Minute == 10 && now.Second == 1;
- }
- }
- public static bool TheTeam
- {
- get
- {
- return (now.Hour == 14 || now.Hour == 2) && now.Minute == 10 && now.Second == 1;
- }
- }
- public static bool ClanWar
- {
- get
- {
- return now.Minute == 30;
- }
- }
- public static bool EliteGW
- {
- get
- {
- return (now.Minute == 0);
- }
- }
- public static bool SkillTeam
- {
- get
- {
- return (now.Hour == 22) && now.Minute == 1;
- }
- }
- public static bool TeamPK
- {
- get
- {
- return (now.Hour == 19) && now.Minute == 1;
- }
- }
- public static bool CTF
- {
- get
- {
- return now.Hour == 19;
- }
- }
- //public static bool TwinWar
- //{
- // get
- // {
- // return (now.Hour == 7 || now.Hour == 19) && now.Minute >= 1;
- // }
- //}
- public static bool NobiltyWarPole
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Wednesday && now.Hour == 23 && now.Minute == 0);
- }
- }
- public static bool GuildPoleWar
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Sunday && now.Hour == 21 && now.Minute == 0);
- }
- }
- //public static bool CrossServer
- // {
- //get
- // {
- // return now.Hour == 22 || now.Hour == 10;
- //}
- // }
- public static bool PoleDomnation
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Saturday && now.Hour == 16 && now.Minute == 0);
- }
- }
- public static bool ClanWarArena2
- {
- get
- {
- return (now.Hour == 22 && now.Minute == 25);
- }
- }
- public static bool ClanWarArena
- {
- get
- {
- return (now.Hour == 22 && now.Minute == 30);
- }
- }
- public static bool StatuesWar
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Thursday && now.Hour == 17 && now.Minute == 0);
- }
- }
- public static bool GuildScoreWar
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Monday && now.Hour == 22 && now.Minute == 0);
- }
- }
- public static bool ClassWar
- {
- get
- {
- return (now.DayOfWeek == DayOfWeek.Saturday && now.Hour == 21 && now.Minute == 0);
- }
- }
- ///////////////////////////////////////////////
- public static bool HeroOfGame
- {
- get
- {
- return now.Minute == 30;
- }
- }
- public static bool FBSS
- {
- get
- {
- return now.Minute == 5;
- }
- }
- public static bool FBSS2
- {
- get
- {
- return now.Minute >= 5 && now.Minute < 7;
- }
- }
- public static int hunterthief = 42;
- public static int dashbash = 46;
- public static int chase = 45;
- public static int dizzy = 49;
- public static bool Nobilty
- {
- get
- {
- return now.Minute >= 20 && now.Minute <= 22;
- }
- }
- }
- public class End
- {
- public static bool FBSS
- {
- get
- {
- return now.Minute >= 8 && now.Minute <= 10;
- }
- }
- public static int hunterthief = 45;
- public static int dashbash = 48;
- public static bool Cyclone
- {
- get
- {
- return now.Minute == 29;
- }
- }
- public static int chase = 45;
- public static int dizzy2 = 50;
- public static bool Nobilty
- {
- get
- {
- return now.Minute >= 23 && now.Minute <= 25;
- }
- }
- /////////////////////
- public static bool EliteGW
- {
- get
- {
- return now.Minute == 30;
- }
- }
- public static bool ClanWar
- {
- get
- {
- return now.Minute == 00;
- }
- }
- }
- }
- public class Kernel32
- {
- public delegate bool ConsoleEventHandler(CtrlType sig);
- public enum CtrlType
- {
- CTRL_C_EVENT = 0,
- CTRL_BREAK_EVENT = 1,
- CTRL_CLOSE_EVENT = 2,
- CTRL_LOGOFF_EVENT = 5,
- CTRL_SHUTDOWN_EVENT = 6
- }
- [DllImport("kernel32.dll")]
- public static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement