Пример #1
0
        /// <summary>
        ///     Invokes the command.
        /// </summary>
        /// <param name="inputData">The input data.</param>
        internal static void InvokeCommand(string inputData)
        {
            if (string.IsNullOrEmpty(inputData) && YupiWriterManager.DisabledState)
            {
                return;
            }

            try
            {
                if (inputData == null)
                {
                    return;
                }

                string firstArgument = inputData, secondArgument = string.Empty;

                if (inputData.Contains(" "))
                {
                    string[] strArguments = inputData.Split(' ');

                    firstArgument  = strArguments[0];
                    secondArgument = strArguments[1];
                }

                switch (firstArgument)
                {
                case "shutdown":
                    YupiLogManager.LogMessage($"Server Shutdowning at {DateTime.Now}.");

                    YupiWriterManager.DisablePrimaryWriting(true);

                    YupiWriterManager.WriteLine("Shutdown Initalized", "Yupi.Life", ConsoleColor.DarkYellow);

                    Yupi.PerformShutDown();

                    Console.WriteLine();
                    break;

                case "restart":
                    YupiLogManager.LogMessage($"Server Restarting at {DateTime.Now}.");

                    YupiWriterManager.DisablePrimaryWriting(true);

                    YupiWriterManager.WriteLine("Restart Initialized", "Yupi.Life", ConsoleColor.DarkYellow);

                    Yupi.PerformRestart();
                    Console.WriteLine();
                    break;

                case "reload":
                    switch (secondArgument)
                    {
                    case "database":
                        Console.WriteLine("Database destroyed");
                        Console.WriteLine();
                        break;

                    case "packets":
                        LibraryParser.ReloadDictionarys();
                        Console.WriteLine("> Packets Reloaded Suceffuly...");
                        Console.WriteLine();
                        break;

                    case "catalogue":
                        FurnitureDataManager.SetCache();

                        using (IQueryAdapter adapter = Yupi.GetDatabaseManager().GetQueryReactor())
                            GetGame().GetCatalogManager().Init(adapter);

                        FurnitureDataManager.Clear();

                        GetGame()
                        .GetClientManager()
                        .QueueBroadcaseMessage(
                            new ServerMessage(LibraryParser.OutgoingRequest("PublishShopMessageComposer")));
                        Console.WriteLine("Catalogue was re-loaded.");
                        Console.WriteLine();
                        break;

                    case "modeldata":
                        using (IQueryAdapter adapter2 = Yupi.GetDatabaseManager().GetQueryReactor())
                            GetGame().GetRoomManager().LoadModels(adapter2);

                        Console.WriteLine("Room models were re-loaded.");
                        Console.WriteLine();
                        break;

                    case "bans":
                        using (IQueryAdapter adapter3 = Yupi.GetDatabaseManager().GetQueryReactor())
                            GetGame().GetBanManager().LoadBans(adapter3);

                        Console.WriteLine("Bans were re-loaded");
                        Console.WriteLine();
                        break;

                    case "filter":
                        UserChatInputFilter.Reload();
                        BlackWordsManager.Reload();
                        break;

                    default:
                        UnknownCommand(inputData);
                        Console.WriteLine();
                        break;
                    }
                    break;

                case "clear":
                    Console.Clear();
                    break;

                case "status":
                    TimeSpan uptime = DateTime.Now - Yupi.YupiServerStartDateTime;

                    Console.WriteLine("Server status:");
                    Console.WriteLine();
                    Console.WriteLine("Uptime:");
                    Console.WriteLine("\tDays:    {0}", uptime.Days);
                    Console.WriteLine("\tHours:   {0}", uptime.Hours);
                    Console.WriteLine("\tMinutes: {0}", uptime.Minutes);
                    Console.WriteLine();
                    Console.WriteLine("Stats:");
                    Console.WriteLine("\tAccepted Connections: {0}",
                                      Yupi.GetConnectionManager().Manager.AcceptedConnections);
                    Console.WriteLine("\tActive Threads: {0}", Process.GetCurrentProcess().Threads.Count);
                    Console.WriteLine();
                    Console.WriteLine();
                    break;

                case "gcinfo":
                {
                    Console.WriteLine("Mode: " + GCSettings.LatencyMode);
                    Console.WriteLine("Is server GC: " + GCSettings.IsServerGC);

                    break;
                }

                case "memstat":
                {
                    Console.WriteLine("GC status:");
                    Console.WriteLine("\tGeneration supported: " + GC.MaxGeneration);
                    Console.WriteLine("\tLatency mode: " + GCSettings.LatencyMode);
                    Console.WriteLine("\tIs server GC: " + GCSettings.IsServerGC);
                    Console.WriteLine();
                    break;
                }

                case "memory":
                {
                    GC.Collect();
                    Console.WriteLine("Memory flushed");

                    break;
                }

                case "help":
                    Console.WriteLine("shutdown");
                    Console.WriteLine("clear");
                    Console.WriteLine("memory");
                    Console.WriteLine("status");
                    Console.WriteLine("restart");
                    Console.WriteLine("memstat");
                    Console.WriteLine("reload catalogue");
                    Console.WriteLine("reload modeldata");
                    Console.WriteLine("reload bans");
                    Console.WriteLine("reload packets");
                    Console.WriteLine("reload filter");
                    Console.WriteLine("reload packets");
                    Console.WriteLine("reload database");
                    Console.WriteLine();
                    break;

                default:
                    UnknownCommand(inputData);
                    break;
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }