예제 #1
0
파일: TcpServer.cs 프로젝트: arkanoid1/Temu
        public static string isLoginValid(string user, string pass)
        {
            LoginAccount loginAccount = new LoginAccount();
            loginAccount = DbQuerys.GetAccountData(user, pass);

            if (loginAccount == null)
            {
                return OpCode.LoginPacket_Auth_INVALID_PASSWORD.GetHashCode().ToString();
            }
            else
            {
                Logger.WriteLine(LogState.Debug, "Checking Account: " + loginAccount.Username);
                //BANN CHECK
                if (loginAccount.IsBanned)
                {
                    Logger.WriteLine(LogState.Debug, "Account.IsBanned: " + loginAccount.Username);
                    Logger.WriteLine(LogState.Debug, "Account.UnBanDate: " + loginAccount.UnBanDate);

                    Int64 timeStampNowValue = Convert.ToInt64(DateTime.Now.Ticks);
                    Int64 timeStampUnbannValue = loginAccount.UnBanDate;
                    Logger.WriteLine(LogState.Debug, "timeStampNowValue: '" + timeStampNowValue + "' !");
                    Logger.WriteLine(LogState.Debug, "timeStampUnbannValue: '" + timeStampUnbannValue + "' !");

                    //Unban Account if Time Ok!
                    if (timeStampUnbannValue <= timeStampNowValue)
                    {
                        DbQuerys.SetBanStatus(user, false, 0);
                        return OpCode.LoginPacket_Auth_UNBANNED.GetHashCode().ToString();
                    }

                    //BANNED
                    loginAccount = null;
                    return OpCode.LoginPacket_Auth_BANNED.GetHashCode().ToString();
                }

                if (loginAccount.IsOnline)
                {
                    Logger.WriteLine(LogState.Info, "Account: " + loginAccount.Username + " already logged in!");
                    //DbQuerys.SetIsOnline(user, false); //this for later setting offline kicking other player maybe... for now no 2nd login possible!
                    loginAccount = null;
                    return OpCode.LoginPacket_Auth_ONLINE.GetHashCode().ToString();
                }

                //AuthorizationSuccessfull
                Logger.WriteLine(LogState.Info, "Account Verification for, " + loginAccount.Username + " Ok!");
                DbQuerys.SetLastOnlineUtc(loginAccount.Username);
                return OpCode.LoginPacket_Auth_OK.GetHashCode().ToString();
            }
        }
예제 #2
0
파일: DbQuerys.cs 프로젝트: arkanoid1/Temu
        //Read AccountData for Username&Pass, return as Account()
        public static LoginAccount GetAccountData(string Username, string Password)
        {
            DataTable Data = new DataTable();
            LoginAccount loginAccount = new LoginAccount();

            using (IQueryAdapter dbClient = LoginServer.dbManager.getQueryreactor())
            {
                string GetAccountQuery = "SELECT * FROM accounts WHERE Username='******' AND Password='******';";
                dbClient.setQuery(GetAccountQuery);
                Data = dbClient.getTable();

                if (Data != null)
                {
                    foreach (DataRow Row in Data.Rows)
                    {
                        loginAccount = new LoginAccount()
                        {
                            AccountId = uint.Parse(Row["id"].ToString()),
                            Username = Row["username"].ToString(),
                            Password = Row["password"].ToString(),
                            Email = Row["email"].ToString(),
                            AccessLevel = uint.Parse(Row["accesslevel"].ToString()),
                            Membership = Row["membership"].ToString(),
                            IsGM = Convert.ToBoolean(int.Parse(Row["isgm"].ToString())),
                            LastOnlineUtc = Convert.ToInt64((long.Parse(Row["lastonlineutc"].ToString()))),
                            Coins = Convert.ToUInt32((Row["coins"].ToString())),
                            Ip = Row["ip"].ToString(),
                            Settings = Row["settings"].ToString(),
                            IsOnline = Convert.ToBoolean(int.Parse(Row["isonline"].ToString())),
                            IsBanned = Convert.ToBoolean(int.Parse(Row["isbanned"].ToString())),
                            UnBanDate = Convert.ToInt64((long.Parse(Row["unbandate"].ToString()))),
                            RegisterDate = Convert.ToInt64((long.Parse(Row["registerdate"].ToString()))),
                        };

                        return loginAccount;
                    }
                }
            }
            Logger.WriteLine(LogState.Error, "Get Account Data failed, wrong pass?");
            loginAccount = null;
            return loginAccount;
        }
