NpcHtmlMessage.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.cache.HtmCache;
  19. import net.sf.l2j.gameserver.clientpackets.RequestBypassToServer;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  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. * BODY
  68. * BAR
  69. * ADDRESS
  70. * A
  71. * SEL
  72. * LIST
  73. * VAR
  74. * FORE
  75. * READONL
  76. * ROWS
  77. * VALIGN
  78. * FIXWIDTH
  79. * BORDERCOLORLI
  80. * BORDERCOLORDA
  81. * BORDERCOLOR
  82. * BORDER
  83. * BGCOLOR
  84. * BACKGROUND
  85. * ALIGN
  86. * VALU
  87. * READONLY
  88. * MULTIPLE
  89. * SELECTED
  90. * TYP
  91. * TYPE
  92. * MAXLENGTH
  93. * CHECKED
  94. * SRC
  95. * Y
  96. * X
  97. * QUERYDELAY
  98. * NOSCROLLBAR
  99. * IMGSRC
  100. * B
  101. * FG
  102. * SIZE
  103. * FACE
  104. * COLOR
  105. * DEFFON
  106. * DEFFIXEDFONT
  107. * WIDTH
  108. * VALUE
  109. * TOOLTIP
  110. * NAME
  111. * MIN
  112. * MAX
  113. * HEIGHT
  114. * DISABLED
  115. * ALIGN
  116. * MSG
  117. * LINK
  118. * HREF
  119. * ACTION
  120. *
  121. *
  122. * @version $Revision: 1.3.2.1.2.3 $ $Date: 2005/03/27 15:29:57 $
  123. */
  124. public final class NpcHtmlMessage extends L2GameServerPacket
  125. {
  126. // d S
  127. // d is usually 0, S is the html text starting with <html> and ending with </html>
  128. //
  129. private static final String _S__1B_NPCHTMLMESSAGE = "[S] 19 NpcHtmlMessage";
  130. private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
  131. private int _npcObjId;
  132. private String _html;
  133. private int _itemId = 0;
  134. /**
  135. *
  136. * @param npcObjId
  137. * @param text
  138. * @param itemId
  139. */
  140. public NpcHtmlMessage(int npcObjId, int itemId)
  141. {
  142. _npcObjId = npcObjId;
  143. _itemId = itemId;
  144. }
  145. /**
  146. * @param _characters
  147. */
  148. public NpcHtmlMessage(int npcObjId, String text)
  149. {
  150. _npcObjId = npcObjId;
  151. setHtml(text);
  152. }
  153. public NpcHtmlMessage(int npcObjId)
  154. {
  155. _npcObjId = npcObjId;
  156. }
  157. @Override
  158. public void runImpl()
  159. {
  160. if (Config.BYPASS_VALIDATION)
  161. buildBypassCache(getClient().getActiveChar());
  162. }
  163. public void setHtml(String text)
  164. {
  165. if(text.length() > 8192)
  166. {
  167. _log.warning("Html is too long! this will crash the client!");
  168. _html = "<html><body>Html was too long</body></html>";
  169. return;
  170. }
  171. _html = text; // html code must not exceed 8192 bytes
  172. }
  173. public boolean setFile(String path)
  174. {
  175. String content = HtmCache.getInstance().getHtm(path);
  176. if (content == null)
  177. {
  178. setHtml("<html><body>My Text is missing:<br>"+path+"</body></html>");
  179. _log.warning("missing html page "+path);
  180. return false;
  181. }
  182. setHtml(content);
  183. return true;
  184. }
  185. public void replace(String pattern, String value)
  186. {
  187. _html = _html.replaceAll(pattern, value);
  188. }
  189. private final void buildBypassCache(L2PcInstance activeChar)
  190. {
  191. if (activeChar == null)
  192. return;
  193. activeChar.clearBypass();
  194. int len = _html.length();
  195. for(int i=0; i<len; i++)
  196. {
  197. int start = _html.indexOf("bypass -h", i);
  198. int finish = _html.indexOf("\"", start);
  199. if(start < 0 || finish < 0)
  200. break;
  201. start += 10;
  202. i = start;
  203. int finish2 = _html.indexOf("$",start);
  204. if (finish2 < finish && finish2 > 0)
  205. activeChar.addBypass2(_html.substring(start, finish2));
  206. else
  207. activeChar.addBypass(_html.substring(start, finish));
  208. //System.err.println("["+_html.substring(start, finish)+"]");
  209. }
  210. }
  211. @Override
  212. protected final void writeImpl()
  213. {
  214. writeC(0x19);
  215. writeD(_npcObjId);
  216. writeS(_html);
  217. writeD(_itemId);
  218. }
  219. /* (non-Javadoc)
  220. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  221. */
  222. @Override
  223. public String getType()
  224. {
  225. return _S__1B_NPCHTMLMESSAGE;
  226. }
  227. }