Exemplo n.º 1
0
        private bool ShouldSend(PlaceSendMessage b, Point3D p)
        {
            if (b.SendCount > 15)
            {
                return(false);
            }
            if (b.NoChecks)
            {
                return(true);
            }
            if (this._room.AccessRight < AccessRight.Edit)
            {
                return(false);
            }

            // TODO: Count blocks
            var isAdministrator = this._connectionManager.PlayerObject.IsAdministrator;
            var isClubMember    = this._connectionManager.PlayerObject.ClubMember;

            if (!WorldUtils.IsPlaceable(b, this._world, !isAdministrator))
            {
                return(false);
            }
            if (!this._connectionManager.ShopData.HasBlock(b.Id, 0, isClubMember, isAdministrator))
            {
                return(false);
            }

            CheckHandle handle;

            return(!(this._sentLocations.TryGetValue(p, out handle)
                ? WorldUtils.AreSame(b, handle.Message)
                : WorldUtils.IsAlreadyPlaced(b, this._world)));
        }
Exemplo n.º 2
0
        private bool ShouldSend(PlaceSendMessage b, Point3D p)
        {
            if (b.SendCount > 10)
            {
                return(false);
            }
            if (b.NoChecks)
            {
                return(true);
            }
            if (!Actions.Of(this.BotBits).CanEdit)
            {
                return(false);
            }

            var playerData      = ConnectionManager.Of(this.BotBits).PlayerData;
            var blocks          = Blocks.Of(this.BotBits);
            var isAdministrator = playerData.PlayerObject.IsAdministrator;

            if (!WorldUtils.IsPlaceable(b, blocks, !isAdministrator))
            {
                return(false);
            }
            if (!playerData.HasBlock(b.Id))
            {
                return(false);
            }

            CheckHandle handle;

            return(!(this._sentLocations.TryGetValue(p, out handle)
                ? WorldUtils.AreSame(b, handle.Message)
                : WorldUtils.IsAlreadyPlaced(b, blocks)));
        }
Exemplo n.º 3
0
        private static bool AreSame <T, TBlock>(PlaceSendMessage sent, T received)
            where T : PlaceEvent <T, TBlock>
            where TBlock : struct
        {
            var bg = received as BackgroundPlaceEvent;

            if (bg != null)
            {
                return(WorldUtils.AreSame(sent, bg));
            }
            var fg = received as ForegroundPlaceEvent;

            if (fg != null)
            {
                return(WorldUtils.AreSame(sent, fg));
            }

            throw new NotSupportedException("Unknown PlaceEvent.");
        }
Exemplo n.º 4
0
        private void Repair <T, TBlock>(Layer layer, T e)
            where T : PlaceEvent <T, TBlock> where TBlock : struct
        {
            // Make sure the block was uploaded by this bot
            var p = e.New.Placer;

            if (p != null && p != Package <Players> .Of(this.BotBits).OwnPlayer)
            {
                return;
            }

            lock (this._sentBlocks)
            {
                var point = new Point3D(layer, e.X, e.Y);

                // Make sure we have sent a block at this location
                CheckHandle testB;
                if (!this._sentLocations.TryGetValue(point, out testB))
                {
                    return;
                }

                // If we have sent mutliple blocks at this position, wait until we receive the last one
                if (testB.OverwrittenSends != 0)
                {
                    testB.OverwrittenSends--;
                }
                else if (WorldUtils.AreSame <T, TBlock>(testB.Message, e))
                {
                    // Reset the timeout
                    this._timeoutResetEvent.Set();

                    this.RepairMissed(point);
                }
            }
        }