Kick() public method

Kicks the player with a given message
public Kick ( string message ) : void
message string The reason the player was kicked
return void
Beispiel #1
0
        // Code to run when used by a player
        public override void Use(Player p, string message)
        {
            if (message != "")
            {
                string who         = message;
                int    index       = message.IndexOf(' ');
                string kickmessage = "kicked and banned by " + p.name + "! (";
                if (index != -1)
                {
                    who          = message.Substring(0, index);
                    kickmessage += message.Substring(index + 1) + ")";
                }
                else
                {
                    kickmessage += "Kicked + Banned!)";
                }

                Player target = Player.Find(who);

                if (!Server.banned.Contains(who))
                {
                    if (p.Rank > Player.GetRank(who))
                    {
                        if (target != null)
                        {
                            if (target != p)
                            {
                                target.Kick(kickmessage);
                                Player.Ban(who);
                            }
                            else
                            {
                                p.SendMessage("You can't kickban yourself!");
                            }
                        }
                        else
                        {
                            Player.Ban(who);
                            Player.GlobalMessage(target.name + " was " + kickmessage);
                            IRCBot.Say(target.name + " was " + kickmessage);
                        }
                    }
                    else
                    {
                        p.SendMessage("You can't kickban someone of equal or higher rank!");
                    }
                }
                else
                {
                    p.SendMessage(who + " is already banned.");
                    if (target != null)
                    {
                        target.Kick(kickmessage);
                    }
                }
            }
            else
            {
                Help(p);
            }
        }
        /// <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);
            }
        }
Beispiel #3
0
        public void Blockchange(Player p, ushort x, ushort y, ushort z, byte type)
        {
            try
            {
                if (x >= width || y > depth || z >= height) { p.Kick("Building outside boundaries!"); return; }
                if (y == depth) { return; }
                byte b = GetTile(x, y, z);

                if (Block.Convert(b) != Block.Convert(type))    //Should save bandwidth sending identical looking blocks, like air/op_air changes.
                {
                    Player.GlobalBlockchange(this, x, y, z, type);
                }

                if (b == Block.sponge && physics > 0 && type != Block.sponge)
                {
                    PhysSpongeRemoved(PosToInt(x, y, z));
                }

                SetTile(x, y, z, type);               //Updates server level blocks

                if (physics > 0)
                {
                    if (Block.Physics(type))
                    {
                        AddCheck(PosToInt(x, y, z));
                    }
                }
                changed = true;
            }
            catch (Exception e)
            {
                Logger.Log(p.name + " has triggered a block change error in Level on " + name, LogType.Error);
                Logger.Log(e.Message, LogType.ErrorMessage);
                Player.GlobalMessageOps(p.name + " has triggered a block change error in level.cs on " + name);
                IRCBot.Say(p.name + " has triggered a block change error in level.cs on " + name);
            }
        }