Experimental DB pool + fixed stat overflow on equips

Implemented EXPERIMENTAL DBCP (connection pool), trying to improve
concorrent access to DB. Added door portals on Kerning Square. Fixed
equipments getting stat overflow when upgrading stats. Fixed expiring
pets crashing the client in some cases.
This commit is contained in:
ronancpl
2017-08-23 18:01:17 -03:00
parent 36db21bf80
commit 6628e3db54
190 changed files with 18265 additions and 2183 deletions

View File

@@ -416,29 +416,31 @@ public class AbstractPlayerInteraction {
Item item = null;
MaplePet evolved = null;
int petId = -1;
if (id >= 5000000 && id <= 5000100) {
petId = MaplePet.createPet(id);
if(from != null) {
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
Point pos = getPlayer().getPosition();
pos.y -= 12;
evolved.setPos(pos);
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
evolved.setStance(0);
evolved.setSummoned(true);
evolved.setName(from.getName());
evolved.setCloseness(from.getCloseness());
evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel());
evolved.saveToDb();
}
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
}
if (quantity >= 0) {
if (id >= 5000000 && id <= 5000100) {
petId = MaplePet.createPet(id);
if(from != null) {
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
Point pos = getPlayer().getPosition();
pos.y -= 12;
evolved.setPos(pos);
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
evolved.setStance(0);
evolved.setSummoned(true);
evolved.setName(from.getName());
evolved.setCloseness(from.getCloseness());
evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel());
evolved.saveToDb();
}
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
}
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.getInventoryType(id).equals(MapleInventoryType.EQUIP)) {
@@ -687,7 +689,7 @@ public class AbstractPlayerInteraction {
}
public void removeAll(int id, MapleClient cl) {
MapleInventoryType invType = MapleItemInformationProvider.getInstance().getInventoryType(id);
MapleInventoryType invType = MapleItemInformationProvider.getInstance().getInventoryType(id);
int possessed = cl.getPlayer().getInventory(invType).countById(id);
if (possessed > 0) {
MapleInventoryManipulator.removeById(cl, MapleItemInformationProvider.getInstance().getInventoryType(id), id, possessed, true, false);

View File

@@ -57,6 +57,7 @@ import client.Skill;
import constants.ItemConstants;
import constants.ServerConstants;
import java.awt.Point;
import java.sql.Connection;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -570,13 +571,16 @@ public class EventInstanceManager {
public void saveWinner(MapleCharacter chr) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO eventstats (event, instance, characterid, channel) VALUES (?, ?, ?, ?)")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO eventstats (event, instance, characterid, channel) VALUES (?, ?, ?, ?)")) {
ps.setString(1, em.getName());
ps.setString(2, getName());
ps.setInt(3, chr.getId());
ps.setInt(4, chr.getClient().getChannel());
ps.executeUpdate();
}
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}

View File

@@ -22,6 +22,7 @@
package scripting.portal;
import client.MapleClient;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -46,14 +47,16 @@ public class PortalPlayerInteraction extends AbstractPlayerInteraction {
public boolean hasLevel30Character() {
PreparedStatement ps = null;
ResultSet rs = null;
Connection con = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
ps.setInt(1, getPlayer().getAccountID());
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("level") >= 30) {
ps.close();
rs.close();
ps.close();
rs.close();
return true;
}
}
@@ -67,11 +70,15 @@ public class PortalPlayerInteraction extends AbstractPlayerInteraction {
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (con != null && !con.isClosed()) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return false;
return getPlayer().getLevel() >= 30;
}
public void blockPortal() {

View File

@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package scripting.reactor;
import client.MapleClient;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
@@ -82,7 +83,8 @@ public class ReactorScriptManager extends AbstractScriptManager {
if (ret == null) {
ret = new LinkedList<>();
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
ps.setInt(1, rid);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
@@ -90,6 +92,8 @@ public class ReactorScriptManager extends AbstractScriptManager {
}
}
}
con.close();
} catch (Throwable e) {
FilePrinter.printError(FilePrinter.REACTOR + rid + ".txt", e);
}