Created
March 7, 2014 17:53
-
-
Save Pandragon/9416377 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Eclipse Workspace Patch 1.0 | |
#P L2J_Server_BETA | |
Index: dist/game/config/L2JMods.properties | |
=================================================================== | |
--- dist/game/config/L2JMods.properties (revision 6469) | |
+++ dist/game/config/L2JMods.properties (working copy) | |
@@ -291,6 +291,10 @@ | |
#Default: True | |
OfflineDisconnectFinished = True | |
+#Store offline trader transactions in realtime. | |
+#Uses more datatabase resources, but helps if server shuts down unexpectedly. | |
+StoreOfflineTradeInRealtime = True | |
+ | |
# --------------------------------------------------------------------------- | |
# Mana Drugs/Potions | |
# --------------------------------------------------------------------------- | |
Index: java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreBuy.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreBuy.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreBuy.java (working copy) | |
@@ -22,6 +22,7 @@ | |
import javolution.util.FastSet; | |
import com.l2jserver.Config; | |
+import com.l2jserver.gameserver.datatables.OfflineTradersTable; | |
import com.l2jserver.gameserver.enums.PrivateStoreType; | |
import com.l2jserver.gameserver.model.ItemRequest; | |
import com.l2jserver.gameserver.model.L2Object; | |
@@ -153,6 +154,12 @@ | |
return; | |
} | |
+ // Update offline trade record, if realtime saving is enabled | |
+ if (Config.OFFLINE_TRADE_ENABLE && Config.STORE_OFFLINE_TRADE_IN_REALTIME && ((storePlayer.getClient() == null) || storePlayer.getClient().isDetached())) | |
+ { | |
+ OfflineTradersTable.onTransaction(storePlayer, storeList.getItemCount() == 0, false); | |
+ } | |
+ | |
if (storeList.getItemCount() == 0) | |
{ | |
storePlayer.setPrivateStoreType(PrivateStoreType.NONE); | |
Index: java/com/l2jserver/Config.java | |
=================================================================== | |
--- java/com/l2jserver/Config.java (revision 6469) | |
+++ java/com/l2jserver/Config.java (working copy) | |
@@ -759,6 +759,7 @@ | |
public static boolean OFFLINE_SET_NAME_COLOR; | |
public static int OFFLINE_NAME_COLOR; | |
public static boolean OFFLINE_FAME; | |
+ public static boolean STORE_OFFLINE_TRADE_IN_REALTIME; | |
public static boolean L2JMOD_ENABLE_MANA_POTIONS_SUPPORT; | |
public static boolean L2JMOD_DISPLAY_SERVER_TIME; | |
public static boolean WELCOME_MESSAGE_ENABLED; | |
@@ -2513,6 +2514,7 @@ | |
OFFLINE_FAME = L2JModSettings.getBoolean("OfflineFame", true); | |
RESTORE_OFFLINERS = L2JModSettings.getBoolean("RestoreOffliners", false); | |
OFFLINE_MAX_DAYS = L2JModSettings.getInt("OfflineMaxDays", 10); | |
+ STORE_OFFLINE_TRADE_IN_REALTIME = L2JModSettings.getBoolean("StoreOfflineTradeInRealtime", true); | |
OFFLINE_DISCONNECT_FINISHED = L2JModSettings.getBoolean("OfflineDisconnectFinished", true); | |
L2JMOD_ENABLE_MANA_POTIONS_SUPPORT = L2JModSettings.getBoolean("EnableManaPotionSupport", false); | |
Index: java/com/l2jserver/gameserver/network/L2GameClient.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/network/L2GameClient.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/network/L2GameClient.java (working copy) | |
@@ -44,6 +44,7 @@ | |
import com.l2jserver.gameserver.ThreadPoolManager; | |
import com.l2jserver.gameserver.datatables.CharNameTable; | |
import com.l2jserver.gameserver.datatables.ClanTable; | |
+import com.l2jserver.gameserver.datatables.OfflineTradersTable; | |
import com.l2jserver.gameserver.datatables.SecondaryAuthData; | |
import com.l2jserver.gameserver.instancemanager.AntiFeedManager; | |
import com.l2jserver.gameserver.model.CharSelectInfoPackage; | |
@@ -802,6 +803,12 @@ | |
getActiveChar().setOfflineStartTime(System.currentTimeMillis()); | |
} | |
+ // Store trade on exit, if realtime saving is enabled. | |
+ if (Config.STORE_OFFLINE_TRADE_IN_REALTIME) | |
+ { | |
+ OfflineTradersTable.onTransaction(getActiveChar(), false, true); | |
+ } | |
+ | |
final LogRecord record = new LogRecord(Level.INFO, "Entering offline mode"); | |
record.setParameters(new Object[] | |
{ | |
Index: java/com/l2jserver/gameserver/Shutdown.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/Shutdown.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/Shutdown.java (working copy) | |
@@ -204,7 +204,7 @@ | |
try | |
{ | |
- if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS) | |
+ if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS && !Config.STORE_OFFLINE_TRADE_IN_REALTIME) | |
{ | |
OfflineTradersTable.getInstance().storeOffliners(); | |
_log.info("Offline Traders Table: Offline shops stored(" + tc.getEstimatedTimeAndRestartCounter() + "ms)."); | |
Index: java/com/l2jserver/gameserver/datatables/OfflineTradersTable.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/datatables/OfflineTradersTable.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/datatables/OfflineTradersTable.java (working copy) | |
@@ -45,7 +45,9 @@ | |
private static final String SAVE_OFFLINE_STATUS = "INSERT INTO character_offline_trade (`charId`,`time`,`type`,`title`) VALUES (?,?,?,?)"; | |
private static final String SAVE_ITEMS = "INSERT INTO character_offline_trade_items (`charId`,`item`,`count`,`price`) VALUES (?,?,?,?)"; | |
private static final String CLEAR_OFFLINE_TABLE = "DELETE FROM character_offline_trade"; | |
+ private static final String CLEAR_OFFLINE_TABLE_PLAYER = "DELETE FROM character_offline_trade WHERE `charId`=?"; | |
private static final String CLEAR_OFFLINE_TABLE_ITEMS = "DELETE FROM character_offline_trade_items"; | |
+ private static final String CLEAR_OFFLINE_TABLE_ITEMS_PLAYER = "DELETE FROM character_offline_trade_items WHERE `charId`=?"; | |
private static final String LOAD_OFFLINE_STATUS = "SELECT * FROM character_offline_trade"; | |
private static final String LOAD_OFFLINE_ITEMS = "SELECT * FROM character_offline_trade_items WHERE charId = ?"; | |
@@ -253,10 +255,13 @@ | |
_log.info(getClass().getSimpleName() + ": Loaded: " + nTraders + " offline trader(s)"); | |
- try (Statement stm1 = con.createStatement()) | |
+ if (!Config.STORE_OFFLINE_TRADE_IN_REALTIME) | |
{ | |
- stm1.execute(CLEAR_OFFLINE_TABLE); | |
- stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS); | |
+ try (Statement stm1 = con.createStatement()) | |
+ { | |
+ stm1.execute(CLEAR_OFFLINE_TABLE); | |
+ stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS); | |
+ } | |
} | |
} | |
catch (Exception e) | |
@@ -265,6 +270,106 @@ | |
} | |
} | |
+ public static synchronized void onTransaction(L2PcInstance trader, boolean finished, boolean firstCall) | |
+ { | |
+ try (Connection con = L2DatabaseFactory.getInstance().getConnection(); | |
+ PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS_PLAYER); | |
+ PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_PLAYER); | |
+ PreparedStatement stm3 = con.prepareStatement(SAVE_ITEMS); | |
+ PreparedStatement stm4 = con.prepareStatement(SAVE_OFFLINE_STATUS)) | |
+ { | |
+ String title = null; | |
+ | |
+ stm1.setInt(1, trader.getObjectId()); // Char Id | |
+ stm1.execute(); | |
+ stm1.close(); | |
+ | |
+ // Trade is done - clear info | |
+ if (finished) | |
+ { | |
+ stm2.setInt(1, trader.getObjectId()); // Char Id | |
+ stm2.execute(); | |
+ stm2.close(); | |
+ } | |
+ else | |
+ { | |
+ try | |
+ { | |
+ if ((trader.getClient() == null) || trader.getClient().isDetached()) | |
+ { | |
+ switch (trader.getPrivateStoreType()) | |
+ { | |
+ case BUY: | |
+ if (firstCall) | |
+ { | |
+ title = trader.getBuyList().getTitle(); | |
+ } | |
+ for (TradeItem i : trader.getBuyList().getItems()) | |
+ { | |
+ stm3.setInt(1, trader.getObjectId()); | |
+ stm3.setInt(2, i.getItem().getId()); | |
+ stm3.setLong(3, i.getCount()); | |
+ stm3.setLong(4, i.getPrice()); | |
+ stm3.executeUpdate(); | |
+ stm3.clearParameters(); | |
+ } | |
+ break; | |
+ case SELL: | |
+ case PACKAGE_SELL: | |
+ if (firstCall) | |
+ { | |
+ title = trader.getSellList().getTitle(); | |
+ } | |
+ for (TradeItem i : trader.getSellList().getItems()) | |
+ { | |
+ stm3.setInt(1, trader.getObjectId()); | |
+ stm3.setInt(2, i.getObjectId()); | |
+ stm3.setLong(3, i.getCount()); | |
+ stm3.setLong(4, i.getPrice()); | |
+ stm3.executeUpdate(); | |
+ stm3.clearParameters(); | |
+ } | |
+ break; | |
+ case MANUFACTURE: | |
+ if (firstCall) | |
+ { | |
+ title = trader.getStoreName(); | |
+ } | |
+ for (L2ManufactureItem i : trader.getManufactureItems().values()) | |
+ { | |
+ stm3.setInt(1, trader.getObjectId()); | |
+ stm3.setInt(2, i.getRecipeId()); | |
+ stm3.setLong(3, 0); | |
+ stm3.setLong(4, i.getCost()); | |
+ stm3.executeUpdate(); | |
+ stm3.clearParameters(); | |
+ } | |
+ } | |
+ stm3.close(); | |
+ if (firstCall) | |
+ { | |
+ stm4.setInt(1, trader.getObjectId()); // Char Id | |
+ stm4.setLong(2, trader.getOfflineStartTime()); | |
+ stm4.setInt(3, trader.getPrivateStoreType().getId()); // store type | |
+ stm4.setString(4, title); | |
+ stm4.executeUpdate(); | |
+ stm4.clearParameters(); | |
+ stm4.close(); | |
+ } | |
+ } | |
+ } | |
+ catch (Exception e) | |
+ { | |
+ _log.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline trader: " + trader.getObjectId() + " " + e, e); | |
+ } | |
+ } | |
+ } | |
+ catch (Exception e) | |
+ { | |
+ _log.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline traders: " + e, e); | |
+ } | |
+ } | |
+ | |
/** | |
* Gets the single instance of OfflineTradersTable. | |
* @return single instance of OfflineTradersTable | |
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (working copy) | |
@@ -26,6 +26,7 @@ | |
import com.l2jserver.gameserver.cache.HtmCache; | |
import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager; | |
import com.l2jserver.gameserver.datatables.AdminTable; | |
+import com.l2jserver.gameserver.datatables.OfflineTradersTable; | |
import com.l2jserver.gameserver.datatables.SkillTreesData; | |
import com.l2jserver.gameserver.instancemanager.CHSiegeManager; | |
import com.l2jserver.gameserver.instancemanager.CastleManager; | |
@@ -596,6 +597,11 @@ | |
{ | |
activeChar.sendPacket(ExNotifyPremiumItem.STATIC_PACKET); | |
} | |
+ | |
+ if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.STORE_OFFLINE_TRADE_IN_REALTIME) | |
+ { | |
+ OfflineTradersTable.onTransaction(activeChar, true, false); | |
+ } | |
} | |
/** | |
Index: java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreSell.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreSell.java (revision 6469) | |
+++ java/com/l2jserver/gameserver/network/clientpackets/RequestPrivateStoreSell.java (working copy) | |
@@ -21,6 +21,7 @@ | |
import static com.l2jserver.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE; | |
import com.l2jserver.Config; | |
+import com.l2jserver.gameserver.datatables.OfflineTradersTable; | |
import com.l2jserver.gameserver.enums.PrivateStoreType; | |
import com.l2jserver.gameserver.model.ItemRequest; | |
import com.l2jserver.gameserver.model.L2World; | |
@@ -138,6 +139,12 @@ | |
return; | |
} | |
+ // Update offline trade record, if realtime saving is enabled | |
+ if (Config.OFFLINE_TRADE_ENABLE && Config.STORE_OFFLINE_TRADE_IN_REALTIME && ((storePlayer.getClient() == null) || storePlayer.getClient().isDetached())) | |
+ { | |
+ OfflineTradersTable.onTransaction(storePlayer, storeList.getItemCount() == 0, false); | |
+ } | |
+ | |
if (storeList.getItemCount() == 0) | |
{ | |
storePlayer.setPrivateStoreType(PrivateStoreType.NONE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment