Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Data.SqlClient;
  8. using System.Threading;
  9. using System.Timers;
  10.  
  11. namespace AllowedGm
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.  
  18.             CheckSetting Check = new CheckSetting();
  19.             GetConnection connection = new GetConnection();
  20.             GetGms Checkgm = new GetGms();
  21.             string check = File.ReadAllText(Environment.CurrentDirectory + "\\AllowedGM.txt");
  22.  
  23.             List<string> gmList = connection.getGMNames();
  24.             foreach (var gm in gmList)
  25.             {
  26.                 if (!Checkgm.GmList.Contains(gm.ToLower()))
  27.                 {
  28.                     Console.WriteLine("Username [" + gm + "] is not allowed!");
  29.                     SqlCommand player = new SqlCommand(String.Format(@"UPDATE account SET gm=0 WHERE act_name ='{0}';", gm), connection.connection1);
  30.                     player.ExecuteNonQuery();
  31.                 }
  32.                 else
  33.                 {
  34.                     Console.WriteLine("Username [" + gm + "] is approved!");
  35.                 }
  36.             }
  37.             Console.WriteLine("");
  38.             Console.WriteLine(@"Total Account Scanneds: [{0}]", gmList.Count);
  39.  
  40.             //SqlCommand command = new SqlCommand(String.Format(@"IF EXISTS (SELECT * WHERE act_name = N'{0}') THEN (SELECT act_id WHERE act_name='{0}') ELSE (SET gm='0' WHERE act_name !='{0}') END as account FROM account", check), connection.connection1);
  41.             //SqlDataReader reader = command.ExecuteReader();
  42.  
  43.             //while (reader.Read() || reader.NextResult() && reader.Read())
  44.             //{
  45.             //    Console.WriteLine(reader[0].ToString());
  46.             //}
  47.             Console.ReadKey();
  48.         }
  49.     }
  50.  
  51.     public class GetGms
  52.     {
  53.         public List<string> GmList = new List<string>();
  54.  
  55.         public GetGms()
  56.         {
  57.             string[] Gm = { "GMNAME1", "GMNAME2" };
  58.             string gmpath = Environment.CurrentDirectory + "\\AllowedGM.txt";
  59.             if (!File.Exists(gmpath))
  60.             {
  61.                 File.WriteAllLines(gmpath, Gm);
  62.                 Console.WriteLine("");
  63.                 Console.WriteLine("Generating Allowed Gms List...");
  64.                 foreach (var gm in Gm)
  65.                 {
  66.                     GmList.Add(gm.ToLower());
  67.                 }
  68.             }
  69.  
  70.             else
  71.             {
  72.                 string ReadGm = File.ReadAllText(gmpath);
  73.                 string[] Gms = ReadGm.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  74.                 Console.WriteLine("");
  75.                 Console.WriteLine("Reading Allowed Gms List...");
  76.                 Console.WriteLine(ReadGm);
  77.                 foreach (var gm in Gms)
  78.                 {
  79.                     GmList.Add(gm.ToLower());
  80.                 }
  81.             }
  82.         }
  83.     }
  84.  
  85.     public class GetConnection
  86.     {
  87.         public SqlConnection connection1;
  88.         public GetConnection()
  89.         {
  90.             string path = Environment.CurrentDirectory + "\\Settings.ini";
  91.             var IniFile = new CreateIni(path);
  92.             var Host = IniFile.Read("Host");
  93.             var DB = IniFile.Read("DB");
  94.             var User = IniFile.Read("User");
  95.             var Pass = IniFile.Read("Pass");
  96.  
  97.             connection1 = new SqlConnection(String.Format(@"Data Source={0}; user id={1}; password={2};Database={3}", Host, User, Pass, DB));
  98.  
  99.             try
  100.             {
  101.                 connection1.Open();
  102.                 Console.WriteLine("Database Connected!");
  103.             }
  104.  
  105.             catch (Exception ex)
  106.             {
  107.                 Console.WriteLine("Error: " + ex.Message);
  108.                 Environment.Exit(0);
  109.             }
  110.         }
  111.         public void Close()
  112.         {
  113.             connection1.Close();
  114.         }
  115.  
  116.         public List<string> getGMNames()
  117.         {
  118.             List<string> Gms = new List<string>();
  119.  
  120.             string sqlQuery = "SELECT act_name FROM account WHERE gm = 99;";
  121.             SqlDataReader reader;
  122.             SqlDataAdapter adapter = new SqlDataAdapter();
  123.             SqlCommand command = new SqlCommand(sqlQuery, connection1);
  124.             command.Connection = connection1;
  125.             adapter.SelectCommand = command;
  126.             reader = command.ExecuteReader();
  127.  
  128.             if (reader.HasRows)
  129.             {
  130.                 while (reader.Read() || (reader.NextResult() && reader.Read()))
  131.                 {
  132.                     Gms.Add(reader[0].ToString());
  133.                 }
  134.             }
  135.             reader.Close();
  136.  
  137.             return Gms;
  138.         }
  139.     }
  140.  
  141.     public class CheckSetting
  142.     {
  143.         public CheckSetting()
  144.         {
  145.             string path = Environment.CurrentDirectory + "\\Settings.ini";
  146.             var IniFile = new CreateIni(path);
  147.             bool FileExists = File.Exists(path);
  148.             if (FileExists == false)
  149.             {
  150.                 Console.WriteLine("Generating Settings File");
  151.                 IniFile.Write("Host", "Hostname");
  152.                 IniFile.Write("DB", "Database");
  153.                 IniFile.Write("User", "Username");
  154.                 IniFile.Write("Pass", "Password");
  155.             }
  156.             else
  157.             {
  158.                 Console.WriteLine("Loading Setting File");
  159.                 var Host = IniFile.Read("Host");
  160.                 var DB = IniFile.Read("DB");
  161.                 var User = IniFile.Read("User");
  162.                 var Pass = IniFile.Read("Pass");
  163.                 Console.WriteLine(@"Hostname: {0}; Database: {1}; Username: {2}; Password: {3}", Host, DB, User, Pass);
  164.             }
  165.         }
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement