Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Data.SqlClient;
- using System.Threading;
- using System.Timers;
- namespace AllowedGm
- {
- class Program
- {
- static void Main(string[] args)
- {
- CheckSetting Check = new CheckSetting();
- GetConnection connection = new GetConnection();
- GetGms Checkgm = new GetGms();
- string check = File.ReadAllText(Environment.CurrentDirectory + "\\AllowedGM.txt");
- List<string> gmList = connection.getGMNames();
- foreach (var gm in gmList)
- {
- if (!Checkgm.GmList.Contains(gm.ToLower()))
- {
- Console.WriteLine("Username [" + gm + "] is not allowed!");
- SqlCommand player = new SqlCommand(String.Format(@"UPDATE account SET gm=0 WHERE act_name ='{0}';", gm), connection.connection1);
- player.ExecuteNonQuery();
- }
- else
- {
- Console.WriteLine("Username [" + gm + "] is approved!");
- }
- }
- Console.WriteLine("");
- Console.WriteLine(@"Total Account Scanneds: [{0}]", gmList.Count);
- //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);
- //SqlDataReader reader = command.ExecuteReader();
- //while (reader.Read() || reader.NextResult() && reader.Read())
- //{
- // Console.WriteLine(reader[0].ToString());
- //}
- Console.ReadKey();
- }
- }
- public class GetGms
- {
- public List<string> GmList = new List<string>();
- public GetGms()
- {
- string[] Gm = { "GMNAME1", "GMNAME2" };
- string gmpath = Environment.CurrentDirectory + "\\AllowedGM.txt";
- if (!File.Exists(gmpath))
- {
- File.WriteAllLines(gmpath, Gm);
- Console.WriteLine("");
- Console.WriteLine("Generating Allowed Gms List...");
- foreach (var gm in Gm)
- {
- GmList.Add(gm.ToLower());
- }
- }
- else
- {
- string ReadGm = File.ReadAllText(gmpath);
- string[] Gms = ReadGm.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
- Console.WriteLine("");
- Console.WriteLine("Reading Allowed Gms List...");
- Console.WriteLine(ReadGm);
- foreach (var gm in Gms)
- {
- GmList.Add(gm.ToLower());
- }
- }
- }
- }
- public class GetConnection
- {
- public SqlConnection connection1;
- public GetConnection()
- {
- string path = Environment.CurrentDirectory + "\\Settings.ini";
- var IniFile = new CreateIni(path);
- var Host = IniFile.Read("Host");
- var DB = IniFile.Read("DB");
- var User = IniFile.Read("User");
- var Pass = IniFile.Read("Pass");
- connection1 = new SqlConnection(String.Format(@"Data Source={0}; user id={1}; password={2};Database={3}", Host, User, Pass, DB));
- try
- {
- connection1.Open();
- Console.WriteLine("Database Connected!");
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex.Message);
- Environment.Exit(0);
- }
- }
- public void Close()
- {
- connection1.Close();
- }
- public List<string> getGMNames()
- {
- List<string> Gms = new List<string>();
- string sqlQuery = "SELECT act_name FROM account WHERE gm = 99;";
- SqlDataReader reader;
- SqlDataAdapter adapter = new SqlDataAdapter();
- SqlCommand command = new SqlCommand(sqlQuery, connection1);
- command.Connection = connection1;
- adapter.SelectCommand = command;
- reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- while (reader.Read() || (reader.NextResult() && reader.Read()))
- {
- Gms.Add(reader[0].ToString());
- }
- }
- reader.Close();
- return Gms;
- }
- }
- public class CheckSetting
- {
- public CheckSetting()
- {
- string path = Environment.CurrentDirectory + "\\Settings.ini";
- var IniFile = new CreateIni(path);
- bool FileExists = File.Exists(path);
- if (FileExists == false)
- {
- Console.WriteLine("Generating Settings File");
- IniFile.Write("Host", "Hostname");
- IniFile.Write("DB", "Database");
- IniFile.Write("User", "Username");
- IniFile.Write("Pass", "Password");
- }
- else
- {
- Console.WriteLine("Loading Setting File");
- var Host = IniFile.Read("Host");
- var DB = IniFile.Read("DB");
- var User = IniFile.Read("User");
- var Pass = IniFile.Read("Pass");
- Console.WriteLine(@"Hostname: {0}; Database: {1}; Username: {2}; Password: {3}", Host, DB, User, Pass);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement