Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package com.rs2.util.mysql.accounts;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import com.rs2.server.game.node.animable.player.PlayerDefinition;
  7. import com.rs2.util.mysql.ReadDatabaseQuery;
  8.  
  9. /**
  10.  *
  11.  * @author Brad
  12.  *
  13.  */
  14. public class CredentialValidation extends ReadDatabaseQuery {
  15.  
  16.     /* Represents the Requested Player Information to validate */
  17.     private PlayerDefinition playerInformation;
  18.    
  19.     /* Represents Account Current State */
  20.     private AccountStatus status;
  21.    
  22.     /* Represents Possibly Account States */
  23.     public enum AccountStatus {
  24.         SUCCESSFUL, INVALID_CREDENTIALS, BANNED
  25.     }
  26.    
  27.     /**
  28.      *
  29.      * @param playerInformation
  30.      */
  31.     public CredentialValidation(PlayerDefinition playerInformation) {
  32.         setPlayerInformation(playerInformation);
  33.         super.fetchResult();
  34.     }
  35.    
  36.     /*
  37.      * (non-Javadoc)
  38.      * @see com.rs2.util.mysql.ReadDatabaseQuery#createStatement()
  39.      */
  40.     @Override
  41.     public String createStatement() {
  42.         builder.append("SELECT * FROM characters WHERE username='" + getPlayerInformation().getUsername() + "' LIMIT 1");
  43.         return builder.toString();
  44.     }
  45.  
  46.     /*
  47.      * (non-Javadoc)
  48.      * @see com.rs2.util.mysql.ReadDatabaseQuery#returnedResult(java.sql.ResultSet)
  49.      */
  50.     @Override
  51.     public void returnedResult(ResultSet result) {
  52.         try {
  53.             while (result.next()) {
  54.                 String password = result.getString("password");
  55.                 String banned = result.getString("bannedTill");
  56.                 if (!getPlayerInformation().getPassword().equals(password)) {
  57.                     setStatus(AccountStatus.INVALID_CREDENTIALS);
  58.                     return;
  59.                 }
  60.                 if (Long.parseLong(banned) > System.currentTimeMillis()) {
  61.                     setStatus(AccountStatus.BANNED);
  62.                     return;
  63.                 }
  64.                 setStatus(AccountStatus.SUCCESSFUL);
  65.             }
  66.         } catch (SQLException e) {
  67.             e.printStackTrace();
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * @return the playerInformation
  73.      */
  74.     public PlayerDefinition getPlayerInformation() {
  75.         return playerInformation;
  76.     }
  77.  
  78.     /**
  79.      * @param playerInformation the playerInformation to set
  80.      */
  81.     public void setPlayerInformation(PlayerDefinition playerInformation) {
  82.         this.playerInformation = playerInformation;
  83.     }
  84.  
  85.     /**
  86.      * @return the status
  87.      */
  88.     public AccountStatus getStatus() {
  89.         return status;
  90.     }
  91.  
  92.     /**
  93.      * @param status the status to set
  94.      */
  95.     public void setStatus(AccountStatus status) {
  96.         this.status = status;
  97.     }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement