using Extreme.Net; using OpenQA.Selenium.Remote; using RuriLib.Models; using RuriLib.ViewModels; using System; using System.Collections.Generic; using System.Net.Security; using System.Net.Sockets; using System.Windows.Media; namespace RuriLib { /// /// The status of the Bot. While the status is NONE or SUCCESS the Bot keeps checking the script until the end, otherwise it stops. /// public enum BotStatus { /// The initial status of the bot. If a bot ends its execution with this stauts, the data line will be registered as ToCheck. NONE, /// Something wrong happened while processing a block. ERROR, /// The data line will be registered as a Hit. SUCCESS, /// The data line will be registered as a fail. FAIL, /// The data line will be retried and the proxy will be banned. BAN, /// The data line will be retried. RETRY, /// The data line will be registered as a Custom. CUSTOM } /// /// Class that holds all the variables needed for checking a single data line. /// public class BotData { /// A random number generator that methods can refer to, in order to avoid the generation of the same random number if executed in rapid succession. public Random Random = new Random(); /// The Status of the Bot. public BotStatus Status { get; set; } /// The Custom Status name in case the Status was set to Custom. public string CustomStatus = "CUSTOM"; /// The Status of the Bot as a string. public string StatusString { get { return Status == BotStatus.CUSTOM ? CustomStatus : Status.ToString(); } } /// The id of the current Bot. public int BotNumber { get; set; } /// The captcha service currently being used. public CaptchaServices.CaptchaService CaptchaService { get; set; } /// The selenium webdriver currently being used. public RemoteWebDriver Driver { get; set; } /// Whether the browser is open or not. public bool BrowserOpen { get; set; } /// The TCP Client used for TCP blocks. public TcpClient TCPClient { get; set; } /// The NET Stream used for TCP blocks with unencrypted connection. public NetworkStream NETStream { get; set; } /// The SSL Stream used for TCP blocks with encrypted connection. public SslStream SSLStream { get; set; } /// Whether to use SSL for the current TCPClient. public bool TCPSSL { get; set; } = true; /// The wrapped data line that needs to be checked. public CData Data { get; set; } /// The proxy currently being used (null if none). public CProxy Proxy { get; set; } /// Whether we should use proxies or not. public bool UseProxies { get; set; } /// The Global RuriLib settings valid for any Config. public RLSettingsViewModel GlobalSettings { get; set; } /// The settings for the current Config. public ConfigSettings ConfigSettings { get; set; } /// The remaining balance on the captcha service account. public double Balance { get; set; } /// The paths of the Screenshots saved by selenium. public List Screenshots { get; set; } #region Response /// The return Address of the HttpResponse. public string Address { get { return Variables.Get("ADDRESS").Value; } set { Variables.SetHidden("ADDRESS", value); } } /// The HTTP code of the HttpResponse. public string ResponseCode { get { return Variables.Get("RESPONSECODE").Value; } set { Variables.SetHidden("RESPONSECODE", value); } } /// The dictionary of headers of the HttpResponse. public Dictionary ResponseHeaders { get { return Variables.Get("HEADERS").Value; } set { Variables.SetHidden("HEADERS", value); } } /// The dictionary of cookies of the HttpResponse. public Dictionary Cookies { get { return Variables.Get("COOKIES").Value; } set { Variables.SetHidden("COOKIES", value); } } /// The source of the HttpResponse. public string ResponseSource { get { return Variables.Get("SOURCE").Value; } set { Variables.SetHidden("SOURCE", value); } } #endregion // Variables and capture /// The local variables of the Bot. public VariableList Variables { get; set; } /// The global variables shared between all the Bots. They can be accessed or set by any bot. public VariableList GlobalVariables { get; set; } /// The global cookies shared between all the Bots. They are set in the local cookie jar at the start of the check. public Dictionary GlobalCookies { get; set; } // Log /// The detailed log of the last block that was run. public List LogBuffer { get; set; } /// Whether this object is being used for a Debugger or for the Runner. public bool IsDebug { get; set; } /// /// Creates a BotData object given some parameters. /// /// The global RuriLib settings /// The settings for the current Config /// The wrapped data line to check /// The proxy to use (set to null if none) /// Whether to use the proxy for requests /// A reference to the global random generator /// The number of the bot that is creating this object /// Whether this object is created from a Debugger or from a Runner public BotData(RLSettingsViewModel globalSettings, ConfigSettings configSettings, CData data, CProxy proxy, bool useProxies, Random random, int botNumber = 0, bool isDebug = true) { Data = data; Proxy = proxy; UseProxies = useProxies; Random = random; Status = BotStatus.NONE; BotNumber = BotNumber; GlobalSettings = globalSettings; ConfigSettings = configSettings; Balance = 0; Screenshots = new List(); Variables = new VariableList(); // Populate the Variables list with hidden variables Address = ""; ResponseCode = "0"; ResponseSource = ""; Cookies = new Dictionary(); ResponseHeaders = new Dictionary(); try { foreach (var v in Data.GetVariables(ConfigSettings.EncodeData)) Variables.Set(v); } catch { } GlobalVariables = new VariableList(); GlobalCookies = new CookieDictionary(); LogBuffer = new List(); Driver = null; BrowserOpen = false; IsDebug = isDebug; BotNumber = botNumber; } /// /// Adds a new LogEntry to the LogBuffer. /// /// The LogEntry to add public void Log(LogEntry entry) { if (GlobalSettings.General.EnableBotLog || IsDebug) LogBuffer.Add(entry); } /// /// Adds multiple new LogEntry objects to the LogBuffer. /// /// The list of log entries to add public void LogRange(List list) { if (GlobalSettings.General.EnableBotLog || IsDebug) LogBuffer.AddRange(list); } /// /// Logs an empty line to the LogBuffer. /// public void LogNewLine() { LogBuffer.Add(new LogEntry("", Colors.White)); } } }