Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net;
- using MySql.Data.MySqlClient;
- using System.Web;
- using System.Text.RegularExpressions;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- namespace csgopicker_main
- {
- public partial class Form1 : Form
- {
- //This function returns true if the emailid matches the pattern. Else it will return false
- private bool IsValidEmailId(string InputEmail)
- {
- //Regex To validate Email Address
- Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
- Match match = regex.Match(InputEmail);
- if (match.Success)
- return true;
- else
- return false;
- }
- //Internet conn
- public bool CheckForInternetConnection()
- {
- try
- {
- using (var client = new WebClient())
- using (var stream = client.OpenRead("http://www.google.com"))
- label_internet.Text = "Internet: online";
- label_internet.ForeColor = System.Drawing.Color.Green;
- label_internet.Visible = true;
- {
- return true;
- }
- }
- catch
- {
- label_internet.Text = "Internet: offline";
- label_internet.ForeColor = System.Drawing.Color.Green;
- label_internet.Visible = true;
- database_conn.Stop();
- MessageBox.Show("Please check your internet connection. Application will be closed.");
- Application.Exit();
- return false;
- }
- }
- //MySQL conn
- public bool MySqlConnection()
- {
- try
- {
- string myConnection = "datasource=localhost;port=3306;username=root;password=root19721999";
- MySqlConnection myConn = new MySqlConnection(myConnection);
- MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
- myDataAdapter.SelectCommand = new MySqlCommand(" select * csgopicker_main.users ;", myConn);
- MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
- myConn.Open();
- DataSet ds = new DataSet();
- label_database.Text = "Database: online";
- label_database.ForeColor = System.Drawing.Color.Green;
- label_database.Visible = true;
- database_conn.Stop();
- myConn.Close();
- return true;
- }
- catch (Exception)
- {
- label_database.Text = "Database: offline";
- label_database.ForeColor = System.Drawing.Color.Red;
- database_conn.Stop();
- return false;
- }
- }
- //Website conn
- public bool WebsiteConnection()
- {
- try
- {
- label_website.Text = "Website: offline";
- label_website.ForeColor = System.Drawing.Color.Red;
- return true;
- }
- catch
- {
- return false;
- }
- }
- //your ip
- public string GetPublicIP()
- {
- WebClient client = new WebClient();
- return client.DownloadString("http://icanhazip.com/");
- }
- //Timer do sprawdzania łączności
- private void timer_conn(object sender, EventArgs e)
- {
- Properties.Settings.Default.ip = GetPublicIP();
- label5.Text = "Your IP address: " + Properties.Settings.Default.ip;
- //internet
- CheckForInternetConnection();
- //MySql
- MySqlConnection();
- //website
- WebsiteConnection();
- //eneble form
- Enabled = true;
- }
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //Wykrywanie internetu
- database_conn.Start();
- textbox_email.Text = Properties.Settings.Default.lastemail;
- textbox_password.Text = Properties.Settings.Default.lastpassword;
- using (var conn = new MySqlConnection("datasource=localhost;port=3306;username=root;password=root19721999"))
- {
- try
- {
- conn.Open();
- using (var cmd = new MySqlCommand("SELECT COUNT(*) FROM csgopicker_main.users", conn))
- {
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- string co = count.ToString();
- labelnumberusersregister.Text = "Users registered: " + co;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- labelnumberusersregister.Text = "OFFLINE";
- }
- }
- }
- //register button i schematy
- private void button_register_Click_1(object sender, EventArgs e)
- {
- //sprawdzanie e-maila
- if (IsValidEmailId(textbox_email_register.Text))
- {
- //sprawdzanie poprawności hasła
- if (textbox_password_register.Text == textbox_password_re_register.Text)
- {
- //sprawdzanie czy zostały zaznaczone terms
- if (checkterms.Checked == true)
- {
- //ID gen
- string NewGUID = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper();
- //connection
- string myConnection = "datasource=localhost;port=3306;username=root;password=root19721999";
- string Query = "insert into csgopicker_main.users set id='" + NewGUID + "', email='" + this.textbox_email_register.Text + "', password='" + this.textbox_password_re_register.Text + "' ;";
- MySqlConnection conDataBase = new MySqlConnection(myConnection);
- MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
- MySqlDataReader myReader;
- try
- {
- conDataBase.Open();
- myReader = cmdDataBase.ExecuteReader();
- MessageBox.Show("Thanks for register. You can now login using your email and password!");
- conDataBase.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- else { MessageBox.Show("Error: u didn't accept terms"); }
- }
- else { MessageBox.Show("Error: wrong repassword"); }
- }
- else
- {
- MessageBox.Show(textbox_email_register.Text + " is not valid email");
- }
- }
- //login (do zrobienia: potwierdzenie o zmianie IP, status online i offline w MySql)
- private void button_login_Click(object sender, EventArgs e)
- {
- //łączność
- database_conn.Start();
- //login
- try
- {
- Properties.Settings.Default.lastemail = textbox_email.Text;
- Properties.Settings.Default.lastpassword = textbox_password.Text;
- Properties.Settings.Default.Save();
- textbox_password.Text = Properties.Settings.Default.lastpassword;
- string myConnection = "datasource=localhost;port=3306;username=root;password=root19721999";
- MySqlDataReader myReader;
- MySqlConnection myConn = new MySqlConnection(myConnection);
- MySqlCommand SelectCommand = new MySqlCommand("select * from csgopicker_main.users where email = '" + textbox_email.Text + "' and password = '" + textbox_password.Text + "';", myConn);
- myConn.Open();
- myReader = SelectCommand.ExecuteReader();
- int count = 0;
- while (myReader.Read())
- {
- count = count + 1;
- }
- if (count == 1)
- {
- MessageBox.Show("Login");
- myConn.Close();
- MySqlConnection conn = null;
- MySqlCommand cmd = null;
- MySqlDataReader reader = null;
- try
- {
- Form1 form1 = new Form1();
- string sql = "SELECT cfgstart FROM csgopicker_main.users WHERE email = '" + Properties.Settings.Default.lastemail + "'";
- conn = new MySqlConnection(myConnection);
- cmd = new MySqlCommand(sql, conn);
- conn.Open();
- reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- Properties.Settings.Default.cfgstart = reader.GetString("cfgstart");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(string.Format("An error occurred {0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- if (reader != null) reader.Close();
- if (conn != null) conn.Close();
- if (Properties.Settings.Default.cfgstart == "0")
- {
- this.Hide();
- var form2 = new cfgstart_form();
- form2.Closed += (s, args) => this.Close();
- form2.Show();
- myConn.Close();
- }
- else
- {
- MessageBox.Show("CFGstart done");
- this.Hide();
- var form2 = new MainForm();
- form2.Closed += (s, args) => this.Close();
- form2.Show();
- myConn.Close();
- }
- }
- }
- else if (count > 1)
- {
- MessageBox.Show("Access denied");
- }
- else
- MessageBox.Show("Not correct");
- myConn.Close();
- }
- catch (Exception ex) { MessageBox.Show(ex.Message); }
- }
- //guest
- private void button_guest_Click(object sender, EventArgs e)
- {
- //czas i data
- DateTime time = DateTime.Now;
- string format = "yyyy-MM-dd HH:mm:ss";
- var mytime = time.ToString(format);
- //connection
- Stopwatch s = new Stopwatch();
- s.Start();
- while (s.Elapsed < TimeSpan.FromSeconds(5))
- {
- label4.Text = "Wait";
- Random rndID = new Random();
- int IDint = rndID.Next(1, 10);
- string ID = IDint.ToString();
- string myConnection = "datasource=localhost;port=3306;username=root;password=root19721999";
- string Query = "insert into csgopicker_main.guest set id='" + ID + "', time='" + mytime + "',ip='" + Properties.Settings.Default.ip + "';";
- MySqlConnection conDataBase = new MySqlConnection(myConnection);
- MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
- MySqlDataReader myReader;
- try
- {
- label4.Text = "Wait";
- conDataBase.Open();
- myReader = cmdDataBase.ExecuteReader();
- label4.Text = "Guest-" + ID;
- MessageBox.Show("Login");
- break;
- }
- catch
- {
- //łączność
- label4.Text = "Wait";
- database_conn.Start();
- label4.Text = "No active slots.\r\nTry again later.";
- conDataBase.Close();
- }
- }
- s.Stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement