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); } }
private void sndNoticeButton_Click(object sender, EventArgs e) { string message = sndNoticeMessage.Text; Systems.SendAll(Packet.ChatPacket(7, 0, message, "")); }