ShowBoard.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 net.sf.l2j.gameserver.serverpackets;
  16. import java.util.List;
  17. public class ShowBoard extends L2GameServerPacket
  18. {
  19. private static final String _S__6E_SHOWBOARD = "[S] 7b ShowBoard";
  20. private String _htmlCode;
  21. private String _id;
  22. private List<String> _arg;
  23. public ShowBoard(String htmlCode, String id)
  24. {
  25. _id = id;
  26. _htmlCode = htmlCode; // html code must not exceed 8192 bytes
  27. }
  28. public ShowBoard(List<String> arg)
  29. {
  30. _id = "1002";
  31. _htmlCode = null;
  32. _arg = arg;
  33. }
  34. private byte[] get1002()
  35. {
  36. int len = _id.getBytes().length * 2 + 2;
  37. for (String arg : _arg)
  38. {
  39. len += (arg.getBytes().length + 4) * 2;
  40. }
  41. byte data[] = new byte[len];
  42. int i = 0;
  43. for (int j = 0; j < _id.getBytes().length; j++, i += 2)
  44. {
  45. data[i] = _id.getBytes()[j];
  46. data[i + 1] = 0;
  47. }
  48. data[i] = 8;
  49. i++;
  50. data[i] = 0;
  51. i++;
  52. for (String arg : _arg)
  53. {
  54. for (int j = 0; j < arg.getBytes().length; j++, i += 2)
  55. {
  56. data[i] = arg.getBytes()[j];
  57. data[i + 1] = 0;
  58. }
  59. data[i] = 0x20;
  60. i++;
  61. data[i] = 0x0;
  62. i++;
  63. data[i] = 0x8;
  64. i++;
  65. data[i] = 0x0;
  66. i++;
  67. }
  68. return data;
  69. }
  70. @Override
  71. protected final void writeImpl()
  72. {
  73. writeC(0x7b);
  74. writeC(0x01); //c4 1 to show community 00 to hide
  75. writeS("bypass _bbshome"); // top
  76. writeS("bypass _bbsgetfav"); // favorite
  77. writeS("bypass _bbsloc"); // region
  78. writeS("bypass _bbsclan"); // clan
  79. writeS("bypass _bbsmemo"); // memo
  80. writeS("bypass _bbsmail"); // mail
  81. writeS("bypass _bbsfriends"); // friends
  82. writeS("bypass bbs_add_fav"); // add fav.
  83. if (!_id.equals("1002"))
  84. {
  85. // getBytes is a very costy operation, and should only be called once
  86. byte htmlBytes[] = null;
  87. if (_htmlCode != null)
  88. htmlBytes = _htmlCode.getBytes();
  89. byte data[] = new byte[2 + 2 + 2 + _id.getBytes().length * 2 + 2
  90. * ((_htmlCode != null) ? htmlBytes.length : 0)];
  91. int i = 0;
  92. for (int j = 0; j < _id.getBytes().length; j++, i += 2)
  93. {
  94. data[i] = _id.getBytes()[j];
  95. data[i + 1] = 0;
  96. }
  97. data[i] = 8;
  98. i++;
  99. data[i] = 0;
  100. i++;
  101. if (_htmlCode == null)
  102. {
  103. }
  104. else
  105. {
  106. for (int j = 0; j < htmlBytes.length; i += 2, j++)
  107. {
  108. data[i] = htmlBytes[j];
  109. data[i + 1] = 0;
  110. }
  111. }
  112. data[i] = 0;
  113. i++;
  114. data[i] = 0;
  115. //writeS(_htmlCode); // current page
  116. writeB(data);
  117. }
  118. else
  119. {
  120. writeB(get1002());
  121. }
  122. }
  123. /* (non-Javadoc)
  124. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  125. */
  126. @Override
  127. public String getType()
  128. {
  129. return _S__6E_SHOWBOARD;
  130. }
  131. }