Beispiel #1
0
        public static void ProcessOpcodes(Session MySession, ushort MessageTypeOpcode, List <byte> myPacket)
        {
            ///Expected message length
            ushort MessageLength;
            ushort MessageNumber;
            ushort Opcode;

            ///Short message, 1 byte for message length
            if ((MessageTypeOpcode == MessageOpcodeTypes.ShortReliableMessage) || (MessageTypeOpcode == MessageOpcodeTypes.UnknownMessage))
            {
                MessageLength = (ushort)myPacket[0];
                ///Remove read byte
                myPacket.RemoveRange(0, 1);
            }

            ///Long message, 2 bytes for message length
            else
            {
                MessageLength = (ushort)(myPacket[1] << 8 | myPacket[0]);
                ///Remove 2 read bytes
                myPacket.RemoveRange(0, 2);
            }

            ///Make sure Message number is expected, needs to be in order.
            MessageNumber = (ushort)(myPacket[1] << 8 | myPacket[0]);


            if (MySession.clientMessageNumber + 1 == MessageNumber)
            {
                ///Increment for every message read, in order.
                MySession.IncrementClientMessageNumber();

                //If F9 type, no opcode process it seperately.
                if (MessageTypeOpcode == MessageOpcodeTypes.UnknownMessage)
                {
                    myPacket.RemoveRange(0, 2);
                    ProcessPingRequest(MySession, myPacket);
                    return;
                }

                Opcode = (ushort)(myPacket[3] << 8 | myPacket[2]);

                Logger.Info($"Message Length: {MessageLength}; OpcodeType: {MessageTypeOpcode.ToString("X")}; Message Number: {MessageNumber.ToString("X")}; Opcode: {Opcode.ToString("X")}.");

                ///Remove 4 read bytes (Opcode and Message #)
                myPacket.RemoveRange(0, 4);

                //Remove the opcode bytes we read
                MessageLength -= 2;

                ///Pass remaining to opcode checker for more processing
                OpcodeChecker(MySession, Opcode, myPacket, MessageLength);
            }

            ///Not expected order?
            ///Expand on eventually
            else
            {
                //Remove packet# and message bytes
                myPacket.RemoveRange(0, MessageLength + 2);
                return;
            }
        }
Beispiel #2
0
 public KeyValuePair <string, string> ToSearchResult() => new KeyValuePair <string, string>(MessageNumber.ToString(), MessageDescription);