Ejemplo n.º 1
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            try
            {
                if (message != "" || message.Split(' ').Length <= 2)
                {
                    int    pos              = message.IndexOf(' ');
                    string phys             = "0";
                    bool   blnAlreadyLoaded = false;

                    if (pos != -1)
                    {
                        phys    = message.Substring(pos + 1);
                        message = message.Substring(0, pos).ToLower();
                    }
                    else
                    {
                        message = message.ToLower();
                    }

                    // Make sure the level isn't already loaded
                    foreach (Map l in Server.levels)
                    {
                        if (l.name == message)
                        {
                            blnAlreadyLoaded = true;
                            break;
                        }
                    }

                    if (!blnAlreadyLoaded)
                    {
                        if (Server.levels.Capacity > 1)
                        {
                            if (Server.levels.Count < Server.levels.Capacity)
                            {
                                if (File.Exists("levels/" + message + ".lvl"))
                                {
                                    // Attempt to load the level
                                    Map level = Map.Load(message);
                                    if (level == null)
                                    {
                                        if (File.Exists("levels/" + message + ".lvl.backup"))
                                        {
                                            Logger.Log("Atempting to load backup.");
                                            File.Copy("levels/" + message + ".lvl.backup", "levels/" + message + ".lvl", true);
                                            level = Map.Load(message);
                                        }
                                        else
                                        {
                                            p.SendMessage("Backup of " + message + " does not exist.");
                                        }
                                    }

                                    // Make sure we loaded something before adding it the level list
                                    if (level != null)
                                    {
                                        lock (Server.levels)
                                        {
                                            Server.levels.Add(level);
                                        }
                                        Player.GlobalMessage("Map \"" + level.name + "\" loaded.");
                                        try
                                        {
                                            int temp = int.Parse(phys);
                                            if (temp >= 0 && temp <= 2)
                                            {
                                                level.Physics = (Physics)temp;
                                            }
                                        }
                                        catch
                                        {
                                            if (!p.disconnected)
                                            {
                                                p.SendMessage("Physics variable invalid");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        p.SendMessage("Failed to load the backup of " + message);
                                    }
                                }
                                else
                                {
                                    p.SendMessage("Map \"" + message + "\" doesn't exist!");
                                }
                            }
                            else
                            {
                                p.SendMessage("You can't load more than " + Server.levels.Capacity + " levels!");
                            }
                        }
                        else
                        {
                            p.SendMessage("Map capacity is 1 or lower, you can't load any levels!");
                        }
                    }
                    else
                    {
                        p.SendMessage(message + " is already loaded!");
                    }
                }
                else
                {
                    Help(p);
                }
            }
            catch (Exception e)
            {
                Player.GlobalMessage("An error occured with /load");
                Logger.Log("An error occured with /load", LogType.Error);
                Logger.Log(e.Message, LogType.ErrorMessage);
            }
        }
Ejemplo n.º 2
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            int number = message.Split(' ').Length;

            if (number > 2)
            {
            }

            if (number == 2) // Change the players rank
            {
                // Seperate message string
                int    pos        = message.IndexOf(' ');
                string tempName   = message.Substring(0, pos).ToLower();
                string newRankmsg = message.Substring(pos + 1).ToLower();

                Player    target    = Player.Find(tempName);
                bool      validRank = true;
                GroupEnum rank      = GroupEnum.Null;

                // Ensure we catch a valid rank
                switch (newRankmsg)
                {
                case "operator":
                case "op":
                    rank = GroupEnum.Operator;
                    break;

                case "moderator":
                case "mod":
                    rank = GroupEnum.Moderator;
                    break;

                case "advbuilder":
                case "adv":
                    rank = GroupEnum.AdvBuilder;
                    break;

                case "builder":
                    rank = GroupEnum.Builder;
                    break;

                case "guest":
                    rank = GroupEnum.Guest;
                    break;

                default:
                    validRank = false;
                    break;
                }
                // Make sure the rank is valid
                if (validRank)
                {
                    // Validate target players name
                    if (Player.ValidName(tempName))
                    {
                        // Can't set your own rank
                        if (p.name != tempName)
                        {
                            // Player must be a lower rank than yourself
                            if (p.Rank > Player.GetRank(tempName))
                            {
                                // Cannot set a banned player's rank
                                if (Player.GetRank(tempName) != GroupEnum.Banned)
                                {
                                    if (rank < p.Rank)
                                    {
                                        if (target != null)
                                        {
                                            Player.GlobalMessage("[Server]: " + target.color + target.name + "&e is now a " + Group.Find(rank).Color + Group.Find(rank).Name);
                                            Player.ChangeRank(target, rank);

                                            target.SendMessage("You are now ranked " + target.group.Color + target.group.Name + "&e, type /help for your new set of commands.");
                                        }
                                        else
                                        {
                                            Player.GlobalMessage("[Server]: " + tempName + " &f(offline)&e is now a " + Group.Find(rank).Color + Group.Find(rank).Name);
                                            Player.ChangeRank(tempName, rank);
                                        }
                                        Logger.Log(tempName + " was set to " + rank + " by " + p.name);
                                    }
                                    else
                                    {
                                        p.SendMessage("You cannot set someone to the same or higher rank than you!");
                                    }
                                }
                                else
                                {
                                    p.SendMessage("You must unban this player before you can change his rank!");
                                }
                            }
                            else
                            {
                                p.SendMessage("You cannot change the rank of someone who is higher rank than you!");
                            }
                        }
                        else
                        {
                            p.SendMessage("You cannot change your own rank");
                        }
                    }
                    else
                    {
                        p.SendMessage("Invalid name \"" + message + "\".");
                    }
                }
                else
                {
                    p.SendMessage("The rank \"" + newRankmsg + "\" is invalid!");
                }
            }
            else if (message != "") // Return the players current rank
            {
                if (Player.ValidName(message))
                {
                    Group rank = MCSharp.Group.Find(Player.GetRank(message));
                    p.SendMessage(message + "'s rank is: " + rank.Color + rank.Name);
                }
            }
            else // Return usage
            {
                Help(p);
            }
        }
