Jump to content

[SHARE] HTML catch validation and decreased heap


Recommended Posts

Simple share reduce the heap of the html cache(less memory usage)and adds html validation(find incorrect tags in html files which usually ingame end up in a html is too long text).

 

Patch for gracia epilogue L2J but simple to adapt to any chronicle(L2J only L2JFree have validation alredy since ages)

 

### Eclipse Workspace Patch 1.0
#P L2_GameServer
Index: java/com/l2jserver/gameserver/cache/HtmCache.java
===================================================================
--- java/com/l2jserver/gameserver/cache/HtmCache.java	(revision 4299)
+++ java/com/l2jserver/gameserver/cache/HtmCache.java	(working copy)
@@ -18,15 +18,16 @@
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.gameserver.util.Util;

-import javolution.util.FastMap;
-
/**
  * @author Layane
  *
@@ -39,6 +40,16 @@

	private int _loadedFiles;
	private long _bytesBuffLen;
+	
+	private static final String[] VALID_TAGS = { "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", "head", "tbody" };
+	private final static HashSet<String> VALID_TAGS_SET = new HashSet<String>(301);
+	static
+	{
+		for (String tag : VALID_TAGS)
+			VALID_TAGS_SET.add(tag);
+	}

	public static HtmCache getInstance()
	{
@@ -47,7 +58,7 @@

	private HtmCache()
	{
-		_cache = new FastMap<Integer, String>();
+		_cache = new HashMap<Integer, String>(16000);
		reload();
	}

@@ -62,6 +73,8 @@
		{
			_log.info("Html cache start...");
			parseDir(f);
+			_log.info("Validation starts...");
+			validate();
			_log.info("Cache[html]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + getLoadedFiles() + " files loaded");
		}
		else
@@ -239,6 +252,32 @@

		return false;
	}
+	
+	private void validate()
+	{
+		for (Entry<Integer, String> entry : _cache.entrySet())
+		{
+			final String html = entry.getValue();
+			outer: for (int begin = 0; (begin = html.indexOf("<", begin)) != -1; begin++)
+			{
+				int end;
+				for (end = begin; end < html.length(); end++)
+				{
+					if (html.charAt(end) == '>' || html.charAt(end) == ' ')
+						break;
+					// some special quest-replaced tag
+					if (end == begin + 1 && html.charAt(end) == '?')
+						continue outer;
+				}
+				end++;
+				String tag = html.substring(begin + 1, end - 1).toLowerCase().replaceAll("/", "");
+				if (!VALID_TAGS_SET.contains(tag))
+				{
+					_log.info("Invalid tag used: '" + tag + "' at pos " + (begin + 1) + " " + entry.getKey());
+				}
+			}
+		}
+	}

	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder

Link to comment
Share on other sites

Just an advice for you and not only...

Stop losing your time with someone's else code. You, most developers in here, got a good start but you lost it on the way up because you never tried to do something different and harder. Take chalanges, code something that you consider you're not prepared for. Always work on stuff with one stage higher than the stage you are at.

 

L2j is a business and you can get pretty money out of it but you have to be prepared for anything, not just easy, normal stuff which anyone can do. That makes you a developer, the rest is wannabes.

 

Good luck to you, and not only.

Link to comment
Share on other sites

Just an advice for you and not only...

Stop losing your time with someone's else code. You, most developers in here, got a good start but you lost it on the way up because you never tried to do something different and harder. Take chalanges, code something that you consider you're not prepared for. Always work on stuff with one stage higher than the stage you are at.

 

L2j is a business and you can get pretty money out of it but you have to be prepared for anything, not just easy, normal stuff which anyone can do. That makes you a developer, the rest is wannabes.

 

Good luck to you, and not only.

 

And who said i dont do that? :)

 

I think we can agree in 1 thing hard work never shared in public ;)

Link to comment
Share on other sites

And who said i dont do that? :)

 

I think we can agree in 1 thing hard work never shared in public ;)

 

Another tip for you. You probably noticed I had no shares lately. And I mean NONE!

 

Oh well, I got awared of the fact that L2j, as most online things, became a business. Money are done on the internet now. Most of them!

 

L2J as a business and a market of sell means much. A single mistake can fuck up the whole market. One shared piece of code that shouldn't be shared can get a lot of money lost. That's why I'm not for sharing anymore. You want any code you can think of? You pay for it. You want to make a server and get money out of donations afterall, don't you? That's a business and as any other business out there you have to invest in it.

 

Make me understand the concept of me, as a developer, to code something from MY OWN and share it with every else. Most of the guys in here got no idea I'm learning this for a very, very long time. Most of the guys got no idea that at 13 years old I was coding flooders in Visual Basic for DC++ networks. I lost a lot and I gained a lot. Why should I use MY OWN lost years for someone else? Why should I share the code I MADE with someone else? I worked hard to be able to do it. Now I do it for myself, and selling it, is doing it for myself too. Give me just ONE SINGLE advantage of sharing something that I could get money out of. You cant. You will talk about fame. You get fame by sharing and that's right. Next, what you're going to do with that fame? Just nothing. I get fame and I get paid at the same time, I consider that WAY better.

 

Hope you all got the point Im going for and there will be no flames like "wtf u doing here if u'r not for sharing then?". Im here for the people who know me and Im here to SELL STUFF. Noone can forbid me that.

Link to comment
Share on other sites

Another tip for you. You probably noticed I had no shares lately. And I mean NONE!

 

Oh well, I got awared of the fact that L2j, as most online things, became a business. Money are done on the internet now. Most of them!

 

L2J as a business and a market of sell means much. A single mistake can -beep- up the whole market. One shared piece of code that shouldn't be shared can get a lot of money lost. That's why I'm not for sharing anymore. You want any code you can think of? You pay for it. You want to make a server and get money out of donations afterall, don't you? That's a business and as any other business out there you have to invest in it.

 

Make me understand the concept of me, as a developer, to code something from MY OWN and share it with every else. Most of the guys in here got no idea I'm learning this for a very, very long time. Most of the guys got no idea that at 13 years old I was coding flooders in Visual Basic for DC++ networks. I lost a lot and I gained a lot. Why should I use MY OWN lost years for someone else? Why should I share the code I MADE with someone else? I worked hard to be able to do it. Now I do it for myself, and selling it, is doing it for myself too. Give me just ONE SINGLE advantage of sharing something that I could get money out of. You cant. You will talk about fame. You get fame by sharing and that's right. Next, what you're going to do with that fame? Just nothing. I get fame and I get paid at the same time, I consider that WAY better.

 

Hope you all got the point Im going for and there will be no flames like "wtf u doing here if u'r not for sharing then?". Im here for the people who know me and Im here to SELL STUFF. Noone can forbid me that.

 

you dont need to tell me that because i do the exact same but some hype to keep your name up never comes bad :)

Link to comment
Share on other sites

you dont need to tell me that because i do the exact same but some hype to keep your name up never comes bad :)

 

I used the oportunity to explain this to anyone else, not just to you.

 

Keep up the good work. I hope Ill see you soon saying "Got no time to stay late for the drink guys, got some projects to do for good money".

Link to comment
Share on other sites

I used the oportunity to explain this to anyone else, not just to you.

 

Keep up the good work. I hope Ill see you soon saying "Got no time to stay late for the drink guys, got some projects to do for good money".

We are talking about Intrepid you know...

 

Ty very much for this share mate...

Link to comment
Share on other sites

I used the oportunity to explain this to anyone else, not just to you.

 

Keep up the good work. I hope Ill see you soon saying "Got no time to stay late for the drink guys, got some projects to do for good money".

 

friends  > all so thats not going to happen but thank you i make fine amount of money with l2j :)

Link to comment
Share on other sites

The thing you forget Vago, it's some ppl makes L2J for free, and you use it to make money on it.

 

Without this teamwork, I don't think you would dev or make money. Just think a lil.

 

Anyway, ty for the -FREE- share. And death to this capitalist conception of coding (and no I'm not a Linux fan).

 

BTW, showing some codes sometimes just show he got talent, just show his programmer skill and make him publicity. You missed a marketing lesson...

 

I don't defend Intrepid, and I have nothing with you Vago. :).

 

----

 

Have you taken the idea from your old anti-L2W commit ? It looks the same :D.

Link to comment
Share on other sites

The thing you forget Vago, it's some ppl makes L2J for free, and you use it to make money on it.

 

Without this teamwork, I don't think you would dev or make money. Just think a lil.

 

Anyway, ty for the -FREE- share. And death to this capitalist conception of coding (and no I'm not a Linux fan).

 

BTW, showing some codes sometimes just show he got talent, just show his programmer skill and make him publicity. You missed a marketing lesson...

 

I don't defend Intrepid, and I have nothing with you Vago. :).

 

----

 

Have you taken the idea from your old anti-L2W commit ? It looks the same :D.

 

Actually that was done way before my anti l2w try :D

Thats made back in l2emu nearly 9months old code :D

Link to comment
Share on other sites

The thing you forget Vago, it's some ppl makes L2J for free, and you use it to make money on it.

 

Without this teamwork, I don't think you would dev or make money. Just think a lil.

 

Anyway, ty for the -FREE- share. And death to this capitalist conception of coding (and no I'm not a Linux fan).

 

BTW, showing some codes sometimes just show he got talent, just show his programmer skill and make him publicity. You missed a marketing lesson...

 

I don't defend Intrepid, and I have nothing with you Vago. :).

 

----

 

Have you taken the idea from your old anti-L2W commit ? It looks the same :D.

 

They could have made lots of money with a non-shared l2j but that's their work and they do whatever they want with it. Im just saying I wont share my considerable work ever again. :)

Link to comment
Share on other sites

They could have made lots of money with a non-shared l2j but that's their work and they do whatever they want with it. Im just saying I wont share my considerable work ever again. :)

 

And you are right with that but as i said before some "hipe" never hurt. :)

Link to comment
Share on other sites

Oh well, I got awared of the fact that L2j, as most online things, became a business. Money are done on the internet now. Most of them!

client modding is awarded the same way...

 

If you do something for free you end up with 99% of the people using it do nothing in return

 

Do realise that thanks to those who did spend their time sharing/making l2j allowed you to now make money from it; the same way I'm still infinitely thankful to those that shared the first guides/tools how to edit L2 client.

 

Thanks for sharing Interpid, it seems helpful

Link to comment
Share on other sites

Actually that was done way before my anti l2w try :D

Thats made back in l2emu nearly 9months old code :D

 

Buhaha.

 

Btw, you should make the message more friendly, cause actually you know you got error in "x" files, but which exactly are them...

 

Or show only useful infos, like bad tags and the total numbers of files, cause if you got 150 bad tags, that shows 150 errors ? Not rly exploitable in a GS log:P.

 

And the big numbers I don't get the use :D. About the pos, it's the file which have been loaded ? So you know it's the 1849th loaded file which bugs ? Not rly exploitable ^^.

 

(Ok with notepad ++ you search for the bad tag in the folder, but still :p.)

 

Works fine on my Archid custom, you have to disable the Lazy cache.

 

plopa.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disbaled AdBlock