示例#1
0
        protected override void OnCommunicationDataReady()
        {
            LoginserverMessageType prevMessageType = 0;
            LoginserverMessageType lastMessageType = 0;

            while (m_InputBuffer.BytesAvailable > 0)
            {
                var messageType = m_InputBuffer.ReadLoginType();
                try {
                    ParseMessage(messageType);
                    prevMessageType = lastMessageType;
                    lastMessageType = messageType;
                } catch (System.Exception e) {
                    var err = string.Format("ProtocolLogin.ParsePacket: error: {0}, type: ({1}), last type ({2}), prev type ({2}), unread ({4}), StackTrace: \n{5}.",
                                            e.Message,
                                            messageType,
                                            lastMessageType,
                                            prevMessageType,
                                            m_InputBuffer.BytesAvailable,
                                            e.StackTrace);

                    OnConnectionError(err);
                }
            }
        }
示例#2
0
        private void ParseMessage(LoginserverMessageType messageType)
        {
            switch (messageType)
            {
            case LoginserverMessageType.ErrorLegacy:
            case LoginserverMessageType.Error:
                onLoginError.Invoke(_inputStream.ReadString());
                _expectingTermination = true;
                break;

            case LoginserverMessageType.TokenSuccess:
                _tokenSuccess = _inputStream.ReadBoolean();
                break;

            case LoginserverMessageType.TokenError:
                byte tries = _inputStream.ReadUnsignedByte();
                onLoginTokenError.Invoke(tries);
                break;

            case LoginserverMessageType.MessageOfTheDay:
                string[] motdinfo = _inputStream.ReadString().Split('\n');
                if (motdinfo.Length == 2 && int.TryParse(motdinfo[0], out int number))
                {
                    onMessageOfTheDay.Invoke(number, motdinfo[1]);
                }
                break;

            case LoginserverMessageType.UpdateRequired:
                onUpdateRequired.Invoke();
                _expectingTermination = true;
                break;

            case LoginserverMessageType.SessionKey:
                _sessionKey = _inputStream.ReadString();
                break;

            case LoginserverMessageType.CharacterList:
                var playData = ReadPlayData(_inputStream);

                if (OpenTibiaUnity.GameManager.GetFeature(GameFeature.GameSessionKey))
                {
                    playData.Session.Key = _sessionKey;
                }
                else
                {
                    playData.Session.AccountName = AccountName;
                    playData.Session.Password    = Password;
                }
                onPlayData.Invoke(playData);
                _expectingTermination = true;
                break;

            default:
                throw new System.Exception("unknown message type");
            }
        }