View Full Version : gametext safe text filter

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;

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 ^^