CommunityBoard.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.communityserver.communityboard;
  16. import java.util.logging.Logger;
  17. import javolution.util.FastList;
  18. import com.l2jserver.communityserver.network.writepackets.PlayerShowBoard;
  19. public abstract class CommunityBoard
  20. {
  21. private final CommunityBoardManager _mgr;
  22. private static Logger _log = Logger.getLogger(CommunityBoard.class.getName());
  23. protected CommunityBoard(final CommunityBoardManager mgr)
  24. {
  25. _mgr = mgr;
  26. }
  27. protected final CommunityBoardManager getCommunityBoardManager()
  28. {
  29. return _mgr;
  30. }
  31. protected final void sendWrite(final int playerObjId, final String html, String string, String string2, String string3)
  32. {
  33. try
  34. {
  35. string = edtiSavedTxT(string);
  36. string2 = edtiSavedTxT(string2);
  37. string3 = edtiSavedTxT(string3);
  38. _mgr.sendPacket(new PlayerShowBoard(playerObjId, html));
  39. FastList<String> arg = new FastList<String>();
  40. arg.add("0");
  41. arg.add("0");
  42. arg.add("0");
  43. arg.add("0");
  44. arg.add("0");
  45. arg.add("0");
  46. arg.add(_mgr.getPlayer(playerObjId).getName());
  47. arg.add(Integer.toString(playerObjId));
  48. arg.add(_mgr.getPlayer(playerObjId).getAccountName());
  49. arg.add("9");
  50. arg.add(string3);
  51. arg.add(string2);
  52. arg.add(string);
  53. arg.add(string3);
  54. arg.add(string3);
  55. arg.add("0");
  56. arg.add("0");
  57. _mgr.sendPacket(new PlayerShowBoard(playerObjId, arg));
  58. }
  59. catch (Exception e)
  60. {
  61. e.printStackTrace();
  62. }
  63. }
  64. protected final void send(final int playerObjId, final String text)
  65. {
  66. try
  67. {
  68. if (text.length() <= 4096)
  69. {
  70. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text, (byte)0));
  71. _mgr.sendPacket(new PlayerShowBoard(playerObjId, null, (byte)1));
  72. _mgr.sendPacket(new PlayerShowBoard(playerObjId, null, (byte)2));
  73. }
  74. else if (text.length() <= 8192)
  75. {
  76. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text.substring(0, 4096), (byte)0));
  77. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text.substring(4096), (byte)1));
  78. _mgr.sendPacket(new PlayerShowBoard(playerObjId, null, (byte)2));
  79. }
  80. else if (text.length() <= 12288)
  81. {
  82. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text.substring(0, 4096), (byte)0));
  83. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text.substring(4096, 8192), (byte)1));
  84. _mgr.sendPacket(new PlayerShowBoard(playerObjId, text.substring(8192), (byte)2));
  85. }
  86. else
  87. {
  88. _log.warning("Text is too big!");
  89. }
  90. }
  91. catch (Exception e)
  92. {
  93. e.printStackTrace();
  94. }
  95. }
  96. protected String edtiPlayerTxT(String txt)
  97. {
  98. if (txt == null)
  99. return "";
  100. txt = txt.replace(">", "&gt;");
  101. txt = txt.replace("<", "&lt;");
  102. txt = txt.replace("\n", "<br1>");
  103. txt = txt.replace("$", "\\$");
  104. return txt;
  105. }
  106. protected String edtiSavedTxT(String txt)
  107. {
  108. if (txt == null)
  109. return "";
  110. txt = txt.replace("&gt;", ">");
  111. txt = txt.replace("&lt;", "<");
  112. txt = txt.replace("<br1>", "\n");
  113. txt = txt.replace("\\$", "$");
  114. return txt;
  115. }
  116. public abstract void parseCmd(final int playerObjId, final String cmd);
  117. public abstract void parseWrite(final int playerObjId, String ar1, String ar2, String ar3, String ar4, String ar5);
  118. }