Advertisement
gabrielb

Untitled

Jun 14th, 2021
1,376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 29.71 KB | None | 0 0
  1. Index: L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java b/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java
  7. --- a/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java   (revision 76a1a838b17075eac38564a899142198d6d06866)
  8. +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java   (date 1623673663023)
  9. @@ -19,6 +19,7 @@
  10.  package l2r.gameserver;
  11.  
  12.  import com.l2jserver.mmocore.SelectorThread;
  13. +import l2r.features.FAQ.FAQController;
  14.  import gabriel.fightClub.FightClubInit;
  15.  import gabriel.GabrielModsInit;
  16.  import gabriel.GabrielScriptsLoader;
  17. @@ -341,7 +342,7 @@
  18.          TaskManager.getInstance();
  19.          AntiFeedManager.getInstance().registerEvent(AntiFeedManager.GAME_ID);
  20.          PunishmentManager.getInstance();
  21. -
  22. +        FAQController.getInstance();
  23.          // Sunrise systems section
  24.          printSection("Event Engine");
  25.          SunriseEvents.start();
  26. Index: L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java
  27. IDEA additional info:
  28. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  29. <+>UTF-8
  30. ===================================================================
  31. diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java b/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java
  32. --- a/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java (revision 76a1a838b17075eac38564a899142198d6d06866)
  33. +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java (date 1623673663011)
  34. @@ -18,6 +18,7 @@
  35.   */
  36.  package l2r.gameserver;
  37.  
  38. +import l2r.features.FAQ.FAQController;
  39.  import gabriel.GabrielBypass;
  40.  import gabriel.events.partyZone.PartyZoneManager;
  41.  import gabrielEventEngine.interf.SunriseEvents;
  42. @@ -221,6 +222,7 @@
  43.              }
  44.  
  45.              try {
  46. +                FAQController.getInstance().store();
  47.                  disconnectAllCharacters();
  48.                  _log.info("All players disconnected and saved(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
  49.              } catch (Throwable t) {
  50. Index: L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java
  51. IDEA additional info:
  52. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  53. <+>UTF-8
  54. ===================================================================
  55. diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java b/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java
  56. --- a/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java  (revision 76a1a838b17075eac38564a899142198d6d06866)
  57. +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java  (date 1623673663007)
  58. @@ -18,6 +18,7 @@
  59.   */
  60.  package l2r.gameserver.network.clientpackets;
  61.  
  62. +import l2r.features.FAQ.FAQController;
  63.  import gabriel.community.GabrielCBB;
  64.  import gabriel.community.Scripts;
  65.  import gabriel.community.communityBuffer.SchemeBufferGabs;
  66. @@ -88,7 +89,7 @@
  67.                      "_olympiad?command",
  68.                      "manor_menu_select",
  69.                      "admin_",
  70. +                    "faq_"
  71.              };
  72.  
  73.      // S
  74. @@ -313,7 +314,12 @@
  75.                      }
  76.  
  77.                  }
  78. -            } else if (_command.startsWith("_diary")) {
  79. +            }
  80. +            else if (_command.startsWith("faq_")) {
  81. +                FAQController.getInstance().useBypass(_command, activeChar);
  82. +                return;
  83. +            }
  84. +            else if (_command.startsWith("_diary")) {
  85.                  String params = _command.substring(_command.indexOf("?") + 1);
  86.                  StringTokenizer st = new StringTokenizer(params, "&");
  87.                  int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
  88. Index: L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java
  89. IDEA additional info:
  90. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  91. <+>UTF-8
  92. ===================================================================
  93. diff --git a/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java b/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java
  94. new file mode 100644
  95. --- /dev/null   (date 1623673964488)
  96. +++ b/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java  (date 1623673964488)
  97. @@ -0,0 +1,779 @@
  98. +package l2r.features.FAQ;
  99. +
  100. +import gnu.trove.map.hash.TIntObjectHashMap;
  101. +import gnu.trove.set.hash.TIntHashSet;
  102. +import l2r.L2DatabaseFactory;
  103. +import l2r.gameserver.cache.HtmCache;
  104. +import l2r.gameserver.data.sql.CharNameTable;
  105. +import l2r.gameserver.idfactory.IdFactory;
  106. +import l2r.gameserver.model.actor.instance.L2PcInstance;
  107. +import l2r.gameserver.network.serverpackets.ShowBoard;
  108. +
  109. +import java.sql.Connection;
  110. +import java.sql.PreparedStatement;
  111. +import java.sql.ResultSet;
  112. +import java.sql.Statement;
  113. +import java.util.StringTokenizer;
  114. +import java.util.stream.Stream;
  115. +
  116. +/**
  117. + * @author xDem (https://maxcheaters.com/profile/76276-xdem/)
  118. + * Adapted Sunrise: l2jgabdev.com
  119. + */
  120. +public class FAQController
  121. +{
  122. +    private static final int STATUS_NOT_APPROVED = 0;
  123. +    private static final int STATUS_APPROVED = 1;
  124. +    private static final int STATUS_DELETED = -1;
  125. +    private static final int STATUS_PINNED = 2;
  126. +
  127. +    private static final int TOPICS_PER_PAGE = 4;
  128. +
  129. +    private static String SELECT_FAQ = "SELECT * FROM server_faq WHERE status > -1";
  130. +
  131. +    private static String topic_header;
  132. +
  133. +    private final TIntObjectHashMap<FAQTopic> _topics = new TIntObjectHashMap<>();
  134. +
  135. +    private FAQController()
  136. +    {
  137. +        reloadHtml();
  138. +
  139. +        load();
  140. +    }
  141. +
  142. +    public void reloadHtml()
  143. +    {
  144. +        topic_header = HtmCache.getInstance().getHtm((L2PcInstance) null, "data/html/aepvp/cubic/faq/topic_header.htm");
  145. +    }
  146. +
  147. +    private void load()
  148. +    {
  149. +        try (final Connection con = L2DatabaseFactory.getInstance().getConnection();
  150. +             final Statement st  = con.createStatement();
  151. +             final ResultSet rs = st.executeQuery(SELECT_FAQ))
  152. +        {
  153. +            while (rs.next())
  154. +            {
  155. +                final FAQTopic faqTopic = new FAQTopic(rs);
  156. +                _topics.put(faqTopic.getTopicId(), faqTopic);
  157. +            }
  158. +
  159. +            try (final Statement st2 = con.createStatement();
  160. +                 final ResultSet rs2 = st2.executeQuery("SELECT * FROM server_faq_likes"))
  161. +            {
  162. +                while (rs2.next())
  163. +                {
  164. +                    final int playerId = rs2.getInt("player_id");
  165. +                    final int topicId = rs2.getInt("topic_id");
  166. +
  167. +                    final FAQTopic topic = _topics.get(topicId);
  168. +                    if (topic != null)
  169. +                        topic.addLike(playerId);
  170. +                }
  171. +            }
  172. +        }
  173. +        catch (Exception e)
  174. +        {
  175. +            e.printStackTrace();
  176. +        }
  177. +    }
  178. +
  179. +    public boolean useBypass(String cmd, L2PcInstance player)
  180. +    {
  181. +        if (cmd.startsWith("faq_main"))
  182. +        {
  183. +            final StringTokenizer st = new StringTokenizer(cmd);
  184. +            st.nextToken();
  185. +            if (st.hasMoreTokens())
  186. +            {
  187. +                final int page = Integer.parseInt(st.nextToken());
  188. +                final String search = st.hasMoreTokens() ? st.nextToken() : null;
  189. +                renderMain(player, search, page);
  190. +            }
  191. +            else
  192. +                renderMain(player, null);
  193. +            return true;
  194. +        }
  195. +        else if (cmd.startsWith("faq_open"))
  196. +        {
  197. +            if (cmd.length() < 9)
  198. +                renderMain(player, null);
  199. +            else
  200. +            {
  201. +                final int topicId = Integer.parseInt(cmd.substring(9));
  202. +                openTopic(player, topicId);
  203. +            }
  204. +        }
  205. +        else if (cmd.startsWith("faq_search"))
  206. +        {
  207. +            if (cmd.length() < 12)
  208. +                renderMain(player, null);
  209. +            else
  210. +            {
  211. +                final String search = cmd.substring(11);
  212. +                renderMain(player, search);
  213. +            }
  214. +            return true;
  215. +        }
  216. +        else if (cmd.startsWith("faq_topic"))
  217. +        {
  218. +            System.out.println("???");
  219. +            return true;
  220. +        }
  221. +        else if (cmd.startsWith("faq_delete"))
  222. +        {
  223. +            if (cmd.length() < 12)
  224. +                renderMain(player, null);
  225. +            else
  226. +            {
  227. +                final int topicId = Integer.parseInt(cmd.substring(11));
  228. +                deleteTopic(topicId);
  229. +                renderMain(player, null);
  230. +            }
  231. +            return true;
  232. +        }
  233. +        else if (cmd.startsWith("faq_like"))
  234. +        {
  235. +            if (cmd.length() < 10)
  236. +                renderMain(player, null);
  237. +            else
  238. +            {
  239. +                final int topicId = Integer.parseInt(cmd.substring(9));
  240. +                likeTopic(player, topicId);
  241. +            }
  242. +            return true;
  243. +        }
  244. +        else if (cmd.startsWith("faq_edit_content"))
  245. +        {
  246. +            final StringTokenizer st = new StringTokenizer(cmd);
  247. +
  248. +            st.nextToken();
  249. +
  250. +            final int topicId = Integer.parseInt(st.nextToken());
  251. +
  252. +            final String content = st.nextToken("\t").substring(1).replace("\r\n", "<br1>");
  253. +
  254. +            editTopicContent(player, topicId, content);
  255. +
  256. +            return true;
  257. +        }
  258. +        else if (cmd.startsWith("faq_edit_title"))
  259. +        {
  260. +            final StringTokenizer st = new StringTokenizer(cmd);
  261. +
  262. +            st.nextToken();
  263. +
  264. +            final int topicId = Integer.parseInt(st.nextToken());
  265. +
  266. +            final String content = st.nextToken("\t").trim().replace("\r\n", "");
  267. +
  268. +            editTopicTitle(player, topicId, content);
  269. +
  270. +            return true;
  271. +        }
  272. +        else if (cmd.startsWith("faq_edit_icon"))
  273. +        {
  274. +            final StringTokenizer st = new StringTokenizer(cmd);
  275. +
  276. +            st.nextToken();
  277. +
  278. +            final int topicId = Integer.parseInt(st.nextToken());
  279. +            final int ic = Integer.parseInt(st.nextToken());
  280. +
  281. +            final String icon = st.nextToken("\t").trim();
  282. +
  283. +            editTopicIcon(player, topicId, icon, ic);
  284. +
  285. +            return true;
  286. +        }
  287. +        else if (cmd.startsWith("faq_edit"))
  288. +        {
  289. +            if (cmd.length() < 10)
  290. +                renderMain(player, null);
  291. +            else
  292. +            {
  293. +                final int topicId = Integer.parseInt(cmd.substring(9));
  294. +                editTopic(player, topicId);
  295. +            }
  296. +            return true;
  297. +        }
  298. +        else if (cmd.startsWith("faq_stat"))
  299. +        {
  300. +            final StringTokenizer st = new StringTokenizer(cmd);
  301. +            st.nextToken();
  302. +
  303. +            if (st.hasMoreTokens())
  304. +            {
  305. +                final int topicId = Integer.parseInt(st.nextToken());
  306. +                final int status = Integer.parseInt(st.nextToken());
  307. +                editTopicStatus(player, topicId, status);
  308. +            }
  309. +            return true;
  310. +        }
  311. +        else if (cmd.startsWith("faq_create_main"))
  312. +        {
  313. +            createMain(player);
  314. +            return true;
  315. +        }
  316. +        else if (cmd.startsWith("faq_create"))
  317. +        {
  318. +            final StringTokenizer st = new StringTokenizer(cmd);
  319. +            st.nextToken();
  320. +
  321. +            if (st.hasMoreTokens())
  322. +            {
  323. +                final String title = st.nextToken("%-%").trim().replace("\r\n", "");
  324. +                if (st.hasMoreTokens())
  325. +                {
  326. +                    final String cont = st.nextToken("%-%").trim().replace("\r\n", "<br1>");
  327. +
  328. +                    createTopic(player, title, cont);
  329. +                }
  330. +
  331. +            }
  332. +
  333. +            return true;
  334. +        }
  335. +        return false;
  336. +    }
  337. +
  338. +    private void createMain(final L2PcInstance player)
  339. +    {
  340. +        String html = HtmCache.getInstance().getHtml("data/html/aepvp/cubic/faq/create.htm", player);
  341. +        separateAndSend(html, player);
  342. +    }
  343. +
  344. +    private void createTopic(final L2PcInstance player, final String title, final String content)
  345. +    {
  346. +        if (!player.isGM())
  347. +        {
  348. +            int counter = 0;
  349. +            for (final FAQTopic topic : _topics.valueCollection())
  350. +            {
  351. +                if (topic._status == STATUS_NOT_APPROVED && topic._author == player.getObjectId() && counter++ > 2)
  352. +                {
  353. +                    player.sendMessage("You have already submitted 3 or more topics that await approval by a GM. Please wait.");
  354. +                    return;
  355. +                }
  356. +            }
  357. +
  358. +            if (player.getLevel() < 90)
  359. +            {
  360. +                player.sendMessage("You must be at least Lv. 90 to create a FAQ.");
  361. +                return;
  362. +            }
  363. +        }
  364. +
  365. +        final FAQTopic topic = new FAQTopic(player, title, content);
  366. +        _topics.put(topic.getTopicId(), topic);
  367. +
  368. +        openTopic(player, topic.getTopicId());
  369. +    }
  370. +
  371. +    private void editTopicStatus(final L2PcInstance player, final int topicId, final int status)
  372. +    {
  373. +        if (player.isGM())
  374. +        {
  375. +            final FAQTopic topic = _topics.get(topicId);
  376. +            if (topic != null)
  377. +            {
  378. +                if (status == STATUS_APPROVED)
  379. +                    topic.toggleActive();
  380. +                else
  381. +                    topic.togglePinned();
  382. +            }
  383. +
  384. +        }
  385. +
  386. +        editTopic(player, topicId);
  387. +    }
  388. +
  389. +    private void editTopicIcon(final L2PcInstance player, final int topicId, final String icon, final int ic)
  390. +    {
  391. +        final FAQTopic topic = _topics.get(topicId);
  392. +        if (topic != null)
  393. +        {
  394. +            topic.updateIcon(icon, ic == 1);
  395. +        }
  396. +        editTopic(player, topicId);
  397. +    }
  398. +
  399. +    private void editTopicTitle(final L2PcInstance player, final int topicId, final String title)
  400. +    {
  401. +        final FAQTopic topic = _topics.get(topicId);
  402. +        if (topic != null)
  403. +            topic.updateTitle(title);
  404. +
  405. +        editTopic(player, topicId);
  406. +    }
  407. +
  408. +    private void editTopicContent(final L2PcInstance player, final int topicId, final String content)
  409. +    {
  410. +        final FAQTopic topic = _topics.get(topicId);
  411. +        if (topic != null)
  412. +            topic.updateContent(content);
  413. +
  414. +        editTopic(player, topicId);
  415. +    }
  416. +
  417. +    private void editTopic(final L2PcInstance player, final int topicId)
  418. +    {
  419. +        final FAQTopic topic = _topics.get(topicId);
  420. +        if (topic != null)
  421. +        {
  422. +
  423. +            String htmlStr = topic.render(HtmCache.getInstance().getHtm(player, "data/html/aepvp/cubic/faq/edit.htm"), player);
  424. +
  425. +
  426. +            htmlStr = htmlStr.replace("%id%", String.valueOf(topicId));
  427. +
  428. +            htmlStr = htmlStr.replace("%appr%", topic.isActive() ? "Hide" : "Approve");
  429. +            htmlStr = htmlStr.replace("%pin%", topic.isPinned() ? "Unpin" : "Pin");
  430. +            separateAndSend(htmlStr, player);
  431. +        }
  432. +    }
  433. +
  434. +    private void openTopic(final L2PcInstance player, final int topicId)
  435. +    {
  436. +        final FAQTopic topic = _topics.get(topicId);
  437. +        if (topic != null)
  438. +        {
  439. +            final String npcHtml = topic.renderTopic(player);
  440. +            separateAndSend(npcHtml, player);
  441. +        }
  442. +    }
  443. +
  444. +    private void renderMain(final L2PcInstance player, final String search)
  445. +    {
  446. +        renderMain(player, search, 0);
  447. +    }
  448. +
  449. +    private void renderMain(final L2PcInstance player, final String search, final int page)
  450. +    {
  451. +        String npcHtml = HtmCache.getInstance().getHtml("data/html/aepvp/cubic/faq/main.htm", player);
  452. +
  453. +        final StringBuilder sb = new StringBuilder(2048);
  454. +
  455. +        final Stream<FAQTopic> topicsStream = getTopics(search);
  456. +
  457. +        final FAQTopic[] topics = topicsStream.filter((topic) -> {return topic.isRenderableFor(player);}).toArray(FAQTopic[]::new);
  458. +        final int topicsLen = topics.length;
  459. +        final int pages = topicsLen < TOPICS_PER_PAGE ? 1 : topicsLen / TOPICS_PER_PAGE + ((topicsLen % TOPICS_PER_PAGE) > 0 ? 1 : 0);
  460. +
  461. +        for (int i = 0; i < TOPICS_PER_PAGE; i++)
  462. +        {
  463. +            final int indx = TOPICS_PER_PAGE * page + i;
  464. +            if (indx < topicsLen)
  465. +            {
  466. +                final FAQTopic topic = topics[indx];
  467. +                topic.renderHeader(sb, player);
  468. +            }
  469. +            else
  470. +                sb.append("<img height=89/>");
  471. +
  472. +        }
  473. +
  474. +        npcHtml = npcHtml.replace("%topic_headers%", sb.toString());
  475. +
  476. +        sb.setLength(0);
  477. +
  478. +        for (int i = 0; i < pages; i++)
  479. +        {
  480. +            if (page == i)
  481. +                sb.append(String.format("<td align=center>Page %d</td>", i+1));
  482. +            else
  483. +                sb.append(String.format("<td align=center><a action=\"bypass faq_main %d %s\">Page %d</a></td>", i, search == null ? "" : search, i + 1));
  484. +        }
  485. +
  486. +
  487. +        npcHtml = npcHtml.replace("%pages1%", sb.toString());
  488. +
  489. +        separateAndSend(npcHtml, player);
  490. +    }
  491. +
  492. +    private Stream<FAQTopic> getTopics(final String search)
  493. +    {
  494. +        final Stream<FAQTopic> topicStream = getTopicsStream();
  495. +        if (search == null)
  496. +            return topicStream;
  497. +        else
  498. +            return topicStream.filter((topic) -> { return topic.matchesSearch(search); });
  499. +    }
  500. +
  501. +    private Stream<FAQTopic> getTopicsStream()
  502. +    {
  503. +        return _topics.valueCollection().stream().sorted();
  504. +    }
  505. +
  506. +    private void likeTopic(final L2PcInstance player, final int topicId)
  507. +    {
  508. +        final FAQTopic topic = _topics.get(topicId);
  509. +        if (topic != null)
  510. +        {
  511. +            topic.tryLike(player);
  512. +        }
  513. +        openTopic(player, topic.getTopicId());
  514. +    }
  515. +
  516. +    private void deleteTopic(final int topicId)
  517. +    {
  518. +        final FAQTopic topic = _topics.get(topicId);
  519. +        if (topic != null)
  520. +        {
  521. +            topic.delete();
  522. +        }
  523. +    }
  524. +
  525. +
  526. +    public static class FAQTopic implements Comparable<FAQTopic>
  527. +    {
  528. +        private final TIntHashSet _likedNew = new TIntHashSet();
  529. +        private final TIntHashSet _liked = new TIntHashSet();
  530. +
  531. +        private static final String nullIcon = "L2UI_ct1.SystemMenuWnd.SystemMenuWnd_df_Help";
  532. +
  533. +        private final int _topicId;
  534. +        private final int _author;
  535. +        private String _title;
  536. +        private String _content;
  537. +
  538. +        private String _icon_a;
  539. +        private String _icon_b;
  540. +
  541. +//      private int _likes;
  542. +
  543. +        private int _status;
  544. +
  545. +        private boolean _updated;
  546. +
  547. +        private boolean _new;
  548. +
  549. +        public boolean matchesSearch(final String search)
  550. +        {
  551. +            final String author = CharNameTable.getInstance().getNameById(_author);
  552. +
  553. +            return author.contains(search)  ||
  554. +                    _title.contains(search)  ||
  555. +                    _content.contains(search)||
  556. +
  557. +                    author.toLowerCase().contains(search.toLowerCase()) ||
  558. +                    _title.toLowerCase().contains(search.toLowerCase())  ||
  559. +                    _content.toLowerCase().contains(search.toLowerCase())
  560. +
  561. +                    ;
  562. +        }
  563. +
  564. +        public FAQTopic(final L2PcInstance author, final String title, final String content)
  565. +        {
  566. +            _topicId = IdFactory.getInstance().getNextId();
  567. +
  568. +            _author = author.getObjectId();
  569. +            _title = title;
  570. +            _content = content;
  571. +
  572. +            _new = true;
  573. +        }
  574. +
  575. +        public FAQTopic(final ResultSet rs) throws Exception
  576. +        {
  577. +            _topicId = rs.getInt("topic_id");
  578. +
  579. +            final int authorId = rs.getInt("author_id");
  580. +            _author = authorId;
  581. +            _title = rs.getString("title");
  582. +            _content = rs.getString("content");
  583. +
  584. +            _icon_a = rs.getString("icon_a");
  585. +            _icon_b = rs.getString("icon_b");
  586. +
  587. +            _status = rs.getInt("status");
  588. +        }
  589. +
  590. +        public void addLike(final int playerId)
  591. +        {
  592. +            _liked.add(playerId);
  593. +        }
  594. +
  595. +        public boolean tryLike(final L2PcInstance player)
  596. +        {
  597. +            final int playerId = player.getObjectId();
  598. +            if (!player.isGM())
  599. +            {
  600. +                if (_liked.contains(playerId))
  601. +                    return false;
  602. +            }
  603. +            _liked.add(playerId);
  604. +            _likedNew.add(playerId);
  605. +            return true;
  606. +        }
  607. +
  608. +        public boolean hasLike(final int playerId)
  609. +        {
  610. +            return _liked.contains(playerId);
  611. +        }
  612. +
  613. +        public void setStatus(final int status)
  614. +        {
  615. +            _status = status;
  616. +        }
  617. +
  618. +        public boolean isRenderableFor(final L2PcInstance player)
  619. +        {
  620. +            return notDeleted() && (isActive() || player.getName().equals(_author) || player.isGM());
  621. +        }
  622. +
  623. +        public boolean isActive()
  624. +        {
  625. +            return _status > STATUS_NOT_APPROVED;
  626. +        }
  627. +
  628. +        public boolean notDeleted()
  629. +        {
  630. +            return _status > STATUS_DELETED;
  631. +        }
  632. +
  633. +        public int getTopicId()
  634. +        {
  635. +            return _topicId;
  636. +        }
  637. +
  638. +        public TIntHashSet getNewLikes()
  639. +        {
  640. +            return _likedNew;
  641. +        }
  642. +
  643. +        public int getLikes()
  644. +        {
  645. +            return _liked.size();
  646. +        }
  647. +
  648. +        public int getRankingLikes()
  649. +        {
  650. +            if (_status == STATUS_PINNED)
  651. +                return getLikes() + 10000;
  652. +            return getLikes();
  653. +        }
  654. +
  655. +        public void updateTitle(final String title)
  656. +        {
  657. +            _title = title;
  658. +            _updated = true;
  659. +        }
  660. +
  661. +        public void updateContent(final String content)
  662. +        {
  663. +            _content = content;
  664. +            _updated = true;
  665. +        }
  666. +
  667. +        public void togglePinned()
  668. +        {
  669. +            if (_status == 2)
  670. +                _status = 1;
  671. +            else
  672. +                _status = 2;
  673. +            _updated = true;
  674. +        }
  675. +
  676. +        public void toggleActive()
  677. +        {
  678. +            if (_status < 1)
  679. +                _status = 1;
  680. +            else
  681. +                _status = 0;
  682. +            _updated = true;
  683. +        }
  684. +
  685. +        public boolean isPinned()
  686. +        {
  687. +            return _status == STATUS_PINNED;
  688. +        }
  689. +
  690. +        public boolean isNew()
  691. +        {
  692. +            return _new;
  693. +        }
  694. +
  695. +        public void renderHeader(final StringBuilder sb, final L2PcInstance viewer)
  696. +        {
  697. +            String topicHeader = render(topic_header, viewer);
  698. +
  699. +            if (_status == 2)
  700. +                topicHeader = topicHeader.replace("_Info", "_HeroConfirm");
  701. +            sb.append(topicHeader);
  702. +        }
  703. +
  704. +        public void renderTopic(final StringBuilder sb)
  705. +        {
  706. +
  707. +        }
  708. +
  709. +        public String render(final String render, final L2PcInstance viewer)
  710. +        {
  711. +            final String gmTemplate = String.format("<td align=center><table width=100%%><tr><td><a action=\"bypass faq_delete %d\" msg=\"You want to delete topic %s?\"><font color=\"c43c3c\">Delete</font></a> </td><td><a action=\"bypass faq_edit %d\">Edit</a></td></tr></table></td>", _topicId, _title, _topicId);
  712. +
  713. +            return render.replace("%title%", _title).
  714. +                    replace("%likes%", String.valueOf(getLikes())).
  715. +                    replace("%topic_id%", String.valueOf(_topicId)).
  716. +                    replace("%icon_a%", _icon_a == null ? nullIcon : String.valueOf(_icon_a)).
  717. +                    replace("%icon_b%", _icon_b == null ? nullIcon : String.valueOf(_icon_b)).
  718. +                    replace("%gm%", viewer.isGM() ? gmTemplate : "").
  719. +                    replace(" Likes", isPinned() ? " Likes - <font color=\"c43c3c\">PINNED</font>" : !isActive() ? " Likes - <font color=\"LEVEL\">UNLISTED</font>" : " Likes").
  720. +                    replace("%content%", _content).
  721. +                    replace("%ilike%", hasLike(viewer.getObjectId()) ? "" : "<tr></tr><tr><td align=center><a action=\"bypass faq_like %id%\">I Like this!</a></td></tr>").
  722. +                    replace("%id%", String.valueOf(_topicId)).
  723. +                    replace("%author%", CharNameTable.getInstance().getNameById(_author));
  724. +        }
  725. +
  726. +        public String renderTopic(final L2PcInstance viewer)
  727. +        {
  728. +            final String html = HtmCache.getInstance().getHtm(viewer, "data/html/aepvp/cubic/faq/topic.htm");
  729. +
  730. +
  731. +            final String renderHtm = render(html, viewer);
  732. +
  733. +            return renderHtm;
  734. +        }
  735. +
  736. +        public void updateIcon(final String icon, final boolean ic)
  737. +        {
  738. +            if (ic)
  739. +                _icon_a = icon;
  740. +            else
  741. +                _icon_b = icon;
  742. +            _updated = true;
  743. +        }
  744. +
  745. +        public void activate()
  746. +        {
  747. +            _status = STATUS_APPROVED;
  748. +            _updated = true;
  749. +        }
  750. +
  751. +        public void delete()
  752. +        {
  753. +            _status = STATUS_DELETED;
  754. +            _updated = true;
  755. +        }
  756. +
  757. +        public boolean isUpdated()
  758. +        {
  759. +            return _updated;
  760. +        }
  761. +
  762. +        @Override
  763. +        public int compareTo(FAQTopic other)
  764. +        {
  765. +            return other.getRankingLikes() - getRankingLikes();
  766. +        }
  767. +
  768. +        @Override
  769. +        public String toString()
  770. +        {
  771. +            return _title + " By " + _author;
  772. +        }
  773. +    }
  774. +
  775. +    private static class InstanceHolder
  776. +    {
  777. +        private static final FAQController _instance = new FAQController();
  778. +    }
  779. +
  780. +    public static FAQController getInstance()
  781. +    {
  782. +        return InstanceHolder._instance;
  783. +    }
  784. +
  785. +    public void exception(Exception e)
  786. +    {
  787. +        e.printStackTrace();
  788. +    }
  789. +
  790. +    public void store()
  791. +    {
  792. +        try (final Connection con = L2DatabaseFactory.getInstance().getConnection();
  793. +             final PreparedStatement psu = con.prepareStatement("UPDATE server_faq SET author_id = ?, title = ?, content = ?, icon_a = ?, icon_b = ?, status = ? WHERE topic_id = ?");
  794. +             final PreparedStatement psn = con.prepareStatement("INSERT INTO server_faq (topic_id, author_id, title, content, icon_a, icon_b, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
  795. +             final PreparedStatement psl = con.prepareStatement("INSERT INTO server_faq_likes (topic_id, player_id) VALUES (?, ?)");)
  796. +        {
  797. +            con.setAutoCommit(false);
  798. +
  799. +            for (final FAQTopic faqTopic : _topics.valueCollection())
  800. +            {
  801. +                if (faqTopic.isNew())
  802. +                {
  803. +                    psn.setInt(1, faqTopic.getTopicId());
  804. +                    psn.setInt(2, faqTopic._author);
  805. +
  806. +                    psn.setString(3, faqTopic._title);
  807. +                    psn.setString(4, faqTopic._content);
  808. +
  809. +                    psn.setString(5, faqTopic._icon_a);
  810. +                    psn.setString(6, faqTopic._icon_b);
  811. +                    psn.setInt(7, faqTopic._status);
  812. +
  813. +                    psn.addBatch();
  814. +                }
  815. +                else if (faqTopic.isUpdated())
  816. +                {
  817. +                    psu.setInt(1, faqTopic._author);
  818. +                    psu.setString(2, faqTopic._title);
  819. +                    psu.setString(3, faqTopic._content);
  820. +
  821. +                    psu.setString(4, faqTopic._icon_a);
  822. +                    psu.setString(5, faqTopic._icon_b);
  823. +                    psu.setInt(6, faqTopic._status);
  824. +
  825. +                    psu.setInt(7, faqTopic._topicId);
  826. +
  827. +                    psu.addBatch();
  828. +                }
  829. +
  830. +                final TIntHashSet newLikes = faqTopic.getNewLikes();
  831. +                if (!newLikes.isEmpty())
  832. +                {
  833. +                    for (final int playerId : newLikes._set) if (playerId > 0)
  834. +                    {
  835. +                        psl.setInt(1, faqTopic.getTopicId());
  836. +                        psl.setInt(2, playerId);
  837. +
  838. +                        psl.addBatch();
  839. +                    }
  840. +                }
  841. +            }
  842. +
  843. +            final int inserted = psn.executeBatch().length;
  844. +            final int updated = psu.executeBatch().length;
  845. +            final int insertdl = psl.executeBatch().length;
  846. +            con.commit();
  847. +
  848. +            System.err.println("FAQController: Inserted " + inserted + " new FAQ Topics!");
  849. +            System.err.println("FAQController: Updated " + updated + " old FAQ Topics!");
  850. +            System.err.println("FAQController: Inserted " + insertdl + " new FAQ Likes!");
  851. +        }
  852. +        catch (Exception e)
  853. +        {
  854. +            e.printStackTrace();
  855. +        }
  856. +    }
  857. +
  858. +    private void separateAndSend(String html, L2PcInstance acha) {
  859. +        if (html == null) {
  860. +            return;
  861. +        }
  862. +        if (html.length() < 8180) {
  863. +            acha.sendPacket(new ShowBoard(html, "101"));
  864. +            acha.sendPacket(new ShowBoard("", "102"));
  865. +            acha.sendPacket(new ShowBoard("", "103"));
  866. +        } else if (html.length() < (8180 * 2)) {
  867. +            acha.sendPacket(new ShowBoard(html.substring(0, 8180), "101"));
  868. +            acha.sendPacket(new ShowBoard(html.substring(8180), "102"));
  869. +            acha.sendPacket(new ShowBoard("", "103"));
  870. +        } else if (html.length() < (8180 * 3)) {
  871. +            acha.sendPacket(new ShowBoard(html.substring(0, 8180), "101"));
  872. +            acha.sendPacket(new ShowBoard(html.substring(8180, 8180 * 2), "102"));
  873. +            acha.sendPacket(new ShowBoard(html.substring(8180 * 2), "103"));
  874. +        }
  875. +    }
  876. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement