CGC_Codes

AMHE

Jul 3rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.70 KB | None | 0 0
  1. using System;
  2. using System.Configuration;
  3. using System.Net.Mail;
  4. using System.Net;
  5.  
  6. using MySql.Data.MySqlClient;
  7.  
  8. namespace AMHE
  9. {
  10.     public class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             DbInfos infos = new DbInfos();
  15.             MySqlConnection mySqlConn = new MySqlConnection();
  16.             MySqlCommand command;
  17.             MySqlDataReader reader;
  18.  
  19.            
  20.             string dbServerIp = ConfigurationSettings.AppSettings.Get("ServerIP");
  21.             string dbPort = ConfigurationSettings.AppSettings.Get("DbPort");
  22.             string dbUserId = ConfigurationSettings.AppSettings.Get("DbUserID");
  23.             string dbPassword = ConfigurationSettings.AppSettings.Get("DbPassword");
  24.             string dbName = ConfigurationSettings.AppSettings.Get("DbName");
  25.  
  26.            
  27.             mySqlConn.ConnectionString = "Server=" + dbServerIp + "userid=" + dbUserId +
  28.                                          "password=" + dbPassword + "port=" + dbPort + "database=" + dbName;
  29.  
  30.             string emailSubject = ConfigurationSettings.AppSettings.Get("EmailSubject");
  31.            
  32.  
  33.             string toEmailAddress = ConfigurationSettings.AppSettings.Get("ToEmail");
  34.  
  35.             string fromEmailAddress = ConfigurationSettings.AppSettings.Get("FromEmail");
  36.             string fromEmailPassword = ConfigurationSettings.AppSettings.Get("FromPassword");
  37.  
  38.             string smtpHost = ConfigurationSettings.AppSettings.Get("smtpHost");
  39.             string smtpPort = ConfigurationSettings.AppSettings.Get("smtpPort");
  40.  
  41.            
  42.             string maxAllowedCashOnHand = ConfigurationSettings.AppSettings.Get("CashOnHand");
  43.             string maxAllowedBankCash = ConfigurationSettings.AppSettings.Get("BankCash");
  44.  
  45.             int counter = 0;
  46.  
  47.             try
  48.             {
  49.                 mySqlConn.Open();
  50.                
  51.                 string query = "SELECT * " +
  52.                                "FROM " + dbName + ".players " +
  53.                                "WHERE cash >= " + Int32.Parse(maxAllowedCashOnHand) +
  54.                                "OR bankacc >= " + Int32.Parse(maxAllowedBankCash);
  55.  
  56.                 command = new MySqlCommand(query, mySqlConn);
  57.                 reader = command.ExecuteReader();
  58.  
  59.  
  60.                 while (reader.Read())
  61.                 {
  62.                    
  63.                     infos.suspectedPlayers[counter] = reader.GetString("name") + ",";
  64.                     infos.playerId[counter] = reader.GetString("playerid") + ",";
  65.                     infos.databaseId[counter] = reader.GetString("id") + ",";
  66.                     infos.cashOnHand[counter] = reader.GetString("cash") + ",";
  67.                     infos.moneyInBank[counter] = reader.GetString("bankacc") + ",";
  68.                     counter++;
  69.                 }
  70.  
  71.                 mySqlConn.Close();
  72.             }
  73.  
  74.             catch (Exception ex)
  75.             {
  76.                 Console.WriteLine(ex.Message);
  77.             }
  78.  
  79.             finally
  80.             {
  81.                 mySqlConn.Dispose();
  82.             }
  83.  
  84.             for (int i = 0; i < counter; i++)
  85.             {
  86.                 var fromMessage = new MailAddress(fromEmailAddress, "Possible Hacker Alert System");
  87.                 string fromPassword = fromEmailPassword;
  88.  
  89.                
  90.                 var toMessage = new MailAddress(toEmailAddress);
  91.  
  92.                 string subject = emailSubject + infos.suspectedPlayers[i];
  93.                
  94.                 string body = "Player name: " + infos.suspectedPlayers[i] +
  95.                               "\n" + "Player ID: " + infos.playerId[i] +
  96.                               "\n" + "Database ID: (UID)" + infos.databaseId[i] +
  97.                               "\n" + "Player cash on hand: " + infos.cashOnHand[i] +
  98.                               "\n" + "Player bank amount: " + infos.moneyInBank[i];
  99.  
  100.                 Console.WriteLine(body);
  101.  
  102.                 var smtp = new SmtpClient
  103.                 {
  104.                     Host = smtpHost,
  105.                     Port = Int32.Parse(smtpPort),
  106.                     EnableSsl = true,
  107.                     DeliveryMethod = SmtpDeliveryMethod.Network,
  108.                     Credentials = new NetworkCredential(fromMessage.Address, fromPassword),
  109.                     Timeout = 20000
  110.                 };
  111.  
  112.                 using (var message = new MailMessage(fromMessage, toMessage)
  113.                 {
  114.                     Subject = subject,
  115.                     Body = body
  116.                 })
  117.                 {
  118.                     smtp.Send(message);
  119.                 }
  120.  
  121.             }
  122.             Console.WriteLine("Message Sent\nPlease Press any button to exit...");
  123.             Console.ReadLine();
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment