Exemple #1
0
        public void ProcessCommandCallback(object obj)
        {
            int     activeLine  = (int)((ParamObject)obj).Param[0];
            string  command     = (string)((ParamObject)obj).Param[1];
            Command fullCommand = Server.CommandProcessor.ParseCommand(command);
            string  fullArgs    = CommandProcessor.JoinArgs(fullCommand.CommandArgs.ToArray());

            switch (fullCommand.CommandArgs[0].ToLower())
            {
            case "/help":
            {
                DisplayHelp();
            }
            break;

            case "/clear":
            {
            }
            break;

            case "/global":
            {
                Messenger.GlobalMsg(fullArgs, Text.White);
                ServerConsole.WriteLine("Global: " + fullArgs);
            }
            break;

            case "/masskick":
            {
                foreach (Client i in ClientManager.GetClients())
                {
                    if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor))
                    {
                        Messenger.GlobalMsg(i.Player.Name + " has been kicked by the server!", Text.White);
                        Messenger.AlertMsg(i, "You have been kicked by the server!");
                    }
                }
                ServerConsole.WriteLine("Everyone has been kicked.");
            }
            break;

            case "/dumpstats":
            {
                Statistics.PacketStatistics.DumpStatistics();
                ServerConsole.WriteLine("Packet statistics dumped to database.");
            }
            break;

            case "/clearstats":
            {
                Statistics.PacketStatistics.ClearStatistics();
                ServerConsole.WriteLine("Packet statistics cleared.");
            }
            break;

            case "/masswarp":
            {
                if (fullCommand.CommandArgs.Count == 4)
                {
                    int map = fullCommand.CommandArgs[1].ToInt(-1);
                    int x   = fullCommand.CommandArgs[2].ToInt(-1);
                    int y   = fullCommand.CommandArgs[3].ToInt(-1);
                    if (map <= 0)
                    {
                        ServerConsole.WriteLine("Invalid Map.");
                        break;
                    }
                    else if (x == -1)
                    {
                        ServerConsole.WriteLine("Invalid X coordinate.");
                        break;
                    }
                    else if (y == -1)
                    {
                        ServerConsole.WriteLine("Invalid Y coordinate.");
                        break;
                    }
                    // TODO: Mass Warp
                    //if (x > MapManager.Maps[map].MaxX) {
                    //    ServerConsole.WriteLine("Invalid X coordinate.");
                    //    break;
                    //}
                    //if (y > MapManager.Maps[map].MaxY) {
                    //    ServerConsole.WriteLine("Invalid Y coordinate.");
                    //    break;
                    //}
                    foreach (Client i in ClientManager.GetClients())
                    {
                        if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Monitor))
                        {
                            Messenger.GlobalMsg("The server has warped everyone!", Text.White);
                            Messenger.PlayerWarp(i, map, x, y);
                        }
                    }
                    ServerConsole.WriteLine("Everyone has been warped.");
                }
                else
                {
                    ServerConsole.WriteLine("Invalid arguments.");
                }
            }
            break;

            case "/kick":
            {
                if (fullCommand.CommandArgs.Count == 2)
                {
                    Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]);
                    if (client == null)
                    {
                        ServerConsole.WriteLine("Player is offline.");
                    }
                    else
                    {
                        Messenger.GlobalMsg(client.Player.Name + " has been kicked by the server!", Text.White);
                        Messenger.AlertMsg(client, "You have been kicked by the server!");
                        ServerConsole.WriteLine(client.Player.Name + " has been kicked!");
                    }
                }
                else
                {
                    ServerConsole.WriteLine("Invalid arguments.");
                }
            }
            break;

            case "/warp":
            {
                if (fullCommand.CommandArgs.Count == 5)
                {
                    Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]);
                    if (client == null)
                    {
                        ServerConsole.WriteLine("Player is offline.");
                    }
                    else
                    {
                        int mapNum = fullCommand.CommandArgs[2].ToInt(-1);
                        int x      = fullCommand.CommandArgs[3].ToInt(-1);
                        int y      = fullCommand.CommandArgs[4].ToInt(-1);
                        if (mapNum <= 0)
                        {
                            ServerConsole.WriteLine("Invalid Map.");
                            break;
                        }
                        else if (x == -1)
                        {
                            ServerConsole.WriteLine("Invalid X coordinate.");
                            break;
                        }
                        else if (y == -1)
                        {
                            ServerConsole.WriteLine("Invalid Y coordinate.");
                            break;
                        }
                        IMap map;
                        if (MapManager.IsMapActive(MapManager.GenerateMapID(mapNum)))
                        {
                            map = MapManager.RetrieveActiveMap(MapManager.GenerateMapID(mapNum));
                        }
                        else
                        {
                            using (Database.DatabaseConnection dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data))
                            {
                                map = MapManager.LoadStandardMap(dbConnection, MapManager.GenerateMapID(mapNum));
                            }
                        }
                        if (x > map.MaxX)
                        {
                            ServerConsole.WriteLine("Invalid X coordinate.");
                            break;
                        }
                        if (y > map.MaxY)
                        {
                            ServerConsole.WriteLine("Invalid Y coordinate.");
                            break;
                        }
                        Messenger.PlayerMsg(client, "You have been warped by the server!", Text.White);
                        Messenger.PlayerWarp(client, mapNum, x, y);
                        ServerConsole.WriteLine(client.Player.Name + " has been warped.");
                    }
                }
                else
                {
                    ServerConsole.WriteLine("Invalid arguments.");
                }
            }
            break;

            case "/mapmsg":
            {
                if (fullCommand.CommandArgs.Count == 3)
                {
                    string map = fullCommand.CommandArgs[1];
                    // Check if the map is active
                    if (!MapManager.IsMapActive(map))
                    {
                        ServerConsole.WriteLine("Invalid Map.");
                        break;
                    }
                    Messenger.MapMsg(map, fullCommand.CommandArgs[2], Text.DarkGrey);
                    ServerConsole.WriteLine("Map Msg (Map " + map.ToString() + "): " + fullCommand.CommandArgs[2]);
                }
                else
                {
                    ServerConsole.WriteLine("Invalid arguments.");
                }
            }
            break;

            case "/reloadscripts":
            {
                Scripting.ScriptManager.Reload();
                ServerConsole.WriteLine("Scripts reloaded.");
            }
            break;

            case "/players":
            {
                string players = "";
                int    count   = 0;
                foreach (Client i in ClientManager.GetClients())
                {
                    if (i.IsPlaying())
                    {
                        count++;
                        players += i.Player.Name + "\r\n";
                    }
                }
                ServerConsole.WriteLine("Players online: \r\n" + players);
                ServerConsole.WriteLine("There are " + count.ToString() + " players online");
            }
            break;

            case "/test":
            {
                //Email.Email.SendEmail("test");
                //ServerConsole.WriteLine("Mail sent!");
                //ServerConsole.WriteLine("There are currently no benchmarking tests");
                //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                //watch.Start();
                //MapGeneralInfo genInfo = MapManager.RetrieveMapGeneralInfo(10);
                //watch.Stop();
                //ServerConsole.WriteLine("Elapsed, New: " + watch.Elapsed.ToString());
                //watch.Reset();
                //watch.Start();
                //Map map = MapManager.LoadMap(10);
                //watch.Stop();
                //ServerConsole.WriteLine("Elapsed, Old: " + watch.Elapsed.ToString());
                //ServerConsole.WriteLine("Name: " + genInfo.Name);
            }
            break;

            case "/finditem":
            {
                int itemsFound = 0;
                for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++)
                {
                    if (ItemManager.Items[i].Name.ToLower().StartsWith(fullCommand.CommandArgs[1].ToLower()))
                    {
                        ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString());
                        itemsFound++;
                        //return;
                    }
                }
                if (itemsFound == 0)
                {
                    ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'");
                }
            }
            break;

            case "/finditemc":
            {
                int itemsFound = 0;
                for (int i = 0; i < Server.Items.ItemManager.Items.MaxItems; i++)
                {
                    if (ItemManager.Items[i].Name.ToLower().Contains(fullCommand.CommandArgs[1].ToLower()))
                    {
                        ServerConsole.WriteLine(ItemManager.Items[i].Name + "'s number is " + i.ToString());
                        itemsFound++;
                        //return;
                    }
                }
                if (itemsFound == 0)
                {
                    ServerConsole.WriteLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'");
                }
            }
            break;

            case "/calcwm":
            {
                ServerConsole.WriteLine("Factorial: " + Server.Math.CalculateFactorial(fullCommand.CommandArgs[1].ToInt()).ToString("R"));
            }
            break;

            case "/gmmode":
            {
                Globals.GMOnly = !Globals.GMOnly;
                ServerConsole.WriteLine("GM Only Mode Active: " + Globals.GMOnly);
            }
            break;

            default:
            {
                Scripting.ScriptManager.InvokeSub("ProcessServerCommand", fullCommand, fullArgs);
            }
            break;
            }
        }