Find() public static method

public static Find ( GroupEnum g ) : Group
g GroupEnum
return Group
Esempio n. 1
0
        /// <summary>
        /// Changes a players rank
        /// </summary>
        /// <param name="p">The player object to change</param>
        /// <param name="g">The rank to change the player to</param>
        public static void ChangeRank(Player p, GroupEnum g)
        {
            bool blnResendMap = ((p.checkOp() && g <= GroupEnum.Moderator) || (!p.checkOp() && g >= GroupEnum.Moderator));

            p.group = Group.Find(g);
            p.ClearActions();
            ChangeRank(p.name, g);

            if (blnResendMap)
            {
                p.ChangeLevel(p.level);
            }
            else
            {
                GlobalDie(p, false);
                GlobalRespawn(p);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get the group of a given player
        /// </summary>
        /// <param name="name">The players name</param>
        /// <returns>The group object the player belongs to</returns>
        public static Group GetGroup(string name)
        {
            // Try to find the player in the active list
            Player who = Player.Find(name);

            if (who != null)
            {
                return(who.group);
            }

            // If the player isn't in the active list, have a look in the banned or operator
            if (Server.banned.All().Contains(name.ToLower()))
            {
                return(Group.Find("banned"));
            }
            if (Server.operators.All().Contains(name.ToLower()))
            {
                return(Group.Find("operator"));
            }
            return(Group.standard);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles a player login packet
        /// </summary>
        /// <param name="message">The login packet</param>
        void HandleLogin(byte[] message)
        {
            try
            {
                //byte[] message = (byte[])m;
                if (loggedIn)
                {
                    return;
                }

                byte version = message[0];
                name = Encoding.ASCII.GetString(message, 1, 64).Trim();
                string verify = Encoding.ASCII.GetString(message, 65, 32).Trim();
                byte   type   = message[129];

                if (Server.banned.Contains(name))
                {
                    Kick("You're banned!"); return;
                }
                if (Player.players.Count >= Properties.MaxPlayers)
                {
                    Kick("Server full!"); return;
                }
                if (version != MinecraftClassicProtocolVersion)
                {
                    Kick("Wrong version!"); return;
                }
                if (name.Length > 16 || !ValidName(name))
                {
                    Kick("Illegal name!"); return;
                }

                if (Properties.VerifyNames)
                {
                    if (verify == "--" || verify != BitConverter.ToString(

                            MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(Server.salt + name))).
                        Replace("-", "").ToLower().TrimStart('0'))
                    {
                        if (ip != "127.0.0.1")
                        {
                            Kick("Login failed! Try again."); return;
                        }
                    }
                }
                Player old = Player.Find(name);
                Logger.Log(ip + " logging in as " + name + ".");

                if (old != null)
                {
                    if (Properties.VerifyNames)
                    {
                        old.Kick("Someone else logged in as " + name + ". Duplicate logins are not allowed!");
                    }
                    else
                    {
                        Kick("Already logged in!"); return;
                    }
                }
                left.Remove(name.ToLower());

                if (Properties.ServerAdministrator == name)
                {
                    group = Group.Find("administrator");
                }
                else if (Server.bot.Contains(name))
                {
                    group = Group.Find("bots");
                }
                else if (Server.operators.Contains(name))
                {
                    group = Group.Find("operator");
                }
                else if (Server.moderators.Contains(name))
                {
                    group = Group.Find("moderator");
                }
                else if (Server.advbuilders.Contains(name))
                {
                    group = Group.Find("advbuilder");
                }
                else if (Server.builders.Contains(name))
                {
                    group = Group.Find("builder");
                }
                else
                {
                    group = Group.standard;
                }

                SendMotd();
                SendMap();

                if (disconnected)
                {
                    return;
                }

                loggedIn = true;
                id       = FreeId();

                players.Add(this);
                connections.Remove(this);



                GlobalChat(this, "&a+ " + color + name + "&e joined the game.", false);

                /*
                 * if (!Server.console && Server.win != null)
                 *  Server.win.UpdateClientList(players);
                 */
                IRCBot.Say(name + " joined the game.");

                //Test code to show wehn people come back with different accounts on the same IP
                string temp  = "Lately known as:";
                bool   found = false;
                if (ip != "127.0.0.1")
                {
                    foreach (KeyValuePair <string, string> prev in left)
                    {
                        if (prev.Value == ip)
                        {
                            found = true;
                            temp += " " + prev.Key;
                        }
                    }
                    if (found)
                    {
                        GlobalMessageOps(temp);
                        Logger.Log(temp);
                        IRCBot.Say(temp);
                    }
                }

                ushort x = (ushort)((0.5 + level.spawnx) * 32);
                ushort y = (ushort)((1 + level.spawny) * 32);
                ushort z = (ushort)((0.5 + level.spawnz) * 32);
                pos = new ushort[3] {
                    x, y, z
                }; rot = new byte[2] {
                    level.rotx, level.roty
                };

                GlobalSpawn(this, x, y, z, rot[0], rot[1], true);
                foreach (Player p in players)
                {
                    if (p.level == level && p != this && !p.hidden)
                    {
                        SendSpawn(p.id,
                                  p.color + p.name,
                                  p.pos[0],
                                  p.pos[1],
                                  p.pos[2],
                                  p.rot[0],
                                  p.rot[1]);
                    }
                }
                Loading = false;
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, LogType.ErrorMessage);
                Player.GlobalMessage("An error occurred: " + e.Message);
            }
        }
Esempio n. 4
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);
            }
        }