Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/java/net/sf/l2j/Config.java b/java/net/sf/l2j/Config.java
- index b883c9f..4c6fdf4 100644
- --- a/java/net/sf/l2j/Config.java
- +++ b/java/net/sf/l2j/Config.java
- @@ -41,6 +41,7 @@
- public static final String SCHEMEBUFF = "./config/CustomMods/SchemeBuff.ini";
- public static final String BOSSESETTIGNS = "./config/CustomMods/BossSettings.ini";
- public static final String FLAGZONEMOD = "./config/CustomMods/FlagZone.ini";
- + public static final String OFFLINEMOD = "./config/CustomMods/OfflineShop.ini";
- // --------------------------------------------------
- // Clans settings
- // --------------------------------------------------
- @@ -543,7 +544,16 @@
- public static int PLAYER_RATE_DROP_ITEM;
- public static int PLAYER_RATE_DROP_EQUIP;
- public static int PLAYER_RATE_DROP_EQUIP_WEAPON;
- -
- + /** Offline Shop */
- + public static boolean OFFLINE_TRADE_ENABLE;
- + public static boolean OFFLINE_CRAFT_ENABLE;
- + public static boolean OFFLINE_MODE_IN_PEACE_ZONE;
- + public static boolean OFFLINE_MODE_NO_DAMAGE;
- + public static boolean RESTORE_OFFLINERS;
- + public static int OFFLINE_MAX_DAYS;
- + public static boolean OFFLINE_DISCONNECT_FINISHED;
- + public static boolean OFFLINE_SET_SLEEP;
- +
- public static int KARMA_DROP_LIMIT;
- public static int KARMA_RATE_DROP;
- public static int KARMA_RATE_DROP_ITEM;
- @@ -1081,6 +1091,19 @@
- RANDOM_SPAWN_TIME_ZAKEN = Boss.getProperty("ZakenRandomSpawn", 20);
- }
- + private static final void loadOff()
- + {
- + final ExProperties offlineshop = initProperties(Config.OFFLINEMOD);
- + OFFLINE_TRADE_ENABLE = offlineshop.getProperty("OfflineTradeEnable", false);
- + OFFLINE_CRAFT_ENABLE = offlineshop.getProperty("OfflineCraftEnable", false);
- + OFFLINE_MODE_IN_PEACE_ZONE = offlineshop.getProperty("OfflineModeInPeaceZone", false);
- + OFFLINE_MODE_NO_DAMAGE = offlineshop.getProperty("OfflineModeNoDamage", false);
- + OFFLINE_SET_SLEEP = offlineshop.getProperty("OfflineSetSleepEffect", false);
- + RESTORE_OFFLINERS = offlineshop.getProperty("RestoreOffliners", false);
- + OFFLINE_MAX_DAYS = offlineshop.getProperty("OfflineMaxDays", 10);
- + OFFLINE_DISCONNECT_FINISHED = offlineshop.getProperty("OfflineDisconnectFinished", true);
- +
- + }
- private static final void loadFlag()
- {
- @@ -1549,6 +1572,9 @@
- // siege settings
- loadSieges();
- +
- + // OffShop settings
- + loadOff();
- // server settings
- loadServer();
- diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java
- index 1071569..a829cab 100644
- --- a/java/net/sf/l2j/gameserver/GameServer.java
- +++ b/java/net/sf/l2j/gameserver/GameServer.java
- @@ -75,6 +75,7 @@
- import net.sf.l2j.gameserver.data.xml.TeleportData;
- import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
- import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
- +import net.sf.l2j.gameserver.enums.actors.OfflineStoresData;
- import net.sf.l2j.gameserver.geoengine.GeoEngine;
- import net.sf.l2j.gameserver.handler.AdminCommandHandler;
- import net.sf.l2j.gameserver.handler.ChatHandler;
- @@ -244,6 +245,10 @@
- Olympiad.getInstance();
- HeroManager.getInstance();
- + StringUtil.printSection("OfflineShop Started");
- + if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
- + OfflineStoresData.getInstance().restoreOfflineTraders();
- +
- StringUtil.printSection("Four Sepulchers");
- FourSepulchersManager.getInstance();
- diff --git a/java/net/sf/l2j/gameserver/LoginServerThread.java b/java/net/sf/l2j/gameserver/LoginServerThread.java
- index 5a78bf2..98a34f5 100644
- --- a/java/net/sf/l2j/gameserver/LoginServerThread.java
- +++ b/java/net/sf/l2j/gameserver/LoginServerThread.java
- @@ -295,6 +295,8 @@
- public void addClient(String account, GameClient client)
- {
- final GameClient existingClient = _clients.putIfAbsent(account, client);
- + if (client.isDetached())
- + return;
- if (existingClient == null)
- {
- try
- diff --git a/java/net/sf/l2j/gameserver/Shutdown.java b/java/net/sf/l2j/gameserver/Shutdown.java
- index f0ab468..440d9aa 100644
- --- a/java/net/sf/l2j/gameserver/Shutdown.java
- +++ b/java/net/sf/l2j/gameserver/Shutdown.java
- @@ -18,6 +18,7 @@
- import net.sf.l2j.gameserver.data.manager.RaidBossManager;
- import net.sf.l2j.gameserver.data.manager.SevenSignsManager;
- import net.sf.l2j.gameserver.data.manager.ZoneManager;
- +import net.sf.l2j.gameserver.enums.actors.OfflineStoresData;
- import net.sf.l2j.gameserver.model.World;
- import net.sf.l2j.gameserver.model.actor.Player;
- import net.sf.l2j.gameserver.model.olympiad.Olympiad;
- @@ -77,7 +78,18 @@
- if (this == SingletonHolder.INSTANCE)
- {
- StringUtil.printSection("Under " + MODE_TEXT[_shutdownMode] + " process");
- -
- + try
- + {
- + if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
- + {
- + OfflineStoresData.getInstance().storeOffliners();
- + LOGGER.info("Offline Traders Table: Offline shops stored.");
- + }
- + }
- + catch (Throwable t)
- + {
- +
- + }
- // disconnect players
- try
- {
- diff --git a/java/net/sf/l2j/gameserver/enums/actors/OfflineStoresData.java b/java/net/sf/l2j/gameserver/enums/actors/OfflineStoresData.java
- new file mode 100644
- index 0000000..6ac09f9
- --- /dev/null
- +++ b/java/net/sf/l2j/gameserver/enums/actors/OfflineStoresData.java
- @@ -0,0 +1,277 @@
- +package net.sf.l2j.gameserver.enums.actors;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.Statement;
- +import java.util.Calendar;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.commons.pool.ConnectionPool;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.LoginServerThread;
- +import net.sf.l2j.gameserver.enums.ZoneId;
- +import net.sf.l2j.gameserver.model.World;
- +import net.sf.l2j.gameserver.model.actor.Player;
- +import net.sf.l2j.gameserver.model.craft.ManufactureItem;
- +import net.sf.l2j.gameserver.model.craft.ManufactureList;
- +import net.sf.l2j.gameserver.model.trade.TradeItem;
- +import net.sf.l2j.gameserver.network.GameClient;
- +import net.sf.l2j.gameserver.network.GameClient.GameClientState;
- +
- +public class OfflineStoresData
- +{
- + private static final Logger LOGGER = Logger.getLogger(OfflineStoresData.class.getName());
- +
- + // SQL DEFINITIONS
- + 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`,`enchant`) VALUES (?,?,?,?,?)";
- + private static final String CLEAR_OFFLINE_TABLE = "DELETE FROM character_offline_trade";
- + private static final String CLEAR_OFFLINE_TABLE_ITEMS = "DELETE FROM character_offline_trade_items";
- + 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 = ?";
- +
- + public void storeOffliners()
- + {
- + try (Connection con = ConnectionPool.getConnection(); PreparedStatement save_offline_status = con.prepareStatement(SAVE_OFFLINE_STATUS); PreparedStatement save_items = con.prepareStatement(SAVE_ITEMS))
- + {
- + try (Statement stm = con.createStatement())
- + {
- + stm.execute(CLEAR_OFFLINE_TABLE);
- + stm.execute(CLEAR_OFFLINE_TABLE_ITEMS);
- + }
- + for (Player pc : World.getInstance().getPlayers())
- + {
- + try
- + {
- + if (pc.getOperateType() != OperateType.NONE && (pc.getClient() == null || pc.getClient().isDetached()))
- + {
- + save_offline_status.setInt(1, pc.getObjectId());
- + save_offline_status.setLong(2, pc.getOfflineStartTime());
- + save_offline_status.setInt(3, pc.getOperateType().getId());
- + switch (pc.getOperateType())
- + {
- + case BUY:
- + if (!Config.OFFLINE_TRADE_ENABLE)
- + continue;
- +
- + save_offline_status.setString(4, pc.getBuyList().getTitle());
- + for (TradeItem i : pc.getBuyList())
- + {
- + save_items.setInt(1, pc.getObjectId());
- + save_items.setInt(2, i.getItem().getItemId());
- + save_items.setLong(3, i.getCount());
- + save_items.setLong(4, i.getPrice());
- + save_items.setLong(5, i.getEnchant());
- + save_items.addBatch();
- + }
- + break;
- + case SELL:
- + case PACKAGE_SELL:
- + if (!Config.OFFLINE_TRADE_ENABLE)
- + continue;
- +
- + save_offline_status.setString(4, pc.getSellList().getTitle());
- + pc.getSellList().updateItems();
- + for (TradeItem i : pc.getSellList())
- + {
- + save_items.setInt(1, pc.getObjectId());
- + save_items.setInt(2, i.getObjectId());
- + save_items.setLong(3, i.getCount());
- + save_items.setLong(4, i.getPrice());
- + save_items.setLong(5, i.getEnchant());
- + save_items.addBatch();
- + }
- + break;
- + case MANUFACTURE:
- + if (!Config.OFFLINE_CRAFT_ENABLE)
- + continue;
- +
- + save_offline_status.setString(4, pc.getManufactureList().getStoreName());
- + for (final ManufactureItem i : pc.getManufactureList())
- + {
- + save_items.setInt(1, pc.getObjectId());
- + save_items.setInt(2, i.getId());
- + save_items.setLong(3, 0L);
- + save_items.setLong(4, i.getValue());
- + save_items.setLong(5, 0L);
- + save_items.addBatch();
- + }
- + break;
- + }
- + save_items.executeBatch();
- + save_offline_status.execute();
- + }
- + }
- + catch (Exception e)
- + {
- + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
- + }
- + }
- +
- + LOGGER.info(getClass().getSimpleName() + ": Offline traders stored.");
- + }
- + catch (Exception e)
- + {
- + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline traders: " + e, e);
- + }
- + }
- +
- + public void restoreOfflineTraders()
- + {
- + LOGGER.info(getClass().getSimpleName() + ": Loading offline traders...");
- + try (Connection con = ConnectionPool.getConnection(); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery(LOAD_OFFLINE_STATUS))
- + {
- + int nTraders = 0;
- + while (rs.next())
- + {
- + final long time = rs.getLong("time");
- + if (Config.OFFLINE_MAX_DAYS > 0)
- + {
- + final Calendar cal = Calendar.getInstance();
- + cal.setTimeInMillis(time);
- + cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
- + if (cal.getTimeInMillis() <= System.currentTimeMillis())
- + continue;
- + }
- +
- + OperateType type = null;
- + for (OperateType t : OperateType.values())
- + {
- + if (t.getId() == rs.getInt("type"))
- + {
- + type = t;
- + break;
- + }
- + }
- + if (type == null)
- + {
- + LOGGER.warning(getClass().getSimpleName() + ": PrivateStoreType with id " + rs.getInt("type") + " could not be found.");
- + continue;
- + }
- + if (type == OperateType.NONE)
- + continue;
- +
- + final Player player = Player.restore(rs.getInt("charId"));
- + if (player == null)
- + continue;
- +
- + try (PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS))
- + {
- + player.isRunning();
- + player.sitDown();
- + player.setOnlineStatus(true, false);
- +
- + World.getInstance().addPlayer(player);
- +
- + final GameClient client = new GameClient(null);
- + client.setDetached(true);
- + player.setClient(client);
- + client.setPlayer(player);
- + client.setAccountName(player.getAccountNamePlayer());
- + player.setOnlineStatus(true, true);
- + client.setState(GameClientState.IN_GAME);
- + player.setOfflineStartTime(time);
- + player.spawnMe();
- +
- + LoginServerThread.getInstance().addClient(player.getAccountName(), client);
- +
- + stm_items.setInt(1, player.getObjectId());
- + try (ResultSet items = stm_items.executeQuery())
- + {
- + switch (type)
- + {
- + case BUY:
- + while (items.next())
- + {
- + player.getBuyList().addItemByItemId(items.getInt(2), items.getInt(3), items.getInt(4), items.getInt(5));
- + }
- +
- + player.getBuyList().setTitle(rs.getString("title"));
- + break;
- + case SELL:
- + case PACKAGE_SELL:
- + while (items.next())
- + if (player.getSellList().addItem(items.getInt(2), items.getInt(3), items.getInt(4)) == null)
- + throw new NullPointerException("NPE at SELL of offlineShop " + player.getObjectId() + " " + items.getInt(2) + " " + items.getInt(3) + " " + items.getInt(4));
- +
- + player.getSellList().setTitle(rs.getString("title"));
- + player.getSellList().setPackaged(type == OperateType.PACKAGE_SELL);
- + break;
- + case MANUFACTURE:
- + final ManufactureList createList = new ManufactureList();
- + createList.setStoreName(rs.getString("title"));
- + while (items.next())
- + player.getManufactureList().add(new ManufactureItem(items.getInt(2), items.getInt(4)));
- + player.getManufactureList().setStoreName(rs.getString("title"));
- + //player.setCreateList(createList);
- + break;
- + }
- + }
- +
- + if (Config.OFFLINE_SET_SLEEP)
- + player.startAbnormalEffect(0x000080);
- +
- + player.setOperateType(type);
- + player.restoreEffects();
- + player.broadcastUserInfo();
- +
- + nTraders++;
- + }
- + catch (Exception e)
- + {
- + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading trader: " + player, e);
- +
- + player.deleteMe();
- + }
- + }
- +
- + LOGGER.info(getClass().getSimpleName() + ": Loaded: " + nTraders + " offline trader(s)");
- +
- + try (Statement stm1 = con.createStatement())
- + {
- + stm1.execute(CLEAR_OFFLINE_TABLE);
- + stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS);
- + }
- + }
- + catch (Exception e)
- + {
- + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while loading offline traders: ", e);
- + }
- + }
- +
- + public static boolean offlineMode(Player player)
- + {
- + if (player.isInOlympiadMode() || player.isFestivalParticipant() || player.isInJail() || player.getBoat() != null)
- + return false;
- +
- + boolean canSetShop = false;
- + switch (player.getOperateType())
- + {
- + case SELL:
- + case PACKAGE_SELL:
- + case BUY:
- + canSetShop = Config.OFFLINE_TRADE_ENABLE;
- + break;
- + case MANUFACTURE:
- + canSetShop = Config.OFFLINE_CRAFT_ENABLE;
- + break;
- + }
- + if (Config.OFFLINE_MODE_IN_PEACE_ZONE && !player.isInsideZone(ZoneId.PEACE))
- + canSetShop = false;
- +
- + return canSetShop;
- + }
- +
- + public static OfflineStoresData getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final OfflineStoresData _instance = new OfflineStoresData();
- + }
- +}
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/enums/actors/OperateType.java b/java/net/sf/l2j/gameserver/enums/actors/OperateType.java
- index a5faa73..562d322 100644
- --- a/java/net/sf/l2j/gameserver/enums/actors/OperateType.java
- +++ b/java/net/sf/l2j/gameserver/enums/actors/OperateType.java
- @@ -23,4 +23,13 @@
- {
- return _id;
- }
- + public static OperateType findById(int id)
- + {
- + for (OperateType privateStoreType : values())
- + {
- + if (privateStoreType.getId() == id)
- + return privateStoreType;
- + }
- + return null;
- + }
- }
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/model/actor/Player.java b/java/net/sf/l2j/gameserver/model/actor/Player.java
- index 92f7065..698ed21 100644
- --- a/java/net/sf/l2j/gameserver/model/actor/Player.java
- +++ b/java/net/sf/l2j/gameserver/model/actor/Player.java
- @@ -2243,8 +2243,14 @@
- public String getAccountName()
- {
- + if (getClient() == null)
- + return getAccountNamePlayer();
- return _accountName;
- }
- + public String getAccountNamePlayer()
- + {
- + return _accountName;
- + }
- public Map<Integer, String> getAccountChars()
- {
- @@ -3292,6 +3298,8 @@
- public void setOperateType(OperateType type)
- {
- _operateType = type;
- + if (Config.OFFLINE_DISCONNECT_FINISHED && type == OperateType.NONE && (getClient() == null || getClient().isDetached()))
- + deleteMe();
- }
- /**
- @@ -7319,7 +7327,16 @@
- final ItemInstance formal = getInventory().getItemFrom(Paperdoll.CHEST);
- return formal != null && formal.getItem().getBodyPart() == Item.SLOT_ALLDRESS;
- }
- + private long _offlineShopStart;
- + public long getOfflineStartTime()
- + {
- + return _offlineShopStart;
- + }
- + public void setOfflineStartTime(long time)
- + {
- + _offlineShopStart = time;
- + }
- public final void startFakeDeath()
- {
- _isFakeDeath = true;
- diff --git a/java/net/sf/l2j/gameserver/network/GameClient.java b/java/net/sf/l2j/gameserver/network/GameClient.java
- index c46ef20..860138d 100644
- --- a/java/net/sf/l2j/gameserver/network/GameClient.java
- +++ b/java/net/sf/l2j/gameserver/network/GameClient.java
- @@ -22,9 +22,12 @@
- import net.sf.l2j.gameserver.data.sql.ClanTable;
- import net.sf.l2j.gameserver.data.sql.PlayerInfoTable;
- import net.sf.l2j.gameserver.enums.FloodProtector;
- +import net.sf.l2j.gameserver.enums.MessageType;
- +import net.sf.l2j.gameserver.enums.ZoneId;
- import net.sf.l2j.gameserver.model.CharSelectSlot;
- import net.sf.l2j.gameserver.model.World;
- import net.sf.l2j.gameserver.model.actor.Player;
- +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
- import net.sf.l2j.gameserver.model.pledge.Clan;
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
- @@ -209,6 +212,29 @@
- if (getPlayer() != null && !isDetached())
- {
- setDetached(true);
- + if (offlineMode(getPlayer()))
- + {
- + if (getPlayer().getParty() != null)
- + getPlayer().getParty().removePartyMember(getPlayer(), MessageType.EXPELLED);
- + OlympiadManager.getInstance().unRegisterNoble(getPlayer());
- +
- + // If the Character has Pet, unsummon it
- + if (getPlayer().hasPet())
- + {
- + getPlayer().getSummon().unSummon(getPlayer());
- + // Dead pet wasn't unsummoned, broadcast npcinfo changes (pet will be without owner name - means owner offline)
- + if (getPlayer().getSummon() != null)
- + getPlayer().getSummon().updateAndBroadcastStatus(0);
- + }
- +
- + if (Config.OFFLINE_SET_SLEEP)
- + getPlayer().startAbnormalEffect(0x000080);
- +
- + if (getPlayer().getOfflineStartTime() == 0)
- + getPlayer().setOfflineStartTime(System.currentTimeMillis());
- +
- + return;
- + }
- fast = !getPlayer().isInCombat() && !getPlayer().isLocked();
- }
- cleanMe(fast);
- @@ -219,6 +245,43 @@
- }
- }
- + /**
- + * @param player the player to be check.
- + * @return {@code true} if the player is allowed to remain as off-line shop.
- + */
- + public static boolean offlineMode(Player player)
- + {
- + if (player.isInOlympiadMode() || player.isFestivalParticipant() || player.isInJail() || player.getBoat() != null)
- + return false;
- +
- + boolean canSetShop = false;
- + switch (player.getOperateType())
- + {
- + case SELL:
- + case PACKAGE_SELL:
- + case BUY:
- + {
- + canSetShop = Config.OFFLINE_TRADE_ENABLE;
- + break;
- + }
- + case MANUFACTURE:
- + {
- + canSetShop = Config.OFFLINE_TRADE_ENABLE;
- + break;
- + }
- + default:
- + {
- + canSetShop = Config.OFFLINE_CRAFT_ENABLE && player.isCrafting();
- + break;
- + }
- + }
- +
- + if (Config.OFFLINE_MODE_IN_PEACE_ZONE && !player.isInsideZone(ZoneId.PEACE))
- + canSetShop = false;
- +
- + return canSetShop;
- + }
- +
- @Override
- protected void onForcedDisconnection()
- {
- @@ -581,6 +644,8 @@
- public void close(L2GameServerPacket gsp)
- {
- + if (getConnection() == null)
- + return;
- getConnection().close(gsp);
- }
- Index: Datapack
- +# =================================================================
- +# Offline trade/craft
- +# =================================================================
- +
- +# Option to enable or disable offline trade feature.
- +# Enable -> true, Disable -> false
- +OfflineTradeEnable = True
- +
- +# Option to enable or disable offline craft feature.
- +# Enable -> true, Disable -> false
- +OfflineCraftEnable = True
- +
- +# If set to True, off-line shops will be possible only in peace zones.
- +# Default: False
- +OfflineModeInPeaceZone = True
- +
- +# If set to True, players in off-line shop mode will not take any damage, thus they cannot be killed.
- +# Default: False
- +OfflineModeNoDamage = False
- +
- +# Restore offline traders/crafters after restart/shutdown.
- +# Default: False
- +RestoreOffliners = True
- +
- +# Do not restore offline characters, after OfflineMaxDays days spent from first restore.
- +# Require server restart to disconnect expired shops.
- +# 0 = disabled (always restore).
- +# Default: 7
- +OfflineMaxDays = 7
- +
- +# Disconnect shop after finished selling, buying.
- +# Default: True
- +OfflineDisconnectFinished = True
- +
- +#Offline Effect Sleep
- +OfflineSetSleepEffect = True
Add Comment
Please, Sign In to add comment