Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database.client;
- import game.GameServer;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import world.World;
- import world.client.Account;
- import com.mysql.jdbc.PreparedStatement;
- import database.ConnectionManager;
- import database.ConnectionManager.Database;
- public class Accounts {
- private static final String TableName = "accounts";
- /*********************
- * UPDATES *
- *********************/
- public static void update(Account acc)
- {
- try
- {
- String baseQuery = "UPDATE `"+TableName+"` SET " +
- "`bankKamas` = ?,"+
- "`bank` = ?,"+
- "`level` = ?,"+
- "`points` = ?,"+
- "`pseudo` = ?,"+
- "`banned` = ?,"+
- "`banned_time` = ?,"+
- "`friends` = ?,"+
- "`enemy` = ?,"+
- "`mute_time` = ?,"+
- "`mute_raison` = ?,"+
- "`mute_pseudo` = ?,"+
- "`warnings` = ?,"+
- "`lastWarningDate` = ?,"+
- "`points` = ?"+
- " WHERE `guid` = ?;";
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- p.setLong( 1, acc.bank.getKamas());
- p.setString(2, acc.bank.toString());
- p.setInt( 3, acc.getGmLevel());
- p.setString(4, acc.getPseudo());
- p.setInt( 5, (acc.isBanned()?1:0));
- p.setLong( 6, acc.getBannedTime());
- p.setString(7, acc.parseFriendListToDB());
- p.setString(8, acc.parseEnemyListToDB());
- p.setLong( 9, acc.getMuteTime());
- p.setString(10, acc.getMuteRaison());
- p.setString(11, acc.getMutePseudo());
- p.setInt( 12, acc.getWarning());
- p.setLong( 13, acc.getLastWarningDate());
- p.setInt( 14, acc.getPoints());
- p.setInt( 15, acc.getGuid());
- p.executeUpdate();
- ConnectionManager.closePreparedStatement(p);
- }catch(SQLException e)
- {
- GameServer.addToLog("SQL ERROR: "+e.getMessage());
- e.printStackTrace();
- }
- }
- public static void update_points(Account account)
- {
- String baseQuery = "UPDATE `"+TableName+"` SET `points` = ? WHERE `guid` = ?;";
- try
- {
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- p.setInt(1, account.getPoints());
- p.setInt(2, account.getGuid());
- p.executeUpdate();
- ConnectionManager.closePreparedStatement(p);
- }catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static void update_lastconnection(Account account)
- {
- String baseQuery = "UPDATE `"+TableName+"` SET " +
- "`lastIP` = ?," +
- "`lastConnectionDate` = ?" +
- " WHERE `guid` = ?;";
- try
- {
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- p.setString(1, account.getCurIp());
- p.setString(2, account.getLastConnectionDate());
- p.setInt(3, account.getGuid());
- p.executeUpdate();
- ConnectionManager.closePreparedStatement(p);
- }catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static void update_vip(Account compte)
- {
- String baseQuery = "UPDATE `"+TableName+"` SET `vip` = ? WHERE `guid` = ?;";
- try
- {
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- p.setInt(1, compte.getVip());
- p.setInt(2, compte.getGuid());
- p.executeUpdate();
- ConnectionManager.closePreparedStatement(p);
- }catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- public static void update_logged(int accID, boolean logged)
- {
- PreparedStatement p;
- String query = "UPDATE `"+TableName+"` SET logged=? WHERE `guid`=?;";
- try {
- p = ConnectionManager.newTransact(query, ConnectionManager.Get(Database.REALM));
- p.setInt(1, logged ? 1 : 0);
- p.setInt(2, accID);
- p.execute();
- ConnectionManager.closePreparedStatement(p);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void set_online(int accID) {
- update_logged(accID, true);
- }
- public static void set_offline(int accID) {
- update_logged(accID, false);
- }
- public static void reset_logged()
- {
- PreparedStatement p;
- String query = "UPDATE `"+TableName+"` SET logged=0;";
- try {
- p = ConnectionManager.newTransact(query, ConnectionManager.Get(Database.REALM));
- p.execute();
- ConnectionManager.closePreparedStatement(p);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void update_gifts(Account account) {
- String baseQuery = "UPDATE `"+TableName+"` SET `cadeau` = 0 WHERE `guid` = ?;";
- try {
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- p.setInt(1, account.getGuid());
- p.executeUpdate();
- ConnectionManager.closePreparedStatement(p);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /*********************
- * SELECT *
- *********************/
- public static Account get(int guid) {
- Account account = null;
- try {
- ResultSet RS = ConnectionManager.executeQuery("SELECT * FROM "+TableName+" WHERE guid = '"+guid+"';", Database.REALM);
- while(RS.next()){
- account = new Account(
- RS.getInt("guid"),
- RS.getString("account").toLowerCase(),
- RS.getString("pass"),
- RS.getString("pseudo"),
- RS.getString("question"),
- RS.getString("reponse"),
- RS.getInt("level"),
- RS.getInt("vip"),
- RS.getInt("points"),
- (RS.getInt("banned") == 1),
- RS.getLong("banned_time"),
- RS.getString("lastIP"),
- RS.getString("lastConnectionDate"),
- RS.getString("bank"),
- RS.getInt("bankKamas"),
- RS.getString("friends"),
- RS.getString("enemy"),
- RS.getInt("cadeau"),
- RS.getLong("mute_time"),
- RS.getString("mute_raison"),
- RS.getString("mute_pseudo"),
- RS.getInt("warnings"),
- RS.getLong("lastWarningDate"),
- RS.getInt("last_vote")
- );
- World.addAccount(account);
- World.ReassignAccountToChar(account);
- }
- RS.getStatement().close();
- RS.close();
- } catch (Exception e){e.printStackTrace();}
- return account;
- }
- public static String getLastIP(int guid) {
- String LastIP = "";
- try {
- ResultSet RS = ConnectionManager.executeQuery("SELECT `lastIP` FROM `"+TableName+"` WHERE `guid` = '"+guid+"';", Database.REALM);
- if(RS.first())
- LastIP = RS.getString("lastIP");
- RS.getStatement().close();
- RS.close();
- } catch (Exception e){e.printStackTrace();}
- return LastIP;
- }
- public static boolean isVIP(Account compte)
- {
- try {
- java.sql.PreparedStatement p = ConnectionManager.Get(Database.REALM).prepareStatement("SELECT * FROM `"+TableName+"` WHERE guid = ?;");
- p.setInt(1, compte.getGuid());
- ResultSet RS = p.executeQuery();
- while(RS.next())
- {
- return (RS.getInt("vip") == 1);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static void load_ByIP(String ip)
- {
- try
- {
- ResultSet RS = ConnectionManager.executeQuery("SELECT * from `"+TableName+"` WHERE `lastIP` = '"+ip+"';", Database.REALM);
- String baseQuery = "UPDATE `"+TableName+"` SET `reload_needed` = 0 WHERE guid = ?;";
- PreparedStatement p = ConnectionManager.newTransact(baseQuery, ConnectionManager.Get(Database.REALM));
- while(RS.next())
- {
- //Si le compte est deja connecte, on zap
- if(World.getCompte(RS.getInt("guid")) != null)
- if(World.getCompte(RS.getInt("guid")).isOnline())
- continue;
- Account C = new Account(
- RS.getInt("guid"),
- RS.getString("account").toLowerCase(),
- RS.getString("pass"),
- RS.getString("pseudo"),
- RS.getString("question"),
- RS.getString("reponse"),
- RS.getInt("level"),
- RS.getInt("vip"),
- RS.getInt("points"),
- (RS.getInt("banned") == 1),
- RS.getLong("banned_time"),
- RS.getString("lastIP"),
- RS.getString("lastConnectionDate"),
- RS.getString("bank"),
- RS.getInt("bankKamas"),
- RS.getString("friends"),
- RS.getString("enemy"),
- RS.getInt("cadeau"),
- RS.getLong("mute_time"),
- RS.getString("mute_raison"),
- RS.getString("mute_pseudo"),
- RS.getInt("warnings"),
- RS.getLong("lastWarningDate"),
- RS.getInt("last_vote")
- );
- World.addAccount(C);
- World.ReassignAccountToChar(C);
- p.setInt(1, RS.getInt("guid"));
- p.executeUpdate();
- }
- ConnectionManager.closePreparedStatement(p);
- ConnectionManager.closeResultSet(RS);
- } catch(SQLException e) {
- GameServer.addToLog("SQL ERROR: "+e.getMessage());
- e.printStackTrace();
- }
- }
- public static int get_lastvote(int guid) {
- int lastvote = 0;
- try {
- ResultSet RS = ConnectionManager.executeQuery("SELECT `guid`, `last_vote` FROM `"+TableName+"` WHERE `guid` = '"+guid+"';", Database.REALM);
- while(RS.next())
- lastvote = RS.getInt("last_vote");
- RS.getStatement().close();
- RS.close();
- } catch (Exception e){e.printStackTrace();}
- return lastvote;
- }
- public static int getPoints(Account account)
- {
- try {
- java.sql.PreparedStatement p = ConnectionManager.Get(Database.REALM).prepareStatement("SELECT * FROM `"+TableName+"` WHERE guid = ?;");
- p.setInt(1, account.getGuid());
- ResultSet RS = p.executeQuery();
- while(RS.next())
- {
- return (RS.getInt("points"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement