NpcQuestHtmlMessage.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 NpcQuestHtmlMessage extends L2GameServerPacket
  126. {
  127. private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
  128. private int _npcObjId;
  129. private String _html;
  130. private int _questId = 0;
  131. /**
  132. *
  133. * @param npcObjId
  134. * @param text
  135. * @param questId
  136. */
  137. public NpcQuestHtmlMessage(int npcObjId, int questId)
  138. {
  139. _npcObjId = npcObjId;
  140. _questId = questId;
  141. }
  142. @Override
  143. public void runImpl()
  144. {
  145. if (Config.BYPASS_VALIDATION)
  146. buildBypassCache(getClient().getActiveChar());
  147. }
  148. public void setHtml(String text)
  149. {
  150. if(text.length() > 8192)
  151. {
  152. _log.warning("Html is too long! this will crash the client!");
  153. _html = "<html><body>Html was too long</body></html>";
  154. return;
  155. }
  156. _html = text; // html code must not exceed 8192 bytes
  157. }
  158. public boolean setFile(String path)
  159. {
  160. String content = HtmCache.getInstance().getHtm(getClient().getActiveChar().getHtmlPrefix(), path);
  161. if (content == null)
  162. {
  163. setHtml("<html><body>My Text is missing:<br>"+path+"</body></html>");
  164. _log.warning("missing html page "+path);
  165. return false;
  166. }
  167. setHtml(content);
  168. return true;
  169. }
  170. public void replace(String pattern, String value)
  171. {
  172. _html = _html.replaceAll(pattern, value);
  173. }
  174. private final void buildBypassCache(L2PcInstance activeChar)
  175. {
  176. if (activeChar == null)
  177. return;
  178. activeChar.clearBypass();
  179. int len = _html.length();
  180. for(int i=0; i<len; i++)
  181. {
  182. int start = _html.indexOf("bypass -h", i);
  183. int finish = _html.indexOf("\"", start);
  184. if(start < 0 || finish < 0)
  185. break;
  186. start += 10;
  187. i = finish;
  188. int finish2 = _html.indexOf("$",start);
  189. if (finish2 < finish && finish2 > 0)
  190. activeChar.addBypass2(_html.substring(start, finish2).trim());
  191. else
  192. activeChar.addBypass(_html.substring(start, finish).trim());
  193. }
  194. }
  195. @Override
  196. protected final void writeImpl()
  197. {
  198. writeC(0xfe);
  199. writeH(0x8d);
  200. writeD(_npcObjId);
  201. writeS(_html);
  202. writeD(_questId);
  203. }
  204. /* (non-Javadoc)
  205. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  206. */
  207. @Override
  208. public String getType()
  209. {
  210. return "[S] FE:8D NpcQuestHtmlMessage";
  211. }
  212. }