Guest User

Untitled

a guest
May 6th, 2015
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.75 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Dream_GameServer
  3. Index: src/com/dream/game/model/itemcontainer/PcInventory.java
  4. ===================================================================
  5. --- src/com/dream/game/model/itemcontainer/PcInventory.java (revision 1760)
  6. +++ src/com/dream/game/model/itemcontainer/PcInventory.java (working copy)
  7. @@ -28,8 +28,8 @@
  8. import com.dream.game.datatables.SkillTable;
  9. import com.dream.game.datatables.sql.ItemTable;
  10. import com.dream.game.manager.FortSiegeManager;
  11. +import com.dream.game.manager.TimedItemManager;
  12. import com.dream.game.model.L2Object;
  13. -import com.dream.game.model.TimedItemControl;
  14. import com.dream.game.model.TradeList;
  15. import com.dream.game.model.TradeList.TradeItem;
  16. import com.dream.game.model.actor.instance.L2ItemInstance;
  17. @@ -309,7 +309,6 @@
  18. }
  19. }
  20. @Override
  21. public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
  22. {
  23. @@ -324,9 +323,9 @@
  24. {
  25. _ancientAdena = item;
  26. }
  27. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  28. + {
  29. + TimedItemManager.getInstance().setTimed(item);
  30. + }
  31. return item;
  32. }
  33. @@ -348,9 +347,9 @@
  34. {
  35. _ancientAdena = item;
  36. }
  37. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  38. + {
  39. + TimedItemManager.getInstance().setTimed(item);
  40. + }
  41. return item;
  42. }
  43. @@ -393,9 +392,9 @@
  44. {
  45. _ancientAdena = null;
  46. }
  47. + if ((item != null) && !Config.LIST_TIMED_ITEMS.contains(item.getItemId()))
  48. + {
  49. + TimedItemManager.getInstance().destroy(item);
  50. + }
  51. return item;
  52. }
  53. Index: src/com/dream/game/L2GameServer.java
  54. ===================================================================
  55. --- src/com/dream/game/L2GameServer.java (revision 1760)
  56. +++ src/com/dream/game/L2GameServer.java (working copy)
  57. @@ -88,6 +88,7 @@
  58. import com.dream.game.manager.RaidBossSpawnManager;
  59. import com.dream.game.manager.RaidPointsManager;
  60. import com.dream.game.manager.SiegeManager;
  61. +import com.dream.game.manager.TimedItemManager;
  62. import com.dream.game.manager.TownManager;
  63. import com.dream.game.manager.ZoneManager;
  64. import com.dream.game.manager.clanhallsiege.BanditStrongholdSiege;
  65. @@ -369,7 +369,7 @@
  66. CastleManorManager.getInstance();
  67. L2Manor.getInstance();
  68. AuctionManager.getInstance();
  69. + TimedItemManager.getInstance();
  70. PartyRoomManager.getInstance();
  71.  
  72. Console.printSection("Olympiad");
  73.  
  74. Index: src/com/dream/Config.java
  75. ===================================================================
  76. --- src/com/dream/Config.java (revision 1783)
  77. +++ src/com/dream/Config.java (working copy)
  78. @@ -91,6 +91,9 @@
  79. public static boolean GRIDS_ALWAYS_ON;
  80. public static String PROTECTED_ITEMS;
  81. public static FastList LIST_PROTECTED_ITEMS = new FastList<>();
  82. + public static String TIMED_ITEMS;
  83. + public static FastList LIST_TIMED_ITEMS = new FastList<>();
  84. + public static int TIMED_ITEM_TIME;
  85. public static Pattern CNAME_PATTERN;
  86. public static Pattern PET_NAME_PATTERN;
  87. public static Pattern CLAN_ALLY_NAME_PATTERN;
  88. @@ -217,6 +220,14 @@
  89. LIST_PROTECTED_ITEMS.add(Integer.parseInt(id.trim()));
  90. }
  91.  
  92. + TIMED_ITEMS = altSettings.getProperty("ListOfTimedItems");
  93. + TIMED_ITEM_TIME = Integer.parseInt(altSettings.getProperty("TimedItemTime", "2"));
  94. + LIST_TIMED_ITEMS = new FastList<>();
  95. + for (String id : TIMED_ITEMS.trim().split(","))
  96. + {
  97. + LIST_TIMED_ITEMS.add(Integer.parseInt(id.trim()));
  98. + }
  99. +
  100. DESTROY_DROPPED_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyPlayerDroppedItem", "false"));
  101. DESTROY_EQUIPABLE_PLAYER_ITEM = Boolean.parseBoolean(altSettings.getProperty("DestroyEquipableItem", "false"));
  102. SAVE_DROPPED_ITEM = Boolean.parseBoolean(altSettings.getProperty("SaveDroppedItem", "false"));
  103. Index: src/com/dream/game/manager/TimedItemManager.java
  104. ===================================================================
  105. --- src/com/dream/game/manager/TimedItemManager.java (revision 0)
  106. +++ src/com/dream/game/manager/TimedItemManager.java (working copy)
  107. @@ -0,0 +1,331 @@
  108. +package com.dream.game.manager;
  109. +
  110. +import java.sql.Connection;
  111. +import java.sql.PreparedStatement;
  112. +import java.sql.ResultSet;
  113. +import java.sql.SQLException;
  114. +
  115. +import javolution.util.FastMap;
  116. +
  117. +import org.apache.log4j.Logger;
  118. +
  119. +import com.dream.Config;
  120. +import com.dream.L2DatabaseFactory;
  121. +import com.dream.game.model.L2Object;
  122. +import com.dream.game.model.actor.instance.L2ItemInstance;
  123. +import com.dream.game.model.actor.instance.L2PcInstance;
  124. +import com.dream.game.model.world.L2World;
  125. +import com.dream.game.network.ExclusiveTask;
  126. +import com.dream.game.network.SystemMessageId;
  127. +import com.dream.game.network.serverpackets.ItemList;
  128. +import com.dream.game.network.serverpackets.SystemMessage;
  129. +
  130. +public class TimedItemManager
  131. +{
  132. + public final FastMap _timedItems = new FastMap<>();
  133. + private static Logger _log = Logger.getLogger(TimedItemManager.class);
  134. + private static Connection con;
  135. +
  136. + public class Info
  137. + {
  138. + int _charId;
  139. + int _itemId;
  140. + long _activationTime;
  141. + }
  142. +
  143. + public static final TimedItemManager getInstance()
  144. + {
  145. + return SingletonHolder._instance;
  146. + }
  147. +
  148. + private static class SingletonHolder
  149. + {
  150. + protected static final TimedItemManager _instance = new TimedItemManager();
  151. + }
  152. +
  153. + public TimedItemManager()
  154. + {
  155. + restore();
  156. + _startControlTask.schedule(60000);
  157. + }
  158. +
  159. + public boolean getActiveTimed(L2PcInstance pl, boolean trade)
  160. + {
  161. + for (Info i : _timedItems.values())
  162. + {
  163. + if ((i != null) && (i._charId == pl.getObjectId()))
  164. + {
  165. + L2ItemInstance item = pl.getInventory().getItemByObjectId(i._itemId);
  166. + if (item != null)
  167. + {
  168. + if (System.currentTimeMillis() < i._activationTime)
  169. + {
  170. + return true;
  171. + }
  172. + }
  173. + }
  174. + }
  175. + return false;
  176. + }
  177. +
  178. + public synchronized void destroy(L2ItemInstance item)
  179. + {
  180. + Info inf = _timedItems.get(item.getObjectId());
  181. + if (inf != null)
  182. + {
  183. + _timedItems.remove(inf._itemId);
  184. + con = null;
  185. + try
  186. + {
  187. + con = L2DatabaseFactory.getInstance().getConnection(con);
  188. + PreparedStatement statement;
  189. + statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
  190. + statement.setInt(1, inf._charId);
  191. + statement.setInt(2, inf._itemId);
  192. + statement.execute();
  193. + statement.close();
  194. + }
  195. + catch (Exception e)
  196. + {
  197. + e.printStackTrace();
  198. + }
  199. + finally
  200. + {
  201. + try
  202. + {
  203. + con.close();
  204. + }
  205. + catch (Exception e)
  206. + {
  207. +
  208. + }
  209. + }
  210. + }
  211. + }
  212. +
  213. + public synchronized void setTimed(L2ItemInstance item)
  214. + {
  215. + Info inf = _timedItems.get(item.getObjectId());
  216. + if (inf != null)
  217. + {
  218. + inf._charId = item.getOwnerId();
  219. + }
  220. + else
  221. + {
  222. + inf = new Info();
  223. + inf._activationTime = (System.currentTimeMillis() / 1000) + (Config.TIMED_ITEM_TIME * 60);
  224. + inf._charId = item.getOwnerId();
  225. + inf._itemId = item.getObjectId();
  226. + _timedItems.put(inf._itemId, inf);
  227. + }
  228. + saveToDb(inf);
  229. + }
  230. +
  231. + public boolean isActive(L2ItemInstance item)
  232. + {
  233. + for (Info i : _timedItems.values())
  234. + {
  235. + if (i._itemId == item.getObjectId())
  236. + {
  237. + return true;
  238. + }
  239. + }
  240. + return false;
  241. + }
  242. +
  243. + private void restore()
  244. + {
  245. + try
  246. + {
  247. + con = L2DatabaseFactory.getInstance().getConnection(con);
  248. + PreparedStatement statement = con.prepareStatement("SELECT charId, itemId, time FROM character_timed_items");
  249. + ResultSet rs = statement.executeQuery();
  250. +
  251. + while (rs.next())
  252. + {
  253. + Info inf = new Info();
  254. + inf._activationTime = rs.getLong("time");
  255. + inf._charId = rs.getInt("charId");
  256. + inf._itemId = rs.getInt("itemId");
  257. + _timedItems.put(inf._itemId, inf);
  258. + }
  259. + rs.close();
  260. + statement.close();
  261. + _log.info("TimedItems: loaded " + _timedItems.size() + " items ");
  262. + }
  263. + catch (Exception e)
  264. + {
  265. + e.printStackTrace();
  266. + }
  267. + finally
  268. + {
  269. + try
  270. + {
  271. + if (con != null)
  272. + {
  273. + con.close();
  274. + }
  275. + }
  276. + catch (SQLException e)
  277. + {
  278. + e.printStackTrace();
  279. + }
  280. + }
  281. + }
  282. +
  283. + private static void saveToDb(Info temp)
  284. + {
  285. + try
  286. + {
  287. + con = L2DatabaseFactory.getInstance().getConnection(con);
  288. + PreparedStatement statement;
  289. + statement = con.prepareStatement("update character_timed_items set charId = ? where itemId = ?");
  290. + statement.setInt(1, temp._charId);
  291. + statement.setInt(2, temp._itemId);
  292. + if (statement.executeUpdate() == 0)
  293. + {
  294. + statement.close();
  295. + statement = con.prepareStatement("INSERT INTO character_timed_items (charId, itemId, time) VALUES (?, ?, ?)");
  296. + statement.setInt(1, temp._charId);
  297. + statement.setInt(2, temp._itemId);
  298. + statement.setLong(3, temp._activationTime);
  299. + statement.execute();
  300. + }
  301. + statement.close();
  302. + }
  303. + catch (Exception e)
  304. + {
  305. + e.printStackTrace();
  306. + }
  307. + finally
  308. + {
  309. + try
  310. + {
  311. + if (con != null)
  312. + {
  313. + con.close();
  314. + }
  315. + }
  316. + catch (SQLException e)
  317. + {
  318. + e.printStackTrace();
  319. + }
  320. + }
  321. + }
  322. +
  323. + public void delete(Info temp)
  324. + {
  325. + _timedItems.remove(temp._itemId);
  326. + try
  327. + {
  328. + con = L2DatabaseFactory.getInstance().getConnection(con);
  329. + PreparedStatement statement;
  330. + statement = con.prepareStatement("DELETE FROM character_timed_items WHERE charId = ? AND itemId = ?");
  331. + statement.setInt(1, temp._charId);
  332. + statement.setInt(2, temp._itemId);
  333. + statement.execute();
  334. + statement.close();
  335. + }
  336. + catch (Exception e)
  337. + {
  338. + e.printStackTrace();
  339. + }
  340. + finally
  341. + {
  342. + try
  343. + {
  344. + if (con != null)
  345. + {
  346. + con.close();
  347. + }
  348. + }
  349. + catch (SQLException e)
  350. + {
  351. + e.printStackTrace();
  352. + }
  353. + }
  354. + L2PcInstance pl = L2World.getInstance().getPlayer(temp._charId);
  355. + if (pl != null)
  356. + {
  357. + L2ItemInstance item = pl.getInventory().getItemByObjectId(temp._itemId);
  358. + if (item != null)
  359. + {
  360. + if (item.isEquipped())
  361. + {
  362. + pl.getInventory().unEquipItemInSlot(item.getLocationSlot());
  363. + }
  364. + pl.getInventory().destroyItem("timeLost", item, pl, pl);
  365. + pl.sendPacket(new ItemList(pl, false));
  366. + }
  367. +
  368. + SystemMessage msg = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
  369. + msg.addItemName(item);
  370. + pl.sendPacket(msg);
  371. +
  372. + }
  373. + else
  374. + {
  375. + con = null;
  376. + try
  377. + {
  378. + con = L2DatabaseFactory.getInstance().getConnection(con);
  379. + PreparedStatement statement;
  380. + if (temp._charId != 0)
  381. + {
  382. + statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? AND object_id = ?");
  383. + statement.setInt(1, temp._charId);
  384. + statement.setInt(2, temp._itemId);
  385. + statement.execute();
  386. + statement.close();
  387. + }
  388. + else
  389. + {
  390. + for (L2Object o : L2World.getInstance().getAllVisibleObjects())
  391. + {
  392. + if (o.getObjectId() == temp._itemId)
  393. + {
  394. + L2World.getInstance().removeVisibleObject(o, o.getWorldRegion());
  395. + break;
  396. + }
  397. + }
  398. + }
  399. + }
  400. + catch (Exception e)
  401. + {
  402. + e.printStackTrace();
  403. + }
  404. + finally
  405. + {
  406. + try
  407. + {
  408. + if (con != null)
  409. + {
  410. + con.close();
  411. + }
  412. + }
  413. + catch (SQLException e)
  414. + {
  415. + e.printStackTrace();
  416. + }
  417. + }
  418. + }
  419. + }
  420. +
  421. + private final ExclusiveTask _startControlTask = new ExclusiveTask()
  422. + {
  423. + @Override
  424. + protected void onElapsed()
  425. + {
  426. + for (Info temp : _timedItems.values())
  427. + {
  428. + if (temp._activationTime < (System.currentTimeMillis() / 1000))
  429. + {
  430. +
  431. + delete(temp);
  432. + }
  433. + }
  434. + schedule(60000);
  435. + }
  436. + };
  437. +
  438. +}
  439. \ No newline at end of file
  440. ### Eclipse Workspace Patch 1.0
  441. #P Dream_GameServer
  442. Index: src/com/dream/game/network/ExclusiveTask.java
  443. ===================================================================
  444. +++ src/com/dream/game/network/ExclusiveTask.java (working copy)
  445. @@ -1,109 +0,0 @@
  446. +package com.dream.game.network;
  447. +
  448. +import java.util.concurrent.Future;
  449. +
  450. +public abstract class ExclusiveTask
  451. +{
  452. + private final boolean _returnIfAlreadyRunning;
  453. +
  454. + private Future<?> _future;
  455. + private boolean _isRunning;
  456. + private Thread _currentThread;
  457. +
  458. + protected ExclusiveTask(boolean returnIfAlreadyRunning)
  459. + {
  460. + _returnIfAlreadyRunning = returnIfAlreadyRunning;
  461. + }
  462. +
  463. + protected ExclusiveTask()
  464. + {
  465. + this(false);
  466. + }
  467. +
  468. + public synchronized boolean isScheduled()
  469. + {
  470. + return _future != null;
  471. + }
  472. +
  473. + public synchronized final void cancel()
  474. + {
  475. + if (_future != null)
  476. + {
  477. + _future.cancel(false);
  478. + _future = null;
  479. + }
  480. + }
  481. +
  482. + public synchronized final void schedule(long delay)
  483. + {
  484. + cancel();
  485. +
  486. + _future = ThreadPoolManager.getInstance().schedule(_runnable, delay);
  487. + }
  488. +
  489. + public synchronized final void scheduleAtFixedRate(long delay, long period)
  490. + {
  491. + cancel();
  492. +
  493. + _future = ThreadPoolManager.getInstance().scheduleAtFixedRate(_runnable, delay, period);
  494. + }
  495. +
  496. + private final Runnable _runnable = new Runnable()
  497. + {
  498. + @Override
  499. + public void run()
  500. + {
  501. + if (tryLock())
  502. + {
  503. + try
  504. + {
  505. + onElapsed();
  506. + }
  507. + finally
  508. + {
  509. + unlock();
  510. + }
  511. + }
  512. + }
  513. + };
  514. +
  515. + protected abstract void onElapsed();
  516. +
  517. + public synchronized boolean tryLock()
  518. + {
  519. + if (_returnIfAlreadyRunning)
  520. + {
  521. + return !_isRunning;
  522. + }
  523. +
  524. + _currentThread = Thread.currentThread();
  525. +
  526. + for (;;)
  527. + {
  528. + try
  529. + {
  530. + notifyAll();
  531. +
  532. + if (_currentThread != Thread.currentThread())
  533. + {
  534. + return false;
  535. + }
  536. +
  537. + if (!_isRunning)
  538. + {
  539. + return true;
  540. + }
  541. +
  542. + wait();
  543. + }
  544. + catch (InterruptedException e)
  545. + {
  546. + }
  547. + }
  548. + }
  549. +
  550. + public synchronized void unlock()
  551. + {
  552. + _isRunning = false;
  553. + }
  554. +}
  555.  
  556.  
  557.  
  558.  
  559.  
  560. ### Eclipse Workspace Patch 1.0
  561. #P Dream_DataPack
  562. Index: sql/server/character_timed_items.sql
  563. ===================================================================
  564. --- sql/server/character_timed_items.sql (revision 1754)
  565. +++ sql/server/character_timed_items.sql (working copy)
  566. @@ -1,6 +0,0 @@
  567. +DROP TABLE IF EXISTS `character_timed_items`;
  568. +CREATE TABLE `character_timed_items` (
  569. + `charId` int(11) NOT NULL,
  570. + `itemId` int(11) NOT NULL,
  571. + `time` decimal(20,0) NOT NULL DEFAULT '0'
  572. +) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  573. \ No newline at end of file
  574.  
  575.  
  576.  
  577. #=======================================#
  578. # Timed item
  579. #=======================================#
  580. # Timed Item ID use , for separate (57,3441,5588...)
  581. ListOfTimedItems = 57,3441,5588
  582.  
  583. # Time for item disappear in Hour's
  584. TimedItemTime = 2
Advertisement
Add Comment
Please, Sign In to add comment