Advertisement
ChristianMacedo

Offline Shop V2 aCis 382

Aug 11th, 2022
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.14 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Trunk382 aCis
  3. diff --git aCis_gameserver/java/net/sf/l2j/Config.java
  4. +++ aCis_gameserver/java/net/sf/l2j/Config.java
  5. @@ -353,12 +353,22 @@
  6. public static int MAX_PVTSTORE_SLOTS_DWARF;
  7. public static int MAX_PVTSTORE_SLOTS_OTHER;
  8. public static boolean DEEPBLUE_DROP_RULES;
  9. public static boolean ALT_GAME_DELEVEL;
  10. public static int DEATH_PENALTY_CHANCE;
  11.  
  12. + /** Offline Shop */
  13. + public static boolean OFFLINE_TRADE_ENABLE;
  14. + public static boolean OFFLINE_CRAFT_ENABLE;
  15. + public static boolean OFFLINE_MODE_IN_PEACE_ZONE;
  16. + public static boolean OFFLINE_MODE_NO_DAMAGE;
  17. + public static boolean RESTORE_OFFLINERS;
  18. + public static int OFFLINE_MAX_DAYS;
  19. + public static boolean OFFLINE_DISCONNECT_FINISHED;
  20. + public static boolean OFFLINE_SET_SLEEP;
  21. +
  22. /** Inventory & WH */
  23. public static int INVENTORY_MAXIMUM_NO_DWARF;
  24. public static int INVENTORY_MAXIMUM_DWARF;
  25. public static int INVENTORY_MAXIMUM_QUEST_ITEMS;
  26. public static int INVENTORY_MAXIMUM_PET;
  27. public static int MAX_ITEM_IN_PACKET;
  28. @@ -987,12 +997,21 @@
  29. MAX_PVTSTORE_SLOTS_DWARF = players.getProperty("MaxPvtStoreSlotsDwarf", 5);
  30. MAX_PVTSTORE_SLOTS_OTHER = players.getProperty("MaxPvtStoreSlotsOther", 4);
  31. DEEPBLUE_DROP_RULES = players.getProperty("UseDeepBlueDropRules", true);
  32. ALT_GAME_DELEVEL = players.getProperty("Delevel", true);
  33. DEATH_PENALTY_CHANCE = players.getProperty("DeathPenaltyChance", 20);
  34.  
  35. + OFFLINE_TRADE_ENABLE = players.getProperty("OfflineTradeEnable", false);
  36. + OFFLINE_CRAFT_ENABLE = players.getProperty("OfflineCraftEnable", false);
  37. + OFFLINE_MODE_IN_PEACE_ZONE = players.getProperty("OfflineModeInPeaceZone", false);
  38. + OFFLINE_MODE_NO_DAMAGE = players.getProperty("OfflineModeNoDamage", false);
  39. + OFFLINE_SET_SLEEP = players.getProperty("OfflineSetSleepEffect", false);
  40. + RESTORE_OFFLINERS = players.getProperty("RestoreOffliners", false);
  41. + OFFLINE_MAX_DAYS = players.getProperty("OfflineMaxDays", 10);
  42. + OFFLINE_DISCONNECT_FINISHED = players.getProperty("OfflineDisconnectFinished", true);
  43. +
  44. INVENTORY_MAXIMUM_NO_DWARF = players.getProperty("MaximumSlotsForNoDwarf", 80);
  45. INVENTORY_MAXIMUM_DWARF = players.getProperty("MaximumSlotsForDwarf", 100);
  46. INVENTORY_MAXIMUM_QUEST_ITEMS = players.getProperty("MaximumSlotsForQuestItems", 100);
  47. INVENTORY_MAXIMUM_PET = players.getProperty("MaximumSlotsForPet", 12);
  48. MAX_ITEM_IN_PACKET = Math.max(INVENTORY_MAXIMUM_NO_DWARF, INVENTORY_MAXIMUM_DWARF);
  49. ALT_WEIGHT_LIMIT = players.getProperty("AltWeightLimit", 1);
  50. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
  51. +++ aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
  52. @@ -68,12 +68,13 @@
  53. import net.sf.l2j.gameserver.data.xml.SoulCrystalData;
  54. import net.sf.l2j.gameserver.data.xml.SpellbookData;
  55. import net.sf.l2j.gameserver.data.xml.StaticObjectData;
  56. import net.sf.l2j.gameserver.data.xml.SummonItemData;
  57. import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
  58. import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
  59. +import net.sf.l2j.gameserver.enums.actors.OfflineStoresData;
  60. import net.sf.l2j.gameserver.geoengine.GeoEngine;
  61. import net.sf.l2j.gameserver.handler.AdminCommandHandler;
  62. import net.sf.l2j.gameserver.handler.ChatHandler;
  63. import net.sf.l2j.gameserver.handler.ItemHandler;
  64. import net.sf.l2j.gameserver.handler.SkillHandler;
  65. import net.sf.l2j.gameserver.handler.UserCommandHandler;
  66. @@ -240,12 +241,22 @@
  67.  
  68. StringUtil.printSection("Olympiads & Heroes");
  69. OlympiadGameManager.getInstance();
  70. Olympiad.getInstance();
  71. HeroManager.getInstance();
  72.  
  73. + StringUtil.printSection("OfflineShop Started");
  74. + if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  75. + {
  76. + OfflineStoresData.getInstance().restoreOfflineTraders();
  77. + }
  78. + else
  79. + {
  80. + LOGGER.info("Offline Shop is disabled.");
  81. + }
  82. +
  83. StringUtil.printSection("Four Sepulchers");
  84. FourSepulchersManager.getInstance();
  85.  
  86. StringUtil.printSection("Quests & Scripts");
  87. ScriptData.getInstance();
  88.  
  89. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/LoginServerThread.java
  90. +++ aCis_gameserver/java/net/sf/l2j/gameserver/LoginServerThread.java
  91. @@ -292,12 +292,14 @@
  92. }
  93. }
  94.  
  95. public void addClient(String account, GameClient client)
  96. {
  97. final GameClient existingClient = _clients.putIfAbsent(account, client);
  98. + if (client.isDetached())
  99. + return;
  100. if (existingClient == null)
  101. {
  102. try
  103. {
  104. sendPacket(new PlayerAuthRequest(client.getAccountName(), client.getSessionId()));
  105. }
  106. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java
  107. +++ aCis_gameserver/java/net/sf/l2j/gameserver/Shutdown.java
  108. @@ -15,12 +15,13 @@
  109. import net.sf.l2j.gameserver.data.manager.GrandBossManager;
  110. import net.sf.l2j.gameserver.data.manager.HeroManager;
  111. import net.sf.l2j.gameserver.data.manager.RaidBossManager;
  112. import net.sf.l2j.gameserver.data.manager.SevenSignsManager;
  113. import net.sf.l2j.gameserver.data.manager.ZoneManager;
  114. import net.sf.l2j.gameserver.data.sql.ServerMemoTable;
  115. +import net.sf.l2j.gameserver.enums.actors.OfflineStoresData;
  116. import net.sf.l2j.gameserver.model.World;
  117. import net.sf.l2j.gameserver.model.actor.Player;
  118. import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  119. import net.sf.l2j.gameserver.network.GameClient;
  120. import net.sf.l2j.gameserver.network.SystemMessageId;
  121. import net.sf.l2j.gameserver.network.gameserverpackets.ServerStatus;
  122. @@ -75,12 +76,26 @@
  123. public void run()
  124. {
  125. if (this == SingletonHolder.INSTANCE)
  126. {
  127. StringUtil.printSection("Under " + MODE_TEXT[_shutdownMode] + " process");
  128.  
  129. + try
  130. + {
  131. + if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
  132. + {
  133. + OfflineStoresData.getInstance().storeOffliners();
  134. + LOGGER.info("Offline Traders Table: Offline shops stored.");
  135. + }
  136. + }
  137. + catch (Throwable t)
  138. + {
  139. +
  140. + }
  141. // disconnect players
  142. try
  143. {
  144. disconnectAllPlayers();
  145. LOGGER.info("All players have been disconnected.");
  146. }
  147. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/enums/actors/OfflineStoresData.java
  148. new file mode 100644
  149. +++ aCis_gameserver/java/net/sf/l2j/gameserver/enums/actors/OfflineStoresData.java
  150. @@ -0,0 +1,276 @@
  151. +package net.sf.l2j.gameserver.enums.actors;
  152. +
  153. +import java.sql.Connection;
  154. +import java.sql.PreparedStatement;
  155. +import java.sql.ResultSet;
  156. +import java.sql.Statement;
  157. +import java.util.Calendar;
  158. +import java.util.logging.Level;
  159. +import java.util.logging.Logger;
  160. +
  161. +
  162. +import net.sf.l2j.Config;
  163. +import net.sf.l2j.L2DatabaseFactory;
  164. +import net.sf.l2j.gameserver.LoginServerThread;
  165. +import net.sf.l2j.gameserver.enums.ZoneId;
  166. +import net.sf.l2j.gameserver.model.World;
  167. +import net.sf.l2j.gameserver.model.actor.Player;
  168. +import net.sf.l2j.gameserver.model.craft.ManufactureItem;
  169. +import net.sf.l2j.gameserver.model.craft.ManufactureList;
  170. +import net.sf.l2j.gameserver.model.tradelist.TradeItem;
  171. +import net.sf.l2j.gameserver.network.GameClient;
  172. +import net.sf.l2j.gameserver.network.GameClient.GameClientState;
  173. +
  174. +public class OfflineStoresData
  175. +{
  176. + private static final Logger LOGGER = Logger.getLogger(OfflineStoresData.class.getName());
  177. +
  178. + // SQL DEFINITIONS
  179. + private static final String SAVE_OFFLINE_STATUS = "INSERT INTO character_offline_trade (`charId`,`time`,`type`,`title`) VALUES (?,?,?,?)";
  180. + private static final String SAVE_ITEMS = "INSERT INTO character_offline_trade_items (`charId`,`item`,`count`,`price`,`enchant`) VALUES (?,?,?,?,?)";
  181. + private static final String CLEAR_OFFLINE_TABLE = "DELETE FROM character_offline_trade";
  182. + private static final String CLEAR_OFFLINE_TABLE_ITEMS = "DELETE FROM character_offline_trade_items";
  183. + private static final String LOAD_OFFLINE_STATUS = "SELECT * FROM character_offline_trade";
  184. + private static final String LOAD_OFFLINE_ITEMS = "SELECT * FROM character_offline_trade_items WHERE charId = ?";
  185. +
  186. + public void storeOffliners()
  187. + {
  188. + try (Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement save_offline_status = con.prepareStatement(SAVE_OFFLINE_STATUS); PreparedStatement save_items = con.prepareStatement(SAVE_ITEMS))
  189. + {
  190. + try (Statement stm = con.createStatement())
  191. + {
  192. + stm.execute(CLEAR_OFFLINE_TABLE);
  193. + stm.execute(CLEAR_OFFLINE_TABLE_ITEMS);
  194. + }
  195. + for (Player pc : World.getInstance().getPlayers())
  196. + {
  197. + try
  198. + {
  199. + if (pc.getStoreType() != StoreType.NONE && (pc.getClient() == null || pc.getClient().isDetached()))
  200. + {
  201. + save_offline_status.setInt(1, pc.getObjectId());
  202. + save_offline_status.setLong(2, pc.getOfflineStartTime());
  203. + save_offline_status.setInt(3, pc.getStoreType().getId());
  204. + switch (pc.getStoreType())
  205. + {
  206. + case BUY:
  207. + if (!Config.OFFLINE_TRADE_ENABLE)
  208. + continue;
  209. +
  210. + save_offline_status.setString(4, pc.getBuyList().getTitle());
  211. + for (TradeItem i : pc.getBuyList().getItems())
  212. + {
  213. + save_items.setInt(1, pc.getObjectId());
  214. + save_items.setInt(2, i.getItem().getItemId());
  215. + save_items.setLong(3, i.getCount());
  216. + save_items.setLong(4, i.getPrice());
  217. + save_items.setLong(5, i.getEnchant());
  218. + save_items.addBatch();
  219. + }
  220. + break;
  221. + case SELL:
  222. + case PACKAGE_SELL:
  223. + if (!Config.OFFLINE_TRADE_ENABLE)
  224. + continue;
  225. +
  226. + save_offline_status.setString(4, pc.getSellList().getTitle());
  227. + pc.getSellList().updateItems();
  228. + for (TradeItem i : pc.getSellList().getItems())
  229. + {
  230. + save_items.setInt(1, pc.getObjectId());
  231. + save_items.setInt(2, i.getObjectId());
  232. + save_items.setLong(3, i.getCount());
  233. + save_items.setLong(4, i.getPrice());
  234. + save_items.setLong(5, i.getEnchant());
  235. + save_items.addBatch();
  236. + }
  237. + break;
  238. + case MANUFACTURE:
  239. + if (!Config.OFFLINE_CRAFT_ENABLE)
  240. + continue;
  241. +
  242. + save_offline_status.setString(4, pc.getCreateList().getStoreName());
  243. + for (ManufactureItem i : pc.getCreateList().getList())
  244. + {
  245. + save_items.setInt(1, pc.getObjectId());
  246. + save_items.setInt(2, i.getId());
  247. + save_items.setLong(3, 0L);
  248. + save_items.setLong(4, i.getValue());
  249. + save_items.setLong(5, 0L);
  250. + save_items.addBatch();
  251. + }
  252. + break;
  253. + }
  254. + save_items.executeBatch();
  255. + save_offline_status.execute();
  256. + }
  257. + }
  258. + catch (Exception e)
  259. + {
  260. + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
  261. + }
  262. + }
  263. +
  264. + LOGGER.info(getClass().getSimpleName() + ": Offline traders stored.");
  265. + }
  266. + catch (Exception e)
  267. + {
  268. + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while saving offline traders: " + e, e);
  269. + }
  270. + }
  271. +
  272. + public void restoreOfflineTraders()
  273. + {
  274. + LOGGER.info(getClass().getSimpleName() + ": Loading offline traders...");
  275. + try (Connection con = L2DatabaseFactory.getInstance().getConnection(); Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery(LOAD_OFFLINE_STATUS))
  276. + {
  277. + int nTraders = 0;
  278. + while (rs.next())
  279. + {
  280. + final long time = rs.getLong("time");
  281. + if (Config.OFFLINE_MAX_DAYS > 0)
  282. + {
  283. + final Calendar cal = Calendar.getInstance();
  284. + cal.setTimeInMillis(time);
  285. + cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
  286. + if (cal.getTimeInMillis() <= System.currentTimeMillis())
  287. + continue;
  288. + }
  289. +
  290. + StoreType type = null;
  291. + for (StoreType t : StoreType.values())
  292. + {
  293. + if (t.getId() == rs.getInt("type"))
  294. + {
  295. + type = t;
  296. + break;
  297. + }
  298. + }
  299. + if (type == null)
  300. + {
  301. + LOGGER.warning(getClass().getSimpleName() + ": PrivateStoreType with id " + rs.getInt("type") + " could not be found.");
  302. + continue;
  303. + }
  304. + if (type == StoreType.NONE)
  305. + continue;
  306. +
  307. + final Player player = Player.restore(rs.getInt("charId"));
  308. + if (player == null)
  309. + continue;
  310. +
  311. + try (PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS))
  312. + {
  313. + player.isRunning();
  314. + player.sitDown();
  315. + player.setOnlineStatus(true, false);
  316. +
  317. + World.getInstance().addPlayer(player);
  318. +
  319. + final GameClient client = new GameClient(null);
  320. + client.setDetached(true);
  321. + player.setClient(client);
  322. + client.setPlayer(player);
  323. + client.setAccountName(player.getAccountNamePlayer());
  324. + player.setOnlineStatus(true, true);
  325. + client.setState(GameClientState.IN_GAME);
  326. + player.setOfflineStartTime(time);
  327. + player.spawnMe();
  328. +
  329. + LoginServerThread.getInstance().addClient(player.getAccountName(), client);
  330. +
  331. + stm_items.setInt(1, player.getObjectId());
  332. + try (ResultSet items = stm_items.executeQuery())
  333. + {
  334. + switch (type)
  335. + {
  336. + case BUY:
  337. + while (items.next())
  338. + {
  339. + player.getBuyList().addItemByItemId(items.getInt(2), items.getInt(3), items.getInt(4));
  340. + }
  341. +
  342. + player.getBuyList().setTitle(rs.getString("title"));
  343. + break;
  344. + case SELL:
  345. + case PACKAGE_SELL:
  346. + while (items.next())
  347. + if (player.getSellList().addItem(items.getInt(2), items.getInt(3), items.getInt(4)) == null)
  348. + throw new NullPointerException("NPE at SELL of offlineShop " + player.getObjectId() + " " + items.getInt(2) + " " + items.getInt(3) + " " + items.getInt(4));
  349. +
  350. + player.getSellList().setTitle(rs.getString("title"));
  351. + player.getSellList().setPackaged(type == StoreType.PACKAGE_SELL);
  352. + break;
  353. + case MANUFACTURE:
  354. + final ManufactureList createList = new ManufactureList();
  355. + createList.setStoreName(rs.getString("title"));
  356. + while (items.next())
  357. + createList.add(new ManufactureItem(items.getInt(2), items.getInt(4)));
  358. + player.setCreateList(createList);
  359. + break;
  360. + }
  361. + }
  362. +
  363. + if (Config.OFFLINE_SET_SLEEP)
  364. + player.startAbnormalEffect(0x000080);
  365. +
  366. + player.setStoreType(type);
  367. + player.restoreEffects();
  368. + player.broadcastUserInfo();
  369. +
  370. + nTraders++;
  371. + }
  372. + catch (Exception e)
  373. + {
  374. + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading trader: " + player, e);
  375. +
  376. + player.deleteMe();
  377. + }
  378. + }
  379. +
  380. + LOGGER.info(getClass().getSimpleName() + ": Loaded: " + nTraders + " offline trader(s)");
  381. +
  382. + try (Statement stm1 = con.createStatement())
  383. + {
  384. + stm1.execute(CLEAR_OFFLINE_TABLE);
  385. + stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS);
  386. + }
  387. + }
  388. + catch (Exception e)
  389. + {
  390. + LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error while loading offline traders: ", e);
  391. + }
  392. + }
  393. +
  394. + public static boolean offlineMode(Player player)
  395. + {
  396. + if (player.isInOlympiadMode() || player.isFestivalParticipant() || player.isInJail() || player.getBoat() != null)
  397. + return false;
  398. +
  399. + boolean canSetShop = false;
  400. + switch (player.getStoreType())
  401. + {
  402. + case SELL:
  403. + case PACKAGE_SELL:
  404. + case BUY:
  405. + canSetShop = Config.OFFLINE_TRADE_ENABLE;
  406. + break;
  407. + case MANUFACTURE:
  408. + canSetShop = Config.OFFLINE_CRAFT_ENABLE;
  409. + break;
  410. + }
  411. + if (Config.OFFLINE_MODE_IN_PEACE_ZONE && !player.isInsideZone(ZoneId.PEACE))
  412. + canSetShop = false;
  413. +
  414. + return canSetShop;
  415. + }
  416. +
  417. + public static OfflineStoresData getInstance()
  418. + {
  419. + return SingletonHolder._instance;
  420. + }
  421. +
  422. + private static class SingletonHolder
  423. + {
  424. + protected static final OfflineStoresData _instance = new OfflineStoresData();
  425. + }
  426. +}
  427. \ No newline at end of file
  428. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/enums/actors/StoreType.java
  429. +++ aCis_gameserver/java/net/sf/l2j/gameserver/enums/actors/StoreType.java
  430. @@ -13,12 +13,21 @@
  431. private int _id;
  432.  
  433. private StoreType(int id)
  434. {
  435. _id = id;
  436. }
  437. + public static StoreType findById(int id)
  438. + {
  439. + for (StoreType privateStoreType : values())
  440. + {
  441. + if (privateStoreType.getId() == id)
  442. + return privateStoreType;
  443. + }
  444. + return null;
  445. + }
  446.  
  447. public int getId()
  448. {
  449. return _id;
  450. }
  451. }
  452. \ No newline at end of file
  453. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
  454. +++ aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
  455. @@ -2604,15 +2604,20 @@
  456. {
  457. _client = client;
  458. }
  459.  
  460. public String getAccountName()
  461. {
  462. + if (getClient() == null)
  463. + return getAccountNamePlayer();
  464. return _accountName;
  465. }
  466. -
  467. + public String getAccountNamePlayer()
  468. + {
  469. + return _accountName;
  470. + }
  471. public Map<Integer, String> getAccountChars()
  472. {
  473. return _chars;
  474. }
  475.  
  476. /**
  477. @@ -4110,22 +4115,34 @@
  478. * Set the Store type of the Player.
  479. * @param type : 0 = none, 1 = sell, 2 = sellmanage, 3 = buy, 4 = buymanage, 5 = manufacture.
  480. */
  481. public void setStoreType(StoreType type)
  482. {
  483. _storeType = type;
  484. + if (Config.OFFLINE_DISCONNECT_FINISHED && type == StoreType.NONE && (getClient() == null || getClient().isDetached()))
  485. + deleteMe();
  486. }
  487.  
  488. /**
  489. * @return The Store type of the Player.
  490. */
  491. public StoreType getStoreType()
  492. {
  493. return _storeType;
  494. }
  495.  
  496. + private long _offlineShopStart;
  497. + public long getOfflineStartTime()
  498. + {
  499. + return _offlineShopStart;
  500. + }
  501. + public void setOfflineStartTime(long time)
  502. + {
  503. + _offlineShopStart = time;
  504. + }
  505. +
  506. /**
  507. * @return true if the {@link Player} can use dwarven recipes.
  508. */
  509. public boolean hasDwarvenCraft()
  510. {
  511. return hasSkill(L2Skill.SKILL_CREATE_DWARVEN);
  512. diff --git aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java
  513. +++ aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java
  514. @@ -18,15 +18,18 @@
  515.  
  516. import net.sf.l2j.Config;
  517. import net.sf.l2j.L2DatabaseFactory;
  518. import net.sf.l2j.gameserver.LoginServerThread;
  519. import net.sf.l2j.gameserver.data.sql.ClanTable;
  520. import net.sf.l2j.gameserver.data.sql.PlayerInfoTable;
  521. +import net.sf.l2j.gameserver.enums.MessageType;
  522. +import net.sf.l2j.gameserver.enums.ZoneId;
  523. import net.sf.l2j.gameserver.model.CharSelectSlot;
  524. import net.sf.l2j.gameserver.model.World;
  525. import net.sf.l2j.gameserver.model.actor.Player;
  526. +import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
  527. import net.sf.l2j.gameserver.model.pledge.Clan;
  528. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  529. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  530. import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  531.  
  532. /**
  533. @@ -205,22 +208,78 @@
  534. ThreadPool.execute(() ->
  535. {
  536. boolean fast = true;
  537. if (getPlayer() != null && !isDetached())
  538. {
  539. setDetached(true);
  540. + if (offlineMode(getPlayer()))
  541. + {
  542. + if (getPlayer().getParty() != null)
  543. + getPlayer().getParty().removePartyMember(getPlayer(), MessageType.EXPELLED);
  544. + OlympiadManager.getInstance().unRegisterNoble(getPlayer());
  545. +
  546. + // If the Character has Pet, unsummon it
  547. + if (getPlayer().hasPet())
  548. + {
  549. + getPlayer().getSummon().unSummon(getPlayer());
  550. + // Dead pet wasn't unsummoned, broadcast npcinfo changes (pet will be without owner name - means owner offline)
  551. + if (getPlayer().getSummon() != null)
  552. + getPlayer().getSummon().updateAndBroadcastStatus(0);
  553. + }
  554. +
  555. + if (Config.OFFLINE_SET_SLEEP)
  556. + getPlayer().startAbnormalEffect(0x000080);
  557. +
  558. + if (getPlayer().getOfflineStartTime() == 0)
  559. + getPlayer().setOfflineStartTime(System.currentTimeMillis());
  560. +
  561. + return;
  562. + }
  563. fast = !getPlayer().isInCombat() && !getPlayer().isLocked();
  564. }
  565. cleanMe(fast);
  566. });
  567. }
  568. catch (RejectedExecutionException e)
  569. {
  570. }
  571. }
  572.  
  573. + public static boolean offlineMode(Player player)
  574. + {
  575. + if (player.isInOlympiadMode() || player.isFestivalParticipant() || player.isInJail() || player.getBoat() != null)
  576. + return false;
  577. +
  578. + boolean canSetShop = false;
  579. + switch (player.getStoreType())
  580. + {
  581. + case SELL:
  582. + case PACKAGE_SELL:
  583. + case BUY:
  584. + {
  585. + canSetShop = Config.OFFLINE_TRADE_ENABLE;
  586. + break;
  587. + }
  588. + case MANUFACTURE:
  589. + {
  590. + canSetShop = Config.OFFLINE_TRADE_ENABLE;
  591. + break;
  592. + }
  593. + default:
  594. + {
  595. + canSetShop = Config.OFFLINE_CRAFT_ENABLE && player.isCrafting();
  596. + break;
  597. + }
  598. + }
  599. +
  600. + if (Config.OFFLINE_MODE_IN_PEACE_ZONE && !player.isInsideZone(ZoneId.PEACE))
  601. + canSetShop = false;
  602. +
  603. + return canSetShop;
  604. + }
  605. +
  606. @Override
  607. protected void onForcedDisconnection()
  608. {
  609. LOGGER.debug("{} disconnected abnormally.", toString());
  610. }
  611.  
  612. @@ -577,12 +636,14 @@
  613. {
  614. _slots = list;
  615. }
  616.  
  617. public void close(L2GameServerPacket gsp)
  618. {
  619. + if (getConnection() == null)
  620. + return;
  621. getConnection().close(gsp);
  622. }
  623.  
  624. private int getObjectIdForSlot(int charslot)
  625. {
  626. final CharSelectSlot info = getCharSelectSlot(charslot);
  627.  
  628.  
  629.  
  630. Index: DataPack
  631.  
  632. +# =================================================================
  633. +# Offline trade/craft
  634. +# =================================================================
  635. +
  636. +# Option to enable or disable offline trade feature.
  637. +# Enable -> true, Disable -> false
  638. +OfflineTradeEnable = True
  639. +
  640. +# Option to enable or disable offline craft feature.
  641. +# Enable -> true, Disable -> false
  642. +OfflineCraftEnable = True
  643. +
  644. +# If set to True, off-line shops will be possible only in peace zones.
  645. +# Default: False
  646. +OfflineModeInPeaceZone = True
  647. +
  648. +# If set to True, players in off-line shop mode will not take any damage, thus they cannot be killed.
  649. +# Default: False
  650. +OfflineModeNoDamage = False
  651. +
  652. +# Restore offline traders/crafters after restart/shutdown.
  653. +# Default: False
  654. +RestoreOffliners = True
  655. +
  656. +# Do not restore offline characters, after OfflineMaxDays days spent from first restore.
  657. +# Require server restart to disconnect expired shops.
  658. +# 0 = disabled (always restore).
  659. +# Default: 7
  660. +OfflineMaxDays = 7
  661. +
  662. +# Disconnect shop after finished selling, buying.
  663. +# Default: True
  664. +OfflineDisconnectFinished = True
  665. +
  666. +#Offline Effect Sleep
  667. +OfflineSetSleepEffect = True
  668.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement