Advertisement
Guest User

AEPVP Server FAQ

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