Esempio n. 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": {
                mainUI.ClearCommands();
            }
            break;

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

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

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

            case "/clearstats": {
                Statistics.PacketStatistics.ClearStatistics();
                mainUI.AddCommandLine("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)
                    {
                        mainUI.AddCommandLine("Invalid Map.");
                        break;
                    }
                    else if (x == -1)
                    {
                        mainUI.AddCommandLine("Invalid X coordinate.");
                        break;
                    }
                    else if (y == -1)
                    {
                        mainUI.AddCommandLine("Invalid Y coordinate.");
                        break;
                    }
                    // TODO: Mass Warp
                    //if (x > MapManager.Maps[map].MaxX) {
                    //    mainUI.AddCommandLine("Invalid X coordinate.");
                    //    break;
                    //}
                    //if (y > MapManager.Maps[map].MaxY) {
                    //    mainUI.AddCommandLine("Invalid Y coordinate.");
                    //    break;
                    //}
                    foreach (Client i in ClientManager.GetClients())
                    {
                        if (i.IsPlaying() && Ranks.IsDisallowed(i, Enums.Rank.Moniter))
                        {
                            Messenger.GlobalMsg("The server has warped everyone!", Text.White);
                            Messenger.PlayerWarp(i, map, x, y);
                        }
                    }
                    mainUI.AddCommandLine("Everyone has been warped.");
                }
                else
                {
                    mainUI.AddCommandLine("Invalid arguments.");
                }
            }
            break;

            case "/kick": {
                if (fullCommand.CommandArgs.Count == 2)
                {
                    Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]);
                    if (client == null)
                    {
                        mainUI.AddCommandLine("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!");
                        mainUI.AddCommandLine(client.Player.Name + " has been kicked!");
                    }
                }
                else
                {
                    mainUI.AddCommandLine("Invalid arguments.");
                }
            }
            break;

            case "/warp": {
                if (fullCommand.CommandArgs.Count == 5)
                {
                    Client client = ClientManager.FindClient(fullCommand.CommandArgs[1]);
                    if (client == null)
                    {
                        mainUI.AddCommandLine("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)
                        {
                            mainUI.AddCommandLine("Invalid Map.");
                            break;
                        }
                        else if (x == -1)
                        {
                            mainUI.AddCommandLine("Invalid X coordinate.");
                            break;
                        }
                        else if (y == -1)
                        {
                            mainUI.AddCommandLine("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)
                        {
                            mainUI.AddCommandLine("Invalid X coordinate.");
                            break;
                        }
                        if (y > map.MaxY)
                        {
                            mainUI.AddCommandLine("Invalid Y coordinate.");
                            break;
                        }
                        Messenger.PlayerMsg(client, "You have been warped by the server!", Text.White);
                        Messenger.PlayerWarp(client, mapNum, x, y);
                        mainUI.AddCommandLine(client.Player.Name + " has been warped.");
                    }
                }
                else
                {
                    mainUI.AddCommandLine("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))
                    {
                        mainUI.AddCommandLine("Invalid Map.");
                        break;
                    }
                    Messenger.MapMsg(map, fullCommand.CommandArgs[2], Text.DarkGrey);
                    mainUI.AddCommandLine("Map Msg (Map " + map.ToString() + "): " + fullCommand.CommandArgs[2]);
                }
                else
                {
                    mainUI.AddCommandLine("Invalid arguments.");
                }
            }
            break;

            case "/reloadscripts": {
                Scripting.ScriptManager.Reload();
                mainUI.AddCommandLine("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";
                    }
                }
                mainUI.AddCommandLine("Players online: \r\n" + players);
                mainUI.AddCommandLine("There are " + count.ToString() + " players online");
            }
            break;

            case "/test": {
                //Email.Email.SendEmail("test");
                //mainUI.AddCommandLine("Mail sent!");
                //mainUI.AddCommandLine("There are currently no benchmarking tests");
                //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                //watch.Start();
                //MapGeneralInfo genInfo = MapManager.RetrieveMapGeneralInfo(10);
                //watch.Stop();
                //mainUI.AddCommandLine("Elapsed, New: " + watch.Elapsed.ToString());
                //watch.Reset();
                //watch.Start();
                //Map map = MapManager.LoadMap(10);
                //watch.Stop();
                //mainUI.AddCommandLine("Elapsed, Old: " + watch.Elapsed.ToString());
                //mainUI.AddCommandLine("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()))
                    {
                        mainUI.AddCommandLine(ItemManager.Items[i].Name + "'s number is " + i.ToString());
                        itemsFound++;
                        //return;
                    }
                }
                if (itemsFound == 0)
                {
                    mainUI.AddCommandLine("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()))
                    {
                        mainUI.AddCommandLine(ItemManager.Items[i].Name + "'s number is " + i.ToString());
                        itemsFound++;
                        //return;
                    }
                }
                if (itemsFound == 0)
                {
                    mainUI.AddCommandLine("Unable to find an item that starts with '" + fullCommand.CommandArgs[1] + "'");
                }
            }
            break;

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

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

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