コード例 #1
0
ファイル: WorldCluster.cs プロジェクト: bmjoy/MangosSharp
        public void WaitConsoleCommand()
        {
            var tmp = "";

            string[] commandList;
            string[] cmds;
            var      cmd = Array.Empty <string>();
            int      varList;

            while (!_clusterServiceLocator.WcNetwork.WorldServer.MFlagStopListen)
            {
                try
                {
                    tmp         = Log.ReadLine();
                    commandList = tmp.Split(";");
                    var loopTo = Information.UBound(commandList);
                    for (varList = Information.LBound(commandList); varList <= loopTo; varList++)
                    {
                        cmds = Strings.Split(commandList[varList], " ", 2);
                        if (commandList[varList].Length > 0)
                        {
                            // <<<<<<<<<<<COMMAND STRUCTURE>>>>>>>>>>
                            switch (cmds[0].ToLower() ?? "")
                            {
                            case "shutdown":
                            {
                                Log.WriteLine(LogType.WARNING, "Server shutting down...");
                                _clusterServiceLocator.WcNetwork.WorldServer.MFlagStopListen = true;
                                break;
                            }

                            case "info":
                            {
                                Log.WriteLine(LogType.INFORMATION, "Used memory: {0}", Strings.Format(GC.GetTotalMemory(false), "### ### ##0 bytes"));
                                break;
                            }

                            case "help":
                            {
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.WriteLine("'WorldCluster' Command list:");
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("---------------------------------");
                                Console.WriteLine("");
                                Console.WriteLine("'help' - Brings up the 'WorldCluster' Command list (this).");
                                Console.WriteLine("");
                                Console.WriteLine("'info' - Displays used memory.");
                                Console.WriteLine("");
                                Console.WriteLine("'shutdown' - Shuts down WorldCluster.");
                                break;
                            }

                            default:
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Error! Cannot find specified command. Please type 'help' for information on console for commands.");
                                Console.ForegroundColor = ConsoleColor.Gray;
                                break;
                            }
                            }
                            // <<<<<<<<<<</END COMMAND STRUCTURE>>>>>>>>>>>>
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.WriteLine(LogType.FAILED, "Error executing command [{0}]. {2}{1}", Strings.Format(DateAndTime.TimeOfDay, "hh:mm:ss"), tmp, e.ToString(), Constants.vbCrLf);
                }
            }
        }
コード例 #2
0
ファイル: WorldServer.cs プロジェクト: bmjoy/MangosSharp
        public void WaitConsoleCommand()
        {
            string tmp = "";

            string[] cmd = new string[0];
            while (!ClsWorldServer._flagStopListen)
            {
                try
                {
                    tmp = Log.ReadLine();
                    string[] CommandList = tmp.Split(";");
                    int      num         = Information.LBound(CommandList);
                    int      num2        = Information.UBound(CommandList);
                    for (int varList = num; varList <= num2; varList = checked (varList + 1))
                    {
                        string[] cmds = Strings.Split(CommandList[varList], " ", 2);
                        if (CommandList[varList].Length > 0)
                        {
                            switch (cmds[0].ToLower())
                            {
                            case "shutdown":
                                Log.WriteLine(LogType.WARNING, "Server shutting down...");
                                ClsWorldServer._flagStopListen = true;
                                break;

                            case "info":
                                Log.WriteLine(LogType.INFORMATION, "Used memory: {0}", Strings.Format(GC.GetTotalMemory(forceFullCollection: false), "### ### ##0 bytes"));
                                break;

                            case "help":
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.WriteLine("'WorldServer' Command list:");
                                Console.ForegroundColor = ConsoleColor.White;
                                Console.WriteLine("---------------------------------");
                                Console.WriteLine("");
                                Console.WriteLine("");
                                Console.WriteLine("'help' - Brings up the 'WorldServer' Command list (this).");
                                Console.WriteLine("");
                                Console.WriteLine("'info' - Brings up a context menu showing server information (such as memory used).");
                                Console.WriteLine("");
                                Console.WriteLine("'shutdown' - Shuts down 'WorldServer'.");
                                break;

                            default:
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Error! Cannot find specified command. Please type 'help' for information on 'WorldServer' console commands.");
                                Console.ForegroundColor = ConsoleColor.Gray;
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProjectData.SetProjectError(ex);
                    Exception e = ex;
                    Log.WriteLine(LogType.FAILED, "Error executing command [{0}]. {2}{1}", Strings.Format(DateAndTime.TimeOfDay, "hh:mm:ss"), tmp, e.ToString(), Environment.NewLine);
                    ProjectData.ClearProjectError();
                }
            }
        }