private void SendAuthRequest2()
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("client is sending auth request: c:{0}", this.clientUserId);
            }

            startTime = watcher.ElapsedMilliseconds;
            var authValues = new AuthenticationValues();

            authValues.SetAuthParameters("yes", "yes");
            if (this.OpAuthenticate(Settings.Default.AppId,
                                    Settings.Default.AppVer,
                                    this.clientUserId,
                                    authValues, Settings.Default.AppRegion))
            {
                Counters.RequestsSent.Increment();
                this.State = ClientState.SecondRequestSent;
            }
            else
            {
                log.WarnFormat("Failed to send auth req. c:{0}", this.clientUserId);
                this.peer.Disconnect();
            }
        }
        public bool OpAuthenticate(string appId, string appVersion, string userId, AuthenticationValues authValues, string regionCode)
        {
            var opParameters = new Dictionary <byte, object>();

            opParameters[(byte)ParameterKey.AppVersion]    = appVersion;
            opParameters[(byte)ParameterKey.ApplicationId] = appId;

            if (!string.IsNullOrEmpty(regionCode))
            {
                opParameters[(byte)ParameterKey.Region] = regionCode;
            }

            if (!string.IsNullOrEmpty(userId))
            {
                opParameters[(byte)ParameterKey.UserId] = userId;
            }

            if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
            {
                opParameters[(byte)ParameterKey.ClientAuthenticationType] = (byte)authValues.AuthType;

                if (!string.IsNullOrEmpty(authValues.AuthParameters))
                {
                    opParameters[(byte)ParameterKey.ClientAuthenticationParams] = authValues.AuthParameters;
                }
                if (authValues.AuthPostData != null)
                {
                    opParameters[(byte)ParameterKey.ClientAuthenticationData] = authValues.AuthPostData;
                }
            }

            var request = new OperationRequest((byte)OperationCode.Authenticate, opParameters);

            return(this.peer.SendOperationRequest(request, new SendParameters {
                Encrypted = Settings.Default.EncryptData
            })
                   == SendResult.Ok);
        }