Advertisement
Guest User

Untitled

a guest
Mar 30th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  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.  
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.sql.SQLException;
  21. import java.util.StringTokenizer;
  22.  
  23. import com.l2jserver.L2DatabaseFactory;
  24. import com.l2jserver.gameserver.cache.HtmCache;
  25. import com.l2jserver.gameserver.communitybbs.CastleStatus;
  26. import com.l2jserver.gameserver.communitybbs.PlayerList;
  27. import com.l2jserver.gameserver.communitybbs.ServerStats;
  28. import com.l2jserver.gameserver.communitybbs.TopAdena;
  29. import com.l2jserver.gameserver.datatables.ClanTable;
  30. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  31. import com.l2jserver.gameserver.model.L2World;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33.  
  34. /**
  35. *
  36. *
  37. */
  38. public class TopBBSManager extends BaseBBSManager
  39. {
  40. private TopBBSManager()
  41. {
  42.  
  43. }
  44.  
  45. @Override
  46. public void parsecmd(String command, L2PcInstance activeChar)
  47. {
  48. String fileName = "";
  49. if (command.equals("_bbstop") || command.equals("_bbshome"))
  50. {
  51. fileName = "data/html/CommunityBoard/index.htm";
  52. }
  53. if (command.startsWith("_bbstop;"))
  54. {
  55. StringTokenizer st = new StringTokenizer(command, ";");
  56. st.nextToken();
  57. int idp = Integer.parseInt(st.nextToken());
  58. fileName = "data/html/CommunityBoard/" + idp + ".htm";
  59. }
  60.  
  61. if(fileName.length() == 0)
  62. {
  63. return;
  64. }
  65.  
  66. String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), fileName);
  67.  
  68. String ip = "N/A";
  69. String account = "N/A";
  70. try
  71. {
  72. String clientInfo = activeChar.getClient().toString();
  73. account = clientInfo.substring(clientInfo.indexOf("Account: ") + 9, clientInfo.indexOf(" - IP: "));
  74. ip = clientInfo.substring(clientInfo.indexOf(" - IP: ") + 7, clientInfo.lastIndexOf("]"));
  75. }
  76. catch (Exception e)
  77. {
  78.  
  79. }
  80.  
  81. if (fileName.equals("data/html/CommunityBoard/3.htm"));
  82. {
  83. // Top 15 PvP List
  84. PlayerList pvp = new PlayerList(1);
  85. content = content.replaceAll("%pvplist%", pvp.loadPlayerList());
  86. }
  87. if (fileName.equals("data/html/CommunityBoard/5.htm"));
  88. {
  89. CastleStatus status = new CastleStatus();
  90. content = content.replaceAll("%castle%", status.loadCastleList());
  91. }
  92. if (fileName.equals("data/html/CommunityBoard/6.htm"));
  93. {
  94. // Top 15 Pk List
  95. PlayerList pk = new PlayerList(0);
  96. content = content.replaceAll("%pklist%", pk.loadPlayerList());
  97. }
  98.  
  99. if (fileName.equals("data/html/CommunityBoard/53.htm"));
  100. {
  101. // Char Info
  102. content = content.replaceAll("%name%", activeChar.getName());
  103. content = content.replaceAll("%level%", String.valueOf(activeChar.getLevel()));
  104. content = content.replaceAll("%clan%", String.valueOf(ClanTable.getInstance().getClan(activeChar.getClanId())));
  105. content = content.replaceAll("%xp%", String.valueOf(activeChar.getExp()));
  106. content = content.replaceAll("%sp%", String.valueOf(activeChar.getSp()));
  107. content = content.replaceAll("%class%", activeChar.getTemplate().className);
  108. content = content.replaceAll("%classid%", String.valueOf(activeChar.getClassId()));
  109. content = content.replaceAll("%currenthp%", String.valueOf((int) activeChar.getCurrentHp()));
  110. content = content.replaceAll("%maxhp%", String.valueOf(activeChar.getMaxHp()));
  111. content = content.replaceAll("%currentmp%", String.valueOf((int) activeChar.getCurrentMp()));
  112. content = content.replaceAll("%maxmp%", String.valueOf(activeChar.getMaxMp()));
  113. content = content.replaceAll("%currentcp%", String.valueOf((int) activeChar.getCurrentCp()));
  114. content = content.replaceAll("%maxcp%", String.valueOf(activeChar.getMaxCp()));
  115. content = content.replaceAll("%currentload%", String.valueOf(activeChar.getCurrentLoad()));
  116. content = content.replaceAll("%maxload%", String.valueOf(activeChar.getMaxLoad()));
  117. content = content.replaceAll("%access%", String.valueOf(activeChar.getAccessLevel().getLevel()));
  118. content = content.replaceAll("%account%", account);
  119. content = content.replaceAll("%ip%", ip);
  120. }
  121. if (fileName.equals("data/html/CommunityBoard/4.htm"));
  122. {
  123. // Top 20 Adena Owners
  124. TopAdena topAdena = new TopAdena();
  125. content = content.replaceAll("%topadena%", topAdena.loadPlayerList());
  126. }
  127. if (fileName.equals("data/html/CommunityBoard/54.htm"));
  128. {
  129. // Online Gamemasters
  130. content = content.replaceAll("%gmlist%", getOnlineGMs());
  131. }
  132. if (fileName.equals("data/html/CommunityBoard/56.htm"));
  133. {
  134. // Raid Status
  135. content = content.replaceAll("%antharas%", bossStatus(29019));
  136. content = content.replaceAll("%valakas%", bossStatus(29028));
  137. content = content.replaceAll("%baium%", bossStatus(29001));
  138. content = content.replaceAll("%antqueen%", bossStatus(29020));
  139. content = content.replaceAll("%core%", bossStatus(29006));
  140. content = content.replaceAll("%zaken%", bossStatus(29022));
  141. content = content.replaceAll("%frintezza%", bossStatus(29045));
  142.  
  143. }
  144. if (fileName.equals("data/html/CommunityBoard/57.htm"));
  145. {
  146. // Character Repair
  147. content = content.replaceAll("%acc_chars%", getCharList(activeChar));
  148. }
  149. if (fileName.equals("data/html/CommunityBoard/55.htm"));
  150. {
  151. // Server Stats
  152. ServerStats stats = new ServerStats();
  153. content = content.replaceAll("%stats%", stats.getServerStats());
  154. content = content.replaceAll("%online%", stats.getOnlineCount());
  155. }
  156.  
  157.  
  158. if (content == null)
  159. {
  160. //sendError404(activeChar, fileName);
  161. }
  162. else
  163. {
  164. separateAndSend(content, activeChar);
  165. }
  166. }
  167.  
  168. @Override
  169. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  170. {
  171.  
  172. }
  173.  
  174. private String getOnlineGMs()
  175. {
  176. String msg = "<br>";
  177.  
  178. if (L2World.getInstance().getAllGMs().isEmpty())
  179. {
  180. msg = "There are not Online GMs at this moment!";
  181. }
  182. else
  183. {
  184. for (L2PcInstance player: L2World.getInstance().getAllGMs())
  185. {
  186. msg += player.getName();
  187. msg += "<br>";
  188. }
  189. }
  190. return msg;
  191. }
  192.  
  193. /**
  194. * @param bossId
  195. * @return
  196. */
  197. private static String bossStatus(int bossId)
  198. {
  199. long delay = GrandBossManager.getInstance().getStatsSet(bossId).getLong("respawn_time");
  200. if (delay <= System.currentTimeMillis())
  201. {
  202. return "<font color=\"9CC300\">Alive</font>";
  203. }
  204. else
  205. {
  206. return "<font color=\"ff0000\">Dead</font>";
  207. }
  208. }
  209.  
  210. /**
  211. * @param activeChar
  212. * @return
  213. */
  214. private String getCharList(L2PcInstance activeChar)
  215. {
  216. String result="";
  217. String repCharAcc=activeChar.getAccountName();
  218. Connection con = null;
  219. try
  220. {
  221. con = L2DatabaseFactory.getInstance().getConnection();
  222. PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters WHERE account_name=?");
  223. statement.setString(1, repCharAcc);
  224. ResultSet rset = statement.executeQuery();
  225. while (rset.next())
  226. {
  227. if (activeChar.getName().compareTo(rset.getString(1)) != 0)
  228. result += rset.getString(1)+";";
  229. }
  230.  
  231. rset.close();
  232. statement.close();
  233. }
  234. catch (SQLException e)
  235. {
  236. e.printStackTrace();
  237. return result;
  238. }
  239. finally
  240. {
  241. try
  242. {
  243. if (con != null)
  244. con.close();
  245. }
  246. catch (SQLException e)
  247. {
  248. e.printStackTrace();
  249. }
  250. }
  251. return result;
  252. }
  253.  
  254. public static TopBBSManager getInstance()
  255. {
  256. return SingletonHolder.INSTANCE;
  257. }
  258.  
  259. @SuppressWarnings("synthetic-access")
  260. private static class SingletonHolder
  261. {
  262. protected static final TopBBSManager INSTANCE = new TopBBSManager();
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement