Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java b/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java
- --- a/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java (revision 76a1a838b17075eac38564a899142198d6d06866)
- +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/GameServer.java (date 1623673663023)
- @@ -19,6 +19,7 @@
- package l2r.gameserver;
- import com.l2jserver.mmocore.SelectorThread;
- +import l2r.features.FAQ.FAQController;
- import gabriel.fightClub.FightClubInit;
- import gabriel.GabrielModsInit;
- import gabriel.GabrielScriptsLoader;
- @@ -341,7 +342,7 @@
- TaskManager.getInstance();
- AntiFeedManager.getInstance().registerEvent(AntiFeedManager.GAME_ID);
- PunishmentManager.getInstance();
- -
- + FAQController.getInstance();
- // Sunrise systems section
- printSection("Event Engine");
- SunriseEvents.start();
- Index: L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java b/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java
- --- a/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java (revision 76a1a838b17075eac38564a899142198d6d06866)
- +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/Shutdown.java (date 1623673663011)
- @@ -18,6 +18,7 @@
- */
- package l2r.gameserver;
- +import l2r.features.FAQ.FAQController;
- import gabriel.GabrielBypass;
- import gabriel.events.partyZone.PartyZoneManager;
- import gabrielEventEngine.interf.SunriseEvents;
- @@ -221,6 +222,7 @@
- }
- try {
- + FAQController.getInstance().store();
- disconnectAllCharacters();
- _log.info("All players disconnected and saved(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
- } catch (Throwable t) {
- Index: L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java b/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java
- --- a/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java (revision 76a1a838b17075eac38564a899142198d6d06866)
- +++ b/L2J_SunriseProject_Core/java/l2r/gameserver/network/clientpackets/RequestBypassToServer.java (date 1623673663007)
- @@ -18,6 +18,7 @@
- */
- package l2r.gameserver.network.clientpackets;
- +import l2r.features.FAQ.FAQController;
- import gabriel.community.GabrielCBB;
- import gabriel.community.Scripts;
- import gabriel.community.communityBuffer.SchemeBufferGabs;
- @@ -88,7 +89,7 @@
- "_olympiad?command",
- "manor_menu_select",
- "admin_",
- + "faq_"
- };
- // S
- @@ -313,7 +314,12 @@
- }
- }
- - } else if (_command.startsWith("_diary")) {
- + }
- + else if (_command.startsWith("faq_")) {
- + FAQController.getInstance().useBypass(_command, activeChar);
- + return;
- + }
- + else if (_command.startsWith("_diary")) {
- String params = _command.substring(_command.indexOf("?") + 1);
- StringTokenizer st = new StringTokenizer(params, "&");
- int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
- Index: L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java
- IDEA additional info:
- Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
- <+>UTF-8
- ===================================================================
- diff --git a/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java b/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java
- new file mode 100644
- --- /dev/null (date 1623673964488)
- +++ b/L2J_SunriseProject_Core/java/l2r/features/FAQ/FAQController.java (date 1623673964488)
- @@ -0,0 +1,779 @@
- +package l2r.features.FAQ;
- +
- +import gnu.trove.map.hash.TIntObjectHashMap;
- +import gnu.trove.set.hash.TIntHashSet;
- +import l2r.L2DatabaseFactory;
- +import l2r.gameserver.cache.HtmCache;
- +import l2r.gameserver.data.sql.CharNameTable;
- +import l2r.gameserver.idfactory.IdFactory;
- +import l2r.gameserver.model.actor.instance.L2PcInstance;
- +import l2r.gameserver.network.serverpackets.ShowBoard;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.Statement;
- +import java.util.StringTokenizer;
- +import java.util.stream.Stream;
- +
- +/**
- + * @author xDem (https://maxcheaters.com/profile/76276-xdem/)
- + * Adapted Sunrise: l2jgabdev.com
- + */
- +public class FAQController
- +{
- + private static final int STATUS_NOT_APPROVED = 0;
- + private static final int STATUS_APPROVED = 1;
- + private static final int STATUS_DELETED = -1;
- + private static final int STATUS_PINNED = 2;
- +
- + private static final int TOPICS_PER_PAGE = 4;
- +
- + private static String SELECT_FAQ = "SELECT * FROM server_faq WHERE status > -1";
- +
- + private static String topic_header;
- +
- + private final TIntObjectHashMap<FAQTopic> _topics = new TIntObjectHashMap<>();
- +
- + private FAQController()
- + {
- + reloadHtml();
- +
- + load();
- + }
- +
- + public void reloadHtml()
- + {
- + topic_header = HtmCache.getInstance().getHtm((L2PcInstance) null, "data/html/aepvp/cubic/faq/topic_header.htm");
- + }
- +
- + private void load()
- + {
- + try (final Connection con = L2DatabaseFactory.getInstance().getConnection();
- + final Statement st = con.createStatement();
- + final ResultSet rs = st.executeQuery(SELECT_FAQ))
- + {
- + while (rs.next())
- + {
- + final FAQTopic faqTopic = new FAQTopic(rs);
- + _topics.put(faqTopic.getTopicId(), faqTopic);
- + }
- +
- + try (final Statement st2 = con.createStatement();
- + final ResultSet rs2 = st2.executeQuery("SELECT * FROM server_faq_likes"))
- + {
- + while (rs2.next())
- + {
- + final int playerId = rs2.getInt("player_id");
- + final int topicId = rs2.getInt("topic_id");
- +
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + topic.addLike(playerId);
- + }
- + }
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + public boolean useBypass(String cmd, L2PcInstance player)
- + {
- + if (cmd.startsWith("faq_main"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- + st.nextToken();
- + if (st.hasMoreTokens())
- + {
- + final int page = Integer.parseInt(st.nextToken());
- + final String search = st.hasMoreTokens() ? st.nextToken() : null;
- + renderMain(player, search, page);
- + }
- + else
- + renderMain(player, null);
- + return true;
- + }
- + else if (cmd.startsWith("faq_open"))
- + {
- + if (cmd.length() < 9)
- + renderMain(player, null);
- + else
- + {
- + final int topicId = Integer.parseInt(cmd.substring(9));
- + openTopic(player, topicId);
- + }
- + }
- + else if (cmd.startsWith("faq_search"))
- + {
- + if (cmd.length() < 12)
- + renderMain(player, null);
- + else
- + {
- + final String search = cmd.substring(11);
- + renderMain(player, search);
- + }
- + return true;
- + }
- + else if (cmd.startsWith("faq_topic"))
- + {
- + System.out.println("???");
- + return true;
- + }
- + else if (cmd.startsWith("faq_delete"))
- + {
- + if (cmd.length() < 12)
- + renderMain(player, null);
- + else
- + {
- + final int topicId = Integer.parseInt(cmd.substring(11));
- + deleteTopic(topicId);
- + renderMain(player, null);
- + }
- + return true;
- + }
- + else if (cmd.startsWith("faq_like"))
- + {
- + if (cmd.length() < 10)
- + renderMain(player, null);
- + else
- + {
- + final int topicId = Integer.parseInt(cmd.substring(9));
- + likeTopic(player, topicId);
- + }
- + return true;
- + }
- + else if (cmd.startsWith("faq_edit_content"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- +
- + st.nextToken();
- +
- + final int topicId = Integer.parseInt(st.nextToken());
- +
- + final String content = st.nextToken("\t").substring(1).replace("\r\n", "<br1>");
- +
- + editTopicContent(player, topicId, content);
- +
- + return true;
- + }
- + else if (cmd.startsWith("faq_edit_title"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- +
- + st.nextToken();
- +
- + final int topicId = Integer.parseInt(st.nextToken());
- +
- + final String content = st.nextToken("\t").trim().replace("\r\n", "");
- +
- + editTopicTitle(player, topicId, content);
- +
- + return true;
- + }
- + else if (cmd.startsWith("faq_edit_icon"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- +
- + st.nextToken();
- +
- + final int topicId = Integer.parseInt(st.nextToken());
- + final int ic = Integer.parseInt(st.nextToken());
- +
- + final String icon = st.nextToken("\t").trim();
- +
- + editTopicIcon(player, topicId, icon, ic);
- +
- + return true;
- + }
- + else if (cmd.startsWith("faq_edit"))
- + {
- + if (cmd.length() < 10)
- + renderMain(player, null);
- + else
- + {
- + final int topicId = Integer.parseInt(cmd.substring(9));
- + editTopic(player, topicId);
- + }
- + return true;
- + }
- + else if (cmd.startsWith("faq_stat"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- + st.nextToken();
- +
- + if (st.hasMoreTokens())
- + {
- + final int topicId = Integer.parseInt(st.nextToken());
- + final int status = Integer.parseInt(st.nextToken());
- + editTopicStatus(player, topicId, status);
- + }
- + return true;
- + }
- + else if (cmd.startsWith("faq_create_main"))
- + {
- + createMain(player);
- + return true;
- + }
- + else if (cmd.startsWith("faq_create"))
- + {
- + final StringTokenizer st = new StringTokenizer(cmd);
- + st.nextToken();
- +
- + if (st.hasMoreTokens())
- + {
- + final String title = st.nextToken("%-%").trim().replace("\r\n", "");
- + if (st.hasMoreTokens())
- + {
- + final String cont = st.nextToken("%-%").trim().replace("\r\n", "<br1>");
- +
- + createTopic(player, title, cont);
- + }
- +
- + }
- +
- + return true;
- + }
- + return false;
- + }
- +
- + private void createMain(final L2PcInstance player)
- + {
- + String html = HtmCache.getInstance().getHtml("data/html/aepvp/cubic/faq/create.htm", player);
- + separateAndSend(html, player);
- + }
- +
- + private void createTopic(final L2PcInstance player, final String title, final String content)
- + {
- + if (!player.isGM())
- + {
- + int counter = 0;
- + for (final FAQTopic topic : _topics.valueCollection())
- + {
- + if (topic._status == STATUS_NOT_APPROVED && topic._author == player.getObjectId() && counter++ > 2)
- + {
- + player.sendMessage("You have already submitted 3 or more topics that await approval by a GM. Please wait.");
- + return;
- + }
- + }
- +
- + if (player.getLevel() < 90)
- + {
- + player.sendMessage("You must be at least Lv. 90 to create a FAQ.");
- + return;
- + }
- + }
- +
- + final FAQTopic topic = new FAQTopic(player, title, content);
- + _topics.put(topic.getTopicId(), topic);
- +
- + openTopic(player, topic.getTopicId());
- + }
- +
- + private void editTopicStatus(final L2PcInstance player, final int topicId, final int status)
- + {
- + if (player.isGM())
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- + if (status == STATUS_APPROVED)
- + topic.toggleActive();
- + else
- + topic.togglePinned();
- + }
- +
- + }
- +
- + editTopic(player, topicId);
- + }
- +
- + private void editTopicIcon(final L2PcInstance player, final int topicId, final String icon, final int ic)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- + topic.updateIcon(icon, ic == 1);
- + }
- + editTopic(player, topicId);
- + }
- +
- + private void editTopicTitle(final L2PcInstance player, final int topicId, final String title)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + topic.updateTitle(title);
- +
- + editTopic(player, topicId);
- + }
- +
- + private void editTopicContent(final L2PcInstance player, final int topicId, final String content)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + topic.updateContent(content);
- +
- + editTopic(player, topicId);
- + }
- +
- + private void editTopic(final L2PcInstance player, final int topicId)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- +
- + String htmlStr = topic.render(HtmCache.getInstance().getHtm(player, "data/html/aepvp/cubic/faq/edit.htm"), player);
- +
- +
- + htmlStr = htmlStr.replace("%id%", String.valueOf(topicId));
- +
- + htmlStr = htmlStr.replace("%appr%", topic.isActive() ? "Hide" : "Approve");
- + htmlStr = htmlStr.replace("%pin%", topic.isPinned() ? "Unpin" : "Pin");
- + separateAndSend(htmlStr, player);
- + }
- + }
- +
- + private void openTopic(final L2PcInstance player, final int topicId)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- + final String npcHtml = topic.renderTopic(player);
- + separateAndSend(npcHtml, player);
- + }
- + }
- +
- + private void renderMain(final L2PcInstance player, final String search)
- + {
- + renderMain(player, search, 0);
- + }
- +
- + private void renderMain(final L2PcInstance player, final String search, final int page)
- + {
- + String npcHtml = HtmCache.getInstance().getHtml("data/html/aepvp/cubic/faq/main.htm", player);
- +
- + final StringBuilder sb = new StringBuilder(2048);
- +
- + final Stream<FAQTopic> topicsStream = getTopics(search);
- +
- + final FAQTopic[] topics = topicsStream.filter((topic) -> {return topic.isRenderableFor(player);}).toArray(FAQTopic[]::new);
- + final int topicsLen = topics.length;
- + final int pages = topicsLen < TOPICS_PER_PAGE ? 1 : topicsLen / TOPICS_PER_PAGE + ((topicsLen % TOPICS_PER_PAGE) > 0 ? 1 : 0);
- +
- + for (int i = 0; i < TOPICS_PER_PAGE; i++)
- + {
- + final int indx = TOPICS_PER_PAGE * page + i;
- + if (indx < topicsLen)
- + {
- + final FAQTopic topic = topics[indx];
- + topic.renderHeader(sb, player);
- + }
- + else
- + sb.append("<img height=89/>");
- +
- + }
- +
- + npcHtml = npcHtml.replace("%topic_headers%", sb.toString());
- +
- + sb.setLength(0);
- +
- + for (int i = 0; i < pages; i++)
- + {
- + if (page == i)
- + sb.append(String.format("<td align=center>Page %d</td>", i+1));
- + else
- + sb.append(String.format("<td align=center><a action=\"bypass faq_main %d %s\">Page %d</a></td>", i, search == null ? "" : search, i + 1));
- + }
- +
- +
- + npcHtml = npcHtml.replace("%pages1%", sb.toString());
- +
- + separateAndSend(npcHtml, player);
- + }
- +
- + private Stream<FAQTopic> getTopics(final String search)
- + {
- + final Stream<FAQTopic> topicStream = getTopicsStream();
- + if (search == null)
- + return topicStream;
- + else
- + return topicStream.filter((topic) -> { return topic.matchesSearch(search); });
- + }
- +
- + private Stream<FAQTopic> getTopicsStream()
- + {
- + return _topics.valueCollection().stream().sorted();
- + }
- +
- + private void likeTopic(final L2PcInstance player, final int topicId)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- + topic.tryLike(player);
- + }
- + openTopic(player, topic.getTopicId());
- + }
- +
- + private void deleteTopic(final int topicId)
- + {
- + final FAQTopic topic = _topics.get(topicId);
- + if (topic != null)
- + {
- + topic.delete();
- + }
- + }
- +
- +
- + public static class FAQTopic implements Comparable<FAQTopic>
- + {
- + private final TIntHashSet _likedNew = new TIntHashSet();
- + private final TIntHashSet _liked = new TIntHashSet();
- +
- + private static final String nullIcon = "L2UI_ct1.SystemMenuWnd.SystemMenuWnd_df_Help";
- +
- + private final int _topicId;
- + private final int _author;
- + private String _title;
- + private String _content;
- +
- + private String _icon_a;
- + private String _icon_b;
- +
- +// private int _likes;
- +
- + private int _status;
- +
- + private boolean _updated;
- +
- + private boolean _new;
- +
- + public boolean matchesSearch(final String search)
- + {
- + final String author = CharNameTable.getInstance().getNameById(_author);
- +
- + return author.contains(search) ||
- + _title.contains(search) ||
- + _content.contains(search)||
- +
- + author.toLowerCase().contains(search.toLowerCase()) ||
- + _title.toLowerCase().contains(search.toLowerCase()) ||
- + _content.toLowerCase().contains(search.toLowerCase())
- +
- + ;
- + }
- +
- + public FAQTopic(final L2PcInstance author, final String title, final String content)
- + {
- + _topicId = IdFactory.getInstance().getNextId();
- +
- + _author = author.getObjectId();
- + _title = title;
- + _content = content;
- +
- + _new = true;
- + }
- +
- + public FAQTopic(final ResultSet rs) throws Exception
- + {
- + _topicId = rs.getInt("topic_id");
- +
- + final int authorId = rs.getInt("author_id");
- + _author = authorId;
- + _title = rs.getString("title");
- + _content = rs.getString("content");
- +
- + _icon_a = rs.getString("icon_a");
- + _icon_b = rs.getString("icon_b");
- +
- + _status = rs.getInt("status");
- + }
- +
- + public void addLike(final int playerId)
- + {
- + _liked.add(playerId);
- + }
- +
- + public boolean tryLike(final L2PcInstance player)
- + {
- + final int playerId = player.getObjectId();
- + if (!player.isGM())
- + {
- + if (_liked.contains(playerId))
- + return false;
- + }
- + _liked.add(playerId);
- + _likedNew.add(playerId);
- + return true;
- + }
- +
- + public boolean hasLike(final int playerId)
- + {
- + return _liked.contains(playerId);
- + }
- +
- + public void setStatus(final int status)
- + {
- + _status = status;
- + }
- +
- + public boolean isRenderableFor(final L2PcInstance player)
- + {
- + return notDeleted() && (isActive() || player.getName().equals(_author) || player.isGM());
- + }
- +
- + public boolean isActive()
- + {
- + return _status > STATUS_NOT_APPROVED;
- + }
- +
- + public boolean notDeleted()
- + {
- + return _status > STATUS_DELETED;
- + }
- +
- + public int getTopicId()
- + {
- + return _topicId;
- + }
- +
- + public TIntHashSet getNewLikes()
- + {
- + return _likedNew;
- + }
- +
- + public int getLikes()
- + {
- + return _liked.size();
- + }
- +
- + public int getRankingLikes()
- + {
- + if (_status == STATUS_PINNED)
- + return getLikes() + 10000;
- + return getLikes();
- + }
- +
- + public void updateTitle(final String title)
- + {
- + _title = title;
- + _updated = true;
- + }
- +
- + public void updateContent(final String content)
- + {
- + _content = content;
- + _updated = true;
- + }
- +
- + public void togglePinned()
- + {
- + if (_status == 2)
- + _status = 1;
- + else
- + _status = 2;
- + _updated = true;
- + }
- +
- + public void toggleActive()
- + {
- + if (_status < 1)
- + _status = 1;
- + else
- + _status = 0;
- + _updated = true;
- + }
- +
- + public boolean isPinned()
- + {
- + return _status == STATUS_PINNED;
- + }
- +
- + public boolean isNew()
- + {
- + return _new;
- + }
- +
- + public void renderHeader(final StringBuilder sb, final L2PcInstance viewer)
- + {
- + String topicHeader = render(topic_header, viewer);
- +
- + if (_status == 2)
- + topicHeader = topicHeader.replace("_Info", "_HeroConfirm");
- + sb.append(topicHeader);
- + }
- +
- + public void renderTopic(final StringBuilder sb)
- + {
- +
- + }
- +
- + public String render(final String render, final L2PcInstance viewer)
- + {
- + 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);
- +
- + return render.replace("%title%", _title).
- + replace("%likes%", String.valueOf(getLikes())).
- + replace("%topic_id%", String.valueOf(_topicId)).
- + replace("%icon_a%", _icon_a == null ? nullIcon : String.valueOf(_icon_a)).
- + replace("%icon_b%", _icon_b == null ? nullIcon : String.valueOf(_icon_b)).
- + replace("%gm%", viewer.isGM() ? gmTemplate : "").
- + replace(" Likes", isPinned() ? " Likes - <font color=\"c43c3c\">PINNED</font>" : !isActive() ? " Likes - <font color=\"LEVEL\">UNLISTED</font>" : " Likes").
- + replace("%content%", _content).
- + replace("%ilike%", hasLike(viewer.getObjectId()) ? "" : "<tr></tr><tr><td align=center><a action=\"bypass faq_like %id%\">I Like this!</a></td></tr>").
- + replace("%id%", String.valueOf(_topicId)).
- + replace("%author%", CharNameTable.getInstance().getNameById(_author));
- + }
- +
- + public String renderTopic(final L2PcInstance viewer)
- + {
- + final String html = HtmCache.getInstance().getHtm(viewer, "data/html/aepvp/cubic/faq/topic.htm");
- +
- +
- + final String renderHtm = render(html, viewer);
- +
- + return renderHtm;
- + }
- +
- + public void updateIcon(final String icon, final boolean ic)
- + {
- + if (ic)
- + _icon_a = icon;
- + else
- + _icon_b = icon;
- + _updated = true;
- + }
- +
- + public void activate()
- + {
- + _status = STATUS_APPROVED;
- + _updated = true;
- + }
- +
- + public void delete()
- + {
- + _status = STATUS_DELETED;
- + _updated = true;
- + }
- +
- + public boolean isUpdated()
- + {
- + return _updated;
- + }
- +
- + @Override
- + public int compareTo(FAQTopic other)
- + {
- + return other.getRankingLikes() - getRankingLikes();
- + }
- +
- + @Override
- + public String toString()
- + {
- + return _title + " By " + _author;
- + }
- + }
- +
- + private static class InstanceHolder
- + {
- + private static final FAQController _instance = new FAQController();
- + }
- +
- + public static FAQController getInstance()
- + {
- + return InstanceHolder._instance;
- + }
- +
- + public void exception(Exception e)
- + {
- + e.printStackTrace();
- + }
- +
- + public void store()
- + {
- + try (final Connection con = L2DatabaseFactory.getInstance().getConnection();
- + final PreparedStatement psu = con.prepareStatement("UPDATE server_faq SET author_id = ?, title = ?, content = ?, icon_a = ?, icon_b = ?, status = ? WHERE topic_id = ?");
- + final PreparedStatement psn = con.prepareStatement("INSERT INTO server_faq (topic_id, author_id, title, content, icon_a, icon_b, status) VALUES (?, ?, ?, ?, ?, ?, ?)");
- + final PreparedStatement psl = con.prepareStatement("INSERT INTO server_faq_likes (topic_id, player_id) VALUES (?, ?)");)
- + {
- + con.setAutoCommit(false);
- +
- + for (final FAQTopic faqTopic : _topics.valueCollection())
- + {
- + if (faqTopic.isNew())
- + {
- + psn.setInt(1, faqTopic.getTopicId());
- + psn.setInt(2, faqTopic._author);
- +
- + psn.setString(3, faqTopic._title);
- + psn.setString(4, faqTopic._content);
- +
- + psn.setString(5, faqTopic._icon_a);
- + psn.setString(6, faqTopic._icon_b);
- + psn.setInt(7, faqTopic._status);
- +
- + psn.addBatch();
- + }
- + else if (faqTopic.isUpdated())
- + {
- + psu.setInt(1, faqTopic._author);
- + psu.setString(2, faqTopic._title);
- + psu.setString(3, faqTopic._content);
- +
- + psu.setString(4, faqTopic._icon_a);
- + psu.setString(5, faqTopic._icon_b);
- + psu.setInt(6, faqTopic._status);
- +
- + psu.setInt(7, faqTopic._topicId);
- +
- + psu.addBatch();
- + }
- +
- + final TIntHashSet newLikes = faqTopic.getNewLikes();
- + if (!newLikes.isEmpty())
- + {
- + for (final int playerId : newLikes._set) if (playerId > 0)
- + {
- + psl.setInt(1, faqTopic.getTopicId());
- + psl.setInt(2, playerId);
- +
- + psl.addBatch();
- + }
- + }
- + }
- +
- + final int inserted = psn.executeBatch().length;
- + final int updated = psu.executeBatch().length;
- + final int insertdl = psl.executeBatch().length;
- + con.commit();
- +
- + System.err.println("FAQController: Inserted " + inserted + " new FAQ Topics!");
- + System.err.println("FAQController: Updated " + updated + " old FAQ Topics!");
- + System.err.println("FAQController: Inserted " + insertdl + " new FAQ Likes!");
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + }
- + }
- +
- + private void separateAndSend(String html, L2PcInstance acha) {
- + if (html == null) {
- + return;
- + }
- + if (html.length() < 8180) {
- + acha.sendPacket(new ShowBoard(html, "101"));
- + acha.sendPacket(new ShowBoard("", "102"));
- + acha.sendPacket(new ShowBoard("", "103"));
- + } else if (html.length() < (8180 * 2)) {
- + acha.sendPacket(new ShowBoard(html.substring(0, 8180), "101"));
- + acha.sendPacket(new ShowBoard(html.substring(8180), "102"));
- + acha.sendPacket(new ShowBoard("", "103"));
- + } else if (html.length() < (8180 * 3)) {
- + acha.sendPacket(new ShowBoard(html.substring(0, 8180), "101"));
- + acha.sendPacket(new ShowBoard(html.substring(8180, 8180 * 2), "102"));
- + acha.sendPacket(new ShowBoard(html.substring(8180 * 2), "103"));
- + }
- + }
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement