Removal of AutoSaveManager as it encourages bad implementations.

This commit is contained in:
MobiusDevelopment 2020-01-29 14:14:20 +00:00
parent 6ef4009091
commit 9d3904e755
7 changed files with 1 additions and 278 deletions

View File

@ -10,29 +10,6 @@
# DeadLockCheck = -1
# Now the demon-stream after completing his tasks will disappear forever.
# AUTO SAVE DAEMON:
# Allows you to customize the preservation of the database of players.
AutoSaveInitial = 300000
AutoSaveDelay = 900000
# CHECK CONNECTION DAEMON:
# Allows you to customize the connection check of players.
CheckConnectionInitial = 300000
CheckConnectionDelay = 900000
# Maximum time without receiving packets from client needed to be checked
# Default: 60sec
CheckConnectionInactivityTime = 60000
# CHECK TELEPORT ZOMBIE STATUS:
# Allow to close connection of "teleport zombies" due to critical errors on teleport
# Default: 60sec
CheckTeleportZombiesDelay = 60000
# Clean database task delay:
CleanDBInitial = 300000
CleanDBDelay = 900000
# ---------------------------------------------------------------------------
# Dead Lock Detector (separate thread for detecting deadlocks)
# ---------------------------------------------------------------------------

View File

@ -1120,14 +1120,6 @@ public class Config
public static ClassMasterSettings CLASS_MASTER_SETTINGS;
public static boolean ALLOW_REMOTE_CLASS_MASTERS;
public static long AUTOSAVE_INITIAL_TIME;
public static long AUTOSAVE_DELAY_TIME;
public static long CHECK_CONNECTION_INACTIVITY_TIME;
public static long CHECK_CONNECTION_INITIAL_TIME;
public static long CHECK_CONNECTION_DELAY_TIME;
public static long CLEANDB_INITIAL_TIME;
public static long CLEANDB_DELAY_TIME;
public static long CHECK_TELEPORT_ZOMBIE_DELAY_TIME;
public static long DEADLOCKCHECK_INTIAL_TIME;
public static long DEADLOCKCHECK_DELAY_TIME;
@ -3491,14 +3483,6 @@ public class Config
{
final L2Properties daemonsSettings = new L2Properties(DAEMONS_CONFIG_FILE);
AUTOSAVE_INITIAL_TIME = Long.parseLong(daemonsSettings.getProperty("AutoSaveInitial", "300000"));
AUTOSAVE_DELAY_TIME = Long.parseLong(daemonsSettings.getProperty("AutoSaveDelay", "900000"));
CHECK_CONNECTION_INITIAL_TIME = Long.parseLong(daemonsSettings.getProperty("CheckConnectionInitial", "300000"));
CHECK_CONNECTION_DELAY_TIME = Long.parseLong(daemonsSettings.getProperty("CheckConnectionDelay", "900000"));
CHECK_CONNECTION_INACTIVITY_TIME = Long.parseLong(daemonsSettings.getProperty("CheckConnectionInactivityTime", "90000"));
CLEANDB_INITIAL_TIME = Long.parseLong(daemonsSettings.getProperty("CleanDBInitial", "300000"));
CLEANDB_DELAY_TIME = Long.parseLong(daemonsSettings.getProperty("CleanDBDelay", "900000"));
CHECK_TELEPORT_ZOMBIE_DELAY_TIME = Long.parseLong(daemonsSettings.getProperty("CheckTeleportZombiesDelay", "90000"));
DEADLOCKCHECK_INTIAL_TIME = Long.parseLong(daemonsSettings.getProperty("DeadLockCheck", "0"));
DEADLOCKCHECK_DELAY_TIME = Long.parseLong(daemonsSettings.getProperty("DeadLockDelay", "0"));
}

View File

@ -85,7 +85,6 @@ import org.l2jmobius.gameserver.handler.UserCommandHandler;
import org.l2jmobius.gameserver.handler.VoicedCommandHandler;
import org.l2jmobius.gameserver.idfactory.IdFactory;
import org.l2jmobius.gameserver.instancemanager.AuctionManager;
import org.l2jmobius.gameserver.instancemanager.AutoSaveManager;
import org.l2jmobius.gameserver.instancemanager.AwayManager;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.CastleManorManager;
@ -223,11 +222,6 @@ public class GameServer
ClassDamageManager.loadConfig();
}
if (Config.AUTOSAVE_DELAY_TIME > 0)
{
AutoSaveManager.getInstance().startAutoSaveManager();
}
Util.printSection("Skills");
if (!SkillTable.getInstance().isInitialized())
{

View File

@ -24,7 +24,6 @@ import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.gameserver.datatables.OfflineTradeTable;
import org.l2jmobius.gameserver.datatables.SchemeBufferTable;
import org.l2jmobius.gameserver.instancemanager.AutoSaveManager;
import org.l2jmobius.gameserver.instancemanager.CastleManorManager;
import org.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import org.l2jmobius.gameserver.instancemanager.FishingChampionshipManager;
@ -303,8 +302,6 @@ public class Shutdown extends Thread
{
}
AutoSaveManager.getInstance().stopAutoSaveManager();
// saveData sends messages to exit players, so shutdown selector after it
saveData();

View File

@ -1,182 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
/**
* @author Shyla
*/
public class AutoSaveManager
{
protected static final Logger LOGGER = Logger.getLogger(AutoSaveManager.class.getName());
private ScheduledFuture<?> _autoSaveInDB;
private ScheduledFuture<?> _autoCheckConnectionStatus;
private ScheduledFuture<?> _autoCleanDatabase;
public static final AutoSaveManager getInstance()
{
return SingletonHolder.INSTANCE;
}
public AutoSaveManager()
{
LOGGER.info("Initializing AutoSaveManager");
}
public void stopAutoSaveManager()
{
if (_autoSaveInDB != null)
{
_autoSaveInDB.cancel(true);
_autoSaveInDB = null;
}
if (_autoCheckConnectionStatus != null)
{
_autoCheckConnectionStatus.cancel(true);
_autoCheckConnectionStatus = null;
}
if (_autoCleanDatabase != null)
{
_autoCleanDatabase.cancel(true);
_autoCleanDatabase = null;
}
}
public void startAutoSaveManager()
{
stopAutoSaveManager();
_autoSaveInDB = ThreadPool.scheduleAtFixedRate(new AutoSaveTask(), Config.AUTOSAVE_INITIAL_TIME, Config.AUTOSAVE_DELAY_TIME);
_autoCheckConnectionStatus = ThreadPool.scheduleAtFixedRate(new ConnectionCheckTask(), Config.CHECK_CONNECTION_INITIAL_TIME, Config.CHECK_CONNECTION_DELAY_TIME);
_autoCleanDatabase = ThreadPool.scheduleAtFixedRate(new AutoCleanDBTask(), Config.CLEANDB_INITIAL_TIME, Config.CLEANDB_DELAY_TIME);
}
protected class AutoSaveTask implements Runnable
{
@Override
public void run()
{
int playerscount = 0;
final Collection<PlayerInstance> players = World.getInstance().getAllPlayers();
for (PlayerInstance player : players)
{
if (player != null)
{
try
{
playerscount++;
player.store();
}
catch (Exception e)
{
LOGGER.warning("Error saving player character: " + player.getName() + " " + e);
}
}
}
LOGGER.info("[AutoSaveManager] AutoSaveTask, " + playerscount + " players data saved.");
}
}
protected class ConnectionCheckTask implements Runnable
{
@Override
public void run()
{
final Collection<PlayerInstance> players = World.getInstance().getAllPlayers();
for (PlayerInstance player : players)
{
if ((player != null) && !player.isInOfflineMode())
{
if ((player.getClient() == null) || (player.isOnline() == 0))
{
LOGGER.info("[AutoSaveManager] Player " + player.getName() + " status == 0 ---> Closing Connection..");
player.store();
player.deleteMe();
}
else if (!player.getClient().isConnectionAlive())
{
try
{
LOGGER.info("[AutoSaveManager] Player " + player.getName() + " connection is not alive ---> Closing Connection..");
player.getClient().onDisconnection();
}
catch (Exception e)
{
LOGGER.warning("[AutoSaveManager] Error saving player character: " + player.getName() + " " + e);
}
}
else if (player.checkTeleportOverTime())
{
try
{
LOGGER.info("[AutoSaveManager] Player " + player.getName() + " has a teleport overtime ---> Closing Connection..");
player.getClient().onDisconnection();
}
catch (Exception e)
{
LOGGER.warning("[AutoSaveManager] Error saving player character: " + player.getName() + " " + e);
}
}
}
}
LOGGER.info("[AutoSaveManager] ConnectionCheckTask, players connections checked.");
}
}
protected class AutoCleanDBTask implements Runnable
{
@Override
public void run()
{
int erased = 0;
// Perform the clean here instead of every time that the skills are saved in order to do it in once step because if skill have 0 reuse delay doesn't affect the game, just makes the table grows bigger
try (Connection con = DatabaseFactory.getConnection())
{
PreparedStatement statement;
statement = con.prepareStatement("DELETE FROM character_skills_save WHERE reuse_delay=0 && restore_type=1");
erased = statement.executeUpdate();
statement.close();
}
catch (Exception e)
{
LOGGER.info("[AutoSaveManager] Error while cleaning skill with 0 reuse time from table.");
}
LOGGER.info("[AutoSaveManager] AutoCleanDBTask, " + erased + " entries cleaned from db.");
}
}
private static class SingletonHolder
{
protected static final AutoSaveManager INSTANCE = new AutoSaveManager();
}
}

View File

@ -281,7 +281,6 @@ public class PlayerInstance extends Playable
private long _voteTimestamp = 0;
private PlayerStatsHolder savedStatus = null;
private final long _instanceLoginTime;
private long _lastTeleportAction = 0;
protected long TOGGLE_USE = 0;
public int _activeBoxes = -1;
public List<String> _activeBoxeCharacters = new ArrayList<>();
@ -9387,7 +9386,6 @@ public class PlayerInstance extends Playable
}
}
@SuppressWarnings("null")
private synchronized void storeEffect()
{
if (!Config.STORE_SKILL_COOLTIME)
@ -9423,7 +9421,7 @@ public class PlayerInstance extends Playable
}
storedSkills.add(skillId);
if ((effect != null) && effect.getInUse() && !effect.getSkill().isToggle() && !effect.getStackType().equals("BattleForce") && !effect.getStackType().equals("SpellForce") && (effect.getSkill().getSkillType() != SkillType.FORCE_BUFF))
if (effect.getInUse() && !effect.getSkill().isToggle() && !effect.getStackType().equals("BattleForce") && !effect.getStackType().equals("SpellForce") && (effect.getSkill().getSkillType() != SkillType.FORCE_BUFF))
{
statement.setInt(1, getObjectId());
statement.setInt(2, skillId);
@ -17249,33 +17247,6 @@ public class PlayerInstance extends Playable
}
}
public boolean checkTeleportOverTime()
{
if (!isTeleporting())
{
return false;
}
if ((System.currentTimeMillis() - _lastTeleportAction) > Config.CHECK_TELEPORT_ZOMBIE_DELAY_TIME)
{
LOGGER.warning("Player " + getName() + " has been in teleport more then " + (Config.CHECK_TELEPORT_ZOMBIE_DELAY_TIME / 1000) + " seconds.. --> Kicking it");
return true;
}
return false;
}
@Override
public void setTeleporting(boolean value)
{
super.setTeleporting(value);
if (value)
{
_lastTeleportAction = System.currentTimeMillis();
}
}
@Override
public PlayerInstance getActingPlayer()
{

View File

@ -115,8 +115,6 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
private final ArrayBlockingQueue<ReceivablePacket<GameClient>> _packetQueue;
private final ReentrantLock _queueLock = new ReentrantLock();
private long _last_received_packet_action_time = 0;
private int _protocolVersion;
public GameClient(MMOConnection<GameClient> con)
@ -929,9 +927,6 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
return;
}
// save last action time
_last_received_packet_action_time = System.currentTimeMillis();
try
{
if (_state == GameClientState.CONNECTED)
@ -1002,24 +997,11 @@ public class GameClient extends MMOClient<MMOConnection<GameClient>> implements
}
}
/**
* @return the _forcedToClose
*/
public boolean isForcedToClose()
{
return _forcedToClose;
}
public boolean isConnectionAlive()
{
if ((System.currentTimeMillis() - _last_received_packet_action_time) > Config.CHECK_CONNECTION_INACTIVITY_TIME)
{
_last_received_packet_action_time = System.currentTimeMillis();
return getConnection().isConnected() && !getConnection().isClosed();
}
return true;
}
public void setProtocolVersion(int version)
{
_protocolVersion = version;