Example #1
0
        /// <summary>
        /// Handles the server action
        /// </summary>
        /// <param name="parameters"></param>
        public void OnAction(Hashtable parameters)
        {
            Console.WriteLine("This server DDTankII, edit and build by Trminhpc!");
            Console.WriteLine("Starting GameServer ... please wait a moment!");
            CenterServer.CreateInstance(new CenterServerConfig());
            StartServer();

            ConsoleClient client = new ConsoleClient();
            bool run = true;
            while (run)
            {
                try
                {
                    Console.Write("> ");
                    string line = Console.ReadLine();
                    string[] para = line.Split('&');

                    switch (para[0].ToLower())
                    {
                        case "exit": run = false; break;
                        case "notice":
                            if (para.Length < 2)
                            {
                                Console.WriteLine("公告需要公告内容,用&隔开!");
                            }
                            else
                            {
                                CenterServer.Instance.SendSystemNotice(para[1]);
                            }
                            break;
                        case "reload":
                            if (para.Length < 2)
                            {
                                Console.WriteLine("加载需要指定表,用&隔开!");
                            }
                            else
                            {
                                CenterServer.Instance.SendReload(para[1]);
                            }
                            //ServerMgr.ReLoadServerList();
                            break;
                        case "shutdown":
                            CenterServer.Instance.SendShutdown();
                            break;
                        case "help":
                            Console.WriteLine(HelpStr);
                            break;
                        case "AAS":
                            if (para.Length < 2)
                            {
                                Console.WriteLine("加载需要指定状态true or false,用&隔开!");
                            }
                            else
                            {
                                CenterServer.Instance.SendAAS(bool.Parse(para[1]));
                            }
                            break;
                        default:
                            if (line.Length <= 0) break;
                            if (line[0] == '/')
                            {
                                line = line.Remove(0, 1);
                                line = line.Insert(0, "&");
                            }

                            try
                            {
                                bool res = CommandMgr.HandleCommandNoPlvl(client, line);
                                if (!res)
                                {
                                    Console.WriteLine("Unknown command: " + line);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());
                            }
                            break;
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Error:" + ex.ToString());
                }
            }

            if (CenterServer.Instance != null)
                CenterServer.Instance.Stop();
        }
Example #2
0
        /// <summary>
        /// Handles the server action
        /// </summary>
        /// <param name="parameters"></param>
        public void OnAction(Hashtable parameters)
        {
            Console.WriteLine("Starting GameServer ... please wait a moment!");
            GameServer.CreateInstance(new GameServerConfig());
            GameServer.Instance.Start();
            GameServer.KeepRunning = true;

            Console.WriteLine("Server started!");
            ConsoleClient client = new ConsoleClient();
            while (GameServer.KeepRunning)
            {
                try
                {
                    handler = ConsoleCtrHandler;
                    SetConsoleCtrlHandler(handler, true);

                    Console.Write("> ");
                    string line = Console.ReadLine();
                    string[] para = line.Split(' ');
                    switch (para[0])
                    {
                        case "exit":
                            GameServer.KeepRunning = false;
                            break;
                        case "cp":
                            GameClient[] clients = GameServer.Instance.GetAllClients();
                            int clientCount = clients == null ? 0 : clients.Length;

                            GamePlayer[] players = WorldMgr.GetAllPlayers();
                            int playerCount = players == null ? 0 : players.Length;
                            List<BaseRoom> rooms = RoomMgr.GetAllUsingRoom();
                            int roomCount = 0;
                            int gameCount = 0;
                            foreach (BaseRoom r in rooms)
                            {
                                if (!r.IsEmpty)
                                {
                                    roomCount++;
                                    if (r.IsPlaying)
                                    {
                                        gameCount++;
                                    }
                                }
                            }

                            double memoryCount = GC.GetTotalMemory(false);
                            Console.WriteLine(string.Format("Total Clients/Players:{0}/{1}", clientCount, playerCount));
                            Console.WriteLine(string.Format("Total Rooms/Games:{0}/{1}", roomCount, gameCount));
                            Console.WriteLine(string.Format("Total Momey Used:{0} MB", memoryCount / 1024 / 1024));
                            break;
                        case "shutdown":

                            _count = 6;
                            //_timer = new Timer(new TimerCallback(GameServer.Instance.ShutDownCallBack), null, 0, 60 * 1000);
                            _timer = new Timer(new TimerCallback(ShutDownCallBack), null, 0, 60 * 1000);
                            break;
                        case "savemap":

                            //TODO:

                            break;
                        case "clear":
                            Console.Clear();
                            break;
                        case "ball&reload":
                            if (BallMgr.ReLoad())
                                Console.WriteLine("Ball info is Reload!");
                            else
                                Console.WriteLine("Ball info is Error!");
                            break;
                        case "map&reload":
                            if (MapMgr.ReLoadMap())
                                Console.WriteLine("Map info is Reload!");
                            else
                                Console.WriteLine("Map info is Error!");
                            break;                        
                        case "mapserver&reload":
                            if (MapMgr.ReLoadMapServer())
                                Console.WriteLine("mapserver info is Reload!");
                            else
                                Console.WriteLine("mapserver info is Error!");
                            break;                        
                        case "prop&reload":
                            if (PropItemMgr.Reload())
                                Console.WriteLine("prop info is Reload!");
                            else
                                Console.WriteLine("prop info is Error!");
                            break;
                        case "item&reload":
                            if (ItemMgr.ReLoad())
                                Console.WriteLine("item info is Reload!");
                            else
                                Console.WriteLine("item info is Error!");
                            break;
                        case "shop&reload":

                            if (ShopMgr.ReLoad())
                                Console.WriteLine("shop info is Reload!");
                            else
                                Console.WriteLine("shop info is Error!");
                            break;
                        case "quest&reload":
                            if (QuestMgr.ReLoad())
                                Console.WriteLine("quest info is Reload!");
                            else
                                Console.WriteLine("quest info is Error!");
                            break;
                        case "fusion&reload":
                            if (FusionMgr.ReLoad())
                                Console.WriteLine("fusion info is Reload!");
                            else
                                Console.WriteLine("fusion info is Error!");
                            break;
                        case "consortia&reload":
                            if (ConsortiaMgr.ReLoad())
                                Console.WriteLine("consortiaMgr info is Reload!");
                            else
                                Console.WriteLine("consortiaMgr info is Error!");
                            break;
                        case "rate&reload":
							if (RateMgr.ReLoad())
                                Console.WriteLine("Rate Rate is Reload!");
                            else
                                Console.WriteLine("Rate Rate is Error!");
                            break;
                        case "fight&reload":
                            if (FightRateMgr.ReLoad())
                                Console.WriteLine("FightRateMgr is Reload!");
                            else
                                Console.WriteLine("FightRateMgr is Error!");
                            break;
                        case "dailyaward&reload":
                            if (AwardMgr.ReLoad())
                                Console.WriteLine("dailyaward is Reload!");
                            else
                                Console.WriteLine("dailyaward is Error!");
                            break;
                        case "language&reload":
                            if (LanguageMgr.Reload(""))
                                Console.WriteLine("language is Reload!");
                            else
                                Console.WriteLine("language is Error!");
                            break;
                        case "nickname":
                            Console.WriteLine("Please enter the nickname");
                            string nickname = Console.ReadLine();
                            string state = WorldMgr.GetPlayerStringByPlayerNickName(nickname);
                            Console.WriteLine(state);
                            break;
                        default:
                            if (line.Length <= 0) break;
                            if (line[0] == '/')
                            {
                                line = line.Remove(0, 1);
                                line = line.Insert(0, "&");
                            }

                            try
                            {
                                bool res = CommandMgr.HandleCommandNoPlvl(client, line);
                                if (!res)
                                {
                                    Console.WriteLine("Unknown command: " + line);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());
                            }
                            break;
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            if (GameServer.Instance != null)
                GameServer.Instance.Stop();

            LogManager.Shutdown();
        }