HikariCP config + MaxHP/MP & EXP overhaul + Venom fix

Overhauled the HikariCP connection, now it properly tries the best to hand out a DB connection. Fixed "commands" NPC crashing out players when entering the command multiple times in a short time. Rebalanced HP/MP gain on leveling up/AP resetting. Rebalanced HP/MP loss when AP resetting to use the same amount they would be earning on levelup. Fixed EXP distribution now computing overall monster maxHP plus heal instead of flat monter maxHP, that rendered on distributions of over 100% of the raw EXP. Added concurrency protection on MapleMonster. Fixed an issue on venom skills that would let an "1 dmg" appear to the client alongside the DOT.
This commit is contained in:
ronancpl
2017-10-27 13:00:36 -02:00
parent 08658f406b
commit 5f1abf3fb3
35 changed files with 757 additions and 362 deletions

View File

@@ -1,6 +1,8 @@
package tools;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.zaxxer.hikari.HikariConfig;
@@ -18,13 +20,51 @@ public class DatabaseConnection {
public static Connection getConnection() throws SQLException {
if(ds != null) {
return ds.getConnection();
} else {
return DriverManager.getConnection(ServerConstants.DB_URL, ServerConstants.DB_USER, ServerConstants.DB_PASS);
try {
return ds.getConnection();
} catch (SQLException sqle) {}
}
int denies = 0;
while(true) { // There is no way it can pass with a null out of here
try {
return DriverManager.getConnection(ServerConstants.DB_URL, ServerConstants.DB_USER, ServerConstants.DB_PASS);
} catch (SQLException sqle) {
denies++;
if(denies == 3) {
// Give up, return null :3
FilePrinter.printError(FilePrinter.SQL_EXCEPTION, "SQL Driver refused to give a connection after " + denies + " tries.");
return null;
}
}
}
}
private static int getNumberOfAccounts() {
try {
Connection con = DriverManager.getConnection(ServerConstants.DB_URL, ServerConstants.DB_USER, ServerConstants.DB_PASS);
try (PreparedStatement ps = con.prepareStatement("SELECT count(*) FROM accounts")) {
try (ResultSet rs = ps.executeQuery()) {
rs.next();
return rs.getInt(1);
}
} finally {
con.close();
}
} catch(SQLException sqle) {
return 20;
}
}
public DatabaseConnection() {
try {
Class.forName("com.mysql.jdbc.Driver"); // touch the mysql driver
} catch (ClassNotFoundException e) {
System.out.println("[SEVERE] SQL Driver Not Found. Consider death by clams.");
e.printStackTrace();
}
ds = null;
if(ServerConstants.DB_EXPERIMENTAL_POOL) {
@@ -36,22 +76,18 @@ public class DatabaseConnection {
config.setUsername(ServerConstants.DB_USER);
config.setPassword(ServerConstants.DB_PASS);
config.addDataSourceProperty("connectionTimeout", "30000");
config.addDataSourceProperty("maximumPoolSize", "100");
int poolSize = getNumberOfAccounts() * 10; // make sure pool size is comfortable for the worst case scenario
if(poolSize < 100) poolSize = 100;
else if(poolSize > 10000) poolSize = 10000;
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setConnectionTimeout(30 * 1000);
config.setMaximumPoolSize(poolSize);
config.addDataSourceProperty("cachePrepStmts", true);
config.addDataSourceProperty("prepStmtCacheSize", 250);
config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
ds = new HikariDataSource(config);
} else {
try {
Class.forName("com.mysql.jdbc.Driver"); // touch the mysql driver
} catch (ClassNotFoundException e) {
System.out.println("[SEVERE] SQL Driver Not Found. Consider death by clams.");
e.printStackTrace();
return;
}
}
}
}