Esempio n. 1
0
        protected override void OnRecv(InputMessage message)
        {
            OpenTibiaUnity.GameManager.InvokeOnMainThread(delegate {
                try {
                    base.OnRecv(message);
                } catch (Exception e) {
                    string err = string.Format("ProtocolGame.OnRecv: {0}\nStackTrace: {1}", e.Message, new System.Diagnostics.StackTrace(e, true));
                    m_ChatStorage.AddDebugMessage(err);
                    return;
                }

                if (m_FirstRecv)
                {
                    m_FirstRecv = false;

                    ushort size    = message.GetU16();
                    int unreadSize = message.GetUnreadSize();
                    if (unreadSize != size)
                    {
                        string err = string.Format("ProtocolGame.OnRecv: Invalid message size (size: {0}, unread: {1})", size, unreadSize);
                        m_ChatStorage.AddDebugMessage(err);
                        return;
                    }
                }

                bool read = false;
                while (message.CanRead(1))
                {
                    read        = true;
                    byte opcode = message.PeekU8();

                    try {
                        if (!ParsePacket(message))
                        {
                            break;
                        }
                    } catch (Exception e) {
                        string err = string.Format("ProtocolGame: Opcode: {0}, last Opcode ({1}), prev Opcode ({2}).\n{3}\nStackTrace: {4}",
                                                   opcode, m_LastOpcode, m_PrevOpcode, e.Message, new System.Diagnostics.StackTrace(e, true));

                        m_ChatStorage.AddDebugMessage(err);
                        break;
                    }
                }

                if (read)
                {
                    m_WorldMapStorage.ProtocolGameMessageProcessingFinished();
                }
            });
        }