Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
82d80ebc4d
  1. 94
      src/engine/db/handlers/dbCSSessionHandler.java

94
src/engine/db/handlers/dbCSSessionHandler.java

@ -17,6 +17,8 @@ import engine.util.StringUtils;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.net.InetAddress; import java.net.InetAddress;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -28,52 +30,90 @@ public class dbCSSessionHandler extends dbHandlerBase {
} }
public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) { public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) {
prepareCallable("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)");
setString(1, secKey); try (Connection connection = DbManager.getConnection();
setLong(2, acc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) {
setString(3, acc.discordAccount);
setString(4, StringUtils.InetAddressToClientString(inet)); preparedStatement.setString(1, secKey);
setString(5, machineID); preparedStatement.setLong(2, acc.getObjectUUID());
return (executeUpdate() != 0); preparedStatement.setString(3, acc.discordAccount);
preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet));
preparedStatement.setString(5, machineID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean DELETE_UNUSED_CSSESSION(String secKey) { public boolean DELETE_UNUSED_CSSESSION(String secKey) {
prepareCallable("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL");
setString(1, secKey); try (Connection connection = DbManager.getConnection();
return (executeUpdate() != 0); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) {
preparedStatement.setString(1, secKey);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean DELETE_CSSESSION(String secKey) { public boolean DELETE_CSSESSION(String secKey) {
prepareCallable("DELETE FROM `dyn_session` WHERE `secretKey`=?");
setString(1, secKey); try (Connection connection = DbManager.getConnection();
return (executeUpdate() != 0); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) {
preparedStatement.setString(1, secKey);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_CSSESSION(String secKey, int charID) { public boolean UPDATE_CSSESSION(String secKey, int charID) {
prepareCallable("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?");
setInt(1, charID); try (Connection connection = DbManager.getConnection();
setString(2, secKey); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, charID);
preparedStatement.setString(2, secKey);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public CSSession GET_CSSESSION(String secKey) { public CSSession GET_CSSESSION(String secKey) {
CSSession css = null; CSSession css = null;
prepareCallable("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?");
setString(1, secKey);
try {
ResultSet rs = executeQuery(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) {
preparedStatement.setString(1, secKey);
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) { if (rs.next())
css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs
.getInt("characterID")), getString("machineID")); .getInt("characterID")), getString("machineID"));
}
rs.close();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("Error with seckey: " + secKey); Logger.error(e);
} finally {
closeCallable();
} }
return css; return css;
} }
} }

Loading…
Cancel
Save