Example #1
0
        /// <summary>
        /// Called when an operation request has been received.
        /// </summary>
        /// <remarks>An operation request is sent when a client sends an operation request to the master. So all operation requests are from game clients</remarks>
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var gameOperationRequest = new GameOperationRequest(operationRequest.Parameters);

            if (!gameOperationRequest.IsValid)
            {
#if MMO_DEBUG
                Logger.DebugFormat("[OnOperationRequest]: GameOperationRequest (OpCode={0}) is not valid", operationRequest.OperationCode);
#endif
                return;
            }

            ISession session;
            if (sessions.TryGetValue(gameOperationRequest.ClientId, out session))
            {
                var messageParameters = new MessageParameters {
                    ChannelId = sendParameters.ChannelId, Encrypted = sendParameters.Encrypted
                };
                session.ReceiveOperationRequest(gameOperationRequest, messageParameters);
            }
            else
            {
                Logger.ErrorFormat("[OnOperationRequest]: Session (Id={0}) cannot be found", gameOperationRequest.ClientId);
            }
        }
Example #2
0
 /// <summary>
 /// Transfers a(n) <see cref="ISession"/> to another world
 /// </summary>
 void IWorldServer.TransferSession(int sessionId, int zoneId)
 {
     this.messageFiber.Enqueue(() =>
     {
         ISession session;
         if (sessions.TryGetValue(sessionId, out session))
         {
             sessions.Remove(sessionId);
             // destroy the session due to disconnect
             session.Destroy(DestroySessionReason.Transfer);
             // notifying the master to update the state so the client can start sending messages
             this.SendOperationRequest(
                 new OperationRequest((byte)ServerOperationCode.TransferSession,
                                      new TransferSession
             {
                 SessionId = session.SessionId,
                 WorldId   = zoneId,
             }),
                 new SendParameters());
         }
         else
         {
             Logger.ErrorFormat("[TransferSession]: Session (Id={0}) cannot be found", sessionId);
         }
     });
 }
Example #3
0
        /// <summary>
        /// Adds a(n) <see cref="IWorld"/> to the social
        /// </summary>
        public bool AddWorld(short worldId, IWorld world)
        {
            // using a while loop for the lock-timeout
            while (!worlds.Add(worldId, world))
            {
                IWorld existingWorld;
                if (worlds.TryGetValue(worldId, out existingWorld))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Creates a new <see cref="MmoZone"/>.
        /// </summary>
        public MmoZone CreateZone(short id, string name, Bounds zoneBounds, Vector3 tileDimentions, ZoneDescription zoneDescription)
        {
            MmoZone existingZone;

            if (zones.TryGetValue(id, out existingZone))
            {
                return(existingZone);
            }

            // locking to update the bounds
            lock (zones)
            {
                this.bounds = this.bounds.Size != Vector3.Zero ? this.bounds.UnionWith(zoneBounds) : zoneBounds;
                var newZone = new MmoZone(this, id, name, zoneBounds, tileDimentions, zoneDescription, configuration);
                zones.Add(id, newZone);
                return(newZone);
            }
        }
Example #5
0
        /// <summary>
        /// Removes a(n) <see cref="Channel"/>.
        /// </summary>
        /// <returns> Returns true if successful </returns>
        public bool RemoveChannel(Channel channel)
        {
            Channel theChannel;

            if (channels.TryGetValue(channel.Id, out theChannel))
            {
                if (theChannel == channel)
                {
                    channels.Remove(theChannel.Id);
                    theChannel.Dispose();
                    return(true);
                }
            }
            return(false);
        }
Example #6
0
 /// <summary>
 /// Tries to retrieve an item
 /// </summary>
 public bool TryGetItem(MmoGuid guid, out MmoObject mmoObject)
 {
     return(objects.TryGetValue(guid.Type, guid.Id, out mmoObject));
 }