Пример #1
0
        /// <summary>
        /// Enqueue <see cref="NetworkObject"/> to be sent to the client.
        /// </summary>
        public void EnqueueMessage(ObjectOpcode opcode, NetworkObject message)
        {
            var packet = new NetworkObject();

            packet.AddField(0, NetworkObjectField.CreateIntField((int)opcode));
            packet.AddField(1, NetworkObjectField.CreateObjectField(message));
            EnqueueMessage(packet);
        }
Пример #2
0
 /// <summary>
 /// Broadcast <see cref="NetworkObject"/> to all members.
 /// </summary>
 public void BroadcastMessage(ObjectOpcode opcode, NetworkObject message)
 {
     foreach (CharacterObject character in members.Values)
     {
         Session session = NetworkManager.FindSessionByCharacter(character);
         session?.EnqueueMessage(opcode, message);
     }
 }
Пример #3
0
        public ServerObjectPacket(ObjectOpcode opcode, NetworkObject networkObject, bool encrypt = true)
        {
            this.opcode        = opcode;
            this.networkObject = networkObject;

            if (encrypt)
            {
                flags |= PacketFlag.Encrypted;
            }
        }
Пример #4
0
        /// <summary>
        /// Enqueue <see cref="NetworkObject"/> to be sent to the client.
        /// </summary>
        public void EnqueueMessage(NetworkObject message)
        {
            var packet = new ServerPacket(message);

            outgoingPackets.Enqueue(packet);

            ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(message.GetField(0));

            log.Trace($"Sent object packet {opcode}(0x{opcode:X}).");
        }
Пример #5
0
        /// <summary>
        /// Invoke message handler delegate for supplied <see cref="ObjectOpcode"/>.
        /// </summary>
        public static void InvokeObjectMessageHandler(NetworkSession session, ObjectOpcode opcode, NetworkObject networkObject)
        {
            if (!objectMessageHandlers.TryGetValue(opcode, out ObjectMessageHandler handler))
            {
                log.Warn($"Received unhandled object opcode 0x{opcode:X}!");
                return;
            }

            handler.Invoke(session, networkObject);
        }
Пример #6
0
        /// <summary>
        /// Broadcast <see cref="NetworkObject"/> to all members that satisfy supplied predicate.
        /// </summary>
        public void BroadcastMessage(ObjectOpcode opcode, NetworkObject message, Func <CharacterObject, bool> func)
        {
            foreach (CharacterObject character in members.Values)
            {
                if (!func(character))
                {
                    continue;
                }

                Session session = NetworkManager.FindSessionByCharacter(character);
                session?.EnqueueMessage(opcode, message);
            }
        }
Пример #7
0
        private void ProcessObjectPacket(byte[] payload)
        {
            NetworkObject networkObject = NetworkObject.UnPack(payload);

            ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(networkObject.GetField(0));

            log.Trace($"Received object packet {opcode}(0x{opcode:X}).");

            if (opcode == ObjectOpcode.Authenticate)
            {
                PacketManager.InvokeObjectMessageHandler(this, opcode, networkObject);
            }
            else
            {
                PacketManager.InvokeObjectMessageHandler(this, opcode, networkObject.GetField(1).ReadObject());
            }
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        private void ProcessObjectPacket(byte[] payload)
        {
            try
            {
                NetworkObject networkObject = NetworkObject.UnPack(payload);

                ObjectOpcode opcode = (ObjectOpcode)NetworkObjectField.ReadIntField(networkObject.GetField(0));
                if (opcode == ObjectOpcode.Authenticate)
                {
                    PacketManager.InvokeObjectPacketHandler(this, opcode, networkObject);
                }
                else
                {
                    PacketManager.InvokeObjectPacketHandler(this, opcode, networkObject.GetField(1).ReadObject());
                }
            }
            catch (OutOfMemoryException exception)
            {
                log.Fatal(exception);
                log.Fatal($"Payload Length: {payload.Length}");
                throw;
            }
        }
Пример #9
0
 public ObjectPacketHandlerAttribute(ObjectOpcode opcode)
 {
     Opcode = opcode;
 }