gametext safe text filter
#1

It is well known that invalid combo of "tilde tags" (~r~ and other such tags) in gametext will crash clients very easily, i made a filter to validate that all tags are properly closed (only 1-char long tags are supported, no others as they arent needed).

Please check the code and try to find any flaws in it:

Код:
stock issafefortextdraw(str[]) {
	
	new safetil = -5;
	
	for (new i = 0; i < strlen(str); i++) {
		
		if ((str[i] == 126) && (i > safetil)) {
			
			if (i >= strlen(str) - 1) // not enough room for the tag to end at all. 
				return false;
			
			if (str[i + 1] == 126)
				return false; // a tilde following a tilde.
			
			if (str[i + 2] != 126)
				return false; // a tilde not followed by another tilde after 2 chars
			
			safetil = i + 2; // tilde tag was verified as safe, ignore anything up to this location from further checks (otherwise it'll report tag end tilde as improperly started tag..).
		}
	}
	
	return true;
}
Reply
#2

Tnx. I was looking for this snippet as Useful Functions include's function names were conflicting with my own functions ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)