コード例 #1
0
        static void Spawner(Client player, string[] cmd, int iarg)
        {
            if (!player.Admin())
            {
                throw new ErrorException("Spawn does no longer work");
            }

            VanillaSession rs = player.Session as VanillaSession;

            if (rs.Spawners.Count == 0)
            {
                player.TellSystem(Chat.Purple, "No spawners yet detected");
                return;
            }
            CoordInt nearby = rs.Spawners [0];
            double   dist   = nearby.DistanceTo(rs.Position);

            foreach (CoordInt c in rs.Spawners)
            {
                double cdist = c.DistanceTo(rs.Position);
                if (cdist < 10)
                {
                    continue;
                }
                if (cdist < dist)
                {
                    dist   = cdist;
                    nearby = c;
                }
            }
            player.Warp(nearby.CloneDouble(), rs.Dimension, player.Session.World);
        }
コード例 #2
0
ファイル: Protected.cs プロジェクト: mctraveler/MineSharp
        /// <summary>
        /// Prevent block modification, aplies to all, residents should never get called here
        /// </summary>
        public static bool ProtectBlockBreak(VanillaSession session, WorldRegion region, PlayerDigging d)
        {
            if (IsBlockProtected(session, region) == false)
                return false;

            //Block single click from outside the adventure mode
            if (d.Status == PlayerDigging.StatusEnum.StartedDigging)
                return true;
            
            if (d.Status != PlayerDigging.StatusEnum.FinishedDigging)
                return false;

            //Old method - not needed
            BlockChange bc = new BlockChange(d.Position, BlockID.Bedrock);
            session.Player.SendToClient(bc);

            //New method - Works
            /*
            PlayerDigging pd = new PlayerDigging();
            pd.Position = d.Position;
            pd.Face = Face.Down;
            pd.Status = PlayerDigging.StatusEnum.CheckBlock;
            session.FromClient(pd);
            */

            return true;
        }
コード例 #3
0
ファイル: Protected.cs プロジェクト: mctraveler/MineSharp
        public static bool ProtectBlockPlace(VanillaSession session, WorldRegion region, PlayerBlockPlacement bp)
        {
            if (IsBlockProtected(session, region) == false)
                return false;

            if (FilterFire(session, bp))
            {
                string i = "";
                if (session.ActiveItem != null)
                    i += "(server)" + session.ActiveItem.ItemID;
                if (bp.Item != null)
                    i += "(client)" + bp.Item.ItemID;

                Chatting.Parser.TellAdmin(session.Player.Name + " tried to use " + i + " in " + region.Name + " at " + session.Position);
                //session.Player.Kick("Arson");
                return true;
            }

            //If adventure protection is active, allow all actions
            if (session.Mode == GameMode.Adventure) //buggy but best bet so far
                return false; //ok, only activate levers and chests

            //Block all placements, non resident must be inside the region
            session.TellSystem(Chat.Aqua, "move inside the region before you open a door or chest");

            //New method, works - no longer works
            /*
            PlayerDigging pd = new PlayerDigging();
            pd.Position = bp.BlockPosition.Offset(bp.FaceDirection);
            pd.Face = Face.Down;
            pd.Status = PlayerDigging.StatusEnum.CheckBlock;
            session.FromClient(pd);
            */

            //Old method - not perfect, disabling:
            /*BlockChange bc = new BlockChange(bp.BlockPosition.Offset(bp.FaceDirection), BlockID.Air);
            session.Player.SendToClient(bc);*/
            return true;
        }
コード例 #4
0
        public void Leave(VanillaSession session)
        {
            lock (players)
            {
                players.Remove(session);
                base.Leave(session);
#if DEBUG
                Console.WriteLine(session.Player.MinecraftUsername + " Leaving Real: " + Players.Length);
#endif
            }
            if (Players.Length < MinecraftServer.MaxSlots) // && session.Error == null)
            {
                World.Wait.BringBack();
            }


            if (Players.Length == 0)
            {
                //Shutdown after 5 minutes
                stopBackend.Change(5 * 60 * 1000, -1);
            }
        }
