DarkEmu_GameServer.Systems.sendnoticecon C# (CSharp) Метод

sendnoticecon() публичный Метод

public sendnoticecon ( int type, int id, string text, string name ) : byte[]
type int
id int
text string
name string
Результат byte[]
        public byte[] sendnoticecon(int type, int id, string text, string name)
        {
            //Create new packet writer
            PacketWriter Writer = new PacketWriter();
            //Add opcode for chat
            Writer.Create(Systems.SERVER_CHAT);
            //Write byte chat type 7 = notice
            Writer.Byte(7);
            //Set message to message long from string text given
            string Message = MessageToMessagelong(text);
            //Write textlenght value
            Writer.Textlen(Message);
            //Repeat for message lenght
            for (int g = 0; g < Message.Length; )
            {
                //Writer word value per letter
                Writer.Word(int.Parse(Message.Substring(g, 2), System.Globalization.NumberStyles.HexNumber, null));
                //Set g + 2
                g = g + 2;
            }
            //Return all bytes
            return Writer.GetBytes();
        }

Usage Example

Пример #1
0
        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);
            }
        }
All Usage Examples Of DarkEmu_GameServer.Systems::sendnoticecon
Systems