refactor: use try-with-resources for various server db operations
This commit is contained in:
@@ -21,28 +21,22 @@
|
||||
*/
|
||||
package net.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.Security;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.MapleFamily;
|
||||
import client.SkillFactory;
|
||||
import client.command.CommandsExecutor;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.inventory.manipulator.MapleCashidGenerator;
|
||||
import client.newyear.NewYearCardRecord;
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import constants.inventory.ItemConstants;
|
||||
import constants.net.OpcodeConstants;
|
||||
import constants.net.ServerConstants;
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.server.audit.ThreadTracker;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReadLock;
|
||||
@@ -51,28 +45,13 @@ import net.server.audit.locks.MonitoredWriteLock;
|
||||
import net.server.audit.locks.factory.MonitoredReadLockFactory;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.server.audit.locks.factory.MonitoredWriteLockFactory;
|
||||
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.task.BossLogTask;
|
||||
import net.server.task.CharacterDiseaseTask;
|
||||
import net.server.task.CouponTask;
|
||||
import net.server.task.EventRecallCoordinatorTask;
|
||||
import net.server.task.DueyFredrickTask;
|
||||
import net.server.task.InvitationTask;
|
||||
import net.server.task.LoginCoordinatorTask;
|
||||
import net.server.task.LoginStorageTask;
|
||||
import net.server.task.RankingCommandTask;
|
||||
import net.server.task.RankingLoginTask;
|
||||
import net.server.task.ReleaseLockTask;
|
||||
import net.server.task.RespawnTask;
|
||||
import net.server.task.*;
|
||||
import net.server.world.World;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.buffer.SimpleBufferAllocator;
|
||||
import org.apache.mina.core.filterchain.IoFilter;
|
||||
@@ -80,21 +59,6 @@ import org.apache.mina.core.service.IoAcceptor;
|
||||
import org.apache.mina.core.session.IdleStatus;
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFilter;
|
||||
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
|
||||
import client.MapleClient;
|
||||
import client.MapleFamily;
|
||||
import client.MapleCharacter;
|
||||
import client.SkillFactory;
|
||||
import client.command.CommandsExecutor;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.inventory.manipulator.MapleCashidGenerator;
|
||||
import client.newyear.NewYearCardRecord;
|
||||
import constants.inventory.ItemConstants;
|
||||
import constants.game.GameConstants;
|
||||
import constants.net.OpcodeConstants;
|
||||
import constants.net.ServerConstants;
|
||||
import java.util.TimeZone;
|
||||
import server.CashShop.CashItemFactory;
|
||||
import server.MapleSkillbookInformationProvider;
|
||||
import server.ThreadManager;
|
||||
@@ -107,6 +71,18 @@ import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
import tools.Pair;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.Security;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
public class Server {
|
||||
|
||||
private static Server instance = null;
|
||||
@@ -209,23 +185,23 @@ public class Server {
|
||||
}
|
||||
|
||||
private void loadPlayerNpcMapStepFromDb() {
|
||||
try {
|
||||
List<World> wlist = this.getWorlds();
|
||||
final List<World> wlist = this.getWorlds();
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs_field");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
int world = rs.getInt("world"), map = rs.getInt("map"), step = rs.getInt("step"), podium = rs.getInt("podium");
|
||||
int world = rs.getInt("world");
|
||||
int map = rs.getInt("map");
|
||||
int step = rs.getInt("step");
|
||||
int podium = rs.getInt("podium");
|
||||
|
||||
World w = wlist.get(world);
|
||||
if(w != null) w.setPlayerNpcMapData(map, step, podium);
|
||||
if (w != null) {
|
||||
w.setPlayerNpcMapData(map, step, podium);
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -339,13 +315,19 @@ public class Server {
|
||||
|
||||
wldRLock.lock();
|
||||
try {
|
||||
if(worldid >= worlds.size()) return -3;
|
||||
if (worldid >= worlds.size()) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
channelInfo = channels.get(worldid);
|
||||
if(channelInfo == null) return -3;
|
||||
if (channelInfo == null) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
channelid = channelInfo.size();
|
||||
if(channelid >= YamlConfig.config.server.CHANNEL_SIZE) return -2;
|
||||
if (channelid >= YamlConfig.config.server.CHANNEL_SIZE) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
channelid++;
|
||||
world = this.getWorld(worldid);
|
||||
@@ -463,7 +445,9 @@ public class Server {
|
||||
|
||||
wldRLock.lock();
|
||||
try {
|
||||
if(worldid >= worlds.size()) return false;
|
||||
if (worldid >= worlds.size()) {
|
||||
return false;
|
||||
}
|
||||
world = worlds.get(worldid);
|
||||
} finally {
|
||||
wldRLock.unlock();
|
||||
@@ -474,7 +458,9 @@ public class Server {
|
||||
wldWLock.lock();
|
||||
try {
|
||||
Map<Integer, String> m = channels.get(worldid);
|
||||
if(m != null) m.remove(channel);
|
||||
if (m != null) {
|
||||
m.remove(channel);
|
||||
}
|
||||
} finally {
|
||||
wldWLock.unlock();
|
||||
}
|
||||
@@ -557,36 +543,37 @@ public class Server {
|
||||
}
|
||||
|
||||
public static void cleanNxcodeCoupons(Connection con) throws SQLException {
|
||||
if (!YamlConfig.config.server.USE_CLEAR_OUTDATED_COUPONS) return;
|
||||
if (!YamlConfig.config.server.USE_CLEAR_OUTDATED_COUPONS) {
|
||||
return;
|
||||
}
|
||||
|
||||
long timeClear = System.currentTimeMillis() - 14 * 24 * 60 * 60 * 1000;
|
||||
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE expiration <= ?");
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM nxcode WHERE expiration <= ?")) {
|
||||
ps.setLong(1, timeClear);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
if (!rs.isLast()) {
|
||||
PreparedStatement ps2 = con.prepareStatement("DELETE FROM nxcode_items WHERE codeid = ?");
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM nxcode_items WHERE codeid = ?")) {
|
||||
while (rs.next()) {
|
||||
ps2.setInt(1, rs.getInt("id"));
|
||||
ps2.addBatch();
|
||||
}
|
||||
ps2.executeBatch();
|
||||
ps2.close();
|
||||
|
||||
ps2 = con.prepareStatement("DELETE FROM nxcode WHERE expiration <= ?");
|
||||
ps2.setLong(1, timeClear);
|
||||
ps2.executeUpdate();
|
||||
ps2.close();
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
try (PreparedStatement ps2 = con.prepareStatement("DELETE FROM nxcode WHERE expiration <= ?")) {
|
||||
ps2.setLong(1, timeClear);
|
||||
ps2.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCouponRates(Connection c) throws SQLException {
|
||||
PreparedStatement ps = c.prepareStatement("SELECT couponid, rate FROM nxcoupons");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
try (PreparedStatement ps = c.prepareStatement("SELECT couponid, rate FROM nxcoupons");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
int cid = rs.getInt("couponid");
|
||||
@@ -594,9 +581,7 @@ public class Server {
|
||||
|
||||
couponRates.put(cid, rate);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Integer> getActiveCoupons() {
|
||||
@@ -608,7 +593,9 @@ public class Server {
|
||||
public void commitActiveCoupons() {
|
||||
for (World world : getWorlds()) {
|
||||
for (MapleCharacter chr : world.getPlayerStorage().getAllCharacters()) {
|
||||
if(!chr.isLoggedin()) continue;
|
||||
if (!chr.isLoggedin()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
chr.updateCouponRates();
|
||||
}
|
||||
@@ -620,8 +607,7 @@ public class Server {
|
||||
synchronized (activeCoupons) {
|
||||
if (activeCoupons.contains(couponId)) {
|
||||
activeCoupons.remove(couponId);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
activeCoupons.add(couponId);
|
||||
}
|
||||
|
||||
@@ -638,9 +624,7 @@ public class Server {
|
||||
int weekDay = c.get(Calendar.DAY_OF_WEEK);
|
||||
int hourDay = c.get(Calendar.HOUR_OF_DAY);
|
||||
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
|
||||
int weekdayMask = (1 << weekDay);
|
||||
PreparedStatement ps = con.prepareStatement("SELECT couponid FROM nxcoupons WHERE (activeday & ?) = ? AND starthour <= ? AND endhour > ?");
|
||||
@@ -649,25 +633,13 @@ public class Server {
|
||||
ps.setInt(3, hourDay);
|
||||
ps.setInt(4, hourDay);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
activeCoupons.add(rs.getInt("couponid"));
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
try {
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex2) {
|
||||
ex2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -798,11 +770,7 @@ public class Server {
|
||||
List<Pair<Integer, List<Pair<String, Integer>>>> rankSystem = new ArrayList<>();
|
||||
List<Pair<String, Integer>> rankUpdate = new ArrayList<>(0);
|
||||
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
|
||||
String worldQuery;
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
@@ -815,8 +783,8 @@ public class Server {
|
||||
worldQuery = (" AND `characters`.`world` >= 0 AND `characters`.`world` <= " + Math.abs(worldid));
|
||||
}
|
||||
|
||||
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
||||
rs = ps.executeQuery();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
int currentWorld = -1;
|
||||
@@ -838,26 +806,9 @@ public class Server {
|
||||
rankUpdate.add(new Pair<>(rs.getString("name"), rs.getInt("level")));
|
||||
}
|
||||
}
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.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();
|
||||
}
|
||||
}
|
||||
|
||||
return rankSystem;
|
||||
@@ -876,24 +827,22 @@ public class Server {
|
||||
|
||||
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
||||
|
||||
Connection c = null;
|
||||
try {
|
||||
c = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = 0")) {
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
cleanNxcodeCoupons(c);
|
||||
loadCouponRates(c);
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET HasMerchant = 0")) {
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
cleanNxcodeCoupons(con);
|
||||
loadCouponRates(con);
|
||||
updateActiveCoupons();
|
||||
|
||||
c.close();
|
||||
} catch (SQLException sqle) {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
applyAllNameChanges(); // -- name changes can be missed by INSTANT_NAME_CHANGE --
|
||||
applyAllWorldTransfers();
|
||||
//MaplePet.clearMissingPetsFromDb(); // thanks Optimist for noticing this taking too long to run
|
||||
@@ -917,7 +866,9 @@ public class Server {
|
||||
|
||||
NewYearCardRecord.startPendingNewYearCardRequests();
|
||||
|
||||
if(YamlConfig.config.server.USE_THREAD_TRACKER) ThreadTracker.getInstance().registerThreadTrackerTask();
|
||||
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
|
||||
ThreadTracker.getInstance().registerThreadTrackerTask();
|
||||
}
|
||||
|
||||
try {
|
||||
Integer worldCount = Math.min(GameConstants.WORLD_NAMES.length, YamlConfig.config.server.WORLDS);
|
||||
@@ -1286,7 +1237,9 @@ public class Server {
|
||||
}
|
||||
|
||||
public void deleteGuildCharacter(MapleGuildCharacter mgc) {
|
||||
if(mgc.getCharacter() != null) setGuildMemberOnline(mgc.getCharacter(), false, (byte) -1);
|
||||
if (mgc.getCharacter() != null) {
|
||||
setGuildMemberOnline(mgc.getCharacter(), false, (byte) -1);
|
||||
}
|
||||
if (mgc.getGuildRank() > 1) {
|
||||
leaveGuild(mgc);
|
||||
} else {
|
||||
@@ -1401,7 +1354,9 @@ public class Server {
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
World wserv = this.getWorld(chrView.getWorld());
|
||||
if(wserv != null) wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
if (wserv != null) {
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
@@ -1422,7 +1377,9 @@ public class Server {
|
||||
MapleCharacter chrView = chr.generateCharacterEntry();
|
||||
|
||||
World wserv = this.getWorld(chrView.getWorld());
|
||||
if(wserv != null) wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
if (wserv != null) {
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
@@ -1439,7 +1396,9 @@ public class Server {
|
||||
Integer world = worldChars.remove(chrid);
|
||||
if (world != null) {
|
||||
World wserv = this.getWorld(world);
|
||||
if(wserv != null) wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
if (wserv != null) {
|
||||
wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
@@ -1452,7 +1411,9 @@ public class Server {
|
||||
Integer chrid = chr.getId(), accountid = chr.getAccountID(), world = worldChars.get(chr.getId());
|
||||
if (world != null) {
|
||||
World wserv = this.getWorld(world);
|
||||
if(wserv != null) wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
if (wserv != null) {
|
||||
wserv.unregisterAccountCharacterView(accountid, chrid);
|
||||
}
|
||||
}
|
||||
|
||||
worldChars.put(chrid, toWorld);
|
||||
@@ -1460,7 +1421,9 @@ public class Server {
|
||||
MapleCharacter chrView = chr.generateCharacterEntry();
|
||||
|
||||
World wserv = this.getWorld(toWorld);
|
||||
if(wserv != null) wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
if (wserv != null) {
|
||||
wserv.registerAccountCharacterView(chrView.getAccountID(), chrView);
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
@@ -1485,7 +1448,9 @@ public class Server {
|
||||
|
||||
public Pair<Pair<Integer, List<MapleCharacter>>, List<Pair<Integer, List<MapleCharacter>>>> loadAccountCharlist(Integer accountId, int visibleWorlds) {
|
||||
List<World> wlist = this.getWorlds();
|
||||
if(wlist.size() > visibleWorlds) wlist = wlist.subList(0, visibleWorlds);
|
||||
if (wlist.size() > visibleWorlds) {
|
||||
wlist = wlist.subList(0, visibleWorlds);
|
||||
}
|
||||
|
||||
List<Pair<Integer, List<MapleCharacter>>> accChars = new ArrayList<>(wlist.size() + 1);
|
||||
int chrTotal = 0;
|
||||
@@ -1517,7 +1482,9 @@ public class Server {
|
||||
private static Pair<Short, List<List<MapleCharacter>>> loadAccountCharactersViewFromDb(int accId, int wlen) {
|
||||
short characterCount = 0;
|
||||
List<List<MapleCharacter>> wchars = new ArrayList<>(wlen);
|
||||
for(int i = 0; i < wlen; i++) wchars.add(i, new LinkedList<MapleCharacter>());
|
||||
for (int i = 0; i < wlen; i++) {
|
||||
wchars.add(i, new LinkedList<MapleCharacter>());
|
||||
}
|
||||
|
||||
List<MapleCharacter> chars = new LinkedList<>();
|
||||
int curWorld = 0;
|
||||
@@ -1535,15 +1502,18 @@ public class Server {
|
||||
playerEquips.add(ae.getLeft());
|
||||
}
|
||||
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE accountid = ? ORDER BY world, id")) {
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE accountid = ? ORDER BY world, id")) {
|
||||
ps.setInt(1, accId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
characterCount++;
|
||||
|
||||
int cworld = rs.getByte("world");
|
||||
if(cworld >= wlen) continue;
|
||||
if (cworld >= wlen) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cworld > curWorld) {
|
||||
wchars.add(curWorld, chars);
|
||||
@@ -1557,7 +1527,6 @@ public class Server {
|
||||
}
|
||||
}
|
||||
}
|
||||
con.close();
|
||||
|
||||
wchars.add(curWorld, chars);
|
||||
} catch (SQLException sqle) {
|
||||
@@ -1568,10 +1537,9 @@ public class Server {
|
||||
}
|
||||
|
||||
public void loadAllAccountsCharactersView() {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT id FROM accounts");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
int accountId = rs.getInt("id");
|
||||
@@ -1579,10 +1547,6 @@ public class Server {
|
||||
loadAccountCharactersView(accountId, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
}
|
||||
@@ -1599,8 +1563,8 @@ public class Server {
|
||||
|
||||
private static void applyAllNameChanges() {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM namechanges WHERE completionTime IS NULL")) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM namechanges WHERE completionTime IS NULL");
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
List<Pair<String, String>> changedNames = new LinkedList<Pair<String, String>>(); //logging only
|
||||
while (rs.next()) {
|
||||
con.setAutoCommit(false);
|
||||
@@ -1609,8 +1573,11 @@ public class Server {
|
||||
String oldName = rs.getString("old");
|
||||
String newName = rs.getString("new");
|
||||
boolean success = MapleCharacter.doNameChange(con, characterId, oldName, newName, nameChangeId);
|
||||
if(!success) con.rollback(); //discard changes
|
||||
else changedNames.add(new Pair<String, String>(oldName, newName));
|
||||
if (!success) {
|
||||
con.rollback(); //discard changes
|
||||
} else {
|
||||
changedNames.add(new Pair<String, String>(oldName, newName));
|
||||
}
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
//log
|
||||
@@ -1626,8 +1593,8 @@ public class Server {
|
||||
private static void applyAllWorldTransfers() {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM worldtransfers WHERE completionTime IS NULL",
|
||||
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
|
||||
ResultSet rs = ps.executeQuery();
|
||||
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = ps.executeQuery()) {
|
||||
List<Integer> removedTransfers = new LinkedList<Integer>();
|
||||
while (rs.next()) {
|
||||
int nameChangeId = rs.getInt("id");
|
||||
@@ -1652,13 +1619,18 @@ public class Server {
|
||||
while (rs.next()) {
|
||||
con.setAutoCommit(false);
|
||||
int nameChangeId = rs.getInt("id");
|
||||
if(removedTransfers.contains(nameChangeId)) continue;
|
||||
if (removedTransfers.contains(nameChangeId)) {
|
||||
continue;
|
||||
}
|
||||
int characterId = rs.getInt("characterId");
|
||||
int oldWorld = rs.getInt("from");
|
||||
int newWorld = rs.getInt("to");
|
||||
boolean success = MapleCharacter.doWorldTransfer(con, characterId, oldWorld, newWorld, nameChangeId);
|
||||
if(!success) con.rollback();
|
||||
else worldTransfers.add(new Pair<Integer, Pair<Integer, Integer>>(characterId, new Pair<Integer, Integer>(oldWorld, newWorld)));
|
||||
if (!success) {
|
||||
con.rollback();
|
||||
} else {
|
||||
worldTransfers.add(new Pair<Integer, Pair<Integer, Integer>>(characterId, new Pair<Integer, Integer>(oldWorld, newWorld)));
|
||||
}
|
||||
con.setAutoCommit(true);
|
||||
}
|
||||
//log
|
||||
@@ -1694,7 +1666,9 @@ public class Server {
|
||||
|
||||
if (wserv != null) {
|
||||
for (MapleCharacter chr : wserv.getAllCharactersView()) {
|
||||
if (gmLevel < chr.gmLevel()) gmLevel = chr.gmLevel();
|
||||
if (gmLevel < chr.gmLevel()) {
|
||||
gmLevel = chr.gmLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1728,7 +1702,9 @@ public class Server {
|
||||
|
||||
for (MapleCharacter chr : wchars) {
|
||||
int cid = chr.getId();
|
||||
if (gmLevel < chr.gmLevel()) gmLevel = chr.gmLevel();
|
||||
if (gmLevel < chr.gmLevel()) {
|
||||
gmLevel = chr.gmLevel();
|
||||
}
|
||||
|
||||
chars.add(cid);
|
||||
worldChars.put(cid, wid);
|
||||
@@ -1897,7 +1873,9 @@ public class Server {
|
||||
|
||||
private synchronized void shutdownInternal(boolean restart) {
|
||||
System.out.println((restart ? "Restarting" : "Shutting down") + " the server!\r\n");
|
||||
if (getWorlds() == null) return;//already shutdown
|
||||
if (getWorlds() == null) {
|
||||
return;//already shutdown
|
||||
}
|
||||
for (World w : getWorlds()) {
|
||||
w.shutdown();
|
||||
}
|
||||
@@ -1923,7 +1901,9 @@ public class Server {
|
||||
|
||||
List<Channel> allChannels = getAllChannels();
|
||||
|
||||
if(YamlConfig.config.server.USE_THREAD_TRACKER) ThreadTracker.getInstance().cancelThreadTrackerTask();
|
||||
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
|
||||
ThreadTracker.getInstance().cancelThreadTrackerTask();
|
||||
}
|
||||
|
||||
for (Channel ch : allChannels) {
|
||||
while (!ch.finishedShutdown()) {
|
||||
|
||||
Reference in New Issue
Block a user