コード例 #5
0
ファイル: Cloak.cs プロジェクト: mctraveler/MineSharp
        public static bool Filter(VanillaSession real, Packet p)
        {
            Client player = real.Player;
            IEntity e = p as IEntity;
            if (e == null)
                return false;
			
            //Pass all own actions normally
            if (e.EID == player.EntityID)
                return false;
			
            Client namedPlayer = null;
            VanillaSession r = World.Main.GetPlayer(e.EID); 
            if (r != null)
                namedPlayer = r.Player;
		
            byte pid = p.PacketID;

            //New named entity
            if (pid == SpawnPlayer.ID)
            {
                SpawnPlayer spawnNamedEntity = (SpawnPlayer)p;
			
                //Search by vanilla uuid since we ahv enot yet modified the packet
                if (namedPlayer == null)
                    namedPlayer = PlayerList.GetPlayerByVanillaUUID(spawnNamedEntity.PlayerUUID);
                if (namedPlayer == null)
                {
                    Debug.WriteLine("NamedEntity not found in player list: " + spawnNamedEntity.PlayerUUID);
                    return false; //Still let through
                }
                				
                //pass any none cloaked player
                if (namedPlayer.Settings.Cloaked == null)
                    return false;
				
                //Invisible mode, hide everything about entity
                if (namedPlayer.Settings.Cloaked == MobType.None.ToString())
                    return true;
				
                if (namedPlayer.Settings.Cloaked == null)
                {
                    //Debug.WriteLine ("Spawning player " + ne.PlayerName + " as nick " + np.Name);
                    return false;
                }
                //Debug.WriteLine ("Spawning player " + ne.PlayerName + " cloaked as \"" + np.Cloaked + "\" nick: " + np.Name);
				
                MobType mt;
                try
                {
                    mt = (MobType)Enum.Parse(typeof(MobType), namedPlayer.Settings.Cloaked);
                } catch (Exception)
                {
                    Debug.WriteLine("Unknown cloak for " + namedPlayer.MinecraftUsername + ": " + namedPlayer.Settings.Cloaked);
                    return false;
                }
				
                SpawnMob ms = new SpawnMob(mt);
                ms.EID = spawnNamedEntity.EID;
                ms.Pos = spawnNamedEntity.Position;
                ms.Pitch = spawnNamedEntity.Pitch;
                ms.Yaw = spawnNamedEntity.Yaw;
				
                //Add metadata to specific mobs - some already set in constructor

                if (ms.Type == MobType.MagmaCube || ms.Type == MobType.Slime)
                    ms.Metadata.SetByte(16, 1);
                if (ms.Type == MobType.Ghast)
                    ms.Metadata.SetByte(16, 0);
                if (ms.Type == MobType.Enderman)
                {
                    ms.Metadata.SetByte(16, (sbyte)BlockID.Dirt);
                    ms.Metadata.SetByte(17, 0);
                }
                if (ms.Type == MobType.Blaze)
                    ms.Metadata.SetByte(16, 0);
                if (ms.Type == MobType.Sheep)
                    ms.Metadata.SetByte(16, 0);
                if (ms.Type == MobType.Spider)
                    ms.Metadata.SetByte(16, 0);
				
                player.Queue.Queue(ms);
                return true;
            }
			
            if (pid == DestroyEntities.ID)
                return false;
			
            //Not in list
            if (namedPlayer == null)
                return false;
			
            //Not cloaked
            if (namedPlayer.Settings.Cloaked == null)
                return false;
			
            //Invisible mode, hide everything about entity
            if (namedPlayer.Settings.Cloaked == MobType.None.ToString())
                return true;
			
            //Else any mob
            if (pid == Animation.ID)
                return true;
			
            if (pid == EntityEquipment.ID)
                return true;
			
            return false;
        }
コード例 #6
0
ファイル: VanillaWorld.cs プロジェクト: mctraveler/MineSharp
        public void Leave(VanillaSession session)
        {
            lock (players)
            {
                players.Remove(session);
                base.Leave(session);
#if DEBUG
                Console.WriteLine(session.Player.MinecraftUsername + " Leaving Real: " + Players.Length);
#endif

            }
            if (Players.Length < MinecraftServer.MaxSlots) // && session.Error == null)
                World.Wait.BringBack();


            if (Players.Length == 0)
            {
                //Shutdown after 5 minutes
                stopBackend.Change(5 * 60 * 1000, -1);
            }
        }
コード例 #7
0
ファイル: Protected.cs プロジェクト: mctraveler/MineSharp
        static bool FilterFire(VanillaSession session, PlayerBlockPlacement placement)
        {
            //Prevent fire, lava and TNT
            SlotItem i = session.ActiveItem;

            //A bit safer but not correctly implemented need to consider WindowClick
            if (i != null)
            {
                if (i.ItemID == BlockID.FlintandSteel
                    || i.ItemID == BlockID.Fireball
                    || i.ItemID == BlockID.Lava
                    || i.ItemID == BlockID.TNT
                    || i.ItemID == BlockID.Lavabucket
                    || i.ItemID == BlockID.CartWithTNT)
                {
                    return true;
                }
            }

            //Safer but forgable client side
            i = placement.Item;
            if (i != null)
            {
                if (i.ItemID == BlockID.FlintandSteel
                    || i.ItemID == BlockID.Fireball
                    || i.ItemID == BlockID.Lava
                    || i.ItemID == BlockID.TNT
                    || i.ItemID == BlockID.Lavabucket)
                {
                    return true;
                }
            }

            return false;
        }
