示例#1
0
        public override void Connect()
        {
            // get or compute identity
            if (string.IsNullOrEmpty(ts3FullClientData.Identity))
            {
                identity = Ts3Crypt.GenerateNewIdentity();
                ts3FullClientData.Identity       = identity.PrivateKeyString;
                ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;
            }
            else
            {
                identity = Ts3Crypt.LoadIdentity(ts3FullClientData.Identity, ts3FullClientData.IdentityOffset);
            }
            // check required security level
            Ts3Crypt.ImproveSecurity(identity, ts3FullClientData.IdentityLevel);
            ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;

            // get or compute password
            if (!string.IsNullOrEmpty(ts3FullClientData.ServerPassword) &&
                ts3FullClientData.ServerPasswordAutoHash &&
                !ts3FullClientData.ServerPasswordIsHashed)
            {
                ts3FullClientData.ServerPassword         = Ts3Crypt.HashPassword(ts3FullClientData.ServerPassword);
                ts3FullClientData.ServerPasswordIsHashed = true;
            }

            tsFullClient.QuitMessage     = QuitMessages[Util.Random.Next(0, QuitMessages.Length)];
            tsFullClient.OnErrorEvent   += TsFullClient_OnErrorEvent;
            tsFullClient.OnDisconnected += TsFullClient_OnDisconnected;
            ConnectClient();
        }
示例#2
0
        private void TsFullClient_OnErrorEvent(object sender, CommandError e)
        {
            switch (e.Id)
            {
            case Ts3ErrorCode.whisper_no_targets:
                stallNoErrorCount = 0;
                isStall           = true;
                break;

            case Ts3ErrorCode.client_could_not_validate_identity:
                if (ts3FullClientData.IdentityLevel == "auto")
                {
                    int targetSecLevel = int.Parse(e.ExtraMessage);
                    Log.Write(Log.Level.Info, "Calculating up to required security level: {0}", targetSecLevel);
                    Ts3Crypt.ImproveSecurity(identity, targetSecLevel);
                    ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;

                    ConnectClient();
                }
                else
                {
                    Log.Write(Log.Level.Warning, "The server reported that the security level you set is not high enough." +
                              "Increase the value to \"{0}\" or set it to \"auto\" to generate it on demand when connecting.", e.ExtraMessage);
                }
                break;

            default:
                Log.Write(Log.Level.Debug, e.ErrorFormat());
                break;
            }
        }
示例#3
0
 private void UpdateIndentityToSecurityLevel(int targetLevel)
 {
     if (Ts3Crypt.GetSecurityLevel(identity) < targetLevel)
     {
         Log.Info("Calculating up to required security level: {0}", targetLevel);
         Ts3Crypt.ImproveSecurity(identity, targetLevel);
         config.Connect.Identity.Offset.Value = identity.ValidKeyOffset;
     }
 }
示例#4
0
 private void UpdateIndentityToSecurityLevel(int targetLevel)
 {
     if (Ts3Crypt.GetSecurityLevel(identity) < targetLevel)
     {
         Log.Info("Calculating up to required security level: {0}", targetLevel);
         Ts3Crypt.ImproveSecurity(identity, targetLevel);
         ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;
     }
 }
示例#5
0
        public override void Connect()
        {
            // get or compute identity
            if (string.IsNullOrEmpty(ts3FullClientData.Identity))
            {
                identity = Ts3Crypt.GenerateNewIdentity();
                ts3FullClientData.Identity       = identity.PrivateKeyString;
                ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;
            }
            else
            {
                identity = Ts3Crypt.LoadIdentity(ts3FullClientData.Identity, ts3FullClientData.IdentityOffset);
            }

            // check required security level
            if (ts3FullClientData.IdentityLevel == "auto")
            {
            }
            else if (int.TryParse(ts3FullClientData.IdentityLevel, out int targetLevel))
            {
                if (Ts3Crypt.GetSecurityLevel(identity) < targetLevel)
                {
                    Log.Info("Calculating up to required security level: {0}", targetLevel);
                    Ts3Crypt.ImproveSecurity(identity, targetLevel);
                    ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;
                }
            }
            else
            {
                Log.Warn("Invalid value for QueryConnection::IdentityLevel, enter a number or \"auto\".");
            }


            // get or compute password
            if (!string.IsNullOrEmpty(ts3FullClientData.ServerPassword) &&
                ts3FullClientData.ServerPasswordAutoHash &&
                !ts3FullClientData.ServerPasswordIsHashed)
            {
                ts3FullClientData.ServerPassword         = Ts3Crypt.HashPassword(ts3FullClientData.ServerPassword);
                ts3FullClientData.ServerPasswordIsHashed = true;
            }

            tsFullClient.QuitMessage     = QuitMessages[Util.Random.Next(0, QuitMessages.Length)];
            tsFullClient.OnErrorEvent   += TsFullClient_OnErrorEvent;
            tsFullClient.OnDisconnected += TsFullClient_OnDisconnected;
            ConnectClient();
        }
示例#6
0
        private void TsFullClient_OnDisconnected(object sender, DisconnectEventArgs e)
        {
            if (e.Error != null)
            {
                var error = e.Error;
                switch (error.Id)
                {
                case Ts3ErrorCode.client_could_not_validate_identity:
                    if (ts3FullClientData.IdentityLevel == "auto")
                    {
                        int targetSecLevel = int.Parse(error.ExtraMessage);
                        Log.Info("Calculating up to required security level: {0}", targetSecLevel);
                        Ts3Crypt.ImproveSecurity(identity, targetSecLevel);
                        ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;

                        ConnectClient();
                        return;                         // skip triggering event, we want to reconnect
                    }
                    else
                    {
                        Log.Warn("The server reported that the security level you set is not high enough." +
                                 "Increase the value to \"{0}\" or set it to \"auto\" to generate it on demand when connecting.", error.ExtraMessage);
                    }
                    break;

                default:
                    Log.Warn("Could not connect: {0}", error.ErrorFormat());
                    break;
                }
            }
            else
            {
                Log.Debug("Bot disconnected. Reason: {0}", e.ExitReason);
            }

            OnBotDisconnect?.Invoke(this, new EventArgs());
        }
示例#7
0
        private void TsFullClient_OnErrorEvent(object sender, CommandError e)
        {
            switch (e.Id)
            {
            case Ts3ErrorCode.whisper_no_targets:
                stallNoErrorCount = 0;
                isStall           = true;
                break;

            case Ts3ErrorCode.client_could_not_validate_identity:
                autoReconnectOnce = true;
                int targetSecLevel = int.Parse(e.ExtraMessage);
                Log.Write(Log.Level.Info, "Calculating up to required security level: {0}", targetSecLevel);
                Ts3Crypt.ImproveSecurity(identity, targetSecLevel);
                ts3FullClientData.IdentityOffset = identity.ValidKeyOffset;

                tsFullClient.Disconnect();
                break;

            default:
                Log.Write(Log.Level.Debug, e.ErrorFormat());
                break;
            }
        }