Ejemplo n.º 3
0
        // Code to run when used by the console
        public override void Use(string message)
        {
            try
            {
                if (message != "" || message.Split(' ').Length <= 2)
                {
                    int    pos  = message.IndexOf(' ');
                    string phys = "0";

                    if (pos != -1)
                    {
                        phys    = message.Substring(pos + 1);
                        message = message.Substring(0, pos).ToLower();
                    }
                    else
                    {
                        message = message.ToLower();
                    }

                    if (!Map.Loaded(message))
                    {
                        if (Server.levels.Capacity > 1)
                        {
                            if (Server.levels.Count < Server.levels.Capacity)
                            {
                                if (Map.Exists(message))
                                {
                                    // Attempt to load the level
                                    Map level = Map.Load(message);
                                    if (level == null)
                                    {
                                        if (File.Exists("levels/" + message + ".lvl.backup"))
                                        {
                                            Logger.Log("Atempting to load backup.", LogType.ConsoleOutput);
                                            File.Copy("levels/" + message + ".lvl.backup", "levels/" + message + ".lvl", true);
                                            level = Map.Load(message);
                                        }
                                        else
                                        {
                                            Logger.Log("Backup of " + message + " does not exist.", LogType.ConsoleOutput);
                                        }
                                    }

                                    // Make sure we loaded something before adding it the level list
                                    if (level != null)
                                    {
                                        lock (Server.levels)
                                        {
                                            Server.levels.Add(level);
                                        }
                                        Player.GlobalMessage("Map \"" + level.name + "\" loaded.");
                                        try
                                        {
                                            int temp = int.Parse(phys);
                                            if (temp >= 0 && temp <= 2)
                                            {
                                                level.Physics = (Physics)temp;
                                            }
                                        }
                                        catch
                                        {
                                            Logger.Log("Physics variable invalid", LogType.ConsoleOutput);
                                        }
                                    }
                                    else
                                    {
                                        Logger.Log("Failed to load the backup of " + message, LogType.ConsoleOutput);
                                    }
                                }
                                else
                                {
                                    Logger.Log("Map \"" + message + "\" doesn't exist!", LogType.ConsoleOutput);
                                }
                            }
                            else
                            {
                                Logger.Log("You can't load more than " + Server.levels.Capacity + " levels!", LogType.ConsoleOutput);
                            }
                        }
                        else
                        {
                            Logger.Log("Map capacity is 1 or lower, you can't load any levels!", LogType.ConsoleOutput);
                        }
                    }
                    else
                    {
                        Logger.Log(message + " is already loaded!", LogType.ConsoleOutput);
                    }
                }
                else
                {
                    // We need to print help to the console somehow
                    Logger.Log("Someday the console will support help messages", LogType.ConsoleOutput);
                }
            }
            catch (Exception e)
            {
                Logger.Log("An error occured with /load", LogType.Error);
                Logger.Log(e.Message, LogType.ErrorMessage);
            }
        }
Ejemplo n.º 4
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p);
            }
            else
            {
                bool stealth = false;
                if (message[0] == '#')
                {
                    message = message.Remove(0, 1).Trim();
                    stealth = true;
                    Logger.Log("Stealth Ban Atempted");
                }

                // Ensure the name is valid
                if (Player.ValidName(message))
                {
                    // Ensure the player isn't banned already
                    if (Player.GetRank(message) != GroupEnum.Banned)
                    {
                        if (p.Rank > Player.GetRank(message))
                        {
                            // Check to see if the player is online
                            // Send appropriate message based on status and stealth option
                            if (Player.IsOnline(message))
                            {
                                if (stealth)
                                {
                                }
                                else
                                {
                                    Player.GlobalMessage("[Server]:" + p.color + p.name + "&e has banned " + message);
                                }
                            }
                            else
                            {
                                Player.GlobalMessage("[Server]:" + p.color + p.name + "&e has banned " + message + "(offline)");
                            }

                            // Actually get around to banning the player
                            Player.Ban(message);

                            IRCBot.Say(message + " was banned");
                        }
                        else
                        {
                            p.SendMessage("You can't ban someone of equal or higher rank!");
                        }
                    }
                    else
                    {
                        p.SendMessage(message + " is already banned.");
                    }
                }
                else
                {
                    p.SendMessage("Invalid name \"" + message + "\".");
                }
            }
        }