refactor: use try-with-resources for client db operations
This commit is contained in:
@@ -21,47 +21,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package client;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import client.inventory.MapleInventoryType;
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
||||
import tools.*;
|
||||
|
||||
import net.server.Server;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.coordinator.login.MapleLoginBypassCoordinator;
|
||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||
import net.server.coordinator.session.MapleSessionCoordinator.AntiMulticlientResult;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.world.MapleMessengerCharacter;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
import net.server.world.PartyOperation;
|
||||
import net.server.world.World;
|
||||
|
||||
import net.server.world.*;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
|
||||
import client.inventory.MapleInventoryType;
|
||||
import constants.game.GameConstants;
|
||||
import scripting.AbstractPlayerInteraction;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import scripting.event.EventManager;
|
||||
@@ -69,13 +43,23 @@ import scripting.npc.NPCConversationManager;
|
||||
import scripting.npc.NPCScriptManager;
|
||||
import scripting.quest.QuestActionManager;
|
||||
import scripting.quest.QuestScriptManager;
|
||||
import server.life.MapleMonster;
|
||||
import server.ThreadManager;
|
||||
import server.maps.*;
|
||||
import server.life.MapleMonster;
|
||||
import server.maps.FieldLimit;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMiniDungeonInfo;
|
||||
import tools.*;
|
||||
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.server.coordinator.login.MapleLoginBypassCoordinator;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.*;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
public class MapleClient {
|
||||
|
||||
@@ -193,20 +177,17 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
private List<CharNameAndId> loadCharactersInternal(int worldId) {
|
||||
PreparedStatement ps;
|
||||
List<CharNameAndId> chars = new ArrayList<>(15);
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?")) {
|
||||
ps.setInt(1, this.getAccID());
|
||||
ps.setInt(2, worldId);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
chars.add(new CharNameAndId(rs.getString("name"), rs.getInt("id")));
|
||||
}
|
||||
}
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -219,9 +200,8 @@ public class MapleClient {
|
||||
|
||||
public boolean hasBannedIP() {
|
||||
boolean ret = false;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) {
|
||||
ps.setString(1, session.getRemoteAddress().toString());
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
@@ -229,21 +209,19 @@ public class MapleClient {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int getVoteTime(){
|
||||
if (voteTime != -1){
|
||||
public int getVoteTime() {
|
||||
if (voteTime != -1) {
|
||||
return voteTime;
|
||||
}
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) {
|
||||
ps.setString(1, accountName);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
@@ -251,8 +229,6 @@ public class MapleClient {
|
||||
}
|
||||
voteTime = rs.getInt("date");
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
FilePrinter.printError("hasVotedAlready.txt", e);
|
||||
return -1;
|
||||
@@ -272,36 +248,24 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public boolean hasBannedHWID() {
|
||||
if(hwid == null) {
|
||||
if (hwid == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean ret = false;
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?")) {
|
||||
ps.setString(1, hwid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if(rs != null && rs.next()) {
|
||||
if(rs.getInt(1) > 0)
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs != null && rs.next()) {
|
||||
if (rs.getInt(1) > 0) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -313,7 +277,6 @@ public class MapleClient {
|
||||
}
|
||||
boolean ret = false;
|
||||
int i;
|
||||
try {
|
||||
StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM macbans WHERE mac IN (");
|
||||
for (i = 0; i < macs.size(); i++) {
|
||||
sql.append("?");
|
||||
@@ -323,12 +286,11 @@ public class MapleClient {
|
||||
}
|
||||
sql.append(")");
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement(sql.toString())) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement(sql.toString())) {
|
||||
i = 0;
|
||||
for (String mac : macs) {
|
||||
i++;
|
||||
ps.setString(i, mac);
|
||||
ps.setString(++i, mac);
|
||||
}
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
@@ -336,27 +298,24 @@ public class MapleClient {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void loadHWIDIfNescessary() throws SQLException {
|
||||
if(hwid == null) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try(PreparedStatement ps = con.prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
|
||||
if (hwid == null) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
try(ResultSet rs = ps.executeQuery()) {
|
||||
if(rs.next()) {
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
hwid = rs.getString("hwid");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,8 +323,8 @@ public class MapleClient {
|
||||
// TODO: Recode to close statements...
|
||||
private void loadMacsIfNescessary() throws SQLException {
|
||||
if (macs.isEmpty()) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
@@ -376,50 +335,37 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void banHWID() {
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
loadHWIDIfNescessary();
|
||||
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)")) {
|
||||
ps.setString(1, hwid);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void banMacs() {
|
||||
Connection con = null;
|
||||
try {
|
||||
loadMacsIfNescessary();
|
||||
|
||||
con = DatabaseConnection.getConnection();
|
||||
List<String> filtered = new LinkedList<>();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters"); ResultSet rs = ps.executeQuery()) {
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
filtered.add(rs.getString("filter"));
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO macbans (mac, aid) VALUES (?, ?)")) {
|
||||
for (String mac : macs) {
|
||||
boolean matched = false;
|
||||
@@ -436,8 +382,7 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -460,15 +405,11 @@ public class MapleClient {
|
||||
|
||||
public void setPin(String pin) {
|
||||
this.pin = pin;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) {
|
||||
ps.setString(1, pin);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -497,15 +438,11 @@ public class MapleClient {
|
||||
|
||||
public void setPic(String pic) {
|
||||
this.pic = pic;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) {
|
||||
ps.setString(1, pic);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
} finally {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -542,14 +479,11 @@ public class MapleClient {
|
||||
return 6; // thanks Survival_Project for finding out an issue with AUTOMATIC_REGISTER here
|
||||
}
|
||||
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT id, password, gender, banned, pin, pic, characterslots, tos, language FROM accounts WHERE name = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT id, password, gender, banned, pin, pic, characterslots, tos, language FROM accounts WHERE name = ?")) {
|
||||
ps.setString(1, login);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
accId = -2;
|
||||
if (rs.next()) {
|
||||
accId = rs.getInt("id");
|
||||
@@ -568,9 +502,6 @@ public class MapleClient {
|
||||
String passhash = rs.getString("password");
|
||||
byte tos = rs.getByte("tos");
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
if (banned) {
|
||||
return 3;
|
||||
}
|
||||
@@ -590,23 +521,10 @@ public class MapleClient {
|
||||
} else {
|
||||
accId = -3;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (rs != null && !rs.isClosed()) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (loginok == 0 || loginok == 4) {
|
||||
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptLoginSession(session, nibbleHwid, accId, loginok == 4);
|
||||
@@ -640,44 +558,31 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public Calendar getTempBanCalendarFromDB() {
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
final Calendar lTempban = Calendar.getInstance();
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?");
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, getAccID());
|
||||
rs = ps.executeQuery();
|
||||
|
||||
final Timestamp tempban;
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Timestamp tempban = rs.getTimestamp("tempban");
|
||||
tempban = rs.getTimestamp("tempban");
|
||||
if (tempban.toLocalDateTime().equals(DefaultDates.getTempban())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
lTempban.setTimeInMillis(tempban.getTime());
|
||||
tempBanCalendar = lTempban;
|
||||
return lTempban;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null) {
|
||||
ps.close();
|
||||
}
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;//why oh why!?!
|
||||
}
|
||||
|
||||
@@ -704,40 +609,25 @@ public class MapleClient {
|
||||
|
||||
public void updateHWID(String newHwid) {
|
||||
String[] split = newHwid.split("_");
|
||||
if(split.length > 1 && split[1].length() == 8) {
|
||||
if (split.length > 1 && split[1].length() == 8) {
|
||||
StringBuilder hwid = new StringBuilder();
|
||||
String convert = split[1];
|
||||
|
||||
int len = convert.length();
|
||||
for(int i=len-2; i>=0; i -= 2) {
|
||||
for (int i = len - 2; i >= 0; i -= 2) {
|
||||
hwid.append(convert.substring(i, i + 2));
|
||||
}
|
||||
hwid.insert(4, "-");
|
||||
|
||||
this.hwid = hwid.toString();
|
||||
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?")) {
|
||||
ps.setString(1, this.hwid);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.disconnect(false, false); // Invalid HWID...
|
||||
@@ -748,7 +638,6 @@ public class MapleClient {
|
||||
macs.addAll(Arrays.asList(macData.split(", ")));
|
||||
StringBuilder newMacData = new StringBuilder();
|
||||
Iterator<String> iter = macs.iterator();
|
||||
PreparedStatement ps = null;
|
||||
while (iter.hasNext()) {
|
||||
String cur = iter.next();
|
||||
newMacData.append(cur);
|
||||
@@ -756,27 +645,14 @@ public class MapleClient {
|
||||
newMacData.append(", ");
|
||||
}
|
||||
}
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?")) {
|
||||
ps.setString(1, newMacData.toString());
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if (con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,17 +670,14 @@ public class MapleClient {
|
||||
MapleSessionCoordinator.getInstance().updateOnlineSession(this.getSession());
|
||||
}
|
||||
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = ? WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = ? WHERE id = ?")) {
|
||||
// using sql currenttime here could potentially break the login, thanks Arnah for pointing this out
|
||||
|
||||
ps.setInt(1, newstate);
|
||||
ps.setTimestamp(2, new java.sql.Timestamp(Server.getInstance().getCurrentTime()));
|
||||
ps.setInt(3, getAccID());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -820,23 +693,23 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public int getLoginState() { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT loggedin, lastlogin, birthday FROM accounts WHERE id = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
int state;
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT loggedin, lastlogin, birthday FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, getAccID());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
throw new RuntimeException("getLoginState - MapleClient AccID: " + getAccID());
|
||||
}
|
||||
|
||||
birthday = Calendar.getInstance();
|
||||
try {
|
||||
birthday.setTime(rs.getDate("birthday"));
|
||||
} catch(SQLException e) {}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
|
||||
int state = rs.getInt("loggedin");
|
||||
state = rs.getInt("loggedin");
|
||||
if (state == LOGIN_SERVER_TRANSITION) {
|
||||
if (rs.getTimestamp("lastlogin").getTime() + 30000 < Server.getInstance().getCurrentTime()) {
|
||||
int accountId = accId;
|
||||
@@ -845,20 +718,18 @@ public class MapleClient {
|
||||
this.setAccID(accountId);
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
if (state == LOGIN_LOGGEDIN) {
|
||||
loggedIn = true;
|
||||
} else if (state == LOGIN_SERVER_TRANSITION) {
|
||||
ps = con.prepareStatement("UPDATE accounts SET loggedin = 0 WHERE id = ?");
|
||||
ps.setInt(1, getAccID());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
try (PreparedStatement ps2 = con.prepareStatement("UPDATE accounts SET loggedin = 0 WHERE id = ?")) {
|
||||
ps2.setInt(1, getAccID());
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
} else {
|
||||
loggedIn = false;
|
||||
}
|
||||
|
||||
con.close();
|
||||
return state;
|
||||
} catch (SQLException e) {
|
||||
loggedIn = false;
|
||||
@@ -1196,32 +1067,32 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public boolean acceptToS() {
|
||||
boolean disconnectForBeingAFaggot = false;
|
||||
if (accountName == null) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `tos` FROM accounts WHERE id = ?");
|
||||
ps.setInt(1, accId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
boolean disconnect = false;
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT `tos` FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
if (rs.getByte("tos") == 1) {
|
||||
disconnectForBeingAFaggot = true;
|
||||
disconnect = true;
|
||||
}
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
ps = con.prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?");
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return disconnectForBeingAFaggot;
|
||||
return disconnect;
|
||||
}
|
||||
|
||||
public void checkChar(int accid) { /// issue with multiple chars from same account login found by shavit, resinate
|
||||
@@ -1240,21 +1111,17 @@ public class MapleClient {
|
||||
}
|
||||
}
|
||||
|
||||
public int getVotePoints(){
|
||||
public int getVotePoints() {
|
||||
int points = 0;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `votepoints` FROM accounts WHERE id = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `votepoints` FROM accounts WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
points = rs.getInt("votepoints");
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1278,15 +1145,11 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
private void saveVotePoints() {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET votepoints = ? WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET votepoints = ? WHERE id = ?")) {
|
||||
ps.setInt(1, votePoints);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1376,17 +1239,12 @@ public class MapleClient {
|
||||
|
||||
public synchronized boolean gainCharacterSlot() {
|
||||
if (canGainCharacterSlot()) {
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET characterslots = ? WHERE id = ?")) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET characterslots = ? WHERE id = ?")) {
|
||||
ps.setInt(1, this.characterSlots += 1);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1396,34 +1254,18 @@ public class MapleClient {
|
||||
}
|
||||
|
||||
public final byte getGReason() {
|
||||
Connection con = null;
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
ps = con.prepareStatement("SELECT `greason` FROM `accounts` WHERE id = ?");
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT `greason` FROM `accounts` WHERE id = ?")) {
|
||||
ps.setInt(1, accId);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
return rs.getByte("greason");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (ps != null) {
|
||||
ps.close();
|
||||
}
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (con != null) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1433,16 +1275,12 @@ public class MapleClient {
|
||||
|
||||
public void setGender(byte m) {
|
||||
this.gender = m;
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) {
|
||||
ps.setByte(1, gender);
|
||||
ps.setInt(2, accId);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user