From c31c85e2a364eb323a56ae128b8a62b375f6d7a9 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Wed, 29 Jan 2020 14:41:07 +0000 Subject: [PATCH] Addition of PlayerInstance auto save task. --- .../dist/game/config/main/General.ini | 12 ++++++ .../java/org/l2jmobius/Config.java | 8 ++++ .../model/actor/instance/PlayerInstance.java | 38 +++++++++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/main/General.ini b/L2J_Mobius_C6_Interlude/dist/game/config/main/General.ini index d19a0e37a6..fad74466a5 100644 --- a/L2J_Mobius_C6_Interlude/dist/game/config/main/General.ini +++ b/L2J_Mobius_C6_Interlude/dist/game/config/main/General.ini @@ -550,6 +550,18 @@ SaveDroppedItemInterval = 60 # WARNING: only works when SaveDroppedItem = False ClearDroppedItemTable = False +# This is the interval (in minutes), that the gameserver will update a players information such as location. +# The higher you set this number, there will be less character information saving so you will have less accessing of the database and your hard drive(s). +# The lower you set this number, there will be more frequent character information saving so you will have more access to the database and your hard drive(s). +# A value of 0 disables periodic saving. +# Independent of this setting the character is always saved after leaving the world. +# Default: 15 +CharacterDataStoreInterval = 15 + +# When enabled, this forces (even if using lazy item updates) the items owned by the character to be updated into DB when saving its character. +# Default: True +UpdateItemsOnCharStore = True + # Remove broken quests player AutoDeleteInvalidQuestData = False diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java index f615d938df..ae1409cdc4 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/Config.java @@ -194,6 +194,10 @@ public class Config public static int DUMP_INTERVAL_SECONDS = 60; public static int DEFAULT_PUNISH; public static int DEFAULT_PUNISH_PARAM; + + public static int CHAR_DATA_STORE_INTERVAL; + public static boolean UPDATE_ITEMS_ON_CHAR_STORE; + public static boolean AUTODELETE_INVALID_QUEST_DATA; public static boolean GRIDS_ALWAYS_ON; public static int GRID_NEIGHBOR_TURNON_TIME; @@ -1631,6 +1635,7 @@ public class Config { LIST_PROTECTED_ITEMS.add(Integer.parseInt(id)); } + DESTROY_DROPPED_PLAYER_ITEM = Boolean.parseBoolean(generalSettings.getProperty("DestroyPlayerDroppedItem", "false")); DESTROY_EQUIPABLE_PLAYER_ITEM = Boolean.parseBoolean(generalSettings.getProperty("DestroyEquipableItem", "false")); SAVE_DROPPED_ITEM = Boolean.parseBoolean(generalSettings.getProperty("SaveDroppedItem", "false")); @@ -1687,6 +1692,9 @@ public class Config FORCE_COMPLETE_STATUS_UPDATE = Boolean.parseBoolean(generalSettings.getProperty("ForceCompletePlayerStatusUpdate", "true")); + CHAR_DATA_STORE_INTERVAL = Integer.parseInt(generalSettings.getProperty("CharacterDataStoreInterval", "15")) * 60 * 1000; + UPDATE_ITEMS_ON_CHAR_STORE = Boolean.parseBoolean(generalSettings.getProperty("UpdateItemsOnCharStore", "false")); + AUTODELETE_INVALID_QUEST_DATA = Boolean.parseBoolean(generalSettings.getProperty("AutoDeleteInvalidQuestData", "false")); DELETE_DAYS = Integer.parseInt(generalSettings.getProperty("DeleteCharAfterDays", "7")); diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java index 64d52f196e..4867ef2378 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java @@ -537,6 +537,7 @@ public class PlayerInstance extends Playable private final HashMap confirmDlgRequests = new HashMap<>(); private int _currentMultiSellId = -1; private int _partyroom = 0; + private Future _autoSaveTask = null; /** The table containing all minimum level needed for each Expertise (None, D, C, B, A, S). */ private static final int[] EXPERTISE_LEVELS = @@ -602,7 +603,6 @@ public class PlayerInstance extends Playable // Add the player in the characters table of the database final boolean ok = player.createDb(); - if (!ok) { return null; @@ -921,7 +921,6 @@ public class PlayerInstance extends Playable */ public class HerbTask implements Runnable { - /** The _process. */ private final String _process; @@ -8927,6 +8926,8 @@ public class PlayerInstance extends Playable player.refreshOverloaded(); player.restoreFriendList(); + + player.startAutoSaveTask(); } catch (Exception e) { @@ -9234,8 +9235,7 @@ public class PlayerInstance extends Playable } /** - * Update PlayerInstance stats in the characters table of the database.
- *
+ * Update PlayerInstance stats in the characters table of the database. */ public synchronized void store() { @@ -10251,6 +10251,34 @@ public class PlayerInstance extends Playable return _hennaDEX; } + private void startAutoSaveTask() + { + if ((Config.CHAR_DATA_STORE_INTERVAL > 0) && (_autoSaveTask == null)) + { + _autoSaveTask = ThreadPool.scheduleAtFixedRate(this::autoSave, Config.CHAR_DATA_STORE_INTERVAL, Config.CHAR_DATA_STORE_INTERVAL); + } + } + + private void stopAutoSaveTask() + { + if (_autoSaveTask != null) + { + _autoSaveTask.cancel(false); + _autoSaveTask = null; + } + } + + protected void autoSave() + { + store(); + + if (Config.UPDATE_ITEMS_ON_CHAR_STORE) + { + _inventory.updateDatabase(); + getWarehouse().updateDatabase(); + } + } + /** * Return True if the PlayerInstance is autoAttackable.
*
@@ -14713,6 +14741,8 @@ public class PlayerInstance extends Playable // Remove WorldObject object from _allObjects of World World.getInstance().removeObject(this); World.getInstance().removeFromAllPlayers(this); // force remove in case of crash during teleport + + stopAutoSaveTask(); } private class ShortBuffTask implements Runnable