コード例 #8
0
ファイル: Protected.cs プロジェクト: mctraveler/MineSharp
        /// <summary>
        /// Return true to block
        /// </summary>
        public static bool ProtectChestsClick(VanillaSession rs, WindowClick wc)
        {
            if (wc.WindowID == 0) //player inventory, allow
                return false;

            if (rs.Player.Admin() && rs.Mode == GameMode.Creative)
                return false;

            if (rs.OpenWindows.ContainsKey(wc.WindowID) == false)
            {
                rs.TellSystem(Chat.Red, "Window not open");
                return BlockClick(rs.Player, wc);
            }
            var w = rs.OpenWindows [wc.WindowID];

            if (w.Region == null)
                return false; //not in a region, allow

            switch (w.Region.Type)
            {
                case Protected.Type:
                case Honeypot.Type:
                    break;
                default:
                    return false;
            }

            if (w.Region.IsResident(rs.Player))
                return false; //residents allow

            //Allow some open types
            if (w.Window.InventoryType == "CraftingTable")
                return false;
            if (w.Window.InventoryType == "Enchant")
                return false;
            if (w.Window.InventoryType == "Anvil")
                return false;
            if (w.Window.WindowTitle == "container.enderchest")
                return false;

            if (w.Region.Type == Protected.Type)
                return BlockClick(rs.Player, wc);

            if (w.Region.Type == Honeypot.Type)
            {
                if (wc.Slot == 11 || wc.Slot == 13 || wc.Slot == 15)
                {
                    if (rs.Player.Admin())
                    {
                        rs.TellSystem(Chat.White, "This spot is protected");
                        return false;
                    }
                    Honeypot.Trigger(rs.Player, w.Region);
                    return true;
                }
            }

            return true;
        }
コード例 #9
0
        public sealed override WorldSession Join(Client player)
        {
            //reset scoreboard
            player.Score = null;

            if (Suspended)
            {
                player.TellSystem(Chat.Purple, "Vanilla is suspended by admin, it will be right back");
                return(null);
            }

            StartBackend();

            lock (players)
            {
                int pc = 0;
                foreach (VanillaSession r in players)
                {
                    if (r.Player.Settings.Cloaked == null)
                    {
                        pc++;
                    }
                }

                if (pc >= MinecraftServer.MaxSlots && player.Settings.Cloaked == null)
                {
                    //Kick old player
                    //New visitors are given an advantage
                    if (player.Uptime.TotalMinutes < 15)
                    {
                        //Kick normal player
                        foreach (VanillaSession r in players)
                        {
                            if (r.Player.Settings.Cloaked != null)
                            {
                                continue;
                            }
                            if (Donors.IsDonor(r.Player))
                            {
                                continue;
                            }
                            if (r.Player.Uptime.TotalMinutes < 15)
                            {
                                continue;
                            }
                            KickSlot(r.Player);
                            World.Main.Say(Chat.Gray, r.Player.Name + " left its slot to " + player.Name + "(new)");
                            goto slotFree;
                        }
                    }

                    if (Donors.IsDonor(player.MinecraftUsername))
                    {
                        //Kick any non donor
                        foreach (VanillaSession r in players)
                        {
                            if (r.Player.Settings.Cloaked != null)
                            {
                                continue;
                            }
                            if (Donors.IsDonor(r.Player))
                            {
                                continue;
                            }
                            if (r.Player.Uptime.TotalMinutes < 15)
                            {
                                continue;
                            }
                            KickSlot(r.Player);
                            this.Say(Chat.Gray, r.Player.Name + " left its slot to donor " + player.Name);
                            goto slotFree;
                        }
                        foreach (VanillaSession r in players)
                        {
                            if (r.Player.Settings.Cloaked != null)
                            {
                                continue;
                            }
                            if (Donors.IsDonor(r.Player))
                            {
                                continue;
                            }
                            KickSlot(r.Player);
                            this.Say(Chat.Gray, r.Player.Name + " left its slot to donor " + player.Name);
                            goto slotFree;
                        }
                        goto slotFree;
                    }

                    //Block
                    Chat.ReadFile("full.txt", Chat.Aqua, player);
                    this.Say(Chat.DarkGreen, "No free slot for " + player.Name);
                    return(null);
                }

slotFree:

                var server = BackendManager.StartServer(ServerName);
                if (server.Running.WaitOne(10) == false)
                {
                    Log.WriteServer("Timeout waiting for server to start");
                }

                VanillaSession s = CreateSession(player);
                players.Add(s);
                base.Join(s);
#if DEBUG
                Console.WriteLine(s.Player.MinecraftUsername + " Joining Real: " + Players.Length);
#endif
                return(s);
            }
        }
コード例 #10
0
        /// <summary>
        /// return true to block packet
        /// </summary>
        bool UseEntityFromClient(UseEntity ue)
        {
            //Attack others
            if (ue.Type == UseEntity.Types.Attack)
            {
                //Admin instant kill using bedrock
                if (Player.Admin(Permissions.AnyAdmin) &&
                    this.ActiveItem != null &&
                    this.ActiveItem.ItemID == BlockID.Bedrock)
                {
                    VanillaSession dust = World.Main.GetPlayer(ue.Target);
                    if (dust == null)
                    {
                        Player.TellSystem(Chat.Purple, "Failed to find player");
                        return(true);
                    }
                    dust.SendToBackend(new ChatMessageClient("/kill"));
                    Log.WritePlayer(this, "Admin kill: " + dust.Player.MinecraftUsername);
                    return(true);
                }

                if (Player.Settings.Cloaked != null)
                {
                    return(false);
                }

                Debug.WriteLine("Attacked: " + ue.Target);
                VanillaSession target = World.Main.GetPlayer(ue.Target);

                if (target == null && Player.Settings.Cloaked == null)
                {
                    Entity      e  = World.Main.GetEntity(ue.Target);
                    var         m  = e as Mob;
                    var         v  = e as Vehicle;
                    WorldRegion cr = CurrentRegion;
                    //prevent killing mobs and villagers inside region
                    if (cr != null && cr.Type == "protected" && (cr.IsResident(Player) == false))
                    {
                        if (m != null && m.Type >= MobType.Pig)
                        {
                            Player.TellSystem(Chat.Pink, "No killing inside this region");
                            return(true);
                        }
                        if (v != null && v.Type == Vehicles.Frame)
                        {
                            //Protect frames
                            Debug.WriteLine("Frame protected");
                            return(true);
                        }
                    }
                    if (m != null && m.Owner != "")
                    {
                        //this could prevent killing of tamed animals
                    }
                }
                if (target != null && target.Player.Settings.Cloaked == null)
                {
                    if (this.ActiveItem != null)
                    {
                        switch (this.ActiveItem.ItemID)
                        {
                        case BlockID.Rose:
                        case BlockID.Dandelion:
                            PlayerInteraction.Prod(this.Player, target.Player);
                            return(true);
                        }
                    }

                    //Anywhere but war
                    WorldRegion r = CurrentRegion;
                    if (r != null && r.Type == "war")
                    {
                        //War Zone
                        //r.Say (Chat.Yellow + Name + Chat.Gold + " attacked " + Chat.Yellow + target.Name + Chat.Gold + " using " + newAttack.Item);
                        SendToBackend(ue);
                        return(true);
                    }

                    //Anywhere but war
                    if (Player.PvP == false)
                    {
                        Player.TellSystem(Chat.Purple, "PvP active");
                        Player.PvP = true;
                    }

                    Attacked newAttack = new Attacked(this.Player);

                    if (target.Attacker == null || target.Attacker.Timestamp.AddSeconds(10) < DateTime.Now)
                    {
                        //Regular zone
                        if (target.Player.PvP == false && ((r == null) || (r.IsResident(Player) == false)))
                        {
                            if (target.lastPvpMessage < DateTime.Now)
                            {
                                target.lastPvpMessage = DateTime.Now.AddSeconds(5);
                                PlayerInteraction.Prod(target.Player);
                                target.Player.TellSystem(Chat.Pink, Player.Name + " can't hurt you");
                            }
                            Player.TellSystem(Chat.Pink, "You challenge " + target.Player.Name + " to a fight to the " + Chat.Red + "death");
                            return(true);
                        }

                        string msg = Player.Name + " attacked " + target.Player.Name + " using " + newAttack.Item;
                        Chatting.Parser.SayFirehose(Chat.Gray, msg);
                        target.TellSystem(Chat.Gray, msg);
                        this.TellSystem(Chat.Gray, msg);
                        Log.WriteAction(target.Player, newAttack, false);
                    }
                    target.Attacker = newAttack;
                }
                return(false);
            }
            else
            {
                //Right click
                Mob m = World.Main.GetEntity(ue.Target) as Mob;
                if (m == null)
                {
                    return(false);
                }
                if (m.Owner == "")
                {
                    return(false);
                }

                if (m.Type == MobType.Ocelot)
                {
                    this.TellSystem(Chat.Pink, "Meow " + m.Owner);
                }
                else if (m.Type == MobType.Wolf)
                {
                    this.TellSystem(Chat.Pink, "Woof " + m.Owner);
                }
                else
                {
                    this.TellSystem(Chat.Pink, "Owner: " + m.Owner);
                }

                return(false);
            }
        }