All pastes #741102 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-18 13:40 UTC
rendered paste body
Index: java/net/sf/l2j/gameserver/serverpackets/NpcHtmlMessage.java
===================================================================
--- java/net/sf/l2j/gameserver/serverpackets/NpcHtmlMessage.java	(revision 1214)
+++ java/net/sf/l2j/gameserver/serverpackets/NpcHtmlMessage.java	(working copy)
@@ -19,6 +19,7 @@
 package net.sf.l2j.gameserver.serverpackets;
 
 import java.util.logging.Logger;
+import java.util.ArrayList;
 
 import net.sf.l2j.gameserver.cache.HtmCache;
 import net.sf.l2j.gameserver.clientpackets.RequestBypassToServer;
@@ -137,6 +138,7 @@
 	private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
 	private int _npcObjId;
 	private String _html;
+	private ArrayList<String> replaces = new ArrayList<String>();
 
 	/**
 	 * @param _characters
@@ -158,15 +160,18 @@
 		buildBypassCache(getClient().getActiveChar());
 	}
 	
-	public void setHtml(String text)
+	public final NpcHtmlMessage 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;
+			return this;
 		}
-		_html = text; // html code must not exceed 8192 bytes 
+        if(!text.contains("<html>"))
+			text = "<html><body>" + text + "</body></html>"; //<title>Message:</title> <br><br><br>
+		_html = text; // html code must not exceed 8192 bytes
+		return this;
 	}
 
 	public boolean setFile(String path)
@@ -186,7 +191,8 @@
 
 	public void replace(String pattern, String value)
 	{
-		_html = _html.replaceAll(pattern, value);
+		replaces.add(pattern);
+		replaces.add(value);
 	}
 	
 	public final void buildBypassCache(L2PcInstance activeChar)
@@ -196,22 +202,30 @@
         
         activeChar.clearBypass();
 		int len = _html.length();
-		for(int i=0; i<len; i++)
+		try
 		{
-			int start = _html.indexOf("bypass -h", i);
-			int finish = _html.indexOf("\"", start);
+			for(int i=0; i<len; i++)
+			{
+				int start = _html.indexOf("bypass -h", i);
+				int finish = _html.indexOf("\"", start);
 
-			if(start < 0 || finish < 0)
-				break;
+				if(start < 0 || finish < 0)
+					break;
 			
-			start += 10;
-			i = start;
-			int finish2 = _html.indexOf("$",start);
-			if (finish2 < finish && finish2 > 0)
-                activeChar.addBypass2(_html.substring(start, finish2));
-			else
-                activeChar.addBypass(_html.substring(start, finish));
-			//System.err.println("["+_html.substring(start, finish)+"]");
+				start += 10;
+				i = start;
+				int finish2 = _html.indexOf("$",start);
+				if (finish2 < finish && finish2 > 0)
+					activeChar.addBypass2(_html.substring(start, finish2));
+				else
+					activeChar.addBypass(_html.substring(start, finish));
+				  //System.err.println("["+_html.substring(start, finish)+"]");
+		      }
+		}
+		catch (Exception e)
+		{
+		setHtml("<html><body>sorry, error</body></html>");
+		System.err.println("NpcHtmlMessage: " + e.getMessage());
 		}		
 	}