PDA

View Full Version : gametext safe text filter


JernejL
31/07/2010, 04:42 PM
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;
}

[HLF]Southclaw
28/01/2012, 10:10 AM
Nice! I've been after something like this for a while!
I tried to make my own ages ago but failed, didn't bother since!

Thanks :p


Edit: Holy crap I just noticed the date on the post!
Someone linked this thread in Useful Functions!

AnnaSB
06/07/2014, 03:08 PM
Tnx. I was looking for this snippet as Useful Functions include's function names were conflicting with my own functions ^^