NpcHtmlMessage.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.network.serverpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.cache.HtmCache;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.clientpackets.RequestBypassToServer;
  21. /**
  22. *
  23. * the HTML parser in the client knowns these standard and non-standard tags and attributes
  24. * VOLUMN
  25. * UNKNOWN
  26. * UL
  27. * U
  28. * TT
  29. * TR
  30. * TITLE
  31. * TEXTCODE
  32. * TEXTAREA
  33. * TD
  34. * TABLE
  35. * SUP
  36. * SUB
  37. * STRIKE
  38. * SPIN
  39. * SELECT
  40. * RIGHT
  41. * PRE
  42. * P
  43. * OPTION
  44. * OL
  45. * MULTIEDIT
  46. * LI
  47. * LEFT
  48. * INPUT
  49. * IMG
  50. * I
  51. * HTML
  52. * H7
  53. * H6
  54. * H5
  55. * H4
  56. * H3
  57. * H2
  58. * H1
  59. * FONT
  60. * EXTEND
  61. * EDIT
  62. * COMMENT
  63. * COMBOBOX
  64. * CENTER
  65. * BUTTON
  66. * BR
  67. * BR1
  68. * BODY
  69. * BAR
  70. * ADDRESS
  71. * A
  72. * SEL
  73. * LIST
  74. * VAR
  75. * FORE
  76. * READONL
  77. * ROWS
  78. * VALIGN
  79. * FIXWIDTH
  80. * BORDERCOLORLI
  81. * BORDERCOLORDA
  82. * BORDERCOLOR
  83. * BORDER
  84. * BGCOLOR
  85. * BACKGROUND
  86. * ALIGN
  87. * VALU
  88. * READONLY
  89. * MULTIPLE
  90. * SELECTED
  91. * TYP
  92. * TYPE
  93. * MAXLENGTH
  94. * CHECKED
  95. * SRC
  96. * Y
  97. * X
  98. * QUERYDELAY
  99. * NOSCROLLBAR
  100. * IMGSRC
  101. * B
  102. * FG
  103. * SIZE
  104. * FACE
  105. * COLOR
  106. * DEFFON
  107. * DEFFIXEDFONT
  108. * WIDTH
  109. * VALUE
  110. * TOOLTIP
  111. * NAME
  112. * MIN
  113. * MAX
  114. * HEIGHT
  115. * DISABLED
  116. * ALIGN
  117. * MSG
  118. * LINK
  119. * HREF
  120. * ACTION
  121. *
  122. *
  123. * @version $Revision: 1.3.2.1.2.3 $ $Date: 2005/03/27 15:29:57 $
  124. */
  125. public final class NpcHtmlMessage extends L2GameServerPacket
  126. {
  127. // d S
  128. // d is usually 0, S is the html text starting with <html> and ending with </html>
  129. //
  130. private static final String _S__1B_NPCHTMLMESSAGE = "[S] 19 NpcHtmlMessage";
  131. private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
  132. private int _npcObjId;
  133. private String _html;
  134. private int _itemId = 0;
  135. private boolean _validate = true;
  136. /**
  137. *
  138. * @param npcObjId
  139. * @param text
  140. * @param itemId
  141. */
  142. public NpcHtmlMessage(int npcObjId, int itemId)
  143. {
  144. _npcObjId = npcObjId;
  145. _itemId = itemId;
  146. }
  147. /**
  148. * @param _characters
  149. */
  150. public NpcHtmlMessage(int npcObjId, String text)
  151. {
  152. _npcObjId = npcObjId;
  153. setHtml(text);
  154. }
  155. public NpcHtmlMessage(int npcObjId)
  156. {
  157. _npcObjId = npcObjId;
  158. }
  159. /**
  160. * disable building bypass validation cache for this packet
  161. */
  162. public void disableValidation()
  163. {
  164. _validate = false;
  165. }
  166. @Override
  167. public void runImpl()
  168. {
  169. if (Config.BYPASS_VALIDATION && _validate)
  170. buildBypassCache(getClient().getActiveChar());
  171. }
  172. public void setHtml(String text)
  173. {
  174. if(text.length() > 8192)
  175. {
  176. _log.warning("Html is too long! this will crash the client!");
  177. _html = "<html><body>Html was too long</body></html>";
  178. return;
  179. }
  180. _html = text; // html code must not exceed 8192 bytes
  181. }
  182. public boolean setFile(String prefix, String path)
  183. {
  184. String content = HtmCache.getInstance().getHtm(prefix, path);
  185. if (content == null)
  186. {
  187. setHtml("<html><body>My Text is missing:<br>"+path+"</body></html>");
  188. _log.warning("missing html page "+path);
  189. return false;
  190. }
  191. setHtml(content);
  192. return true;
  193. }
  194. public void replace(String pattern, String value)
  195. {
  196. _html = _html.replaceAll(pattern, value.replaceAll("\\$", "\\\\\\$"));
  197. }
  198. private final void buildBypassCache(L2PcInstance activeChar)
  199. {
  200. if (activeChar == null)
  201. return;
  202. activeChar.clearBypass();
  203. int len = _html.length();
  204. for (int i = 0; i < len; i++)
  205. {
  206. int start = _html.indexOf("\"bypass ", i);
  207. int finish = _html.indexOf("\"", start + 1);
  208. if (start < 0 || finish < 0)
  209. break;
  210. if (_html.substring(start+8, start+10).equals("-h"))
  211. start += 11;
  212. else
  213. start += 8;
  214. i = finish;
  215. int finish2 = _html.indexOf("$", start);
  216. if (finish2 < finish && finish2 > 0)
  217. activeChar.addBypass2(_html.substring(start, finish2).trim());
  218. else
  219. activeChar.addBypass(_html.substring(start, finish).trim());
  220. }
  221. }
  222. @Override
  223. protected final void writeImpl()
  224. {
  225. writeC(0x19);
  226. writeD(_npcObjId);
  227. writeS(_html);
  228. writeD(_itemId);
  229. }
  230. /* (non-Javadoc)
  231. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  232. */
  233. @Override
  234. public String getType()
  235. {
  236. return _S__1B_NPCHTMLMESSAGE;
  237. }
  238. }