Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ecstasy.util;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import ecstasy.rs2.model.Client;
- /**
- * MySQL Class
- *
- * @author 'Ecstasy?!
- */
- public class MysqlManager {
- /**
- * Variables
- */
- public int userGroup;
- public int unreadMessages;
- /**
- * Instances
- */
- public static Connection connection;
- public static Client client;
- public MysqlManager(Client client) {
- this.client = client;
- }
- /**
- * Constant variables
- */
- public static final String URL = "jdbc:mysql://localhost";
- public static final String DATABASE = "forum";
- public static final String USER = "root";
- public static final String PASSWORD = "";
- public static final int ADMIN = 6;
- public static final int MOD = 7;
- public static final int REGULAR_PLAYER = 2;
- public static final int GLOBAL_MOD = 5;
- public static final int BANNED_PLAYER = 8;
- /**
- * @return the database
- */
- public static String getDatabase() {
- return DATABASE;
- }
- /**
- * @return the URL of the database
- */
- public static String getUrl() {
- return URL;
- }
- /**
- * @return the username to connect to the database with
- */
- public static String getUser() {
- return USER;
- }
- /**
- * @return the password to connect to the database with
- */
- public static String getPassword() {
- return PASSWORD;
- }
- /**
- * This basically puts everything together, just to keep it organized.
- *
- * @return the entire url to connect to the database
- */
- public static String URL() {
- return getUrl() + "/" + getDatabase();
- }
- /**
- * Creates a connection to the database.
- */
- public static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- connection = DriverManager.getConnection(URL(), getUser(),
- getPassword());
- Misc.println_debug("Sucessfully connceted to the database.");
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- /**
- * @param name
- * the players username
- * @param password
- * the players password.
- * @return true or false, if the name & password is registered on the
- * forums.
- */
- public boolean loadAccount(String name, String password) {
- try {
- Statement statement = connection.createStatement();
- ResultSet group = statement
- .executeQuery("SELECT * FROM user WHERE username = '"
- + name + "'");
- while (group.next()) {
- String pass = group.getString("password");
- String salt = group.getString("salt");
- userGroup = group.getInt("usergroupid");
- unreadMessages = group.getInt("pmunread");
- String encryptedPassword = passHash(password, salt);
- if (pass.equalsIgnoreCase(encryptedPassword)) {
- statement.close();
- return true;
- } else {
- statement.close();
- return false;
- }
- }
- } catch (Exception e) {
- return false;
- }
- return false;
- }
- /**
- * @param name
- * The players username This method will load all additional
- * info, other than the username and password.
- * @Author Ecstasy
- */
- public void loadInfo(String name) {
- try {
- Statement statement = connection.createStatement();
- ResultSet group = statement
- .executeQuery("SELECT * FROM user WHERE username = '"
- + name + "'");
- while (group.next()) {
- userGroup = group.getInt("usergroupid");
- unreadMessages = group.getInt("pmunread");
- }
- } catch (Exception e) {
- System.out.println("Oh fuck");
- }
- }
- /**
- * @param in
- * the password before it's encrypted
- * @param salt
- * the encryption of the password (In this case, the vBulletin
- * encryption
- * @return the encrypted password
- */
- public String passHash(String in, String salt) {
- String a = new MD5(in).compute();
- String b = new MD5(a + salt).compute();
- return b;
- }
- public void loadPlayerRights() {
- switch (userGroup) {
- case ADMIN:
- client.playerRights = 3;
- return;
- case MOD:
- client.playerRights = 1;
- return;
- case REGULAR_PLAYER:
- client.playerRights = 0;
- return;
- case GLOBAL_MOD:
- client.playerRights = 1;
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement