/// <summary>
        /// Message handler.
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override Error ReadMessage(PacketBuffer packet, BinaryReader reader)
        {
            switch ((ObjectMessageID)packet.Header.MessageID)
            {
            default:
            case ObjectMessageID.Null:
                return(new Error(ErrorCode.InvalidMessageID, packet.Header.MessageID));

            case ObjectMessageID.Create:
                // Read the create message details.
                CreateMessage create = new CreateMessage();
                if (!create.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(create, packet, reader));

            case ObjectMessageID.Update:
                // Read the create message details.
                UpdateMessage update = new UpdateMessage();
                if (!update.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(update, packet, reader));

            case ObjectMessageID.Destroy:
                // Read the create message details.
                DestroyMessage destroy = new DestroyMessage();
                if (!destroy.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, packet.Header.MessageID));
                }
                return(HandleMessage(destroy));
            }
        }
Exemple #2
0
        /// <summary>
        /// Message routing function.
        /// </summary>
        /// <param name="messageID">The ID of the message.</param>
        /// <param name="packet">Packet buffer used to decode the message.</param>
        /// <param name="reader">The reader from which additional message data may be read.</param>
        /// <returns>An error code on failure.</returns>
        /// <remarks>
        /// The default implementation handles the following messages:
        /// Routes the following messages:
        /// <list type="bullet">
        /// <item><see cref="ObjectMessageID.Create"/></item>
        /// <item><see cref="ObjectMessageID.Update"/></item>
        /// <item><see cref="ObjectMessageID.Destroy"/></item>
        /// <item><see cref="ObjectMessageID.Data"/></item>
        /// </list>
        /// </remarks>
        protected virtual Error HandleMessage(ushort messageID, PacketBuffer packet, BinaryReader reader)
        {
            switch ((ObjectMessageID)messageID)
            {
            default:
            case ObjectMessageID.Null:
                return(new Error(ErrorCode.InvalidMessageID, messageID));

            case ObjectMessageID.Create:
                // Read the create message details.
                CreateMessage create = new CreateMessage();
                if (!create.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, create.ObjectID, create.Category))
                {
                    return(new Error());
                }
                return(HandleMessage(create, packet, reader));

            case ObjectMessageID.Update:
                // Read the create message details.
                UpdateMessage update = new UpdateMessage();
                if (!update.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, update.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(update, packet, reader));

            case ObjectMessageID.Destroy:
                // Read the create message details.
                DestroyMessage destroy = new DestroyMessage();
                if (!destroy.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, destroy.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(destroy, packet, reader));

            case ObjectMessageID.Data:
                // Read the create message details.
                DataMessage data = new DataMessage();
                if (!data.Read(reader))
                {
                    return(new Error(ErrorCode.InvalidContent, messageID));
                }
                if (!FilterMessage(messageID, data.ObjectID, 0))
                {
                    return(new Error());
                }
                return(HandleMessage(data, packet, reader));
            }

            //return new Error();
        }