예제 #3
0
파일: DbQuerys.cs 프로젝트: arkanoid1/Temu
        public static int GetCurrentAccountCount()
        {
            DataTable Data = new DataTable();
            LoginAccount loginAccount = new LoginAccount();

            using (IQueryAdapter dbClient = LoginServer.dbManager.getQueryreactor())
            {
                string GetAccountQuery = "SELECT * FROM accounts";
                dbClient.setQuery(GetAccountQuery);
                Data = dbClient.getTable();

                if (Data != null)
                {
                    foreach (DataRow Row in Data.Rows)
                    {
                        loginAccount = new LoginAccount()
                        {
                            AccountId = uint.Parse(Row["Id"].ToString()),
                            Username = Row["Username"].ToString(),
                            Password = Row["Password"].ToString(),
                            Email = Row["Email"].ToString(),
                            AccessLevel = uint.Parse(Row["AccessLevel"].ToString()),
                            Membership = Row["Membership"].ToString(),
                            IsGM = bool.Parse(Row["IsGM"].ToString()),
                            LastOnlineUtc = Convert.ToInt64((long.Parse(Row["LastOnlineUtc"].ToString()))),
                            Coins = Convert.ToUInt32((Row["Coins"].ToString())),
                            Ip = Row["Ip"].ToString(),
                            Settings = Row["Settings"].ToString(),
                            IsOnline = bool.Parse(Row["IsOnline"].ToString()),
                            IsBanned = bool.Parse(Row["IsBanned"].ToString()),
                            UnBanDate = Convert.ToInt64((long.Parse(Row["UnBanDate"].ToString()))),
                        };
                    }

                    return (int)Data.Rows.Count;
                }
            }
            Logger.WriteLine(LogState.Info, "No Users found, All Accounts free?");
            return 0;
        }
예제 #4
0
파일: DbQuerys.cs 프로젝트: arkanoid1/Temu
        //Check if Username Exists
        public static bool UserExists(string Username)
        {
            DataTable Data = new DataTable();
            LoginAccount loginAccount = new LoginAccount();

            using (IQueryAdapter dbClient = LoginServer.dbManager.getQueryreactor())
            {
                string GetAccountQuery = "SELECT * FROM accounts WHERE Username='******' LIMIT 1;";
                dbClient.setQuery(GetAccountQuery);
                Data = dbClient.getTable();

                if (Data != null)
                {
                    foreach (DataRow Row in Data.Rows)
                    {
                        loginAccount = new LoginAccount()
                        {
                            AccountId = uint.Parse(Row["id"].ToString()),
                            Username = Row["username"].ToString(),
                            Password = Row["password"].ToString(),
                            Email = Row["email"].ToString(),
                            AccessLevel = uint.Parse(Row["accesslevel"].ToString()),
                            Membership = Row["membership"].ToString(),
                            IsGM = Convert.ToBoolean(int.Parse(Row["isgm"].ToString())),
                            LastOnlineUtc = Convert.ToInt64((long.Parse(Row["lastonlineutc"].ToString()))),
                            Coins = Convert.ToUInt32((Row["coins"].ToString())),
                            Ip = Row["ip"].ToString(),
                            Settings = Row["settings"].ToString(),
                            IsOnline = Convert.ToBoolean(int.Parse(Row["isonline"].ToString())),
                            IsBanned = Convert.ToBoolean(int.Parse(Row["isbanned"].ToString())),
                            UnBanDate = Convert.ToInt64((long.Parse(Row["unbandate"].ToString()))),
                            RegisterDate = Convert.ToInt64((long.Parse(Row["registerdate"].ToString()))),
                        };

                        if (loginAccount.Username != null || loginAccount.Username == Username)
                        {
                            Logger.WriteLine(LogState.Debug, "User {0} found!!", Username);
                            return true;
                        }
                    }
                }
            }
            Logger.WriteLine(LogState.Debug, "User {0} not found!", Username);
            return false;
        }