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.ConquerStructures.Socie ty;
using Conquer_Online_Server.Game;
using System.Collections.Generic;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Conquer_Online_Server
{
class Program
{
public static void WriteLine(object text) { Applications.Output.WriteLine(text.ToString() + "\n"); }
public static int PlayerCap = 400;
public static AsyncSocket AuthServer;
public static AsyncSocket GameServer;
public static ServerBase.Counter EntityUID;
public static string GameIP;
public static DayOfWeek Today;
public static ushort GamePort;
public static ushort AuthPort;
public static DateTime StartDate;
public static DateTime RestartDate = DateTime.Now.AddHours(24);
public static DateTime SaveDate = DateTime.Now.AddSeconds(2);
public static ServerBase.Thread StatusFlagChange = new Conquer_Online_Server.ServerBase.Thread(500);
public static ServerBase.Thread CharacterThread = new ServerBase.Thread(1000);
public static ServerBase.Thread AttackThread = new ServerBase.Thread(800);
public static ServerBase.Thread CompanionThread = new Conquer_Online_Server.ServerBase.Thread(1000);
public static ServerBase.Thread BlessThread = new ServerBase.Thread(4000);
public static ServerBase.Thread ServerStuff = new ServerBase.Thread(500);
public static ServerBase.Thread ArenaSystem = new Conquer_Online_Server.ServerBase.Thread(2000);
public static Client.GameState[] Values = null;
[MTAThread]
static void Main(string[] args)
{
Thread outputThread = new Thread(new ThreadStart(LoadOutput));
outputThread.Priority = ThreadPriority.Lowest;
outputThread.Start();
//Application.ThreadException += Application_ThreadException;
// Application.Run(new NotForPublicNotAtAll.NoCrash());
}
protected static void LoadOutput()
{
Application.Run(new Applications.Output());
}
//static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
//{
// SaveException(e.Exception);
//}
public static void SaveException(Exception e)
{
if (e.TargetSite.Name == "ThrowInvalidOperationException")
return;
Program.WriteLine(e);
var dt = DateTime.Now;
string date = dt.Month + "-" + dt.Day + "//";
if (!Directory.Exists(Application.StartupPath + ServerBase.Constants.UnhandledExceptionsPath))
Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath);
if (!Directory.Exists(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date))
Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date);
if (!Directory.Exists(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date + e.TargetSite.Name))
Directory.CreateDirectory(Application.StartupPath + "\\" + ServerBase.Constants.UnhandledExceptionsPath + date + e.TargetSite.Name);
string fullPath = Application.StartupPath + "\\" + ServerBase.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");
//Lines.Add("----Data from exception----");
//foreach (KeyValuePair<object, object> data in e.Data)
// Lines.Add(data.Key.ToString() + "->" + data.Value.ToString());
//Lines.Add("----End of data from exception----\r\n");
File.WriteAllLines(fullPath + date2 + ".txt", Lines.ToArray());
}
//public static void StartEngine()
//{
// EngineThread_Execute();
//}
public static int RandomSeed = 0;
static void EngineThread_Execute()
{
Time32 Start = Time32.Now;
RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remo ve(DateTime.Now.Ticks.ToString().Length / 2));
ServerBase.Kernel.Random = new Random(RandomSeed);
StartDate = DateTime.Now;
//Console.Title = "Conquer Online Server Emulator. Start time: " + StartDate.ToString("dd MM yyyy hh:mm"); Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.DarkRed;
Program.WriteLine("-- This source has been writen by Bagu Alexandru. --");
Program.WriteLine("-- Copyright (c) Bagu Alexandru 2008-2010. --");
Program.WriteLine("-- Source created with the help of all mighty God.--");
//Console.BackgroundColor = ConsoleColor.Black;
//Console.ForegroundColor = ConsoleColor.White;
Program.WriteLine("Load server configuration! !");
string ConfigFileName = "configuration.ini";
ServerBase.IniFile IniFile = new ServerBase.IniFile(ConfigFileName);
/* if (Environment.UserName.ToLower().Contains("impulse" ))
{
GameIP = "192.168.1.101";
GamePort = IniFile.ReadUInt16("Configuration", "GamePort");
AuthPort = IniFile.ReadUInt16("Configuration", "AuthPort");
ServerBase.Constants.ServerName = IniFile.ReadString("Configuration", "ServerName");
Database.DataHolder.CreateConnection("root", "123456", IniFile.ReadString("MySql", "Database"), "localhost");
}*/
// else
{
GameIP = IniFile.ReadString("configuration", "IP");
GamePort = IniFile.ReadUInt16("configuration", "GamePort");
AuthPort = IniFile.ReadUInt16("configuration", "AuthPort");
ServerBase.Constants.ServerName = IniFile.ReadString("configuration", "ServerName");
Database.DataHolder.CreateConnection(IniFile.ReadS tring("MySql", "Username"), IniFile.ReadString("MySql", "Password"), IniFile.ReadString("MySql", "Database"), IniFile.ReadString("MySql", "Host"));
}
MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("conf iguration").Where("Server", ServerBase.Constants.ServerName);
MySqlReader r = new MySqlReader(cmd);
if (r.Read())
{
EntityUID = new ServerBase.Counter(r.ReadUInt32("EntityID"));
Game.ConquerStructures.Society.Guild.GuildCounter = new Conquer_Online_Server.ServerBase.Counter(r.ReadUIn t32("GuildID"));
Network.GamePackets.ConquerItem.ItemUID = new Conquer_Online_Server.ServerBase.Counter(r.ReadUIn t32("ItemUID"));
ServerBase.Constants.ExtraExperienceRate = r.ReadUInt32("ExperienceRate");
ServerBase.Constants.ExtraSpellRate = r.ReadUInt32("ProficiencyExperienceRate");
ServerBase.Constants.ExtraProficiencyRate = r.ReadUInt32("SpellExperienceRate");
ServerBase.Constants.MoneyDropRate = r.ReadUInt32("MoneyDropRate");
ServerBase.Constants.MoneyDropMultiple = r.ReadUInt32("MoneyDropMultiple");
ServerBase.Constants.ConquerPointsDropRate = r.ReadUInt32("ConquerPointsDropRate");
ServerBase.Constants.ConquerPointsDropMultiple = r.ReadUInt32("ConquerPointsDropMultiple");
ServerBase.Constants.ItemDropRate = r.ReadUInt32("ItemDropRate");
ServerBase.Constants.ItemDropQualityRates = r.ReadString("ItemDropQualityString").Split('~');
ServerBase.Constants.WebAccExt = r.ReadString("AccountWebExt");
ServerBase.Constants.WebVoteExt = r.ReadString("VoteWebExt");
ServerBase.Constants.WebDonateExt = r.ReadString("DonateWebExt");
ServerBase.Constants.ServerWebsite = r.ReadString("ServerWebsite");
PlayerCap = r.ReadInt32("PlayerCap");
}
r.Close();
if (EntityUID.Now == 0) // i fixed the bug, now it shows what it's supposed to, you have database problems
{
Console.Clear();
Program.WriteLine("Database error. Please check your MySQL. Server will now close.");
return;
}
Program.WriteLine("Initializing database.");
Database.ConquerItemInformation.Load();
Database.DataHolder.ReadStats();
Database.MonsterInformation.Load();
Database.SpellTable.Load();
Database.ShopFile.Load();
Database.MapsTable.Load();
Database.NobilityTable.Load();
Database.ArenaTable.Load();
Database.GuildTable.Load();
Database.ClanTable.LoadAllClans();
Database.LotteryTable.Load();
Database.DMaps.Load();
Database.QuizData.Load();
Values = new Client.GameState[0];
new Game.Map(1038, Database.DMaps.MapPaths[1038]);
Game.ConquerStructures.Society.GuildWar.Initiate() ;
Program.WriteLine("Guild war initializated.");
Network.AuthPackets.Forward.Incrementer = new ServerBase.Counter();
Network.Cryptography.AuthCryptography.PrepareAuthC ryptography();
Program.WriteLine("Initializing sockets.");
AuthServer = new AsyncSocket(AuthPort);
AuthServer.OnClientConnect += new Action<Interfaces.ISocketWrapper>(AuthServer_Annou nceNewConnection);
AuthServer.OnClientReceive += new Action<byte[], Interfaces.ISocketWrapper>(AuthServer_AnnounceRece ive);
AuthServer.OnClientDisconnect += new Action<Interfaces.ISocketWrapper>(AuthServer_Annou nceDisconnection);
GameServer = new AsyncSocket(GamePort);
GameServer.OnClientConnect += new Action<Interfaces.ISocketWrapper>(GameServer_Annou nceNewConnection);
GameServer.OnClientReceive += new Action<byte[], Interfaces.ISocketWrapper>(GameServer_AnnounceRece ive);
GameServer.OnClientDisconnect += new Action<Interfaces.ISocketWrapper>(GameServer_Annou nceDisconnection);
Program.WriteLine("Auth server online.");
Program.WriteLine("Game server online.");
//Program.WriteLine();
Program.WriteLine("Server loaded in " + (Time32.Now - Start) + " milliseconds.");
StatusFlagChange.Execute += new Action(StatusFlagChange_Execute);
StatusFlagChange.Start();
CharacterThread.Execute += new Action(CharacterThread_Execute);
CharacterThread.Start();
AttackThread.Execute += new Action(AttackThread_Execute);
AttackThread.Start();
CompanionThread.Execute += new Action(CompanionThread_Execute);
CompanionThread.Start();
BlessThread.Execute += new Action(BlessThread_Execute);
BlessThread.Start();
ServerStuff.Execute += new Action(ServerStuff_Execute);
ServerStuff.Start();
ArenaSystem.Execute += new Action(Game.ConquerStructures.Arena.ArenaSystem_Ex ecute);
ArenaSystem.Start();
new MySqlCommand(MySqlCommandType.UPDATE).Update("enti ties").Set("Online", 0).Execute();
GC.Collect();
System.Threading.Thread.Sleep(000);
// Console.Clear();
// Program.WriteLine("Server ready.");
while (true)
CommandsAI(Console.ReadLine());
}
static void AttackThread_Execute()
{
foreach (Client.GameState client in Values)
{
if (client.Socket.Connected)
{
if (client.Entity.HandleTiming)
{
#region Auto attack
if (client.Entity.AttackPacket != null || client.Entity.VortexAttackStamp != null)
{
try
{
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.ShurikenVortex))
{
if (client.Entity.VortexPacket != null && client.Entity.VortexPacket.ToArray() != null)
{
if (Time32.Now > client.Entity.VortexAttackStamp.AddMilliseconds(14 00))
{
client.Entity.VortexAttackStamp = Time32.Now;
new Game.Attacking.Handle(client.Entity.VortexPacket, client.Entity, null);
}
}
}
else
{
client.Entity.VortexPacket = null;
var AttackPacket = client.Entity.AttackPacket;
if (AttackPacket != null && AttackPacket.ToArray() != null)
{
uint AttackType = AttackPacket.AttackType;
if (AttackType == Network.GamePackets.Attack.Magic || AttackType == Network.GamePackets.Attack.Melee || AttackType == Network.GamePackets.Attack.Ranged)
{
if (AttackType == Network.GamePackets.Attack.Magic)
{
if (Time32.Now > client.Entity.AttackStamp.AddSeconds(1))
{
new Game.Attacking.Handle(AttackPacket, client.Entity, null);
}
}
else
{
int decrease = -300;
if (client.Entity.OnCyclone())
decrease = 700;
if (client.Entity.OnSuperman())
decrease = 200;
if (Time32.Now > client.Entity.AttackStamp.AddMilliseconds((1000 - client.Entity.Agility - decrease) * (int)(AttackType == Network.GamePackets.Attack.Ranged ? 1 : 1)))
{
new Game.Attacking.Handle(AttackPacket, client.Entity, null);
}
}
}
}
}
}
catch (Exception e)
{
SaveException(e);
client.Entity.AttackPacket = null;
client.Entity.VortexPacket = null;
}
}
#endregion
}
}
//else
// client.Disconnect();
}
}
static DateTime LastRandomReset = DateTime.Now;
static void ServerStuff_Execute()
{
Console.Title = "Conquer Online Server Emulator. Start time: " + StartDate.ToString("dd MM yyyy hh:mm") + ". Players online: " + ServerBase.Kernel.GamePool.Count + "/" + PlayerCap;
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("GuildID", Game.ConquerStructures.Society.Guild.GuildCounter. Now).Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.Constants.ServerName).Execute();
if (DateTime.Now > Game.ConquerStructures.Broadcast.LastBroadcast.Add Minutes(1))
{
if (Game.ConquerStructures.Broadcast.Broadcasts.Count > 0)
{
Game.ConquerStructures.Broadcast.CurrentBroadcast = Game.ConquerStructures.Broadcast.Broadcasts[0];
Game.ConquerStructures.Broadcast.Broadcasts.Remove (Game.ConquerStructures.Broadcast.CurrentBroadcast );
Game.ConquerStructures.Broadcast.LastBroadcast = DateTime.Now;
ServerBase.Kernel.SendWorldMessage(new Network.GamePackets.Message(Game.ConquerStructures .Broadcast.CurrentBroadcast.Message, "ALLUSERS", Game.ConquerStructures.Broadcast.CurrentBroadcast. EntityName, System.Drawing.Color.Red, Network.GamePackets.Message.BroadcastMessage), ServerBase.Kernel.GamePool.Values);
}
else
Game.ConquerStructures.Broadcast.CurrentBroadcast. EntityID = 1;
}
DateTime Now = DateTime.Now;
if (Now > LastRandomReset.AddMinutes(30))
{
LastRandomReset = Now;
ServerBase.Kernel.Random = new Random(RandomSeed);
}
Today = Now.DayOfWeek;
if (Now >= RestartDate)
{
CommandsAI("@restart");
ServerStuff.Closed = true;
return;
}
if (Now >= SaveDate)
{
CommandsAI("@save");
return;
}
var Values = ServerBase.Kernel.WasInGamePool.Base.ToArray();
foreach (KeyValuePair<uint, Client.GameState> vals in Values)
{
Client.GameState client = vals.Value;
if (client.Disconnected2 == true)
return;
if (client == null || client.Entity == null || client.Account == null)
{
ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
return;
}
if (!client.Socket.Connected)
{
Database.EntityTable.SaveEntity(client);
Database.SkillTable.SaveProficiencies(client);
Database.SkillTable.SaveSpells(client);
Database.ArenaTable.SaveArenaStatistics(client.Are naStatistic);
ServerBase.Kernel.WasInGamePool.Remove(vals.Key);
Database.EntityTable.UpdateOnlineStatus(client, false);
}
}
if (Game.ConquerStructures.Society.GuildWar.IsWar)
{
if (Time32.Now > Game.ConquerStructures.Society.GuildWar.ScoreSendS tamp.AddSeconds(3))
{
Game.ConquerStructures.Society.GuildWar.ScoreSendS tamp = Time32.Now;
Game.ConquerStructures.Society.GuildWar.SendScores ();
}
if (!Game.ConquerStructures.Society.GuildWar.Flame10t h)
{
if (Now >= Game.ConquerStructures.Society.GuildWar.StartTime. AddHours(1).AddMinutes(30))
{
Game.ConquerStructures.Society.GuildWar.Flame10th = true;
ServerBase.Kernel.SendWorldMessage(new Network.GamePackets.Message("You can now go and light the last flame which is near the Pole in GuildWar.", System.Drawing.Color.Orange, Network.GamePackets.Message.Center), ServerBase.Kernel.GamePool.Values);
}
}
else
{
if (Now >= Game.ConquerStructures.Society.GuildWar.StartTime. AddHours(2))
{
Game.ConquerStructures.Society.GuildWar.Flame10th = false;
Game.ConquerStructures.Society.GuildWar.End();
}
}
}
else
{
if (Now.DayOfWeek == DayOfWeek.Sunday)
{
if (Now.Hour == 18)
{
Game.ConquerStructures.Society.GuildWar.Start();
}
}
else if (Now.DayOfWeek == DayOfWeek.Thursday)
{
if (Now.Hour == 10)
{
Game.ConquerStructures.Society.GuildWar.Start();
}
}
}
}
static void CharacterThread_Execute()
{
Time32 Now = Time32.Now;
foreach (Client.GameState client in Values)
{
if (client.Socket.Connected)
{
if (client.Entity.HandleTiming)
{
#region Training points
if (client.Entity.HeavenBlessing > 0 && !client.Entity.Dead)
{
if (Now > client.LastTrainingPointsUp.AddMinutes(10))
{
client.OnlineTrainingPoints += 10;
if (client.OnlineTrainingPoints >= 30)
{
client.OnlineTrainingPoints -= 30;
client.IncreaseExperience(client.ExpBall / 100, false);
}
client.LastTrainingPointsUp = Now;
client.Entity.Update(Network.GamePackets.Update.On lineTraining, client.OnlineTrainingPoints, false);
}
}
#endregion
#region Minning
if (client.Mining && !client.Entity.Dead)
{
if (Now >= client.MiningStamp.AddSeconds(2))
{
client.MiningStamp = Now;
Game.ConquerStructures.Mining.Mine(client);
}
}
#endregion
#region MentorPrizeSave
if (Now > client.LastMentorSave.AddSeconds(5))
{
Database.KnownPersons.SaveApprenticeInfo(client.As Apprentice);
client.LastMentorSave = Now;
}
#endregion
#region Attackable
if (client.JustLoggedOn)
{
client.JustLoggedOn = false;
client.ReviveStamp = Now;
}
if (!client.Attackable)
{
if (Now > client.ReviveStamp.AddSeconds(5))
{
client.Attackable = true;
}
}
#endregion
#region DoubleExperience
if (client.Entity.DoubleExperienceTime > 0)
{
if (Now > client.Entity.DoubleExpStamp.AddMilliseconds(1000) )
{
client.Entity.DoubleExpStamp = Now;
client.Entity.DoubleExperienceTime--;
}
}
#endregion
#region HeavenBlessing
if (client.Entity.HeavenBlessing > 0)
{
if (Now > client.Entity.HeavenBlessingStamp.AddMilliseconds( 1000))
{
client.Entity.HeavenBlessingStamp = Now;
client.Entity.HeavenBlessing--;
}
}
#endregion
#region Enlightment
if (client.Entity.EnlightmentTime > 0)
{
if (Now >= client.Entity.EnlightmentStamp.AddMinutes(1))
{
client.Entity.EnlightmentStamp = Now;
client.Entity.EnlightmentTime--;
if (client.Entity.EnlightmentTime % 10 == 0 && client.Entity.EnlightmentTime > 0)
client.IncreaseExperience(Game.Attacking.Calculate .Percent((int)client.ExpBall, .10F), false);
}
}
#endregion
#region PKPoints
if (Now >= client.Entity.PKPointDecreaseStamp.AddMinutes(5))
{
client.Entity.PKPointDecreaseStamp = Now;
if (client.Entity.PKPoints > 0)
{
client.Entity.PKPoints--;
}
else
client.Entity.PKPoints = 0;
}
#endregion
#region OverHP
if (client.Entity.FullyLoaded)
{
if (client.Entity.Hitpoints > client.Entity.MaxHitpoints && client.Entity.MaxHitpoints > 1 && !client.Entity.Transformed)
{
client.Entity.Hitpoints = client.Entity.MaxHitpoints;
}
}
#endregion
#region Stamina
if (Now > client.Entity.StaminaStamp.AddMilliseconds(500))
{
if (client.Vigor < client.MaxVigor)
{
client.Vigor += (ushort)(3 + (client.Entity.Action == Game.Enums.ConquerAction.Sit ? 2 : 0));
{
Network.GamePackets.Vigor vigor = new Network.GamePackets.Vigor(true);
vigor.Amount = client.Vigor;
vigor.Send(client);
}
}
if (!client.Entity.ContainsFlag(Network.GamePackets.U pdate.Flags.Ride) && !client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Fly))
{
int limit = 0;
if (client.Entity.HeavenBlessing > 0)
limit = 50;
if (client.Entity.Stamina != 100 + limit)
{
if (client.Entity.Action == Game.Enums.ConquerAction.Sit)
{
if (client.Entity.Stamina <= 93 + limit)
{
client.Entity.Stamina += 7;
}
else
{
if (client.Entity.Stamina != 100 + limit)
client.Entity.Stamina = (byte)(100 + limit);
}
}
else
{
if (client.Entity.Stamina <= 97 + limit)
{
client.Entity.Stamina += 3;
}
else
{
if (client.Entity.Stamina != 100 + limit)
client.Entity.Stamina = (byte)(100 + limit);
}
}
}
client.Entity.StaminaStamp = Now;
}
}
#endregion
#region SoulShackle
if (client.Entity.ContainsFlag2(Network.GamePackets.U pdate.Flags2.Shackled))
{
if (Now > client.Entity.ShackleStamp.AddSeconds(client.Entit y.ShackleTime))
{
client.Entity.RemoveFlag2(Network.GamePackets.Upda te.Flags2.Shackled);
}
}
#endregion
}
}
//else
// client.Disconnect();
}
}
static void CompanionThread_Execute()
{
Time32 Now = Time32.Now;
foreach (Client.GameState client in Values)
{
if (client.Companion != null)
{
short distance = ServerBase.Kernel.GetDistance(client.Companion.X, client.Companion.Y, client.Entity.X, client.Entity.Y);
if (distance >= 8)
{
ushort X = (ushort)(client.Entity.X + ServerBase.Kernel.Random.Next(2));
ushort Y = (ushort)(client.Entity.Y + ServerBase.Kernel.Random.Next(2));
if (!client.Map.SelectCoordonates(ref X, ref Y))
{
X = client.Entity.X;
Y = client.Entity.Y;
}
client.Companion.X = X;
client.Companion.Y = Y;
Network.GamePackets.Data data = new Conquer_Online_Server.Network.GamePackets.Data(tru e);
data.ID = Network.GamePackets.Data.Jump;
data.dwParam = (uint)((Y << 16) | X);
data.wParam1 = X;
data.wParam2 = Y;
data.UID = client.Companion.UID;
client.Companion.MonsterInfo.SendScreen(data);
}
else if (distance > 4)
{
Enums.ConquerAngle facing = ServerBase.Kernel.GetAngle(client.Companion.X, client.Companion.Y, client.Companion.Owner.Entity.X, client.Companion.Owner.Entity.Y);
if (!client.Companion.Move(facing))
{
facing = (Enums.ConquerAngle)ServerBase.Kernel.Random.Next( 7);
if (client.Companion.Move(facing))
{
client.Companion.Facing = facing;
Network.GamePackets.GroundMovement move = new Conquer_Online_Server.Network.GamePackets.GroundMo vement(true);
move.Direction = facing;
move.UID = client.Companion.UID;
move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
client.Companion.MonsterInfo.SendScreen(move);
}
}
else
{
client.Companion.Facing = facing;
Network.GamePackets.GroundMovement move = new Conquer_Online_Server.Network.GamePackets.GroundMo vement(true);
move.Direction = facing;
move.UID = client.Companion.UID;
move.GroundMovementType = Network.GamePackets.GroundMovement.Run;
client.Companion.MonsterInfo.SendScreen(move);
}
}
else
{
var monster = client.Companion;
if (monster.MonsterInfo.InSight == 0)
{
if (client.Entity.AttackPacket != null)
{
if (client.Entity.AttackPacket.AttackType == Network.GamePackets.Attack.Magic)
{
if (client.Entity.AttackPacket.Decoded)
{
if (SpellTable.SpellInformations.ContainsKey((ushort) client.Entity.AttackPacket.Damage))
{
var info = Database.SpellTable.SpellInformations[(ushort)client.Entity.AttackPacket.Damage].Values.ToArray()[client.Spells[(ushort)client.Entity.AttackPacket.Damage].Level];
if (info.CanKill)
{
monster.MonsterInfo.InSight = client.Entity.AttackPacket.Attacked;
}
}
}
}
else
{
monster.MonsterInfo.InSight = client.Entity.AttackPacket.Attacked;
}
}
}
else
{
if (monster.MonsterInfo.InSight > 400000 && monster.MonsterInfo.InSight < 600000 || monster.MonsterInfo.InSight > 800000 && monster.MonsterInfo.InSight != monster.UID)
{
Entity attacked = null;
if (client.Screen.TryGetValue(monster.MonsterInfo.InS ight, out attacked))
{
if (Now > monster.AttackStamp.AddMilliseconds(monster.Monste rInfo.AttackSpeed))
{
monster.AttackStamp = Now;
if (attacked.Dead)
{
monster.MonsterInfo.InSight = 0;
}
else
new Game.Attacking.Handle(null, monster, attacked);
}
}
else
monster.MonsterInfo.InSight = 0;
}
}
}
}
}
}
static void BlessThread_Execute()
{
lock (Values)
Values = ServerBase.Kernel.GamePool.Values.ToArray();
foreach (Client.GameState client in Values)
{
if (client.Screen == null || client.Entity == null)
{
client.Disconnect();
}
if (client.Socket.Connected)
{
if (client.Entity.Reborn > 1)
continue;
if (!client.Entity.ContainsFlag(Network.GamePackets.U pdate.Flags.Praying))
{
foreach (Interfaces.IMapObject ClientObj in client.Screen.Objects)
{
if (ClientObj != null)
{
if (ClientObj is Game.Entity)
{
if (ClientObj.MapObjType == Conquer_Online_Server.Game.MapObjectType.Player)
{
var Client = ClientObj.Owner;
if (Client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.CastPray))
{
if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, ClientObj.X, ClientObj.Y) <= 3)
{
client.Entity.AddFlag(Network.GamePackets.Update.F lags.Praying);
client.PrayLead = Client;
client.Entity.Action = Client.Entity.Action;
Client.Prayers.Add(client);
}
}
}
}
}
}
}
else
{
if (client.PrayLead != null)
{
if (ServerBase.Kernel.GetDistance(client.Entity.X, client.Entity.Y, client.PrayLead.Entity.X, client.PrayLead.Entity.Y) > 4)
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Praying);
client.PrayLead.Prayers.Remove(client);
client.PrayLead = null;
}
}
}
}
}
}
static void StatusFlagChange_Execute()
{
Time32 Now = Time32.Now;
foreach (Client.GameState client in Values)
{
if (client.Socket.Connected && client.Entity != null)
{
#region Bless
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.CastPray))
{
if (client.BlessTime <= 345000)
client.BlessTime += 1500;
else
client.BlessTime = 360000;
}
else if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Praying))
{
if (client.PrayLead != null)
{
if (client.PrayLead.Socket.Connected)
{
if (client.BlessTime <= 355000)
client.BlessTime += 500;
else
client.BlessTime = 3600;
}
else
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Praying);
}
else
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Praying);
}
else
{
if (client.BlessTime > 0)
{
if (client.BlessTime >= 500)
{
client.BlessTime -= 500;
client.Entity.Update(Network.GamePackets.Update.Lu ckyTimeTimer, client.BlessTime, false);
}
else
{
client.BlessTime = 0;
client.Entity.Update(Network.GamePackets.Update.Lu ckyTimeTimer, client.BlessTime, false);
}
}
}
#endregion
#region Flashing name
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.FlashingName))
{
if (Now > client.Entity.FlashingNameStamp.AddSeconds(client. Entity.FlashingNameTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.FlashingName);
}
}
#endregion
#region XPList
if (!client.Entity.ContainsFlag(Network.GamePackets.U pdate.Flags.XPList))
{
if (Now > client.XPCountStamp.AddSeconds(3))
{
#region Arrows
if (client.Equipment != null)
{
if (!client.Equipment.Free(5))
{
if (Network.PacketHandler.IsArrow(client.Equipment.Tr yGetItem(5).ID))
{
Database.ConquerItemTable.UpdateDurabilityItem(cli ent.Equipment.TryGetItem(5));
}
}
}
#endregion
client.XPCountStamp = Now;
client.XPCount++;
if (client.XPCount >= 100)
{
client.Entity.AddFlag(Network.GamePackets.Update.F lags.XPList);
client.XPCount = 0;
client.XPListStamp = Now;
}
}
}
else
{
if (Now > client.XPListStamp.AddSeconds(20))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.XPList);
}
}
#endregion
#region KOSpell
if (client.Entity.OnKOSpell())
{
if (client.Entity.OnCyclone())
{
int Seconds = Now.AllSeconds() - client.Entity.CycloneStamp.AddSeconds(client.Entit y.CycloneTime).AllSeconds();
if (Seconds >= 1)
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Cyclone);
}
}
if (client.Entity.OnSuperman())
{
int Seconds = Now.AllSeconds() - client.Entity.SupermanStamp.AddSeconds(client.Enti ty.SupermanTime).AllSeconds();
if (Seconds >= 1)
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Superman);
}
}
if (!client.Entity.OnKOSpell())
{
//Record KO
client.Entity.KOCount = 0;
}
}
#endregion
#region Buffers
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Stigma))
{
if (Now >= client.Entity.StigmaStamp.AddSeconds(client.Entity .StigmaTime))
{
client.Entity.StigmaTime = 0;
client.Entity.StigmaIncrease = 0;
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Stigma);
}
}
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Dodge))
{
if (Now >= client.Entity.DodgeStamp.AddSeconds(client.Entity. DodgeTime))
{
client.Entity.DodgeTime = 0;
client.Entity.DodgeIncrease = 0;
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Dodge);
}
}
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Invisibility))
{
if (Now >= client.Entity.InvisibilityStamp.AddSeconds(client. Entity.InvisibilityTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Invisibility);
}
}
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.StarOfAccuracy))
{
if (client.Entity.StarOfAccuracyTime != 0)
{
if (Now >= client.Entity.StarOfAccuracyStamp.AddSeconds(clien t.Entity.StarOfAccuracyTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.StarOfAccuracy);
}
}
else
{
if (Now >= client.Entity.AccuracyStamp.AddSeconds(client.Enti ty.AccuracyTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.StarOfAccuracy);
}
}
}
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.MagicShield))
{
if (client.Entity.MagicShieldTime != 0)
{
if (Now >= client.Entity.MagicShieldStamp.AddSeconds(client.E ntity.MagicShieldTime))
{
client.Entity.MagicShieldIncrease = 0;
client.Entity.MagicShieldTime = 0;
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.MagicShield);
}
}
else
{
if (Now >= client.Entity.ShieldStamp.AddSeconds(client.Entity .ShieldTime))
{
client.Entity.ShieldIncrease = 0;
client.Entity.ShieldTime = 0;
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.MagicShield);
}
}
}
#endregion
#region Fly
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.Fly))
{
if (Now >= client.Entity.FlyStamp.AddSeconds(client.Entity.Fl yTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.Fly);
client.Entity.FlyTime = 0;
}
}
#endregion
#region PoisonStar
if (client.Entity.NoDrugsTime > 0)
{
if (Now > client.Entity.NoDrugsStamp.AddSeconds(client.Entit y.NoDrugsTime))
{
client.Entity.NoDrugsTime = 0;
}
}
#endregion
#region ToxicFog
if (client.Entity.ToxicFogLeft > 0)
{
if (Now >= client.Entity.ToxicFogStamp.AddSeconds(2))
{
float Percent = client.Entity.ToxicFogPercent;
//Remove this line if you want it normal
Percent = Math.Min(0.1F, client.Entity.ToxicFogPercent);
client.Entity.ToxicFogLeft--;
client.Entity.ToxicFogStamp = Now;
if (client.Entity.Hitpoints > 1)
{
uint damage = Game.Attacking.Calculate.Percent(client.Entity, Percent);
client.Entity.Hitpoints -= damage;
Network.GamePackets.SpellUse suse = new Conquer_Online_Server.Network.GamePackets.SpellUse (true);
suse.Attacker = client.Entity.UID;
suse.SpellID = 10010;
suse.Targets.Add(client.Entity.UID, damage);
client.SendScreen(suse, true);
if (client.QualifierGroup != null)
client.QualifierGroup.UpdateDamage(ServerBase.Kern el.GamePool[client.ArenaStatistic.PlayWith], damage);
}
}
}
#endregion
#region FatalStrike
if (client.Entity.OnFatalStrike())
{
if (Now > client.Entity.FatalStrikeStamp.AddSeconds(client.E ntity.FatalStrikeTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.FatalStrike);
}
}
#endregion
if (client.Entity.OnOblivion())
{
if (Now > client.Entity.OblivionStamp.AddSeconds(client.Enti ty.OblivionTime))
{
client.Entity.RemoveFlag2(Network.GamePackets.Upda te.Flags2.Oblivion);
}
}
#region ShurikenVortex
if (client.Entity.ContainsFlag(Network.GamePackets.Up date.Flags.ShurikenVortex))
{
if (Now > client.Entity.ShurikenVortexStamp.AddSeconds(clien t.Entity.ShurikenVortexTime))
{
client.Entity.RemoveFlag(Network.GamePackets.Updat e.Flags.ShurikenVortex);
}
}
#endregion
#region Transformations
if (client.Entity.Transformed)
{
if (Now > client.Entity.TransformationStamp.AddSeconds(clien t.Entity.TransformationTime))
{
client.Entity.Untransform();
}
}
#endregion
}
//else
// client.Disconnect();
}
}
public static void CommandsAI(string command)
{
if (command == null)
return;
string[] data = command.Split(' ');
switch (data[0])
{
case "@alivetime":
{
DateTime now = DateTime.Now;
TimeSpan t2 = new TimeSpan(StartDate.ToBinary());
TimeSpan t1 = new TimeSpan(now.ToBinary());
Program.WriteLine("The server has been online " + (int)(t1.TotalHours - t2.TotalHours) + " hours, " + (int)((t1.TotalMinutes - t2.TotalMinutes) % 60) + " minutes.");
break;
}
case "@online":
{
Program.WriteLine("Online players count: " + ServerBase.Kernel.GamePool.Count);
string line = "";
foreach (Client.GameState pClient in ServerBase.Kernel.GamePool.Values)
line += pClient.Entity.Name + ",";
if (line != "")
{
line = line.Remove(line.Length - 1);
Program.WriteLine("Players: " + line);
}
break;
}
case "@memoryusage":
{
var proc = System.Diagnostics.Process.GetCurrentProcess();
Program.WriteLine("Thread count: " + proc.Threads.Count);
Program.WriteLine("Memory set(MB): " + ((double)((double)proc.WorkingSet64 / 1024)) / 1024);
proc.Close();
break;
}
case "@save":
{
foreach (Client.GameState client in ServerBase.Kernel.GamePool.Values)
{
client.Account.Save();
Database.EntityTable.SaveEntity(client);
Database.SkillTable.SaveProficiencies(client);
Database.SkillTable.SaveSpells(client);
Database.ArenaTable.SaveArenaStatistics(client.Are naStatistic);
}
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.Constants.ServerName).Execute();
}
break;
case "@playercap":
{
try
{
PlayerCap = int.Parse(data[1]);
}
catch
{
}
break;
}
case "@exit":
{
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.Constants.ServerName).Execute();
GameServer.Disable();
AuthServer.Disable();
var WC = ServerBase.Kernel.GamePool.Values.ToArray();
foreach (Client.GameState client in WC)
client.Disconnect();
if (GuildWar.IsWar)
GuildWar.End();
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.Constants.ServerName).Execute();
Environment.Exit(0);
}
break;
case "@restart":
{
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.Constants.ServerName).Execute();
GameServer.Disable();
AuthServer.Disable();
var WC = ServerBase.Kernel.GamePool.Values.ToArray();
foreach (Client.GameState client in WC)
client.Disconnect();
if (GuildWar.IsWar)
GuildWar.End();
new Database.MySqlCommand(Database.MySqlCommandType.UP DATE).Update("configuration").Set("ItemUID", Network.GamePackets.ConquerItem.ItemUID.Now).Where ("Server", ServerBase.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;
}
}
static void GameServer_AnnounceNewConnection(Interfaces.ISocke tWrapper obj)
{
obj.Connector = new Client.GameState(obj.Socket);
Client.GameState Client = obj.Connector as Client.GameState;
Client.Send(Client.DHKeyExchance.CreateServerKeyPa cket());
}
public static void GameServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
{
Client.GameState Client = arg2.Connector as Client.GameState;
try
{
Client.Cryptography.Decrypt(arg1);
}
catch {}
if (Client != null)
{
if (Client.Exchange)
{
try
{
Client.Exchange = false;
Client.Action = 1;
ushort position = 7;
uint PacketLen = BitConverter.ToUInt32(arg1, position); position += 4;
int JunkLen = BitConverter.ToInt32(arg1, position); position += 4; position += (ushort)JunkLen;
int Len = BitConverter.ToInt32(arg1, position); position += 4;
byte[] pubKey = new byte[Len];
for (int x = 0; x < Len; x++)
pubKey[x] = arg1[x + position];
string PubKey = System.Text.ASCIIEncoding.ASCII.GetString(pubKey);
Client.Cryptography = Client.DHKeyExchance.HandleClientKeyPacket(PubKey, Client.Cryptography);
}
catch
{
Client.Socket.Disconnect(false);
}
}
else
{
if (!Client.Exchange && Client.Action != 0)
Network.PacketHandler.HandleBuffer(arg1, Client);
}
}
}
static void GameServer_AnnounceDisconnection(Interfaces.ISocke tWrapper obj)
{
if (obj.Connector != null)
{
Client.GameState Client = obj.Connector as Client.GameState;
Client.Disconnect();
}
}
static void AuthServer_AnnounceNewConnection(Interfaces.ISocke tWrapper obj)
{
Client.AuthState authState = new Client.AuthState(obj.Socket);
authState.Cryptographer = new Network.Cryptography.AuthCryptography();
Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
pcs.Seed = ServerBase.Kernel.Random.Next();
authState.PasswordSeed = pcs.Seed;
authState.Send(pcs);
obj.Connector = authState;
}
static void AuthServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
{
if (arg1.Length == 276)
{
Client.AuthState player = arg2.Connector as Client.AuthState;
player.Cryptographer.Decrypt(arg1);
player.Info = new Authentication();
player.Info.Deserialize(arg1);
player.Account = new AccountTable(player.Info.Username);
msvcrt.msvcrt.srand(player.PasswordSeed);
byte[] encpw = new byte[16];
var rc5Key = new byte[0x10];
for (int i = 0; i < 0x10; i++)
rc5Key[i] = (byte)msvcrt.msvcrt.rand();
Buffer.BlockCopy(arg1, 132, encpw, 0, 16);
var password = "";
//try
//{
password = System.Text.Encoding.ASCII.GetString(
(new Network.Cryptography.ConquerPasswordCryptpographer (player.Info.Username)).Decrypt(
(new Network.Cryptography.RC5(rc5Key)).Decrypt(encpw))) ;
password = password.Split('\0')[0];
//}
//catch
//{
// player.Send(new Conquer_Online_Server.Network.GamePackets.Message( "Invalid client version.", "ALLUSERS", System.Drawing.Color.Orange, Conquer_Online_Server.Network.GamePackets.Message. Dialog));
// return;
//}
string NoNumPadNumbers = "";
foreach (char c in password)
{
switch (c.ToString())
{
case "-": NoNumPadNumbers += "0"; break;
case "#": NoNumPadNumbers += "1"; break;
case "(": NoNumPadNumbers += "2"; break;
case "\"": NoNumPadNumbers += "3"; break;
case "%": NoNumPadNumbers += "4"; break;
case "\f": NoNumPadNumbers += "5"; break;
case "'": NoNumPadNumbers += "6"; break;
case "$": NoNumPadNumbers += "7"; break;
case "&": NoNumPadNumbers += "8"; break;
case "!": NoNumPadNumbers += "9"; break;
default: NoNumPadNumbers += c; break;
}
}
password = NoNumPadNumbers;
Forward Fw = new Forward();
if (password == player.Account.Password)
{
//if (player.Account.State == AccountTable.AccountState.Banned)
// Fw.Type = Forward.ForwardType.Banned;
//else
Fw.Type = Forward.ForwardType.Ready;
}
else
{
Fw.Type = Forward.ForwardType.InvalidInfo;
}
if (Fw.Type != Network.AuthPackets.Forward.ForwardType.InvalidInf o)
{
Fw.Identifier = Network.AuthPackets.Forward.Incrementer.Next;
ServerBase.Kernel.AwaitingPool.Add(Fw.Identifier, player.Account);
}
Fw.IP = GameIP;
Fw.Port = GamePort;
player.Send(Fw);
}
else
{
arg2.Socket.Disconnect(false);
}
}
static void AuthServer_AnnounceDisconnection(Interfaces.ISocke tWrapper obj)
{
}
}
}
|