PlayerShowBoard.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.network.writepackets;
  16. import java.io.UnsupportedEncodingException;
  17. import javolution.util.FastList;
  18. import com.l2jserver.communityserver.network.netcon.BaseWritePacket;
  19. public final class PlayerShowBoard extends BaseWritePacket
  20. {
  21. private static final byte[] DEC_HEAD =
  22. {
  23. 123, // C 0x7B
  24. 1, // C 0x01
  25. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,104,0,111,0,109,0,101,0,0,0, // S "bypass _bbshome"
  26. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,103,0,101,0,116,0,102,0,97,0,118,0,0,0, // S "bypass _bbsgetfav"
  27. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,108,0,111,0,99,0,0,0, // S "bypass _bbsloc"
  28. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,99,0,108,0,97,0,110,0,0,0, // S "bypass _bbsclan"
  29. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,109,0,101,0,109,0,111,0,0,0, // S "bypass _bbsmemo"
  30. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,109,0,97,0,105,0,108,0,0,0, // S "bypass _bbsmail"
  31. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,102,0,114,0,105,0,101,0,110,0,100,0,115,0,0,0, // S "bypass _bbsfriends"
  32. 98,0,121,0,112,0,97,0,115,0,115,0,32,0,95,0,98,0,98,0,115,0,95,0,97,0,100,0,100,0,95,0,102,0,97,0,118,0,0,0, // S "bypass _bbs_add_fav"
  33. };
  34. private static final byte[][] DEC_10X =
  35. {
  36. {49,0,48,0,49,0,8,0,0,0,0,0}, // "101"
  37. {49,0,48,0,50,0,8,0,0,0,0,0}, // "102"
  38. {49,0,48,0,51,0,8,0,0,0,0,0}, // "103"
  39. {49,0,48,0,52,0,8,0,0,0,0,0} // "104"
  40. };
  41. private PlayerShowBoard(final int playerObjId)
  42. {
  43. writeC(0x02);
  44. writeC(0x00);
  45. writeD(playerObjId);
  46. }
  47. /**
  48. * ID: 10X
  49. * @param playerObjId
  50. * @param html
  51. * @param id (101 = 0, 102 = 1, 103 = 2, 104 = 3)
  52. */
  53. public PlayerShowBoard(final int playerObjId, final String html, final byte id)
  54. {
  55. this(playerObjId);
  56. try
  57. {
  58. final byte[] data = getBytes10X(html, id);
  59. writeD(DEC_HEAD.length + data.length); // write DEC_HEAD length + html length
  60. writeB(DEC_HEAD); // write head
  61. writeB(data); // write html
  62. }
  63. catch (UnsupportedEncodingException e)
  64. {
  65. e.printStackTrace();
  66. }
  67. }
  68. /**
  69. * ID: 1001
  70. * @param playerObjId
  71. * @param html
  72. */
  73. public PlayerShowBoard(final int playerObjId, final String html)
  74. {
  75. this(playerObjId);
  76. try
  77. {
  78. final byte[] data = getBytes1001(html);
  79. writeD(DEC_HEAD.length + data.length); // write DEC_HEAD length + html length
  80. writeB(DEC_HEAD); // write head
  81. writeB(data); // write html
  82. }
  83. catch (UnsupportedEncodingException e)
  84. {
  85. e.printStackTrace();
  86. }
  87. }
  88. /**
  89. * ID: 1002
  90. * @param playerObjId
  91. * @param args (FastList<String>)
  92. */
  93. public PlayerShowBoard(final int playerObjId, final FastList<String> args)
  94. {
  95. this(playerObjId);
  96. try
  97. {
  98. final byte[] data = getBytes1002(args);
  99. writeD(DEC_HEAD.length + data.length); // write DEC_HEAD length + args length
  100. writeB(DEC_HEAD); // write head
  101. writeB(data); // write args
  102. }
  103. catch (UnsupportedEncodingException e)
  104. {
  105. e.printStackTrace();
  106. }
  107. }
  108. private final byte[] getBytes10X(final String html, final byte id) throws UnsupportedEncodingException
  109. {
  110. if (html == null) return DEC_10X[id];
  111. final byte[] dataHtml = html.getBytes("UTF-16LE");
  112. final byte[] data = new byte[12 + dataHtml.length];
  113. data[0] = 49;
  114. data[2] = 48;
  115. data[4] = (byte)(49 + id);
  116. data[6] = 8;
  117. System.arraycopy(dataHtml, 0, data, 8, dataHtml.length);
  118. return data;
  119. }
  120. private final byte[] getBytes1001(final String html) throws UnsupportedEncodingException
  121. {
  122. final byte[] dataHtml = html.getBytes("UTF-16LE");
  123. final byte[] data = new byte[14 + dataHtml.length];
  124. data[0] = 49;
  125. data[2] = 48;
  126. data[4] = 48;
  127. data[6] = 49;
  128. data[8] = 8;
  129. System.arraycopy(dataHtml, 0, data, 10, dataHtml.length);
  130. return data;
  131. }
  132. private final byte[] getBytes1002(final FastList<String> args) throws UnsupportedEncodingException
  133. {
  134. int len = 10;
  135. for (final String arg : args)
  136. {
  137. len += (arg.length() + 4) * 2;
  138. }
  139. final byte data[] = new byte[len];
  140. data[0] = 49;
  141. data[2] = 48;
  142. data[4] = 48;
  143. data[6] = 50;
  144. data[8] = 8;
  145. int i = 10;
  146. for (final String arg : args)
  147. {
  148. final byte[] dataHtml = arg.getBytes("UTF-16LE");
  149. System.arraycopy(dataHtml, 0, data, i, dataHtml.length);
  150. i += dataHtml.length;
  151. data[i] = 0x20;
  152. i+=2;
  153. data[i] = 0x08;
  154. i+=2;
  155. }
  156. return data;
  157. }
  158. }