rendered paste bodyIndex: C:/workspace/c4/dist/GameServer_loop.sh
===================================================================
--- C:/workspace/c4/dist/GameServer_loop.sh (revision 1654)
+++ C:/workspace/c4/dist/GameServer_loop.sh (working copy)
@@ -5,7 +5,7 @@
do
mv log/java0.log.0 "log/`date +%Y-%m-%d_%H-%M-%S`_java.log"
mv log/stdout.log "log/`date +%Y-%m-%d_%H-%M-%S`_stdout.log"
- nice -n -2 java -Xms512m -Xmx512m -cp bsf.jar:javolution.jar:bsh-2.0.jar:jython.jar:c3p0-0.9.0.jar:mysql-connector-java-3.1.10-bin.jar:sqljdbc.jar:l2jserver.jar net.sf.l2j.gameserver.GameServer > log/stdout.log 2>&1
+ nice -n -2 java -Xms128m -Xmx512m -Xss128k -Xincgc -server -cp bsf.jar:javolution.jar:bsh-2.0.jar:jython.jar:c3p0-0.9.0.jar:mysql-connector-java-3.1.10-bin.jar:sqljdbc.jar:l2jserver.jar net.sf.l2j.gameserver.GameServer > log/stdout.log 2>&1
err=$?
# /etc/init.d/mysql restart
sleep 10;
Index: C:/workspace/c4/dist/LoginServer_loop.sh
===================================================================
--- C:/workspace/c4/dist/LoginServer_loop.sh (revision 1654)
+++ C:/workspace/c4/dist/LoginServer_loop.sh (working copy)
@@ -5,7 +5,7 @@
do
mv log/java0.log.0 "log/`date +%Y-%m-%d_%H-%M-%S`_java.log"
mv log/stdout.log "log/`date +%Y-%m-%d_%H-%M-%S`_stdout.log"
- nice -n -2 java -Xms512m -Xmx512m -cp javolution.jar:c3p0-0.9.0.jar:mysql-connector-java-3.1.10-bin.jar:sqljdbc.jar:l2jserver.jar net.sf.l2j.loginserver.LoginServer > log/stdout.log 2>&1
+ nice -n -2 java -Xms8m -Xmx32m -Xss128k -Xincgc -server -cp javolution.jar:c3p0-0.9.0.jar:mysql-connector-java-3.1.10-bin.jar:sqljdbc.jar:l2jserver.jar net.sf.l2j.loginserver.LoginServer > log/stdout.log 2>&1
err=$?
# /etc/init.d/mysql restart
sleep 10;
Index: C:/workspace/c4/dist/hexid.txt
===================================================================
--- C:/workspace/c4/dist/hexid.txt (revision 0)
+++ C:/workspace/c4/dist/hexid.txt (revision 0)
@@ -0,0 +1,3 @@
+#the hexID to auth into login
+#Sat Mar 18 17:38:35 CET 2006
+HexID=25f8d31f8e50d118dd72d93b9da888d1
Index: C:/workspace/c4/dist/startGameServer.bat
===================================================================
--- C:/workspace/c4/dist/startGameServer.bat (revision 1654)
+++ C:/workspace/c4/dist/startGameServer.bat (working copy)
@@ -2,7 +2,7 @@
:start
echo Starting L2J Game Server.
echo.
-java -Xmx512m -cp bsf.jar;bsh-2.0.jar;javolution.jar;c3p0-0.9.0.jar;mysql-connector-java-3.1.10-bin.jar;sqljdbc.jar;l2jserver.jar;jython.jar net.sf.l2j.gameserver.GameServer
+java -Xms128m -Xmx512m -Xss128k -Xincgc -cp bsf.jar;bsh-2.0.jar;javolution.jar;c3p0-0.9.0.jar;mysql-connector-java-3.1.10-bin.jar;sqljdbc.jar;l2jserver.jar;jython.jar net.sf.l2j.gameserver.GameServer
if ERRORLEVEL 2 goto restart
if ERRORLEVEL 1 goto error
goto end
Index: C:/workspace/c4/dist/startGameServer.sh
===================================================================
--- C:/workspace/c4/dist/startGameServer.sh (revision 1654)
+++ C:/workspace/c4/dist/startGameServer.sh (working copy)
@@ -1,6 +1,8 @@
#!/bin/bash
./GameServer_loop.sh &
-
+echo Attaching to log file, press Ctrl+C to return to shell
+echo
+tail -f log/stdout.log
Index: C:/workspace/c4/dist/startLoginServer.bat
===================================================================
--- C:/workspace/c4/dist/startLoginServer.bat (revision 1654)
+++ C:/workspace/c4/dist/startLoginServer.bat (working copy)
@@ -2,7 +2,7 @@
:start
echo Starting L2J Login Server.
echo.
-java -Xmx128m -cp javolution.jar;c3p0-0.9.0.jar;mysql-connector-java-3.1.10-bin.jar;sqljdbc.jar;l2jserver.jar; net.sf.l2j.loginserver.LoginServer
+java -Xms8m -Xmx32m -Xss128k -Xincgc -cp javolution.jar;c3p0-0.9.0.jar;mysql-connector-java-3.1.10-bin.jar;sqljdbc.jar;l2jserver.jar; net.sf.l2j.loginserver.LoginServer
if ERRORLEVEL 2 goto restart
if ERRORLEVEL 1 goto error
goto end
Index: C:/workspace/c4/dist/startLoginServer.sh
===================================================================
--- C:/workspace/c4/dist/startLoginServer.sh (revision 1654)
+++ C:/workspace/c4/dist/startLoginServer.sh (working copy)
@@ -1,6 +1,9 @@
#!/bin/bash
./LoginServer_loop.sh &
+echo Attaching to log file, press Ctrl+C to return to shell
+echo
+tail -f log/stdout.log
Index: C:/workspace/c4/java/net/sf/l2j/Config.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/Config.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/Config.java (working copy)
@@ -62,6 +62,7 @@
public static String DATABASE_LOGIN;
public static String DATABASE_PASSWORD;
public static int DATABASE_MAX_CONNECTIONS;
+ public static int SQL_LOG_EXEC_TIME_MAX;
public static int MAXIMUM_ONLINE_USERS;
@@ -234,7 +235,7 @@
public static int PLAYER_RATE_DROP_ITEM;
public static int PLAYER_RATE_DROP_EQUIP;
public static int PLAYER_RATE_DROP_EQUIP_WEAPON;
-
+
/** Pet Rates (Multipliers) */
public static float PET_XP_RATE;
public static int PET_FOOD_RATE;
@@ -322,7 +323,7 @@
public static final String HEXID_FILE = "./config/hexid.txt";
public static final String COMMAND_PRIVILEGES_FILE = "./config/command-privileges.properties";
public static final String AI_FILE = "./config/ai.properties";
-
+
public static boolean CHECK_KNOWN;
public static int GAME_SERVER_LOGIN_PORT;
@@ -577,7 +578,7 @@
PLAYER_RATE_DROP_ITEM = Integer.parseInt(serverSettings.getProperty("PlayerRateDropItem", "70"));
PLAYER_RATE_DROP_EQUIP = Integer.parseInt(serverSettings.getProperty("PlayerRateDropEquip", "25"));
PLAYER_RATE_DROP_EQUIP_WEAPON = Integer.parseInt(serverSettings.getProperty("PlayerRateDropEquipWeapon", "5"));
-
+
PET_XP_RATE = Float.parseFloat(serverSettings.getProperty("PetXpRate", "1."));
PET_FOOD_RATE = Integer.parseInt(serverSettings.getProperty("PetFoodRate", "1"));
@@ -660,6 +661,7 @@
DATABASE_LOGIN = serverSettings.getProperty("Login", "root");
DATABASE_PASSWORD = serverSettings.getProperty("Password", "");
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
+ SQL_LOG_EXEC_TIME_MAX = Integer.parseInt(serverSettings.getProperty("SqlLogExecTimeMax", "1000"));
COUNT_PACKETS = Boolean.valueOf(serverSettings.getProperty("CountPacket", "false"));
DUMP_PACKET_COUNTS = Boolean.valueOf(serverSettings.getProperty("DumpPacketCounts", "false"));
@@ -835,6 +837,7 @@
GM_NAME_COLOUR = Integer.decode("0x" + otherSettings.getProperty("GMNameColour", "00FF00"));
GM_STARTUP_INVISIBLE = Boolean.parseBoolean(otherSettings.getProperty("GMStartupInvisible", "True"));
GM_STARTUP_SILENCE = Boolean.parseBoolean(otherSettings.getProperty("GMStartupSilence", "True"));
+
}
catch (Exception e)
{
@@ -880,7 +883,7 @@
ALT_GAME_CANCEL_CAST = altSettings.getProperty("AltGameCancelByHit", "Cast").equalsIgnoreCase("cast") || altSettings.getProperty("AltGameCancelByHit", "Cast").equalsIgnoreCase("all");
ALT_GAME_SHIELD_BLOCKS = Boolean.parseBoolean(altSettings.getProperty("AltShieldBlocks", "false"));
ALT_GAME_DELEVEL = Boolean.parseBoolean(altSettings.getProperty("Delevel", "true"));
- ALT_GAME_MAGICFAILURES = Boolean.parseBoolean(altSettings.getProperty("MagicFailures", "false"));
+ ALT_GAME_MAGICFAILURES = Boolean.parseBoolean(altSettings.getProperty("MagicFailures", "false"));
ALT_GAME_MOB_ATTACK_AI = Boolean.parseBoolean(altSettings.getProperty("AltGameMobAttackAI", "false"));
ALT_GAME_SKILL_FORMULAS = altSettings.getProperty("AltGameSkillFormulas", "none");
ALT_GAME_EXPONENT_XP = Float.parseFloat(altSettings.getProperty("AltGameExponentXp", "0."));
@@ -1057,6 +1060,7 @@
DATABASE_LOGIN = serverSettings.getProperty("Login", "root");
DATABASE_PASSWORD = serverSettings.getProperty("Password", "");
DATABASE_MAX_CONNECTIONS = Integer.parseInt(serverSettings.getProperty("MaximumDbConnections", "10"));
+ SQL_LOG_EXEC_TIME_MAX = Integer.parseInt(serverSettings.getProperty("SqlLogExecTimeMax","1000"));
SHOW_LICENCE = Boolean.parseBoolean(serverSettings.getProperty("ShowLicence", "true"));
IP_UPDATE_TIME = Integer.parseInt(serverSettings.getProperty("IpUpdateTime","15"));
Index: C:/workspace/c4/java/net/sf/l2j/L2DatabaseFactory.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/L2DatabaseFactory.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/L2DatabaseFactory.java (working copy)
@@ -44,10 +44,9 @@
private static L2DatabaseFactory _instance;
private ProviderType _Provider_Type;
private DataSource _source;
-
// =========================================================
// Constructor
- public L2DatabaseFactory() throws SQLException
+ public L2DatabaseFactory() // throws SQLException
{
try
{
@@ -59,19 +58,52 @@
PoolConfig config = new PoolConfig();
config.setAutoCommitOnClose(true);
- config.setInitialPoolSize(1);
+ config.setInitialPoolSize(3); // 3 is the default for c3p0 anyway
+ // if > MaxPoolSize, it will be ignored - no worry
+ // (as said in c3p0 docs, it's only a suggestion
+ // how many connections to acquire to start with)
+
config.setMinPoolSize(1);
config.setMaxPoolSize(Config.DATABASE_MAX_CONNECTIONS);
- config.setMaxStatements(100);
- config.setIdleConnectionTestPeriod(0); // test idle connection every 1 minute
- config.setMaxIdleTime(0); // remove unused connection after 10 minutes
+
+
+ config.setAcquireRetryAttempts(0); // try to obtain connections indefinitely (0 = never quit)
+ config.setAcquireRetryDelay(500); // 500 miliseconds wait before try to acquire connection again
+ config.setCheckoutTimeout(0); // 0 = wait indefinitely for new connection
+ // if pool is exhausted
+ config.setAcquireIncrement(5); // if pool is exhausted, get 5 more connections at a time
+ // cause there is a "long" delay on acquire connection
+ // so taking more than one connection at once will make connection pooling
+ // more effective.
+
+ // this "connection_test_table" is automatically created if not already there
+ config.setAutomaticTestTable("connection_test_table"); // very very fast test, don't worry
+ config.setTestConnectionOnCheckin(true); // this will *not* make l2j slower in any way
+
+ // testing OnCheckin used with IdleConnectionTestPeriod is faster than testing on checkout
+
+ config.setIdleConnectionTestPeriod(60); // test idle connection every 60 sec
+ config.setMaxIdleTime(60*60); // 0 = idle connections never expire
+ // *THANKS* to connection testing configured above
+ // but I'd prefer to disconnect all connections
+ // not used for more than 1 hour
+ // enables statement caching, there is a "semi-bug" in c3p0 0.9.0 but in 0.9.0.2 and later it's fixed
+ //config.setMaxStatements(0);
+ config.setMaxStatementsPerConnection(500);
+
+ config.setBreakAfterAcquireFailure(false); // never fail if any way possible
+ // setting this to true will make
+ // c3p0 "crash" and refuse to work
+ // till restart thus making acquire
+ // errors "FATAL" ... we don't want that
+ // it should be possible to recover
+
Class.forName(Config.DATABASE_DRIVER).newInstance();
if (Config.DEBUG) _log.fine("Database Connection Working");
-
DataSource unpooled = DataSources.unpooledDataSource(Config.DATABASE_URL, Config.DATABASE_LOGIN, Config.DATABASE_PASSWORD);
- _source = DataSources.pooledDataSource( unpooled, config);
+ _source=DataSources.pooledDataSource( unpooled, config);
/* Test the connection */
_source.getConnection().close();
@@ -83,14 +115,14 @@
}
catch (SQLException x)
{
- if (Config.DEBUG) _log.fine("Database Connection FAILED");
- // rethrow the exception
- throw x;
+ if (Config.DEBUG) _log.warning("Database Connection FAILED");
+ // do not rethrow the exception - no point, it will crash server anyway
+ // throw x;
}
catch (Exception e)
{
- if (Config.DEBUG) _log.fine("Database Connection FAILED");
- throw new SQLException("could not init DB connection:"+e);
+ if (Config.DEBUG) _log.warning("Database Connection FAILED - could not init DB connection: "+e);
+ // throw new SQLException("could not init DB connection:"+e);
}
}
@@ -113,10 +145,10 @@
{
try {
((PooledDataSource) _source).close();
- } catch (SQLException e) {_log.log(Level.INFO, "", e);}
+ } catch (SQLException e) {_log.log(Level.WARNING, "", e);}
try {
DataSources.destroy(_source);
- } catch (SQLException e) {_log.log(Level.INFO, "", e);}
+ } catch (SQLException e) {_log.log(Level.WARNING, "", e);}
}
public final String safetyString(String[] whatToCheck)
@@ -141,7 +173,7 @@
// =========================================================
// Property - Public
- public static L2DatabaseFactory getInstance() throws SQLException
+ public static L2DatabaseFactory getInstance() // throws SQLException
{
if (_instance == null)
{
@@ -150,11 +182,31 @@
return _instance;
}
- public Connection getConnection() throws SQLException
+ public Connection getConnection(boolean use_transactions) //throws SQLException
{
- return _source.getConnection();
+ Connection con=null;
+
+ while(con==null)
+ {
+ try
+ {
+ con=_source.getConnection();
+ con.setAutoCommit(!use_transactions);
+ } catch (SQLException e)
+ {
+ _log.warning("L2DatabaseFactory: getConnection() failed with error "+e+ ", trying again");
+ }
+ };
+ return con;
}
+ public Connection getConnection() // for compatibility and transparent switch to transactions
+ // old method defaults to no-transactions
+ {
+ Connection con=getConnection(false);
+ return con;
+ }
+
public int getBusyConnectionCount() throws SQLException
{
return ((PooledDataSource) _source).getNumBusyConnectionsDefaultUser();
@@ -162,7 +214,7 @@
public int getIdleConnectionCount() throws SQLException
{
- return ((PooledDataSource) _source).getNumIdleConnectionsDefaultUser();
+ return ((PooledDataSource) _source).getNumIdleConnectionsDefaultUser();
}
public final ProviderType getProviderType() { return _Provider_Type; }
Index: C:/workspace/c4/java/net/sf/l2j/accountmanager/SQLAccountManager.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/accountmanager/SQLAccountManager.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/accountmanager/SQLAccountManager.java (working copy)
@@ -29,7 +29,7 @@
import net.sf.l2j.Base64;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.Server;
/**
@@ -113,11 +113,13 @@
return;
}
- private static void printAccInfo() throws SQLException
+ private static void printAccInfo()
{
int count = 0;
- java.sql.Connection con = null;
- con = L2DatabaseFactory.getInstance().getConnection();
+ java.sql.Connection con = sql.Open(false);
+
+ try
+ {
PreparedStatement statement = con.prepareStatement("SELECT login, access_level FROM accounts ORDER BY login ASC");
ResultSet rset = statement.executeQuery();
while (rset.next())
@@ -127,10 +129,17 @@
}
rset.close();
statement.close();
- System.out.println("Number of accounts: " + count + ".");
+ sql.Commit(con); // does nothing, query doesn't write to DB, but for code consistency ...
+ } catch (SQLException e)
+ {
+ sql.Rollback(con,e); // nothing to rollback actually but for code consistency...
+ } finally {
+ System.out.println("Number of accounts: " + count + ".");
+ sql.Close(con);
+ }
}
- private static void AddOrUpdateAccount(String account,String password, String level) throws IOException, SQLException, NoSuchAlgorithmException
+ private static void AddOrUpdateAccount(String account,String password, String level) throws IOException, NoSuchAlgorithmException
{
// Encode Password
MessageDigest md = MessageDigest.getInstance("SHA");
@@ -139,8 +148,9 @@
newpass = md.digest(newpass);
// Add to Base
- java.sql.Connection con = null;
- con = L2DatabaseFactory.getInstance().getConnection();
+ java.sql.Connection con = sql.Open();
+ try
+ {
PreparedStatement statement = con.prepareStatement("REPLACE accounts (login, password, access_level) VALUES (?,?,?)");
statement.setString(1, account);
statement.setString(2, Base64.encodeBytes(newpass));
@@ -147,13 +157,22 @@
statement.setString(3, level);
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
+ } catch (SQLException e)
+ {
+ sql.Rollback(con,e);
+ } finally
+ {
+ sql.Close(con);
+ }
}
- private static void ChangeAccountLevel(String account, String level) throws SQLException
+ private static void ChangeAccountLevel(String account, String level)
{
- java.sql.Connection con = null;
- con = L2DatabaseFactory.getInstance().getConnection();
+ java.sql.Connection con = sql.Open();
+ try
+ {
// Check Account Exist
PreparedStatement statement = con.prepareStatement("SELECT COUNT(*) FROM accounts WHERE login=?;");
statement.setString(1, account);
@@ -178,16 +197,23 @@
System.out.println("Account " + account + " does not exist.");
}
rset.close();
+ sql.Commit(con);
+ // Close Connection
+ statement.close();
+ } catch (SQLException e) {
+ sql.Rollback(con,e);
+ } finally {
+ sql.Close(con);
+ }
- // Close Connection
- statement.close();
}
- private static void DeleteAccount(String account) throws SQLException
+ private static void DeleteAccount(String account)
{
- java.sql.Connection con = null;
- con = L2DatabaseFactory.getInstance().getConnection();
+ java.sql.Connection con = sql.Open();
+
+ try{
// Check Account Exist
PreparedStatement statement = con.prepareStatement("SELECT COUNT(*) FROM accounts WHERE login=?;");
statement.setString(1, account);
@@ -192,9 +218,10 @@
PreparedStatement statement = con.prepareStatement("SELECT COUNT(*) FROM accounts WHERE login=?;");
statement.setString(1, account);
ResultSet rset = statement.executeQuery();
+
if(rset.next()==false) {
System.out.println("False");
- rset.close();
+ rset.close();
} else if(rset.getInt(1)>0) {
rset.close();
// Account exist
@@ -308,8 +335,7 @@
statement.setString(1, account);
statement.executeUpdate();
- System.out.println("Account " + account + " has been deleted.");
-
+ System.out.println("Account " + account + " has been deleted.");
} else {
// Not Exist
System.out.println("Account " + account + " does not exist.");
@@ -314,9 +340,15 @@
// Not Exist
System.out.println("Account " + account + " does not exist.");
}
-
+
+ statement.close();
+ sql.Commit(con);
// Close Connection
- statement.close();
+ } catch (SQLException e) {
+ sql.Rollback(con,e);
+ } finally {
+ sql.Close(con);
+ }
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/CharNameTable.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/CharNameTable.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/CharNameTable.java (working copy)
@@ -23,8 +23,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Logger;
-
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
/**
* This class ...
@@ -49,11 +48,10 @@
public boolean doesCharNameExist(String name)
{
boolean result = true;
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open(false);
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?");
statement.setString(1, name);
ResultSet rset = statement.executeQuery();
@@ -60,9 +58,11 @@
result = rset.next();
rset.close();
statement.close();
+ con.commit();
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not check existing charname:"+e.getMessage());
}
finally
@@ -67,7 +67,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return result;
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/CharTemplateTable.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/CharTemplateTable.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/CharTemplateTable.java (working copy)
@@ -25,10 +25,10 @@
import java.util.logging.Logger;
import javolution.util.FastMap;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.model.base.ClassId;
import net.sf.l2j.gameserver.templates.L2PcTemplate;
import net.sf.l2j.gameserver.templates.StatsSet;
+import net.sf.l2j.sql;
/**
* This class ...
@@ -71,11 +71,10 @@
private CharTemplateTable()
{
_templates = new FastMap<Integer, L2PcTemplate>();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open(false);
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(
"SELECT * FROM class_list, char_templates, lvlupgain" +
" WHERE class_list.id = char_templates.classId" +
@@ -176,7 +175,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
_log.config("CharTemplateTable: Loaded " + _templates.size() + " Character Templates.");
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/ClanTable.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/ClanTable.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/ClanTable.java (working copy)
@@ -20,6 +20,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.Map;
import java.util.logging.Logger;
@@ -24,8 +25,8 @@
import java.util.logging.Logger;
import javolution.util.FastMap;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.idfactory.IdFactory;
import net.sf.l2j.gameserver.model.L2Clan;
import net.sf.l2j.gameserver.model.L2ClanMember;
@@ -85,10 +86,9 @@
public L2Clan getClanIfExists(int clanId)
{
String clanName = null;
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT clan_name FROM clan_data WHERE clan_id=?");
statement.setInt(1, clanId);
ResultSet result = statement.executeQuery();
@@ -100,12 +100,14 @@
result.close();
statement.close();
+ sql.Commit(con);
}
- catch (Exception e) {
+ catch (SQLException e) {
+ sql.Rollback(con,e);
_log.warning("data error on clan item: " + e);
e.printStackTrace();
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
L2Clan clan = null;
@@ -120,11 +122,10 @@
public L2Clan getClanByName(String clanName)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
L2Clan clan = null;
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM clan_data WHERE clan_name LIKE ?");
statement.setString(1, clanName);
ResultSet result = statement.executeQuery();
@@ -135,11 +136,13 @@
}
result.close();
statement.close();
+ sql.Commit(con);
}
- catch (Exception e) {
+ catch (SQLException e) {
+ sql.Rollback(con,e);
_log.warning("data error on clan item: " + e);
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return clan;
}
@@ -150,7 +153,7 @@
*/
public L2Clan createClan(L2PcInstance player, String clanName)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
boolean clanExists = true;
L2Clan clan = null;
@@ -156,7 +159,6 @@
try//store the new clan in db
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM clan_data WHERE clan_name=?");
statement.setString(1, clanName);
ResultSet result = statement.executeQuery();
@@ -163,9 +165,11 @@
clanExists = result.next();
result.close();
statement.close();
+ sql.Commit(con);
}
- catch (Exception e)
+ catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("error while saving new clan to db "+e);
}
finally
@@ -170,7 +174,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
if (!clanExists)
@@ -191,11 +195,10 @@
}
public boolean isAllyExists(String allyName)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
boolean allyExists = true;
try//store the new clan in db
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT ally_id FROM clan_data WHERE ally_name=?");
statement.setString(1, allyName);
ResultSet result = statement.executeQuery();
@@ -202,9 +205,11 @@
allyExists = result.next();
result.close();
statement.close();
+ sql.Commit(con);
}
- catch (Exception e)
+ catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("error while saving new clan to db "+e);
}
finally
@@ -209,7 +214,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return allyExists;
}
@@ -221,10 +226,9 @@
//clan2.setEnemyClan(clan1);
clan1.broadcastClanStatus();
//clan2.broadcastClanStatus();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement;
statement = con.prepareStatement("INSERT INTO clan_wars (clan1, clan2, wantspeace1, wantspeace2) VALUES(?,?,?,?)");
statement.setInt(1, clanId1);
@@ -232,10 +236,12 @@
statement.setInt(3, 0);
statement.setInt(4, 0);
statement.execute();
- statement.close();
+ statement.close();
+ sql.Commit(con);
}
- catch (Exception e)
+ catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not store clans wars data:"+e);
}
finally
@@ -240,7 +246,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
//SystemMessage msg = new SystemMessage(SystemMessage.WAR_WITH_THE_S1_CLAN_HAS_BEGUN);
//
@@ -274,10 +280,9 @@
// if(player.getPlayerInstance()!=null)
// player.getPlayerInstance().setWantsPeace(0);
//}
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement;
statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?");
statement.setInt(1,clanId1);
@@ -283,6 +288,7 @@
statement.setInt(1,clanId1);
statement.setInt(2,clanId2);
statement.execute();
+
//statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?");
//statement.setInt(1,clanId2);
//statement.setInt(2,clanId1);
@@ -287,9 +293,12 @@
//statement.setInt(1,clanId2);
//statement.setInt(2,clanId1);
//statement.execute();
+
+ sql.Commit(con);
}
- catch (Exception e)
+ catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not restore clans wars data:"+e);
}
finally
@@ -294,7 +303,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
//SystemMessage msg = new SystemMessage(SystemMessage.WAR_WITH_THE_S1_CLAN_HAS_ENDED);
SystemMessage msg = new SystemMessage(1567);
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/GameServer.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/GameServer.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/GameServer.java (working copy)
@@ -24,125 +24,11 @@
import java.util.Calendar;
import java.util.logging.LogManager;
import java.util.logging.Logger;
-
+import net.sf.l2j.gameserver.Singletons;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.Server;
-import net.sf.l2j.gameserver.cache.CrestCache;
-import net.sf.l2j.gameserver.cache.HtmCache;
-import net.sf.l2j.gameserver.handler.AdminCommandHandler;
-import net.sf.l2j.gameserver.handler.ItemHandler;
-import net.sf.l2j.gameserver.handler.SkillHandler;
-import net.sf.l2j.gameserver.handler.UserCommandHandler;
-import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminAdmin;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminAnnouncements;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminBan;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminBanChat;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCache;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminChangeAccessLevel;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminCreateItem;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminDelete;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminDoorControl;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditChar;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditNpc;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEffects;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminExpSp;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminFightCalculator;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGm;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGmChat;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminHeal;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminHelpPage;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminInvul;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKick;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEventEngine;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKill;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLevel;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLogin;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMammon;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMenu;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMobGroup;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMonsterRace;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPathNode;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPForge;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPledge;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminPolymorph;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminQuest;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRepairChar;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShutdown;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSpawn;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTarget;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTeleport;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTalk;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminTest;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminUnblockIp;
-import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminZone;
-import net.sf.l2j.gameserver.handler.itemhandlers.AdvQuestItems;
-import net.sf.l2j.gameserver.handler.itemhandlers.BlessedSpiritShot;
-import net.sf.l2j.gameserver.handler.itemhandlers.CharChangePotions;
-import net.sf.l2j.gameserver.handler.itemhandlers.ChristmasTree;
-import net.sf.l2j.gameserver.handler.itemhandlers.CompBlessedSpiritShotPacks;
-import net.sf.l2j.gameserver.handler.itemhandlers.CompShotPacks;
-import net.sf.l2j.gameserver.handler.itemhandlers.CompSpiritShotPacks;
-import net.sf.l2j.gameserver.handler.itemhandlers.CrystalCarol;
-import net.sf.l2j.gameserver.handler.itemhandlers.EnchantScrolls;
-import net.sf.l2j.gameserver.handler.itemhandlers.Firework;
-import net.sf.l2j.gameserver.handler.itemhandlers.Guide;
-import net.sf.l2j.gameserver.handler.itemhandlers.Harvester;
-import net.sf.l2j.gameserver.handler.itemhandlers.MercTicket;
-import net.sf.l2j.gameserver.handler.itemhandlers.MysteryPotion;
-import net.sf.l2j.gameserver.handler.itemhandlers.PetSummon;
-import net.sf.l2j.gameserver.handler.itemhandlers.Potions;
-import net.sf.l2j.gameserver.handler.itemhandlers.Recipes;
-import net.sf.l2j.gameserver.handler.itemhandlers.Remedy;
-import net.sf.l2j.gameserver.handler.itemhandlers.RollingDice;
-import net.sf.l2j.gameserver.handler.itemhandlers.ScrollOfEscape;
-import net.sf.l2j.gameserver.handler.itemhandlers.ScrollOfResurrection;
-import net.sf.l2j.gameserver.handler.itemhandlers.Scrolls;
-import net.sf.l2j.gameserver.handler.itemhandlers.Seed;
-import net.sf.l2j.gameserver.handler.itemhandlers.SevenSignsRecord;
-import net.sf.l2j.gameserver.handler.itemhandlers.SoulCrystals;
-import net.sf.l2j.gameserver.handler.itemhandlers.SoulShots;
-import net.sf.l2j.gameserver.handler.itemhandlers.SpiritShot;
-import net.sf.l2j.gameserver.handler.itemhandlers.WorldMap;
-import net.sf.l2j.gameserver.handler.skillhandlers.Charge;
-import net.sf.l2j.gameserver.handler.skillhandlers.CombatPointHeal;
-import net.sf.l2j.gameserver.handler.skillhandlers.Continuous;
-import net.sf.l2j.gameserver.handler.skillhandlers.Craft;
-import net.sf.l2j.gameserver.handler.skillhandlers.Disablers;
-import net.sf.l2j.gameserver.handler.skillhandlers.DrainSoul;
-import net.sf.l2j.gameserver.handler.skillhandlers.Heal;
-import net.sf.l2j.gameserver.handler.skillhandlers.ManaHeal;
-import net.sf.l2j.gameserver.handler.skillhandlers.Mdam;
-import net.sf.l2j.gameserver.handler.skillhandlers.Pdam;
-import net.sf.l2j.gameserver.handler.skillhandlers.Recall;
-import net.sf.l2j.gameserver.handler.skillhandlers.Resurrect;
-import net.sf.l2j.gameserver.handler.skillhandlers.SiegeFlag;
-import net.sf.l2j.gameserver.handler.skillhandlers.Spoil;
-import net.sf.l2j.gameserver.handler.skillhandlers.Sweep;
-import net.sf.l2j.gameserver.handler.skillhandlers.TakeCastle;
-import net.sf.l2j.gameserver.handler.skillhandlers.Unlock;
-import net.sf.l2j.gameserver.handler.usercommandhandlers.Escape;
-import net.sf.l2j.gameserver.handler.usercommandhandlers.Loc;
-import net.sf.l2j.gameserver.handler.usercommandhandlers.PartyInfo;
-import net.sf.l2j.gameserver.handler.usercommandhandlers.Time;
-import net.sf.l2j.gameserver.handler.voicedcommandhandlers.stats;
import net.sf.l2j.gameserver.idfactory.IdFactory;
-import net.sf.l2j.gameserver.instancemanager.CastleManager;
-import net.sf.l2j.gameserver.instancemanager.MercTicketManager;
-import net.sf.l2j.gameserver.instancemanager.QuestManager;
-import net.sf.l2j.gameserver.instancemanager.ZoneManager;
-import net.sf.l2j.gameserver.instancemanager.BoatManager;
-import net.sf.l2j.gameserver.model.AutoChatHandler;
-import net.sf.l2j.gameserver.model.AutoSpawnHandler;
-import net.sf.l2j.gameserver.model.L2World;
-import net.sf.l2j.gameserver.model.L2PetDataTable;
-import net.sf.l2j.gameserver.taskmanager.TaskManager;
+
import net.sf.l2j.status.Status;
/**
@@ -153,26 +39,11 @@
public class GameServer
{
private static final Logger _log = Logger.getLogger(GameServer.class.getName());
+ public static Status statusServer;
+ private LoginServerThread _loginThread;
private final SelectorThread _selectorThread;
- private final SkillTable _skillTable;
- private final ItemTable _itemTable;
- private final NpcTable _npcTable;
- private final HennaTable _hennaTable;
- private final IdFactory _idFactory;
- public static GameServer gameServer;
-
- private final ItemHandler _itemHandler;
- private final SkillHandler _skillHandler;
- private final AdminCommandHandler _adminCommandHandler;
- private final Shutdown _shutdownHandler;
- private final UserCommandHandler _userCommandHandler;
- private final VoicedCommandHandler _voicedCommandHandler;
- private final DoorTable _doorTable;
- private final SevenSigns _sevenSignsEngine;
- private final AutoChatHandler _autoChatHandler;
- private final AutoSpawnHandler _autoSpawnHandler;
- private LoginServerThread _loginThread;
- public static Status statusServer;
+ private final Singletons _singletons;
+ public static GameServer gameServer;
public static final Calendar DateTimeServerStarted = Calendar.getInstance();
@@ -192,6 +63,10 @@
gameServer = this;
_log.finest("used mem:" + getUsedMemoryMB()+"MB" );
+ new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
+ new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
+ new File("pathnode").mkdirs();
+
if (Config.SERVER_VERSION != null)
{
_log.info("L2J Server Version: "+Config.SERVER_VERSION);
@@ -197,245 +72,24 @@
_log.info("L2J Server Version: "+Config.SERVER_VERSION);
_log.info("L2J Server Build Date: "+Config.SERVER_BUILD_DATE);
}
- _idFactory = IdFactory.getInstance();
- if (!_idFactory.isInitialized())
- {
- _log.severe("Could not read object IDs from DB. Please Check Your Data.");
- throw new Exception("Could not initialize the ID factory");
- }
-
- ClientScheduler.getInstance();
-
- new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
- new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
- new File("pathnode").mkdirs();
-
- // start game time control early
- GameTimeController.getInstance();
-
- // keep the references of Singletons to prevent garbage collection
- CharNameTable.getInstance();
-
- _itemTable = ItemTable.getInstance();
- if (!_itemTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the item table");
- }
-
- TradeController.getInstance();
- _skillTable = SkillTable.getInstance();
- if (!_skillTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the skill table");
- }
-
- RecipeController.getInstance();
-
- SkillTreeTable.getInstance();
- SkillSpellbookTable.getInstance();
- CharTemplateTable.getInstance();
-
- //Call to load caches
- HtmCache.getInstance();
- CrestCache.getInstance();
-
- _npcTable = NpcTable.getInstance();
- if (!_npcTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the npc table");
- }
- _hennaTable = HennaTable.getInstance();
- if (!_hennaTable.isInitialized())
- {
- throw new Exception("Could not initialize the Henna Table");
- }
- HennaTreeTable.getInstance();
- if (!_hennaTable.isInitialized())
- {
- throw new Exception("Could not initialize the Henna Tree Table");
- }
-
- TeleportLocationTable.getInstance();
- LevelUpData.getInstance();
- L2World.getInstance();
- ZoneManager.getInstance();
- SpawnTable.getInstance();
- Announcements.getInstance();
- MapRegionTable.getInstance();
- EventDroplist.getInstance();
-
- if (Config.AUTODESTROY_ITEM_AFTER > 0)
- ItemsAutoDestroy.getInstance();
-
- MonsterRace.getInstance();
-
- _doorTable = DoorTable.getInstance();
- StaticObjects.getInstance();
-
- _sevenSignsEngine = SevenSigns.getInstance();
- SevenSignsFestival.getInstance();
- _autoSpawnHandler = AutoSpawnHandler.getInstance();
- _autoChatHandler = AutoChatHandler.getInstance();
-
- // Spawn the Orators/Preachers if in the Seal Validation period.
- if (_sevenSignsEngine.isSealValidationPeriod())
- _sevenSignsEngine.spawnSevenSignsNPCs();
-
- _log.config("AutoChatHandler: Loaded " + _autoChatHandler.size() + " handlers in total.");
- _log.config("AutoSpawnHandler: Loaded " + _autoSpawnHandler.size() + " handlers in total.");
-
- _itemHandler = ItemHandler.getInstance();
- _itemHandler.registerItemHandler(new ChristmasTree());
- _itemHandler.registerItemHandler(new PetSummon());
- _itemHandler.registerItemHandler(new ScrollOfEscape());
- _itemHandler.registerItemHandler(new ScrollOfResurrection());
- _itemHandler.registerItemHandler(new SoulShots());
- _itemHandler.registerItemHandler(new SpiritShot());
- _itemHandler.registerItemHandler(new BlessedSpiritShot());
- _itemHandler.registerItemHandler(new WorldMap());
- _itemHandler.registerItemHandler(new Potions());
- _itemHandler.registerItemHandler(new Recipes());
- _itemHandler.registerItemHandler(new CompShotPacks());
- _itemHandler.registerItemHandler(new CompSpiritShotPacks());
- _itemHandler.registerItemHandler(new CompBlessedSpiritShotPacks());
- _itemHandler.registerItemHandler(new RollingDice());
- _itemHandler.registerItemHandler(new MysteryPotion());
- _itemHandler.registerItemHandler(new EnchantScrolls());
- _itemHandler.registerItemHandler(new Remedy());
- _itemHandler.registerItemHandler(new Guide());
- _itemHandler.registerItemHandler(new Scrolls());
- _itemHandler.registerItemHandler(new CrystalCarol());
- _itemHandler.registerItemHandler(new SoulCrystals());
- _itemHandler.registerItemHandler(new SevenSignsRecord());
- _itemHandler.registerItemHandler(new CharChangePotions());
- _itemHandler.registerItemHandler(new Firework());
- _itemHandler.registerItemHandler(new AdvQuestItems());
- _itemHandler.registerItemHandler(new Seed());
- _itemHandler.registerItemHandler(new Harvester());
- _itemHandler.registerItemHandler(new MercTicket());
- _log.config("ItemHandler: Loaded " + _itemHandler.size() + " handlers.");
-
- _skillHandler = SkillHandler.getInstance();
- _skillHandler.registerSkillHandler(new Pdam());
- _skillHandler.registerSkillHandler(new Mdam());
- _skillHandler.registerSkillHandler(new Heal());
- _skillHandler.registerSkillHandler(new CombatPointHeal());
- _skillHandler.registerSkillHandler(new ManaHeal());
- _skillHandler.registerSkillHandler(new Charge());
- _skillHandler.registerSkillHandler(new Continuous());
- _skillHandler.registerSkillHandler(new Resurrect());
- _skillHandler.registerSkillHandler(new Spoil());
- _skillHandler.registerSkillHandler(new Sweep());
- _skillHandler.registerSkillHandler(new Disablers());
- _skillHandler.registerSkillHandler(new Recall());
- _skillHandler.registerSkillHandler(new SiegeFlag());
- _skillHandler.registerSkillHandler(new TakeCastle());
- _skillHandler.registerSkillHandler(new Unlock());
- _skillHandler.registerSkillHandler(new DrainSoul());
- _skillHandler.registerSkillHandler(new Craft());
- _log.config("SkillHandler: Loaded " + _skillHandler.size() + " handlers.");
-
- _adminCommandHandler = AdminCommandHandler.getInstance();
- _adminCommandHandler.registerAdminCommandHandler(new AdminAdmin());
- _adminCommandHandler.registerAdminCommandHandler(new AdminInvul());
- _adminCommandHandler.registerAdminCommandHandler(new AdminDelete());
- _adminCommandHandler.registerAdminCommandHandler(new AdminKill());
- _adminCommandHandler.registerAdminCommandHandler(new AdminTarget());
- _adminCommandHandler.registerAdminCommandHandler(new AdminShop());
- _adminCommandHandler.registerAdminCommandHandler(new AdminAnnouncements());
- _adminCommandHandler.registerAdminCommandHandler(new AdminCreateItem());
- _adminCommandHandler.registerAdminCommandHandler(new AdminHeal());
- _adminCommandHandler.registerAdminCommandHandler(new AdminHelpPage());
- _adminCommandHandler.registerAdminCommandHandler(new AdminShutdown());
- _adminCommandHandler.registerAdminCommandHandler(new AdminSpawn());
- _adminCommandHandler.registerAdminCommandHandler(new AdminSkill());
- _adminCommandHandler.registerAdminCommandHandler(new AdminExpSp());
- _adminCommandHandler.registerAdminCommandHandler(new AdminEventEngine());
- _adminCommandHandler.registerAdminCommandHandler(new AdminGmChat());
- _adminCommandHandler.registerAdminCommandHandler(new AdminEditChar());
- _adminCommandHandler.registerAdminCommandHandler(new AdminGm());
- _adminCommandHandler.registerAdminCommandHandler(new AdminTeleport());
- _adminCommandHandler.registerAdminCommandHandler(new AdminRepairChar());
- _adminCommandHandler.registerAdminCommandHandler(new AdminChangeAccessLevel());
- _adminCommandHandler.registerAdminCommandHandler(new AdminBan());
- _adminCommandHandler.registerAdminCommandHandler(new AdminPolymorph());
- _adminCommandHandler.registerAdminCommandHandler(new AdminBanChat());
- _adminCommandHandler.registerAdminCommandHandler(new AdminKick());
- _adminCommandHandler.registerAdminCommandHandler(new AdminMonsterRace());
- _adminCommandHandler.registerAdminCommandHandler(new AdminEditNpc());
- _adminCommandHandler.registerAdminCommandHandler(new AdminFightCalculator());
- _adminCommandHandler.registerAdminCommandHandler(new AdminMenu());
- _adminCommandHandler.registerAdminCommandHandler(new AdminSiege());
- _adminCommandHandler.registerAdminCommandHandler(new AdminPathNode());
- _adminCommandHandler.registerAdminCommandHandler(new AdminPForge());
- _adminCommandHandler.registerAdminCommandHandler(new AdminEffects());
- _adminCommandHandler.registerAdminCommandHandler(new AdminDoorControl());
- _adminCommandHandler.registerAdminCommandHandler(new AdminTalk());
- _adminCommandHandler.registerAdminCommandHandler(new AdminTest());
- _adminCommandHandler.registerAdminCommandHandler(new AdminMobGroup());
- _adminCommandHandler.registerAdminCommandHandler(new AdminRes());
- _adminCommandHandler.registerAdminCommandHandler(new AdminMammon());
- _adminCommandHandler.registerAdminCommandHandler(new AdminUnblockIp());
- _adminCommandHandler.registerAdminCommandHandler(new AdminPledge());
- _adminCommandHandler.registerAdminCommandHandler(new AdminRideWyvern());
- _adminCommandHandler.registerAdminCommandHandler(new AdminLogin());
- _adminCommandHandler.registerAdminCommandHandler(new AdminCache());
- _adminCommandHandler.registerAdminCommandHandler(new AdminLevel());
- _adminCommandHandler.registerAdminCommandHandler(new AdminQuest());
- _adminCommandHandler.registerAdminCommandHandler(new AdminZone());
-
- //_adminCommandHandler.registerAdminCommandHandler(new AdminRadar());
- _log.config("AdminCommandHandler: Loaded " + _adminCommandHandler.size() + " handlers.");
-
- _userCommandHandler = UserCommandHandler.getInstance();
- _userCommandHandler.registerUserCommandHandler(new Loc());
- _userCommandHandler.registerUserCommandHandler(new Escape());
- _userCommandHandler.registerUserCommandHandler(new Time());
- _userCommandHandler.registerUserCommandHandler(new PartyInfo());
- _log.config("UserCommandHandler: Loaded " + _userCommandHandler.size() + " handlers.");
- _voicedCommandHandler = VoicedCommandHandler.getInstance();
- _voicedCommandHandler.registerVoicedCommandHandler(new stats());
-
- _log.config("VoicedCommandHandler: Loaded " + _voicedCommandHandler.size() + " handlers.");
-
- TaskManager.getInstance();
-
- GmListTable.getInstance();
-
- // read pet stats from db
- L2PetDataTable.getInstance().loadPetsData();
-
- Universe.getInstance();
-
- QuestManager.getInstance();
-
- CastleManager.getInstance();
-
- MercTicketManager.getInstance();
-
- BoatManager.getInstance();
-
- _shutdownHandler = Shutdown.getInstance();
- Runtime.getRuntime().addShutdownHook(_shutdownHandler);
+ _singletons = new Singletons(); // load all single-instance data that server needs and keep it
+ Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
try
{
- _doorTable.getDoor(24190001).openMe();
- _doorTable.getDoor(24190002).openMe();
- _doorTable.getDoor(24190003).openMe();
- _doorTable.getDoor(24190004).openMe();
- _doorTable.getDoor(23180001).openMe();
- _doorTable.getDoor(23180002).openMe();
- _doorTable.getDoor(23180003).openMe();
- _doorTable.getDoor(23180004).openMe();
- _doorTable.getDoor(23180005).openMe();
- _doorTable.getDoor(23180006).openMe();
-
- _doorTable.checkAutoOpen();
+ DoorTable test=DoorTable.getInstance();
+ test.getDoor(24190001).openMe();
+ test.getDoor(24190002).openMe();
+ test.getDoor(24190003).openMe();
+ test.getDoor(24190004).openMe();
+ test.getDoor(23180001).openMe();
+ test.getDoor(23180002).openMe();
+ test.getDoor(23180003).openMe();
+ test.getDoor(23180004).openMe();
+ test.getDoor(23180005).openMe();
+ test.getDoor(23180006).openMe();
+ test.checkAutoOpen();
}
catch (NullPointerException e)
{
@@ -478,7 +132,7 @@
// Initialize config
Config.load();
- L2DatabaseFactory.getInstance();
+
gameServer = new GameServer();
if ( Config.IS_TELNET_ENABLED ) {
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/GameTimeController.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/GameTimeController.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/GameTimeController.java (working copy)
@@ -54,7 +54,7 @@
private static List<L2Character> movingObjects = new FastList<L2Character>();
- protected TimerThread _timer;
+ protected static TimerThread _timer;
/**
* one ingame day is 240 real minutes
@@ -167,7 +167,7 @@
public TimerThread()
{
- super("TimerThread");
+ super("GameTimeController");
setDaemon(true);
setPriority(MAX_PRIORITY);
_stop = false;
@@ -177,11 +177,15 @@
public void run()
{
try {
+ int _oldTicks;
for (;;)
{
long runtime = System.currentTimeMillis() - _gameStartTime;
+ _oldTicks=_gameTicks;
_gameTicks = (int)(runtime / MILLIS_IN_TICK);
- moveObjects();
+ if(_oldTicks!=_gameTicks) moveObjects();
+ else yield();
+
runtime = System.currentTimeMillis() - _gameStartTime;
int sleepTime = 1 + MILLIS_IN_TICK - ((int)runtime) % MILLIS_IN_TICK;
sleep( sleepTime );
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/ItemTable.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/ItemTable.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/ItemTable.java (working copy)
@@ -29,7 +29,7 @@
import javolution.util.FastMap;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.idfactory.IdFactory;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Object;
@@ -193,10 +193,9 @@
_armors = new FastMap<Integer, L2Armor>();
_weapons = new FastMap<Integer, L2Weapon>();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open(false);
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
for (String selectQuery : SQL_ITEM_SELECTS)
{
PreparedStatement statement = con.prepareStatement(selectQuery);
@@ -227,7 +226,7 @@
{
_log.log(Level.WARNING, "data error on item: ", e);
}
- finally { try { con.close(); } catch (Exception e) {} }
+ finally { sql.Close(con); }
for (L2Armor armor : SkillsEngine.getInstance().loadArmors(armorData))
{
@@ -700,7 +699,7 @@
|| item.getItemId() == 3500 || item.getItemId() == 3501 || item.getItemId() == 3502 // hatchlings
|| item.getItemId() == 4422 || item.getItemId() == 4423 || item.getItemId() == 4424) // striders
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
/* con = L2DatabaseFactory.getInstance().getConnection();
@@ -721,7 +720,6 @@
}
*/
// Delete the pet in db
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("DELETE FROM pets WHERE item_obj_id=?");
statement.setInt(1, item.getObjectId());
statement.execute();
@@ -726,9 +724,11 @@
statement.setInt(1, item.getObjectId());
statement.execute();
statement.close();
+ sql.Commit(con);
}
- catch (Exception e)
+ catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.log(Level.WARNING, "could not restore pet objectid:", e);
}
finally
@@ -733,7 +733,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/SelectorThread.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/SelectorThread.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/SelectorThread.java (working copy)
@@ -203,7 +203,7 @@
if (Config.ASSERT) assert b.position() == 0;
if (Config.ASSERT) assert b.limit() == WRITE_BUF_SIZE;
writeBuffers[numWriteBuffers++] = b;
- }
+ } else b=null;
}
/** Main loop, see class description */
@@ -317,6 +317,7 @@
if (b != null) {
int r = ((SocketChannel)sk.channel()).write(b);
if (r < 0) {
+ _log.warning("could not write data to channel, closing client");
closeClient(con);
return;
}
@@ -589,6 +590,13 @@
continue;
}
+ if (msg.getTime()>0 &&(System.currentTimeMillis()-msg.getTime()>2000)) // no packet should live that long
+ {
+ _log.warning("removed strange, suspicious packet lagging >1 second not removed but consider it");
+ _log.warning("details: type="+msg.getType()+" packet time:"+msg.getTime() + " packet lived for:"+(System.currentTimeMillis()-msg.getTime())+" ms");
+ //iter.remove();
+ //continue;
+ }
Connection con = msg.getConnection();
SelectionKey sk = con.getChannel().keyFor(_selector);
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/cache/CrestCache.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/cache/CrestCache.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/cache/CrestCache.java (working copy)
@@ -15,8 +15,8 @@
import java.util.logging.Logger;
import javolution.util.FastMap;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ClanTable;
import net.sf.l2j.gameserver.idfactory.BitSetIDFactory;
import net.sf.l2j.gameserver.model.L2Clan;
@@ -135,11 +135,10 @@
file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_"+newId+".bmp"));
_log.info("Renamed Clan crest to new format: Crest_"+newId+".bmp");
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
statement.setInt(1, newId);
statement.setInt(2, clan.getClanId());
@@ -145,9 +144,11 @@
statement.setInt(2, clan.getClanId());
statement.executeUpdate();
statement.close();
+ con.commit();
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not update the crest id:"+e.getMessage());
}
finally
@@ -152,7 +153,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
clan.setCrestId(newId);
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (working copy)
@@ -22,6 +22,7 @@
import java.nio.ByteBuffer;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.logging.Logger;
import net.sf.l2j.Base64;
@@ -26,7 +27,7 @@
import net.sf.l2j.Base64;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.Announcements;
import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.LoginServerThread;
@@ -223,9 +224,8 @@
*/
private void notifyFriends(L2PcInstance cha)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement;
statement = con.prepareStatement("SELECT char_id,friend_name from character_friends where char_id=? or friend_name=?");
statement.setInt(1, cha.getObjectId());
@@ -251,10 +251,12 @@
if (friend != null) //friend logged in.
friend.sendPacket(sm);
}
- } catch (Exception e) {
+ sql.Commit(con);
+ } catch (SQLException e) {
+ sql.Rollback(con,e);
_log.warning("could not restore friend data:"+e);
} finally {
- try {con.close();} catch (Exception e){}
+ sql.Close(con);
}
cha.updateEffectIcons();
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestExSetPledgeCrestLarge.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestExSetPledgeCrestLarge.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestExSetPledgeCrestLarge.java (working copy)
@@ -24,7 +24,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.cache.CrestCache;
import net.sf.l2j.gameserver.idfactory.BitSetIDFactory;
@@ -95,11 +95,10 @@
crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
}
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?");
statement.setInt(1, newId);
statement.setInt(2, clan.getClanId());
@@ -105,9 +104,11 @@
statement.setInt(2, clan.getClanId());
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not update the large crest id:"+e.getMessage());
}
finally
@@ -112,7 +113,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
clan.setCrestLargeId(newId);
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetAllyCrest.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetAllyCrest.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetAllyCrest.java (working copy)
@@ -24,7 +24,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ClanTable;
import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.cache.CrestCache;
@@ -31,6 +30,7 @@
import net.sf.l2j.gameserver.idfactory.BitSetIDFactory;
import net.sf.l2j.gameserver.model.L2Clan;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.sql;
/**
* This class ...
@@ -80,11 +80,10 @@
crestCache.removeAllyCrest(leaderclan.getAllyCrestId());
}
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?");
statement.setInt(1, newId);
statement.setInt(2, leaderclan.getAllyId());
@@ -90,9 +89,11 @@
statement.setInt(2, leaderclan.getAllyId());
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not update the ally crest id:"+e.getMessage());
}
finally
@@ -97,7 +98,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetPledgeCrest.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetPledgeCrest.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/RequestSetPledgeCrest.java (working copy)
@@ -23,8 +23,7 @@
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
-
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.cache.CrestCache;
import net.sf.l2j.gameserver.idfactory.BitSetIDFactory;
@@ -83,11 +82,10 @@
return;
}
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
statement.setInt(1, newId);
statement.setInt(2, clan.getClanId());
@@ -93,9 +91,11 @@
statement.setInt(2, clan.getClanId());
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("could not update the crest id:"+e.getMessage());
}
finally
@@ -100,7 +100,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
clan.setCrestId(newId);
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/ValidatePosition.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/ValidatePosition.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/clientpackets/ValidatePosition.java (working copy)
@@ -166,7 +166,15 @@
}
}
+ try
+ {
activeChar.getKnownList().updateKnownObjects();
+ } catch (Exception e)
+ {
+ _log.warning("clientpackets.ValidatePosition - updateKnownObjects exception: "+e);
+ e.printStackTrace();
+ }
+
// // check for objects that are now out of range
// activeChar.updateKnownCounter += 1;
// if (activeChar.updateKnownCounter >3)
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBanChat.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBanChat.java (revision 1663)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminBanChat.java (working copy)
@@ -21,9 +21,9 @@
import java.sql.PreparedStatement;
import java.util.StringTokenizer;
import java.util.logging.Logger;
-
+import java.sql.SQLException;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.GMAudit;
import net.sf.l2j.gameserver.model.L2Object;
@@ -114,11 +114,9 @@
private void setCharacterAccessLevel(String user, L2PcInstance player, int banLevel)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
-
String stmt = "UPDATE characters SET characters.accesslevel = ? WHERE characters.char_name=?";
PreparedStatement statement = con.prepareStatement(stmt);
statement.setInt(1, banLevel);
@@ -125,6 +123,7 @@
statement.setString(2, user);
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
L2PcInstance userInstance = L2World.getInstance().getPlayer(user);
if (userInstance != null)
@@ -134,9 +133,9 @@
sm.addString("Character Access Level for "+user+" set to "+banLevel+".");
player.sendPacket(sm);
}
- catch (Exception e)
+ catch (SQLException e)
{
- //System.out.println("Error in sql");
+ sql.Rollback(con,e);
_log.warning("Could not set accessLevl:"+e);
}
finally
@@ -141,7 +140,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/CompactionIDFactory.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/CompactionIDFactory.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/CompactionIDFactory.java (working copy)
@@ -33,8 +33,8 @@
import java.sql.SQLException;
import java.util.logging.Logger;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
/**
* This class ...
@@ -54,13 +54,12 @@
_curOID = FIRST_OID;
_freeSize = 0;
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
- //con.createStatement().execute("drop table if exists tmp_obj_id");
+ int[] tmp_obj_ids = extractUsedObjectIDTable();
- int[] tmp_obj_ids = extractUsedObjectIDTable();
+ if(Config.ASSERT) assert(tmp_obj_ids!=null);
int N = tmp_obj_ids.length;
for (int idx = 0; idx < N; idx++)
@@ -78,7 +77,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/IdFactory.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/IdFactory.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/IdFactory.java (working copy)
@@ -23,8 +23,8 @@
import java.sql.Statement;
import java.util.logging.Logger;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
/**
* This class ...
@@ -111,12 +111,13 @@
*/
private void setAllCharacterOffline()
{
- java.sql.Connection con2 = null;
+ java.sql.Connection con2 = sql.Open();
try
{
- con2 = L2DatabaseFactory.getInstance().getConnection();
Statement s2 = con2.createStatement();
s2.executeUpdate("update characters set online=0");
+ sql.Commit(con2);
+
_log.info("Updated characters online status.");
}
catch (SQLException e)
@@ -121,16 +122,11 @@
}
catch (SQLException e)
{
+ sql.Rollback(con2,e);
}
finally
{
- try
- {
- con2.close();
- }
- catch (Exception e)
- {
- }
+ sql.Close(con2);
}
}
@@ -139,12 +135,11 @@
*/
private void cleanUpDB()
{
- java.sql.Connection conn = null;
+ java.sql.Connection con = sql.Open();
try
{
int cleanCount = 0;
- conn = L2DatabaseFactory.getInstance().getConnection();
- Statement stmt = conn.createStatement();
+ Statement stmt = con.createStatement();
cleanCount += stmt.executeUpdate("DELETE FROM clan_data WHERE clan_data.leader_id NOT IN (SELECT obj_Id FROM characters);");
cleanCount += stmt.executeUpdate("DELETE FROM character_skills WHERE character_skills.char_obj_id NOT IN (SELECT obj_Id FROM characters);");
@@ -156,8 +151,9 @@
cleanCount += stmt.executeUpdate("DELETE FROM pets WHERE pets.item_obj_id NOT IN (SELECT object_id FROM items);");
stmt.executeUpdate("UPDATE characters SET clanid=0 WHERE characters.clanid NOT IN (SELECT clan_id FROM clan_data);");
cleanCount += stmt.executeUpdate("DELETE FROM siege_clans WHERE siege_clans.clan_id NOT IN (SELECT clan_id FROM clan_data);");
-
stmt.close();
+
+ sql.Commit(con);
_log.info("Cleaned " + cleanCount + " elements from database.");
}
catch (SQLException e)
@@ -162,16 +158,12 @@
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
+ _log.info("Error while cleaning old data from database.");
}
finally
{
- try
- {
- conn.close();
- }
- catch (Exception e)
- {
- }
+ sql.Close(con);
}
}
@@ -180,56 +172,71 @@
* @return
* @throws SQLException
*/
- protected int[] extractUsedObjectIDTable() throws SQLException
- {
- java.sql.Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
-
- //create a temporary table
- Statement s = con.createStatement();
- try
- {
- s.executeUpdate("drop table temporaryObjectTable");
- }
- catch (SQLException e)
- {
- }
-
- s.executeUpdate("create table temporaryObjectTable" + " (object_id int NOT NULL PRIMARY KEY)");
-
- s.executeUpdate("insert into temporaryObjectTable (object_id)" + " select obj_id from characters");
- s.executeUpdate("insert into temporaryObjectTable (object_id)" + " select object_id from items");
- s.executeUpdate("insert into temporaryObjectTable (object_id)" + " select clan_id from clan_data");
-// s.executeUpdate("insert into temporaryObjectTable (object_id)" + " select crest_id from clan_data where crest_id > 0");
-
- ResultSet result = s.executeQuery("select count(object_id) from temporaryObjectTable");
-
- result.next();
- int size = result.getInt(1);
- int[] tmp_obj_ids = new int[size];
- // System.out.println("tmp table size: " + tmp_obj_ids.length);
- result.close();
-
- result = s.executeQuery("select object_id from temporaryObjectTable ORDER BY object_id");
-
- int idx = 0;
- while (result.next())
- {
- tmp_obj_ids[idx++] = result.getInt(1);
- }
-
- result.close();
- s.close();
-
- return tmp_obj_ids;
- }
- finally
- {
- try { con.close(); } catch (Exception e) {}
- }
- }
+ protected int[] extractUsedObjectIDTable()
+ {
+ int[] tmp_obj_ids = null;
+ java.sql.Connection con = sql.Open();
+ Statement s = null;
+
+ // attempt to remove table if it exists - safely
+ // yes, I know temporary tables don't support transactions, but in that case
+ // commit will be silently ignored so no harm done
+ try
+ {
+ s=con.createStatement();
+ s.executeUpdate("drop table temporaryObjectTable");
+ sql.Commit(con);
+ }
+ catch (SQLException e)
+ {
+ sql.Rollback(con, e);
+ }
+
+ try
+ {
+ s.executeUpdate("create table temporaryObjectTable"
+ + " (object_id int NOT NULL PRIMARY KEY)");
+
+ s.executeUpdate("insert into temporaryObjectTable (object_id)"
+ + " select obj_id from characters");
+ s.executeUpdate("insert into temporaryObjectTable (object_id)"
+ + " select object_id from items");
+ s.executeUpdate("insert into temporaryObjectTable (object_id)"
+ + " select clan_id from clan_data");
+ // s.executeUpdate("insert into temporaryObjectTable (object_id)" + " select crest_id from clan_data where crest_id > 0");
+
+ sql.Commit(con);
+ ResultSet result = s.executeQuery("select count(object_id) from temporaryObjectTable");
+
+ result.next();
+ int size = result.getInt(1);
+ tmp_obj_ids = new int[size];
+ // System.out.println("tmp table size: " + tmp_obj_ids.length);
+ result.close();
+
+ result = s.executeQuery("select object_id from temporaryObjectTable ORDER BY object_id");
+
+ int idx = 0;
+ while (result.next())
+ {
+ tmp_obj_ids[idx++] = result.getInt(1);
+ }
+
+ result.close();
+ s.close();
+ sql.Commit(con);
+ }
+ catch (SQLException e)
+ {
+ sql.Rollback(con, e);
+ }
+
+ finally
+ {
+ sql.Close(con);
+ }
+ return tmp_obj_ids;
+ }
public boolean isInitialized() {
return initialized;
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/StackIDFactory.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/StackIDFactory.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/idfactory/StackIDFactory.java (working copy)
@@ -25,7 +25,7 @@
import java.util.logging.Logger;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
/**
* This class ...
@@ -47,10 +47,9 @@
_curOID = FIRST_OID;
_tempOID = FIRST_OID;
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
//con.createStatement().execute("drop table if exists tmp_obj_id");
int[] tmp_obj_ids = extractUsedObjectIDTable();
@@ -77,7 +76,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/ItemContainer.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/ItemContainer.java (revision 1663)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/ItemContainer.java (working copy)
@@ -155,7 +155,7 @@
// Updates database
item.updateDatabase();
}
- // If item hasn't be found in inventory, create new one
+ // If item hasn't been found in inventory, create new one
else
for(int i = 0; i < count; i++)
{
@@ -330,8 +330,14 @@
item.setCount(process, item.getCount() - count, actor, reference);
item.setLastChange(L2ItemInstance.MODIFIED);
}
- // Directly drop entire item
- else return destroyItem(process, item, actor, reference);
+ else
+ {
+ if (item.getCount() < count) {
+ _log.warning("ItemContainer.destroyItemByItemId error: requested to destroy more items than available");
+ _log.warning("Proceeding with destroying what we have available");
+ }
+ return destroyItem(process, item, actor, reference);
+ }
item.updateDatabase();
refreshWeight();
@@ -396,7 +402,7 @@
for (L2ItemInstance item : _items)
{
if (item != null)
- item.updateDatabase();
+ item.updateDatabase();
}
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2ItemInstance.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2ItemInstance.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2ItemInstance.java (working copy)
@@ -589,7 +589,7 @@
*/
public void updateDatabase()
{
- if(isWear()) //avoid saving weared items
+ if(isWear()) //avoid saving worn items
{
return;
}
@@ -714,6 +714,7 @@
try
{
con = L2DatabaseFactory.getInstance().getConnection();
+ con.setAutoCommit(false);
PreparedStatement statement = con.prepareStatement(
"INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,price_sell,price_buy,object_id,custom_type1,custom_type2) " +
"VALUES (?,?,?,?,?,?,?,?,?,?,?)");
@@ -730,12 +731,14 @@
statement.setInt(11, _type2);
statement.executeUpdate();
+ statement.close();
+ con.commit();
_existsInDb = true;
_storedInDb = true;
- statement.close();
} catch (Exception e) {
_log.log(Level.SEVERE, "Could not insert item "+getObjectId()+" into DB: Reason: " +
"Duplicate itemId" );
+ try {con.rollback();} catch (Exception e2) { _log.warning("rollback failed");};
} finally {
try { con.close(); } catch (Exception e) {}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2Skill.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2Skill.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/L2Skill.java (working copy)
@@ -373,7 +373,6 @@
else
_ispotion = false;
-
_displayId = set.getInteger("displayId", _id);
_name = set.getString("name");
_operateType = set.getEnum("operateType", SkillOpType.class);
@@ -461,6 +460,12 @@
return _ispotion;
}
+ public final boolean isCraftingSkillType()
+ {
+ if (getSkillType() == SkillType.DWARVEN_CRAFT || getSkillType() == SkillType.COMMON_CRAFT) return true;
+ return false;
+ }
+
public final int getArmorsAllowed()
{
return _armorsAllowed;
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2MerchantInstance.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2MerchantInstance.java (revision 1663)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2MerchantInstance.java (working copy)
@@ -33,8 +33,8 @@
import javolution.util.FastList;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ClientScheduler;
import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.ItemTable;
@@ -733,10 +733,10 @@
private static synchronized boolean addBidder(int merchant_id, int player_id, BidderDbType bt, int bid, String name)
{
- boolean ok;
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
+
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement1 = con.prepareStatement(
"INSERT INTO merchant_lease (merchant_id, player_id, bid, type, player_name)" +
" VALUES (?,?,?,?,?)");
@@ -747,11 +747,13 @@
statement1.setString(5, name);
ok = statement1.executeUpdate() > 0;
statement1.close();
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
- return false;
+ ok=false;
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return ok;
}
@@ -758,10 +760,10 @@
private static synchronized boolean updateBidder(int merchant_id, int player_id, BidderDbType bt, int bid)
{
- boolean ok;
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
+
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement1 = con.prepareStatement(
"UPDATE merchant_lease SET bid=?" +
" WHERE merchant_id = ? AND player_id = ? AND type = ?");
@@ -771,11 +773,13 @@
statement1.setInt(4, bt.ordinal());
ok = statement1.executeUpdate() > 0;
statement1.close();
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
- return false;
+ ok=false;
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return ok;
}
@@ -782,9 +786,10 @@
private static synchronized boolean removeBidder(int merchant_id, int player_id, BidderDbType bt)
{
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
+
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement1 = con.prepareStatement(
"DELETE FROM merchant_lease" +
" WHERE merchant_id = ? AND player_id = ? AND type = ?");
@@ -793,13 +798,15 @@
statement1.setInt(3, bt.ordinal());
statement1.executeUpdate();
statement1.close();
+ sql.Commit(con);
+ ok=true;
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
- return false;
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
- return true;
+ return ok;
}
private static synchronized boolean returnItems(int merchant_id, int player_id)
@@ -804,10 +811,10 @@
private static synchronized boolean returnItems(int merchant_id, int player_id)
{
- boolean ok;
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
+
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement1 = con.prepareStatement(
"UPDATE items" +
" SET loc='WAREHOUSE', loc_data=0 " +
@@ -816,11 +823,13 @@
statement1.setInt(2, player_id);
ok = statement1.executeUpdate() > 0;
statement1.close();
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
- return false;
+ ok=false;
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return ok;
}
@@ -827,10 +836,8 @@
private static void loadBidders()
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try {
- con = L2DatabaseFactory.getInstance().getConnection();
-
PreparedStatement statement;
ResultSet rset;
@@ -853,11 +860,12 @@
}
rset.close();
statement.close();
-
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
@@ -864,10 +872,9 @@
private void loadMerchant()
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
+
try {
- con = L2DatabaseFactory.getInstance().getConnection();
-
PreparedStatement statement = con.prepareStatement("SELECT merchant_id, player_id, bid, type, player_name FROM merchant_lease WHERE merchant_id = ?");
statement.setInt(1, getTemplate().npcId);
ResultSet rset = statement.executeQuery();
@@ -891,10 +898,12 @@
}
rset.close();
statement.close();
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
@@ -901,10 +910,8 @@
private synchronized void loadItems(int player_id)
{
leaseList = new FastList<L2ItemInstance>();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try {
- con = L2DatabaseFactory.getInstance().getConnection();
-
PreparedStatement statement;
ResultSet rset;
@@ -926,10 +933,12 @@
}
rset.close();
statement.close();
+ sql.Commit(con);
} catch (SQLException e) {
+ sql.Rollback(con,e);
_log.log(Level.SEVERE, "", e);
} finally {
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 1663)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
@@ -1911,16 +1911,16 @@
sm.addNumber(count);
sendPacket(sm);
}
-
- if(count>0)
- {
- _inventory.addAdena(process, count, this, reference);
- // Send update packet
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(_inventory.getAdenaInstance());
- sendPacket(iu);
- }
+ if(count>0)
+ {
+ _inventory.addAdena(process, count, this, reference);
+
+ // Send update packet
+ InventoryUpdate iu = new InventoryUpdate();
+ iu.addItem(_inventory.getAdenaInstance());
+ sendPacket(iu);
+ }
}
@@ -1957,98 +1957,98 @@
sendPacket(sm);
}
}
-
+
return true;
}
- /**
- * Adds item to inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
+ /**
+ * Adds item to inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
* @param process : String Identifier of process triggering this action
- * @param item : L2ItemInstance to be added
+ * @param item : L2ItemInstance to be added
* @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
* @param sendMessage : boolean Specifies whether to send message to Client about this action
- */
- public void addItem(String process, L2ItemInstance item, L2Object reference, boolean sendMessage)
- {
+ */
+ public void addItem(String process, L2ItemInstance item, L2Object reference, boolean sendMessage)
+ {
if(item.getCount()>0)
{
- // Sends message to client if requested
- if (sendMessage)
+ // Sends message to client if requested
+ if (sendMessage)
{
- if (item.getCount() > 1)
- {
- SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1_S2);
- sm.addItemName(item.getItemId());
- sm.addNumber(item.getCount());
- sendPacket(sm);
- }
- else
- {
- SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1);
- sm.addItemName(item.getItemId());
- sendPacket(sm);
- }
+ if (item.getCount() > 1)
+ {
+ SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1_S2);
+ sm.addItemName(item.getItemId());
+ sm.addNumber(item.getCount());
+ sendPacket(sm);
+ }
+ else
+ {
+ SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1);
+ sm.addItemName(item.getItemId());
+ sendPacket(sm);
+ }
}
-
- // Add the item to inventory
- L2ItemInstance newitem = _inventory.addItem(process, item, this, reference);
-
- // Send inventory update packet
+
+ // Add the item to inventory
+ L2ItemInstance newitem = _inventory.addItem(process, item, this, reference);
+
+ // Send inventory update packet
InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(newitem);
- sendPacket(playerIU);
-
- // Update current load as well
- StatusUpdate su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
+ playerIU.addItem(newitem);
+ sendPacket(playerIU);
+
+ // Update current load as well
+ StatusUpdate su = new StatusUpdate(getObjectId());
+ su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
+ sendPacket(su);
}
- }
+ }
- /**
- * Adds item to Inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
+ /**
+ * Adds item to Inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
* @param process : String Identifier of process triggering this action
- * @param itemId : int Item Identifier of the item to be added
- * @param count : int Quantity of items to be added
+ * @param itemId : int Item Identifier of the item to be added
+ * @param count : int Quantity of items to be added
* @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
* @param sendMessage : boolean Specifies whether to send message to Client about this action
- */
- public void addItem(String process, int itemId, int count, L2Object reference, boolean sendMessage)
- {
+ */
+ public void addItem(String process, int itemId, int count, L2Object reference, boolean sendMessage)
+ {
if(count>0)
{
- // Sends message to client if requested
- if (sendMessage)
+ // Sends message to client if requested
+ if (sendMessage)
{
- if (count > 1)
- {
- SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1_S2);
- sm.addItemName(itemId);
- sm.addNumber(count);
- sendPacket(sm);
- }
- else
- {
- SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1);
- sm.addItemName(itemId);
- sendPacket(sm);
- }
+ if (count > 1)
+ {
+ SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1_S2);
+ sm.addItemName(itemId);
+ sm.addNumber(count);
+ sendPacket(sm);
+ }
+ else
+ {
+ SystemMessage sm = new SystemMessage(SystemMessage.YOU_PICKED_UP_S1);
+ sm.addItemName(itemId);
+ sendPacket(sm);
+ }
}
-
- // Add the item to inventory
- L2ItemInstance item = _inventory.addItem(process, itemId, count, this, reference);
-
- // Send inventory update packet
+
+ // Add the item to inventory
+ L2ItemInstance item = _inventory.addItem(process, itemId, count, this, reference);
+
+ // Send inventory update packet
InventoryUpdate playerIU = new InventoryUpdate();
- playerIU.addItem(item);
- sendPacket(playerIU);
-
- // Update current load as well
- StatusUpdate su = new StatusUpdate(getObjectId());
- su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
- sendPacket(su);
+ playerIU.addItem(item);
+ sendPacket(playerIU);
+
+ // Update current load as well
+ StatusUpdate su = new StatusUpdate(getObjectId());
+ su.addAttribute(StatusUpdate.CUR_LOAD, getCurrentLoad());
+ sendPacket(su);
}
- }
+ }
/**
* Destroy item from inventory and send a Server->Client InventoryUpdate packet to the L2PcInstance.
@@ -2180,20 +2180,20 @@
for (L2ItemInstance item : getInventory().getItems())
{
if (item.isWear())
- {
-// if (item.isEquipped()) getInventory().unEquipItemInSlotAndRecord(item.getEquipSlot());
- if (_inventory.destroyItem(process, item, this, reference) == null)
{
- _log.warning("Player " + getName() + " can't destroy weared item: " + item.getName() + "[ " + item.getObjectId() + " ]");
- continue;
+// if (item.isEquipped()) getInventory().unEquipItemInSlotAndRecord(item.getEquipSlot());
+ if (_inventory.destroyItem(process, item, this, reference) == null)
+ {
+ _log.warning("Player " + getName() + " can't destroy weared item: " + item.getName() + "[ " + item.getObjectId() + " ]");
+ continue;
+ }
+
+ // Send Unequip packet
+ SystemMessage sm = new SystemMessage(0x1a1);
+ sm.addItemName(item.getItemId());
+ sendPacket(sm);
+// playerIU.addRemovedItem(item);
}
-
- // Send Unequip packet
- SystemMessage sm = new SystemMessage(0x1a1);
- sm.addItemName(item.getItemId());
- sendPacket(sm);
-// playerIU.addRemovedItem(item);
- }
}
// Send inventory update packet
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/knownlist/ObjectKnownList.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/knownlist/ObjectKnownList.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/model/actor/knownlist/ObjectKnownList.java (working copy)
@@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
+import java.util.logging.Logger;
import net.sf.l2j.gameserver.model.L2Character;
@@ -17,7 +18,8 @@
public class ObjectKnownList
{
- // =========================================================
+ private static Logger _log = Logger.getLogger(ObjectKnownList.class.getName());
+ // =========================================================
// Data Field
private L2Object[] _ActiveObject; // Use array as a dirty trick to keep object as byref instead of byval
private Set<L2Object> _KnownObjects;
@@ -71,8 +73,21 @@
// Only bother updating knownobjects for L2Character; don't for L2Object
if (getActiveObject() instanceof L2Character)
{
- findCloseObjects();
+ try {
+ findCloseObjects();
+ } catch (Exception e)
+ {
+ _log.warning("exception in call to findCloseObjects() "+e);
+ e.printStackTrace();
+ }
+ try
+ {
forgetObjects();
+ } catch (Exception e)
+ {
+ _log.warning("exception in call to forgetObjects() "+e);
+ e.printStackTrace();
+ }
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/TaskManager.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/TaskManager.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/TaskManager.java (working copy)
@@ -22,7 +22,7 @@
import javolution.util.FastList;
import javolution.util.FastMap;
-import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.sql;
import net.sf.l2j.gameserver.ClientScheduler;
import net.sf.l2j.gameserver.taskmanager.tasks.TaskCleanUp;
import net.sf.l2j.gameserver.taskmanager.tasks.TaskJython;
@@ -78,11 +78,10 @@
_lastActivation = System.currentTimeMillis();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[1]);
statement.setLong(1, _lastActivation);
statement.setInt(2, _id);
@@ -88,9 +87,11 @@
statement.setInt(2, _id);
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("cannot updated the Global Task " + _id + ": " + e.getMessage());
}
finally
@@ -95,7 +96,7 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
if (_type == TYPE_SHEDULED || _type == TYPE_TIME)
@@ -183,11 +184,10 @@
private void startAllTasks()
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
try {
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[0]);
ResultSet rset = statement.executeQuery();
@@ -211,7 +211,6 @@
rset.close();
rset.close();
-
} catch (Exception e) {
_log.severe("error while loading Global Task table " + e);
e.printStackTrace();
@@ -317,11 +316,11 @@
public static boolean addUniqueTask(String task, TaskTypes type, String param1, String param2, String param3, long lastActivation)
{
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[2]);
statement.setString(1, task);
ResultSet rset = statement.executeQuery();
@@ -340,11 +339,11 @@
rset.close();
statement.close();
-
- return true;
+ ok=sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("cannot add the unique task: " + e.getMessage());
}
finally
@@ -349,10 +348,10 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
- return false;
+ return ok;
}
public static boolean addTask(String task, TaskTypes type, String param1, String param2, String param3)
@@ -362,11 +361,11 @@
public static boolean addTask(String task, TaskTypes type, String param1, String param2, String param3, long lastActivation)
{
- java.sql.Connection con = null;
+ boolean ok=false;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[3]);
statement.setString(1, task);
statement.setString(2, type.toString());
@@ -377,10 +376,11 @@
statement.execute();
statement.close();
- return true;
+ ok=sql.Commit(con);
}
catch (SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("cannot add the task: " + e.getMessage());
}
finally
@@ -385,10 +385,10 @@
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
- return false;
+ return ok;
}
}
Index: C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/tasks/TaskCleanUp.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/tasks/TaskCleanUp.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/gameserver/taskmanager/tasks/TaskCleanUp.java (working copy)
@@ -23,8 +23,8 @@
public void onTimeElapsed(ExecutedTask task)
{
- System.runFinalization();
- System.gc();
+ //System.runFinalization();
+ //System.gc();
}
public void initializate()
Index: C:/workspace/c4/java/net/sf/l2j/loginserver/GameServerTable.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/loginserver/GameServerTable.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/loginserver/GameServerTable.java (working copy)
@@ -48,8 +48,8 @@
import javolution.xml.pull.XmlPullParserException;
import javolution.xml.pull.XmlPullParserImpl;
+import net.sf.l2j.sql;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.loginserver.gameserverpackets.ServerStatus;
import net.sf.l2j.loginserver.serverpackets.ServerList;
@@ -136,7 +136,7 @@
_gameServerList = new FastList<GameServer>();
serverNames = new FastMap<Integer, String>();
loadServerNames();
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
PreparedStatement statement = null;
int id = 0;
int number = 0;
@@ -143,7 +143,6 @@
int previousID = 0;
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM gameservers");
ResultSet rset = statement.executeQuery();
while(rset.next())
@@ -168,8 +167,8 @@
}
finally
{
- try { con.close();} catch (Exception e2) {}
- try { statement.close();} catch (Exception e2) {}
+ try { statement.close();} catch (Exception e2) {}
+ sql.Close(con);
}
if (Config.DEBUG)
{
@@ -349,11 +348,10 @@
public void createServer(GameServer gs)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
PreparedStatement statement = null;
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(
"INSERT INTO gameservers " +
"(hexid,server_id,host)" +
@@ -370,9 +368,11 @@
}
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch(SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("SQL error while saving gameserver :"+e);
}
finally
@@ -377,7 +377,7 @@
}
finally
{
- try { con.close();} catch (Exception e) {}
+ sql.Close(con);
try { statement.close();} catch (Exception e) {}
}
}
@@ -404,11 +404,10 @@
public void deleteServer(int id)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
PreparedStatement statement = null;
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(
"DELETE FROM gameservers WHERE gameservers.server_id=?");
statement.setInt(1, id);
@@ -414,9 +413,11 @@
statement.setInt(1, id);
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch(SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("SQL error while deleting gameserver :"+e);
}
finally
@@ -421,7 +422,7 @@
}
finally
{
- try { con.close();} catch (Exception e) {}
+ sql.Close(con);
try { statement.close();} catch (Exception e) {}
}
}
@@ -534,11 +535,10 @@
*/
public void createServer(GameServerThread thread)
{
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
PreparedStatement statement = null;
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(
"INSERT INTO gameservers " +
"(hexid,server_id,host)" +
@@ -548,9 +548,11 @@
statement.setString(3, thread.getGameExternalHost());
statement.executeUpdate();
statement.close();
+ sql.Commit(con);
}
catch(SQLException e)
{
+ sql.Rollback(con,e);
_log.warning("SQL error while saving gameserver :"+e);
}
finally
@@ -555,7 +557,7 @@
}
finally
{
- try { con.close();} catch (Exception e) {}
+ sql.Close(con);
try { statement.close();} catch (Exception e) {}
}
}
Index: C:/workspace/c4/java/net/sf/l2j/status/LoginStatusThread.java
===================================================================
--- C:/workspace/c4/java/net/sf/l2j/status/LoginStatusThread.java (revision 1654)
+++ C:/workspace/c4/java/net/sf/l2j/status/LoginStatusThread.java (working copy)
@@ -19,9 +19,9 @@
import java.util.Properties;
import java.util.logging.Logger;
+import net.sf.l2j.sql;
import net.sf.l2j.Base64;
import net.sf.l2j.Config;
-import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.loginserver.GameServerTable;
import net.sf.l2j.loginserver.LoginController;
import net.sf.l2j.loginserver.LoginServer;
@@ -202,10 +202,9 @@
{
if(!LoginController.getInstance().isGM(login))
return false;
- java.sql.Connection con = null;
+ java.sql.Connection con = sql.Open();
try
{
- con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
statement.setString(1, login);
ResultSet rset = statement.executeQuery();
@@ -217,14 +216,16 @@
return true;
}
statement.close();
+ sql.Commit(con);
}
- catch(SQLException sqle)
+ catch(SQLException e)
{
- sqle.printStackTrace();
+ sql.Rollback(con,e);
+ e.printStackTrace();
}
finally
{
- try { con.close(); } catch (Exception e) {}
+ sql.Close(con);
}
return false;
}