123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.network.serverpackets;
- import java.util.logging.Logger;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.cache.HtmCache;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.network.clientpackets.RequestBypassToServer;
- /**
- *
- * the HTML parser in the client knowns these standard and non-standard tags and attributes
- * VOLUMN
- * UNKNOWN
- * UL
- * U
- * TT
- * TR
- * TITLE
- * TEXTCODE
- * TEXTAREA
- * TD
- * TABLE
- * SUP
- * SUB
- * STRIKE
- * SPIN
- * SELECT
- * RIGHT
- * PRE
- * P
- * OPTION
- * OL
- * MULTIEDIT
- * LI
- * LEFT
- * INPUT
- * IMG
- * I
- * HTML
- * H7
- * H6
- * H5
- * H4
- * H3
- * H2
- * H1
- * FONT
- * EXTEND
- * EDIT
- * COMMENT
- * COMBOBOX
- * CENTER
- * BUTTON
- * BR
- * BR1
- * BODY
- * BAR
- * ADDRESS
- * A
- * SEL
- * LIST
- * VAR
- * FORE
- * READONL
- * ROWS
- * VALIGN
- * FIXWIDTH
- * BORDERCOLORLI
- * BORDERCOLORDA
- * BORDERCOLOR
- * BORDER
- * BGCOLOR
- * BACKGROUND
- * ALIGN
- * VALU
- * READONLY
- * MULTIPLE
- * SELECTED
- * TYP
- * TYPE
- * MAXLENGTH
- * CHECKED
- * SRC
- * Y
- * X
- * QUERYDELAY
- * NOSCROLLBAR
- * IMGSRC
- * B
- * FG
- * SIZE
- * FACE
- * COLOR
- * DEFFON
- * DEFFIXEDFONT
- * WIDTH
- * VALUE
- * TOOLTIP
- * NAME
- * MIN
- * MAX
- * HEIGHT
- * DISABLED
- * ALIGN
- * MSG
- * LINK
- * HREF
- * ACTION
- *
- *
- * @version $Revision: 1.3.2.1.2.3 $ $Date: 2005/03/27 15:29:57 $
- */
- public final class NpcHtmlMessage extends L2GameServerPacket
- {
- // d S
- // d is usually 0, S is the html text starting with <html> and ending with </html>
- //
- private static final String _S__1B_NPCHTMLMESSAGE = "[S] 19 NpcHtmlMessage";
- private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
- private int _npcObjId;
- private String _html;
- private int _itemId = 0;
- private boolean _validate = true;
-
- /**
- *
- * @param npcObjId
- * @param text
- * @param itemId
- */
- public NpcHtmlMessage(int npcObjId, int itemId)
- {
- _npcObjId = npcObjId;
- _itemId = itemId;
- }
- /**
- * @param _characters
- */
- public NpcHtmlMessage(int npcObjId, String text)
- {
- _npcObjId = npcObjId;
- setHtml(text);
- }
- public NpcHtmlMessage(int npcObjId)
- {
- _npcObjId = npcObjId;
- }
- /**
- * disable building bypass validation cache for this packet
- */
- public void disableValidation()
- {
- _validate = false;
- }
- @Override
- public void runImpl()
- {
- if (Config.BYPASS_VALIDATION && _validate)
- buildBypassCache(getClient().getActiveChar());
- }
- public void setHtml(String text)
- {
- if(text.length() > 8192)
- {
- _log.warning("Html is too long! this will crash the client!");
- _html = "<html><body>Html was too long</body></html>";
- return;
- }
- _html = text; // html code must not exceed 8192 bytes
- }
- public boolean setFile(String prefix, String path)
- {
- String content = HtmCache.getInstance().getHtm(prefix, path);
- if (content == null)
- {
- setHtml("<html><body>My Text is missing:<br>"+path+"</body></html>");
- _log.warning("missing html page "+path);
- return false;
- }
- setHtml(content);
- return true;
- }
- public void replace(String pattern, String value)
- {
- _html = _html.replaceAll(pattern, value);
- }
- private final void buildBypassCache(L2PcInstance activeChar)
- {
- if (activeChar == null)
- return;
- activeChar.clearBypass();
- int len = _html.length();
- for (int i = 0; i < len; i++)
- {
- int start = _html.indexOf("\"bypass ", i);
- int finish = _html.indexOf("\"", start + 1);
- if (start < 0 || finish < 0)
- break;
- if (_html.substring(start+8, start+10).equals("-h"))
- start += 11;
- else
- start += 8;
- i = finish;
- int finish2 = _html.indexOf("$", start);
- if (finish2 < finish && finish2 > 0)
- activeChar.addBypass2(_html.substring(start, finish2).trim());
- else
- activeChar.addBypass(_html.substring(start, finish).trim());
- }
- }
- @Override
- protected final void writeImpl()
- {
- writeC(0x19);
- writeD(_npcObjId);
- writeS(_html);
- writeD(_itemId);
- }
- /* (non-Javadoc)
- * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
- */
- @Override
- public String getType()
- {
- return _S__1B_NPCHTMLMESSAGE;
- }
- }
|