Пример #1
0
        protected sealed override void HandleChatPayloadType(ChatPayloads.ChatTypes chatPayloadType, ChatPayloadPrefix chatPayload, PayloadWriter writer)
        {
            Program.LogDebug($" --- Chat Payload received: {chatPayloadType} ---");
            chatPayload.Serialize(Logger);

            switch (chatPayloadType)
            {
            case ChatPayloads.ChatTypes.CreateChannel:
                ChatHandleCreateChannel((CreateChannel)chatPayload, writer);
                break;

            default:
                return;
            }
        }
        protected sealed override void HandleMessage(BinaryReader reader, BinaryWriter writer)
        {
            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            PayloadReader payloadReader = new PayloadReader(reader);
            PayloadWriter payloadWriter = new PayloadWriter(writer);

            PayloadPrefix prefix = new PayloadPrefix();

            prefix.Serialize(payloadReader);


            if (prefix.Magic == PayloadPrefix.PayloadMagic)
            {
                if (prefix.Type1 != prefix.Type2)
                {
                    Program.Log($" Corrupt payload type, first is {prefix.Type1:X04} but second is {prefix.Type2:X04}");
                }

                Payloads.Types payloadType = (Payloads.Types)prefix.Type2;
                PayloadPrefix  payload     = Payloads.CreatePayload(payloadType);

                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                payload.Serialize(payloadReader);

                HandlePayloadType(payloadType, payload, payloadWriter);
            }
            else if (prefix.Magic == ChatPayloadPrefix.PayloadMagic)
            {
                if (prefix.Type1 != 0)
                {
                    Program.Log($" Corrupt payload chatTypes, is {prefix.Type1:X04} but expected 0");
                }

                ChatPayloads.ChatTypes chatPayloadType = (ChatPayloads.ChatTypes)prefix.Type2;
                ChatPayloadPrefix      chatPayload     = ChatPayloads.CreateChatPayload(chatPayloadType);

                reader.BaseStream.Seek(0, SeekOrigin.Begin);
                chatPayload.Serialize(payloadReader);

                HandleChatPayloadType(chatPayloadType, chatPayload, payloadWriter);
            }
            else
            {
                Program.Log($" Incorrect payload magic, is {prefix.Magic:X04} but should be {PayloadPrefix.PayloadMagic:X04}");
            }
        }
 protected virtual void HandleChatPayloadType(ChatPayloads.ChatTypes chatPayloadType, ChatPayloadPrefix chatPayload, PayloadWriter payloadWriter)
 {
     Program.LogDebug(" Unknown chat payload message received");
     chatPayload.Serialize(Logger);
 }