View Full Version : Using User.getUsername() For Node Names Can Corrupt Campaign Database

May 10th, 2012, 18:01
Hi All,

Not really an issue I suppose for FG2, but I thought that I would mention it anyway.

I have a ruleset where I allow each player to keep their own notes. I store the notes under a node in the database called 'notes.<username>' where <username> is retrieved using User.getUsername();

This seemed to work fine, until a player used invalid characters in their username (such as brackets). FG2 happily used the username for the node name, and wrote the node to the db.xml upon exit. However, when attempting to load the campaign again FG2 complained because the XML now had validation errors as there were invalid characters in an xml node. This caused FG2 to error, backup the database, and then create a blank database - making it appear as though the campaign had been lost. I had to fix the campaign by restoring the backup and manually removing the invalid nodes.

I have worked around this by stripping out invalid characters using:

string.gsub(username, "([^/A-Za-z0-9_])" , "_")

Thought that I'd point this out in case anyone else hits the same issue.

May 10th, 2012, 18:10
I have encountered this "issue" before myself and fixed it with similar solution. However, since databasenode cannot contains special characters it would be feasible that FG engine would validate databasenode names before creating one. In case of invalid name there could be script error log in console.

May 12th, 2012, 12:01
Yep, Savage Worlds used to do this. One of my players (da'flibble) killed our entire campaign in one login... the fix got written VERY soon afterwards ;)

Moon Wizard
May 12th, 2012, 22:05
I'm looking into patching this for the long run, but you should still leave the checks in.