ForumsBBSManager.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.communitybbs.Manager;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.List;
  20. import java.util.logging.Logger;
  21. import com.l2jserver.L2DatabaseFactory;
  22. import com.l2jserver.gameserver.communitybbs.BB.Forum;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import javolution.util.FastList;
  25. public class ForumsBBSManager extends BaseBBSManager
  26. {
  27. private static Logger _log = Logger.getLogger(ForumsBBSManager.class.getName());
  28. private List<Forum> _table;
  29. private int _lastid = 1;
  30. /**
  31. * @return
  32. */
  33. public static ForumsBBSManager getInstance()
  34. {
  35. return SingletonHolder._instance;
  36. }
  37. private ForumsBBSManager()
  38. {
  39. _table = new FastList<Forum>();
  40. Connection con = null;
  41. try
  42. {
  43. con = L2DatabaseFactory.getInstance().getConnection();
  44. PreparedStatement statement = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_type=0");
  45. ResultSet result = statement.executeQuery();
  46. while (result.next())
  47. {
  48. int forumId = result.getInt("forum_id");
  49. Forum f = new Forum(forumId, null);
  50. addForum(f);
  51. }
  52. result.close();
  53. statement.close();
  54. }
  55. catch (Exception e)
  56. {
  57. _log.warning("data error on Forum (root): " + e);
  58. e.printStackTrace();
  59. }
  60. finally
  61. {
  62. try
  63. {
  64. con.close();
  65. }
  66. catch (Exception e)
  67. {
  68. }
  69. }
  70. }
  71. public void initRoot()
  72. {
  73. for (Forum f : _table)
  74. f.vload();
  75. _log.info("Loaded " + _table.size() + " forums. Last forum id used: " + _lastid);
  76. }
  77. public void addForum(Forum ff)
  78. {
  79. if (ff == null)
  80. return;
  81. _table.add(ff);
  82. if (ff.getID() > _lastid)
  83. {
  84. _lastid = ff.getID();
  85. }
  86. }
  87. /* (non-Javadoc)
  88. * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  89. */
  90. @Override
  91. public void parsecmd(String command, L2PcInstance activeChar)
  92. {
  93. // TODO Auto-generated method stub
  94. }
  95. /**
  96. * @param string
  97. * @return
  98. */
  99. public Forum getForumByName(String Name)
  100. {
  101. for (Forum f : _table)
  102. {
  103. if (f.getName().equals(Name))
  104. {
  105. return f;
  106. }
  107. }
  108. return null;
  109. }
  110. /**
  111. * @param name
  112. * @param forumByName
  113. * @return
  114. */
  115. public Forum createNewForum(String name, Forum parent, int type, int perm, int oid)
  116. {
  117. Forum forum = new Forum(name, parent, type, perm, oid);
  118. forum.insertIntoDb();
  119. //addForum(forum); // not needed to addForum(Forum) because already called in new Forum(String, Forum, int, int, int)
  120. return forum;
  121. }
  122. /**
  123. * @return
  124. */
  125. public int getANewID()
  126. {
  127. return ++_lastid;
  128. }
  129. /**
  130. * @param idf
  131. * @return
  132. */
  133. public Forum getForumByID(int idf)
  134. {
  135. for (Forum f : _table)
  136. {
  137. if (f.getID() == idf)
  138. {
  139. return f;
  140. }
  141. }
  142. return null;
  143. }
  144. /* (non-Javadoc)
  145. * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  146. */
  147. @Override
  148. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  149. {
  150. // TODO Auto-generated method stub
  151. }
  152. @SuppressWarnings("synthetic-access")
  153. private static class SingletonHolder
  154. {
  155. protected static final ForumsBBSManager _instance = new ForumsBBSManager();
  156. }
  157. }