Пример #1
0
 internal void ReconnectTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (this.Client.State != IrcClientState.Disconnected)
     {
         return;
     }
     try {
         ConsoleUtils.WriteLine("Connecting to {0} ({1}) on port {2}.", this.Name, this.Address, this.Port);
         this.UpdateSettings();
         this.Client.Connect(this.Address, this.Port);
     } catch (Exception ex) {
         ConsoleUtils.WriteLine("%cREDConnection to {0} failed: {1}%r", this.Name, ex.Message);
         this.StartReconnect();
     }
 }
Пример #2
0
        public static void LoadUsers()
        {
            // This is not a strict INI file, so the IniFile class cannot be used here.
            Bot.commandCallbackNeeded = false;
            Bot.Accounts.Clear();
            if (File.Exists("CBotUsers.ini"))
            {
                try {
                    using (var Reader = new StreamReader("CBotUsers.ini")) {
                        string  Section = null;
                        Account newUser = null;

                        while (!Reader.EndOfStream)
                        {
                            string s = Reader.ReadLine();
                            if (Regex.IsMatch(s, @"^(?>\s*);"))
                            {
                                continue;                                                              // Comment check
                            }
                            Match Match = Regex.Match(s, @"^\s*\[(?<Section>.*?)\]?\s*$");
                            if (Match.Success)
                            {
                                if (Section != null)
                                {
                                    Bot.Accounts.Add(Section, newUser);
                                }
                                Section = Match.Groups["Section"].Value;
                                if (!Bot.Accounts.ContainsKey(Section))
                                {
                                    newUser = new Account {
                                        Permissions = new string[0]
                                    };
                                    if (Section.StartsWith("$a"))
                                    {
                                        Bot.commandCallbackNeeded = true;
                                    }
                                }
                            }
                            else
                            {
                                if (Section != null)
                                {
                                    Match = Regex.Match(s, @"^\s*((?>[^=]*))=(.*)$");
                                    if (Match.Success)
                                    {
                                        string Field = Match.Groups[1].Value;
                                        string Value = Match.Groups[2].Value;
                                        switch (Field.ToUpper())
                                        {
                                        case "PASSWORD":
                                        case "PASS":
                                            newUser.Password = Value;
                                            if (newUser.HashType == HashType.None && newUser.Password != null)
                                            {
                                                // Old format
                                                newUser.HashType = (newUser.Password.Length == 128 ? HashType.SHA256Salted : HashType.PlainText);
                                            }
                                            break;

                                        case "HASHTYPE":
                                            newUser.HashType = (HashType)Enum.Parse(typeof(HashType), Value, true);
                                            break;
                                        }
                                    }
                                    else if (s.Trim() != "")
                                    {
                                        string[] array = newUser.Permissions;
                                        newUser.Permissions = new string[array.Length + 1];
                                        Array.Copy(array, newUser.Permissions, array.Length);
                                        newUser.Permissions[array.Length] = s.Trim();
                                    }
                                }
                            }
                        }

                        Bot.Accounts.Add(Section, newUser);
                    }
                } catch (Exception ex) {
                    ConsoleUtils.WriteLine("%cGRAY[%cREDERROR%cGRAY] %cWHITEI was unable to retrieve user data from the file: $k04" + ex.Message + "%r");
                }
            }
        }