/* Copyright 2010 © by YeZZx aka Crunkx */
using System;
using System.Data;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
namespace LoginServer
{
    class cDatabase
    {
        public MySQL conn;
        public bool Connect()
        {
            conn = new MySQL();
            bool sqlconn = conn.TestConnect();
            if (!sqlconn)
            {
                return false;
            }

            return true;
        }
        public static string Stripslash(string Query)
        {
            try { return Query.Replace(@"\", "\\").Replace("'", @"`"); }
            catch { return ""; }
        }

        public string proc_checkAccount(string sUsername, string sPassword)
        {
            conn.OpenConnection();
            using (MySqlCommand command = new MySqlCommand("SELECT `userID`,`password`,`accesslevel`,`Logged`,`username`,`Nickname`,`Banned`,`Banntime`,`banDate`,`Login1` FROM `account` WHERE `username`='" + sUsername + "' LIMIT 1", conn.mySqlConnection))
            {
                int UserID = 0;
                int Banned = 0;
                string password = string.Empty;
                int accesslevel = 0;
                string username = string.Empty;
                int Logged = 0;
                string Nickname = string.Empty;
                int CountRows = 0;
                int Banntime = 0;
                string Bandate = "";
                int FirstLogin = 0;
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    UserID = reader.GetInt32("userID");
                    username = reader.GetString("username");
                    password = reader.GetString("password");
                    Nickname = reader.GetString("Nickname");
                    accesslevel = (short)reader.GetInt32("accesslevel");
                    Banned = (short)reader.GetInt32("Banned");
                    Logged = (short)reader.GetInt32("Logged");
                    Bandate = reader.GetMySqlDateTime("banDate").ToString();
                    Banntime = reader.GetInt32("Banntime");
                    FirstLogin = reader.GetInt32("Login1");
                    CountRows++;
                }
                reader.Close();
                conn.CloseConnection();
                return "/" + UserID + "/" + username + "/" + password + "/"
                + Nickname + "/" + accesslevel + "/" + Banned + "/" + Logged + "/"
                + CountRows + "/" + Banntime + "/" + Bandate + "/" + FirstLogin + "/";

            }
        }
        public void proc_unbanAccount(long lUserID)
        {
            conn.OpenConnection();
            MySqlCommand unban = new MySqlCommand("UPDATE account SET  Banntime='0' WHERE userID='" + lUserID + "';", conn.mySqlConnection);
            MySqlDataReader test = unban.ExecuteReader();
            conn.CloseConnection();
        }
    }
}
/* Copyright 2010 © by YeZZx aka Crunkx */