public static void PrivateItemPacket(PacketWriter Writer, int id, byte max, byte avatar, bool mspawn) { try { List<byte> slots = new List<byte>(); Systems.MsSQL ms = new Systems.MsSQL("SELECT * FROM char_items WHERE owner='" + id + "' AND slot >= '0' AND slot <= '" + max + "' AND inavatar='" + avatar + "' AND storagetype='0' AND quantity='1'"); using (SqlDataReader reader = ms.Read()) { int count = ms.Count(); Writer.Byte(count); while (reader.Read()) { byte slot = reader.GetByte(5); byte plusvalue = reader.GetByte(4); int itemid = reader.GetInt32(2); if (itemid != 0) { if (!slots.Exists(delegate(byte bk) { return bk == slot; })) { slots.Add(slot); } Writer.DWord(itemid); Writer.Byte(plusvalue); } } } ms.Close(); } catch (Exception ex) { Console.WriteLine("Item Error : {0}", ex); Systems.Debugger.Write(ex); } }
public static void PrivateItemPacket(PacketWriter Writer, int id, byte max, byte avatar, bool mspawn) { try { List <byte> slots = new List <byte>(); Systems.MsSQL ms = new Systems.MsSQL("SELECT * FROM char_items WHERE owner='" + id + "' AND slot >= '0' AND slot <= '" + max + "' AND inavatar='" + avatar + "' AND storagetype='0' AND quantity='1'"); using (SqlDataReader reader = ms.Read()) { int count = ms.Count(); Writer.Byte(count); while (reader.Read()) { byte slot = reader.GetByte(5); byte plusvalue = reader.GetByte(4); int itemid = reader.GetInt32(2); if (itemid != 0) { if (!slots.Exists(delegate(byte bk) { return(bk == slot); })) { slots.Add(slot); } Writer.DWord(itemid); Writer.Byte(plusvalue); } } } ms.Close(); } catch (Exception ex) { Console.WriteLine("Item Error : {0}", ex); Systems.Debugger.Write(ex); } }
public static byte[] GuildStorageData(character c) { Systems.MsSQL getstorage = new Systems.MsSQL("SELECT * FROM char_items WHERE guild_storage_id='" + c.Network.Guild.Guildid + "' AND storagetype='3'"); int itemcount = getstorage.Count(); PacketWriter Writer = new PacketWriter(); Writer.Create(Systems.SERVER_GUILD_STORAGE3); Writer.Byte(c.Network.Guild.StorageSlots); Writer.Byte(itemcount); if (itemcount != 0) { using (System.Data.SqlClient.SqlDataReader reader = getstorage.Read()) { while (reader.Read()) { Item.AddItemPacket(Writer, reader.GetByte(5), reader.GetInt32(2), reader.GetByte(4), reader.GetInt16(6), reader.GetInt32(7), reader.GetInt32(0), reader.GetInt32(9), reader.GetInt32(30)); } } } getstorage.Close(); return(Writer.GetBytes()); }
public static byte[] UnionInfo(Systems c) { PacketWriter Writer = new PacketWriter(); Writer.Create(Systems.SERVER_GUILD_UNIONS); Writer.DWord(c.Character.Information.CharacterID); // Union owner id Writer.DWord(7); // ??Need to check Writer.DWord(c.Character.Network.Guild.Guildid); // Union leader guild id Writer.Byte(c.Character.Network.Guild.Unions.Count); // Count guilds in union //Get all guilds details foreach (int guild in c.Character.Network.Guild.Unions) { //Load other guild data Systems.MsSQL guild_data = new Systems.MsSQL("SELECT * FROM guild WHERE id='" + guild + "'"); using (System.Data.SqlClient.SqlDataReader reader = guild_data.Read()) { while (reader.Read()) { string Guildname = reader.GetString(1); byte Guildlevel = reader.GetByte(2); byte Guildmembercount = reader.GetByte(6); int Ownerid = reader.GetInt32(9); string Charname = Systems.MsSQL.GetData("SELECT name FROM character WHERE id='" + Ownerid + "'", "name").ToString(); int Charmodel = Convert.ToInt32(Systems.MsSQL.GetData("SELECT chartype FROM character WHERE id='" + Ownerid + "'", "chartype")); Writer.DWord(guild); //Guild ID Writer.Text(reader.GetString(1)); //Guildname Writer.Byte(reader.GetByte(2)); //Guildlevel Writer.Text(Charname); //Ownername Writer.DWord(Charmodel); //Owner model Writer.Byte(reader.GetByte(6)); //Guild member count //Get guild details Systems Guildmembers = Systems.GetGuildPlayer(guild); //Add clients that are online to union list //Null check if (Guildmembers != null) { foreach (int member in Guildmembers.Character.Network.Guild.Members) { //make sure member isnt 0 if (member != 0) { //Get player details Systems getmember = Systems.GetPlayerMainid(member); //Make sure that the player is there if (getmember != null) { //Add client to union list c.Character.Network.Guild.UnionMembers.Add(getmember.Character.Information.CharacterID); //Add to member if (c.Character.Information.CharacterID != getmember.Character.Information.CharacterID) { getmember.Character.Network.Guild.UnionMembers.Add(c.Character.Information.CharacterID); } } } } } } } } return(Writer.GetBytes()); }
public static void ExecuteCommand(string aCommand, Socket aSocket) { try { if (aCommand != null) { string[] command = aCommand.Split(' '); if (command[0] == "/help") { if (aSocket == null) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" Ingame notice: Type 1 space then message."); Console.WriteLine(" //clear"); Console.WriteLine(" //repairitems"); Console.WriteLine(" //respawn_unique"); Console.WriteLine(" //event"); Console.WriteLine(" //shutdown"); Console.WriteLine(" //manager"); Console.ForegroundColor = ConsoleColor.Yellow; } else { sendSocket(aSocket, "Ingame notice: Type 1 space then message." + Environment.NewLine); sendSocket(aSocket, " //clear = cleanup unused memory" + Environment.NewLine); sendSocket(aSocket, " //repairitems" + Environment.NewLine); sendSocket(aSocket, " //respawn_unique" + Environment.NewLine); sendSocket(aSocket, " //event" + Environment.NewLine); sendSocket(aSocket, " //shutdown" + Environment.NewLine); } } else if (command[0] == "//clear") { System.GC.Collect(); GC.Collect(0, GCCollectionMode.Forced); sendSocket(aSocket, "done memory cleanup" + Environment.NewLine); } else if (command[0] == "//shutdown") { byte waitTime = 5; if (command.Length > 1) { waitTime = System.Convert.ToByte(command[1]); } if (aSocket != null) { aSocket.Send(Encoding.ASCII.GetBytes("SHUTDOWN_START" + Environment.NewLine)); } lock (Systems.clients) { Console.WriteLine("{0}stopping server and sending notice to clients ...", DarkEmu_GameServer.Global.Product.Prefix); sendSocket(aSocket, "SHUTDOWN: stopping server and sending notice to clients ..." + Environment.NewLine); net.ServerCheck(true); net.Stop(); // disable any new connection try { Systems.SendAll(Packet.ChatPacket(7, 0, "The server is stopping, your information will be saved.", "")); Systems.SendAll(Packet.StartingLeaveGame(waitTime, 0)); } catch { } Thread.Sleep(waitTime); Console.WriteLine("@SHUTDOWN: logoff clients ..."); sendSocket(aSocket, "@SHUTDOWN: logoff clients ..." + Environment.NewLine); while (Systems.clients.Count > 0) { try { try { Systems.clients[0].Send(Packet.EndLeaveGame()); } catch { } //Ignore new character case (used for disconnect kick). Systems c = new Systems(); Systems.clients[0].Disconnect("normal"); } catch { } } } sendSocket(aSocket, "SHUTDOWN_END" + Environment.NewLine); cancelServer = true; Systems.UpdateServerInfo(0); //Environment.Exit(0); } else if (command[0] == "//repairitems") { int fixeditem = 0; Systems.MsSQL ms = new Systems.MsSQL("SELECT * FROM char_items"); using (System.Data.SqlClient.SqlDataReader reader = ms.Read()) { while (reader.Read()) { short amount = reader.GetInt16(7); if (amount < 1) { fixeditem++; amount = 1; Systems.MsSQL.InsertData("UPDATE char_items SET quantity='" + amount + "' WHERE itemnumber='" + "item" + reader.GetByte(5) + "' AND owner='" + reader.GetInt32(3) + "' AND itemid='" + reader.GetInt32(2) + "'"); } } } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("@Gameserver: Items Repaired: {0}", fixeditem); Console.ForegroundColor = ConsoleColor.Yellow; sendSocket(aSocket, String.Format("@Gameserver: Items Repaired: {0}", fixeditem) + Environment.NewLine); } else if (command[0] == "//respawn_unique") { DarkEmu_GameServer.GlobalUnique.StartTGUnique(6000 * 10, 6000 * 10); DarkEmu_GameServer.GlobalUnique.StartUriUnique(7000 * 10, 7000 * 10); DarkEmu_GameServer.GlobalUnique.StartIsyUnique(8000 * 10, 8000 * 10); DarkEmu_GameServer.GlobalUnique.StartLordUnique(9000 * 10, 9000 * 10); DarkEmu_GameServer.GlobalUnique.StartDemonUnique(10000 * 10, 10000 * 10); DarkEmu_GameServer.GlobalUnique.StartCerbUnique(11000 * 10, 11000 * 10); DarkEmu_GameServer.GlobalUnique.StartIvyUnique(11000 * 10, 11000 * 10); //Game.GlobalUnique.StartRoc(11000 * 10, 11000 * 10); DarkEmu_GameServer.GlobalUnique.StartMedusa(11000 * 10, 11000 * 10); DarkEmu_GameServer.GlobalUnique.StartNeith(11000 * 10, 11000 * 10); //Game.GlobalUnique.StartSphinx(11000 * 10, 11000 * 10); DarkEmu_GameServer.GlobalUnique.StartIsis(11000 * 10, 11000 * 10); sendSocket(aSocket, "done respawn" + Environment.NewLine); } else if (command[0] == "//event") { EventMain eventnew = new EventMain(System.IO.Directory.GetCurrentDirectory() + "/data/event.txt"); eventnew.Start(); sendSocket(aSocket, "Event Started" + Environment.NewLine); } else if (command[0] == "") { string information = aCommand; DarkEmu_GameServer.Systems c = new DarkEmu_GameServer.Systems(); DarkEmu_GameServer.Systems.SendAll(c.sendnoticecon(7, 0, information, "")); Console.WriteLine("Notice: " + information); sendSocket(aSocket, "Sent Notice: " + information + Environment.NewLine); } } } catch (Exception ex) { Console.WriteLine("Program.Main {0}", ex); } }
public static void ExecuteCommand(string aCommand, Socket aSocket) { try { if (aCommand != null) { string[] command = aCommand.Split(' '); if (command[0] == "/help") { if (aSocket == null) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(" Ingame notice: Type 1 space then message."); Console.WriteLine(" //clear"); Console.WriteLine(" //repairitems"); Console.WriteLine(" //respawn_unique"); Console.WriteLine(" //shutdown"); Console.WriteLine(" //manager"); Console.ForegroundColor = ConsoleColor.Yellow; } else { sendSocket(aSocket, "Ingame notice: Type 1 space then message." + Environment.NewLine); sendSocket(aSocket, " //clear = cleanup unused memory" + Environment.NewLine); sendSocket(aSocket, " //repairitems" + Environment.NewLine); sendSocket(aSocket, " //respawn_unique" + Environment.NewLine); sendSocket(aSocket, " //shutdown" + Environment.NewLine); } } else if (command[0] == "//clear") { System.GC.Collect(); GC.Collect(0, GCCollectionMode.Forced); sendSocket(aSocket, "done memory cleanup" + Environment.NewLine); } else if (command[0] == "//manager") { if (aSocket == null) { Application.EnableVisualStyles(); Application.Run(new Main()); } } else if (command[0] == "//shutdown") { byte waitTime = 5; if (command.Length > 1) { waitTime = System.Convert.ToByte(command[1]); } if (aSocket != null) { aSocket.Send(Encoding.ASCII.GetBytes("SHUTDOWN_START" + Environment.NewLine)); } lock (Systems.clients) { Console.WriteLine("{0}stopping server and sending notice to clients ...", Game.Global.Product.Prefix); sendSocket(aSocket, "SHUTDOWN: stopping server and sending notice to clients ..." + Environment.NewLine); net.ServerCheck(true); net.Stop(); // disable any new connection try { Systems.SendAll(Packet.ChatPacket(7, 0, "The server is stopping, your information will be saved.", "")); Systems.SendAll(Packet.StartingLeaveGame(waitTime, 0)); } catch { } Thread.Sleep(waitTime); Console.WriteLine("@SHUTDOWN: logoff clients ..."); sendSocket(aSocket, "@SHUTDOWN: logoff clients ..." + Environment.NewLine); while (Systems.clients.Count > 0) { try { try { Systems.clients[0].Send(Packet.EndLeaveGame()); } catch { } //Ignore new character case (used for disconnect kick). Systems c = new Systems(); Systems.clients[0].Disconnect("normal"); } catch { } } } sendSocket(aSocket, "SHUTDOWN_END" + Environment.NewLine); cancelServer = true; Systems.UpdateServerInfo(0); //Environment.Exit(0); } else if (command[0] == "//repairitems") { int fixeditem = 0; Systems.MsSQL ms = new Systems.MsSQL("SELECT * FROM char_items"); using (System.Data.SqlClient.SqlDataReader reader = ms.Read()) { while (reader.Read()) { short amount = reader.GetInt16(7); if (amount < 1) { fixeditem++; amount = 1; Systems.MsSQL.InsertData("UPDATE char_items SET quantity='" + amount + "' WHERE itemnumber='" + "item" + reader.GetByte(5) + "' AND owner='" + reader.GetInt32(3) + "' AND itemid='" + reader.GetInt32(2) + "'"); } } } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("@Gameserver: Items Repaired: {0}", fixeditem); Console.ForegroundColor = ConsoleColor.Yellow; sendSocket(aSocket, String.Format("@Gameserver: Items Repaired: {0}", fixeditem) + Environment.NewLine); } else if (command[0] == "//respawn_unique") { Game.GlobalUnique.StartTGUnique(6000 * 10, 6000 * 10); Game.GlobalUnique.StartUriUnique(7000 * 10, 7000 * 10); Game.GlobalUnique.StartIsyUnique(8000 * 10, 8000 * 10); Game.GlobalUnique.StartLordUnique(9000 * 10, 9000 * 10); Game.GlobalUnique.StartDemonUnique(10000 * 10, 10000 * 10); Game.GlobalUnique.StartCerbUnique(11000 * 10, 11000 * 10); Game.GlobalUnique.StartIvyUnique(11000 * 10, 11000 * 10); //Game.GlobalUnique.StartRoc(11000 * 10, 11000 * 10); Game.GlobalUnique.StartMedusa(11000 * 10, 11000 * 10); Game.GlobalUnique.StartNeith(11000 * 10, 11000 * 10); //Game.GlobalUnique.StartSphinx(11000 * 10, 11000 * 10); Game.GlobalUnique.StartIsis(11000 * 10, 11000 * 10); sendSocket(aSocket, "done respawn" + Environment.NewLine); } else if (command[0] == "") { string information = aCommand; Game.Systems c = new Game.Systems(); Game.Systems.SendAll(c.sendnoticecon(7, 0, information, "")); Console.WriteLine("Notice: " + information); sendSocket(aSocket, "Sent Notice: " + information + Environment.NewLine); } } } catch (Exception ex) { Console.WriteLine("Program.Main {0}", ex); } }
public static byte[] UnionInfo(Systems c) { PacketWriter Writer = new PacketWriter(); Writer.Create(Systems.SERVER_GUILD_UNIONS); Writer.DWord(c.Character.Information.CharacterID); // Union owner id Writer.DWord(7); // ??Need to check Writer.DWord(c.Character.Network.Guild.Guildid); // Union leader guild id Writer.Byte(c.Character.Network.Guild.Unions.Count); // Count guilds in union //Get all guilds details foreach (int guild in c.Character.Network.Guild.Unions) { //Load other guild data Systems.MsSQL guild_data = new Systems.MsSQL("SELECT * FROM guild WHERE id='"+ guild +"'"); using (System.Data.SqlClient.SqlDataReader reader = guild_data.Read()) { while (reader.Read()) { string Guildname = reader.GetString(1); byte Guildlevel = reader.GetByte(2); byte Guildmembercount = reader.GetByte(6); int Ownerid = reader.GetInt32(9); string Charname = Systems.MsSQL.GetData("SELECT name FROM character WHERE id='" + Ownerid + "'", "name").ToString(); int Charmodel = Convert.ToInt32(Systems.MsSQL.GetData("SELECT chartype FROM character WHERE id='" + Ownerid + "'", "chartype")); Writer.DWord(guild); //Guild ID Writer.Text(reader.GetString(1)); //Guildname Writer.Byte(reader.GetByte(2)); //Guildlevel Writer.Text(Charname); //Ownername Writer.DWord(Charmodel); //Owner model Writer.Byte(reader.GetByte(6)); //Guild member count //Get guild details Systems Guildmembers = Systems.GetGuildPlayer(guild); //Add clients that are online to union list //Null check if (Guildmembers != null) { foreach (int member in Guildmembers.Character.Network.Guild.Members) { //make sure member isnt 0 if (member != 0) { //Get player details Systems getmember = Systems.GetPlayerMainid(member); //Make sure that the player is there if (getmember != null) { //Add client to union list c.Character.Network.Guild.UnionMembers.Add(getmember.Character.Information.CharacterID); //Add to member if (c.Character.Information.CharacterID != getmember.Character.Information.CharacterID) { getmember.Character.Network.Guild.UnionMembers.Add(c.Character.Information.CharacterID); } } } } } } } } return Writer.GetBytes(); }
public static byte[] GuildStorageData(character c) { Systems.MsSQL getstorage = new Systems.MsSQL("SELECT * FROM char_items WHERE guild_storage_id='" + c.Network.Guild.Guildid + "' AND storagetype='3'"); int itemcount = getstorage.Count(); PacketWriter Writer = new PacketWriter(); Writer.Create(Systems.SERVER_GUILD_STORAGE3); Writer.Byte(c.Network.Guild.StorageSlots); Writer.Byte(itemcount); if (itemcount != 0) { using (System.Data.SqlClient.SqlDataReader reader = getstorage.Read()) { while (reader.Read()) { Item.AddItemPacket(Writer, reader.GetByte(5), reader.GetInt32(2), reader.GetByte(4), reader.GetInt16(6), reader.GetInt32(7), reader.GetInt32(0), reader.GetInt32(9), reader.GetInt32(30)); } } } getstorage.Close(); return Writer.GetBytes(); }