Beispiel #1
0
 public Bullet(Vector position, Vector velocity, Hashtable properties, MmoActorOperationHandler owner, string id,
               byte type, World world)
     : base(position, velocity, properties, owner, id, type, world)
 {
     timeToLive             = GlobalVars.bulletLiveTime;
     secsFromLastUpdateDone = null;
 }
Beispiel #2
0
        public Item(Vector position, Vector rotation, Hashtable properties, MmoActorOperationHandler owner, string id, byte type, World world)
        {
            this.Position              = position;
            this.Rotation              = rotation;
            this.Owner                 = owner;
            this.eventChannel          = new MessageChannel <ItemEventMessage>(ItemEventMessage.CounterEventSend);
            this.disposeChannel        = new MessageChannel <ItemDisposedMessage>(MessageCounters.CounterSend);
            this.positionUpdateChannel = new MessageChannel <ItemPositionMessage>(MessageCounters.CounterSend);
            this.properties            = properties ?? new Hashtable();
            if (properties != null)
            {
                this.PropertiesRevision++;
            }

            this.id    = id;
            this.world = world;
            this.type  = type;
        }
Beispiel #3
0
        public Item(Vector position, Vector rotation, Hashtable properties, MmoActorOperationHandler owner, string id, byte type, World world)
        {
            this.Position = position;
            this.Rotation = rotation;
            this.Owner = owner;
            this.eventChannel = new MessageChannel<ItemEventMessage>(ItemEventMessage.CounterEventSend);
            this.disposeChannel = new MessageChannel<ItemDisposedMessage>(MessageCounters.CounterSend);
            this.positionUpdateChannel = new MessageChannel<ItemPositionMessage>(MessageCounters.CounterSend);
            this.properties = properties ?? new Hashtable();
            if (properties != null)
            {
                this.PropertiesRevision++;
            }

            this.id = id;
            this.world = world;
            this.type = type;
        }
        /// <summary>
        /// Expects operation EnterWorld and creates a new MmoActor with a new Item as avatar and a new MmoClientInterestArea. 
        /// </summary>
        /// <remarks>
        /// The MmoActor becomes the new Peer.CurrentOperationHandler.
        /// If another MmoActor with the same name exists he is disconnected.
        /// An OperationResponse with error code ReturnCode.Ok is published on success.
        /// </remarks>
        public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new EnterWorld(peer.Protocol, request);
            if (!operation.IsValid)
            {
                return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
            }

            World world;
            if (WorldCache.Instance.TryGet(operation.WorldName, out world) == false)
            {
                return operation.GetOperationResponse((int)ReturnCode.WorldNotFound, "WorldNotFound");
            }

            var interestArea = new ClientInterestArea(peer, operation.InterestAreaId, world)
                {
                    ViewDistanceEnter = operation.ViewDistanceEnter,
                    ViewDistanceExit = operation.ViewDistanceExit
                };

            var actor = new MmoActorOperationHandler(peer, world, interestArea);
            var avatar = new Item(operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar, world);

            while (world.ItemCache.AddItem(avatar) == false)
            {
                Item otherAvatarItem;
                if (world.ItemCache.TryGetItem(avatar.Id, out otherAvatarItem))
                {
                    avatar.Dispose();
                    actor.Dispose();
                    interestArea.Dispose();

                    (((Item)otherAvatarItem).Owner).DisconnectByOtherPeer(this.peer, request, sendParameters);

                    // request continued later, no response here
                    return null;
                }
            }

            // init avatar
            actor.AddItem(avatar);
            actor.Avatar = avatar;

            ((Peer)peer).SetCurrentOperationHandler(actor);

            // set return values
            var responseObject = new EnterWorldResponse
                {
                    BoundingBox = world.Area,
                    TileDimensions = world.TileDimensions,
                    WorldName = world.Name
                };

            // send response; use item channel to ensure that this event arrives before any move or subscribe events
            var response = new OperationResponse(request.OperationCode, responseObject);
            sendParameters.ChannelId = Settings.ItemEventChannel;
            peer.SendOperationResponse(response, sendParameters);

            lock (interestArea.SyncRoot)
            {
                interestArea.AttachToItem(avatar);
                interestArea.UpdateInterestManagement();
            }

            avatar.Spawn(operation.Position);
            world.Radar.AddItem(avatar, operation.Position);

            // response already sent
            return null;
        }
Beispiel #5
0
 /// <summary>
 /// Checks wheter the actor is allowed to change the item.
 /// </summary>
 public bool GrantWriteAccess(MmoActorOperationHandler actor)
 {
     return(this.Owner == actor);
 }
Beispiel #6
0
        /// <summary>
        /// Expects operation EnterWorld and creates a new MmoActor with a new Item as avatar and a new MmoClientInterestArea.
        /// </summary>
        /// <remarks>
        /// The MmoActor becomes the new Peer.CurrentOperationHandler.
        /// If another MmoActor with the same name exists he is disconnected.
        /// An OperationResponse with error code ReturnCode.Ok is published on success.
        /// </remarks>
        public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
        {
            var operation = new EnterWorld(peer.Protocol, request);

            if (!operation.IsValid)
            {
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage()
                });
            }

            World world;

            if (WorldCache.Instance.TryGet(operation.WorldName, out world) == false)
            {
                return(operation.GetOperationResponse((int)ReturnCode.WorldNotFound, "WorldNotFound"));
            }

            var interestArea = new ClientInterestArea(peer, operation.InterestAreaId, world)
            {
                ViewDistanceEnter = operation.ViewDistanceEnter,
                ViewDistanceExit  = operation.ViewDistanceExit
            };

            var actor  = new MmoActorOperationHandler(peer, world, interestArea);
            var avatar = new Item(operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar, world);

            while (world.ItemCache.AddItem(avatar) == false)
            {
                Item otherAvatarItem;
                if (world.ItemCache.TryGetItem(avatar.Id, out otherAvatarItem))
                {
                    avatar.Dispose();
                    actor.Dispose();
                    interestArea.Dispose();

                    (((Item)otherAvatarItem).Owner).DisconnectByOtherPeer(this.peer, request, sendParameters);

                    // request continued later, no response here
                    return(null);
                }
            }

            // init avatar
            actor.AddItem(avatar);
            actor.Avatar = avatar;

            ((Peer)peer).SetCurrentOperationHandler(actor);

            // set return values
            var responseObject = new EnterWorldResponse
            {
                BoundingBox    = world.Area,
                TileDimensions = world.TileDimensions,
                WorldName      = world.Name
            };

            // send response; use item channel to ensure that this event arrives before any move or subscribe events
            var response = new OperationResponse(request.OperationCode, responseObject);

            sendParameters.ChannelId = Settings.ItemEventChannel;
            peer.SendOperationResponse(response, sendParameters);

            lock (interestArea.SyncRoot)
            {
                interestArea.AttachToItem(avatar);
                interestArea.UpdateInterestManagement();
            }

            avatar.Spawn(operation.Position);
            world.Radar.AddItem(avatar, operation.Position);

            // response already sent
            return(null);
        }
Beispiel #7
0
 /// <summary>
 /// Checks wheter the actor is allowed to change the item.
 /// </summary>
 public bool GrantWriteAccess(MmoActorOperationHandler actor)
 {
     return this.Owner == actor;
 }