コード例 #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();
                }
            });
        }
コード例 #2
0
        protected override void OnRecv(InputMessage message)
        {
            try {
                base.OnRecv(message);
            } catch (System.Exception e) {
                UnityEngine.Debug.LogWarning(e.Message);
            }

            OpenTibiaUnity.GameManager.InvokeOnMainThread(() => {
                while (message.CanRead(1))
                {
                    byte opcode = message.GetU8();
                    switch (opcode)
                    {
                    case LoginServerOpCodes.LoginRetry:
                        break;

                    case LoginServerOpCodes.LoginError:
                        string error = message.GetString();
                        onLoginError.Invoke(error);
                        break;

                    case LoginServerOpCodes.LoginTokenSuccess:
                        message.GetU8();     // Ok...
                        break;

                    case LoginServerOpCodes.LoginTokenError:
                        byte unknown = message.GetU8();
                        onLoginTokenError.Invoke(unknown);
                        break;

                    case LoginServerOpCodes.LoginMotd:
                        string[] motdinfo = message.GetString().Split('\n');
                        if (motdinfo.Length == 2)
                        {
                            int number;
                            int.TryParse(motdinfo[0], out number);
                            onMotd.Invoke(number, motdinfo[1]);
                        }
                        break;

                    case LoginServerOpCodes.UpdateRequired:
                        onUpdateRequired.Invoke();
                        break;

                    case LoginServerOpCodes.LoginSessionKey:
                        string sessionKey = message.GetString();
                        onSessionKey.Invoke(sessionKey);
                        break;

                    case LoginServerOpCodes.LoginCharacterList:
                        CharacterList characterList = new CharacterList(message);
                        onCharacterList.Invoke(characterList);
                        break;

                    default:
                        break;
                    }
                }
            });
        }