mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 13:23:56 -07:00
Prohibit lobby nick registration with some previously not-filtered characters between 32 and 127, in particular parentheses.
Use whitelist instead of blacklist, remove dead options and noisy unneeded gui/common/ function. Still allow existing players with now prohibited characters to login. This could be enforced in ejabberd too and then the now incomplete JS string can be replaced with a more general one. Differential Revision: https://code.wildfiregames.com/D715 Refs #4671 Reviewed By: Imarok This was SVN commit r19881.
This commit is contained in:
parent
f876eb86fa
commit
23d8bc11a5
2 changed files with 7 additions and 22 deletions
|
|
@ -130,24 +130,6 @@ function removeDupes(array)
|
|||
}
|
||||
}
|
||||
|
||||
// Filter out conflicting characters and limit the length of a given name.
|
||||
// @param name Name to be filtered.
|
||||
// @param stripUnicode Whether or not to remove unicode characters.
|
||||
// @param stripSpaces Whether or not to remove whitespace.
|
||||
function sanitizePlayerName(name, stripUnicode, stripSpaces)
|
||||
{
|
||||
// We delete the '[', ']' characters (GUI tags) and delete the ',' characters (player name separators) by default.
|
||||
var sanitizedName = name.replace(/[\[\],]/g, "");
|
||||
// Optionally strip unicode
|
||||
if (stripUnicode)
|
||||
sanitizedName = sanitizedName.replace(/[^\x20-\x7f]/g, "");
|
||||
// Optionally strip whitespace
|
||||
if (stripSpaces)
|
||||
sanitizedName = sanitizedName.replace(/\s/g, "");
|
||||
// Limit the length to 20 characters
|
||||
return sanitizedName.substr(0,20);
|
||||
}
|
||||
|
||||
function singleplayerName()
|
||||
{
|
||||
return Engine.ConfigDB_GetValue("user", "playername.singleplayer") || Engine.GetSystemUsername();
|
||||
|
|
|
|||
|
|
@ -91,8 +91,9 @@ function onTick()
|
|||
continueButton.enabled = false;
|
||||
feedback.caption = translate("Please enter your username");
|
||||
}
|
||||
// Check that they are using a valid username.
|
||||
else if (username != sanitizePlayerName(username, true, true))
|
||||
|
||||
// Prevent registation (but not login) with non-alphanumerical characters
|
||||
if (!pageRegisterHidden && (!username.match(/^[a-z0-9._-]*$/i) || username.length > 20))
|
||||
{
|
||||
continueButton.enabled = false;
|
||||
feedback.caption = translate("Usernames can't contain \\[, ], unicode, whitespace, or commas");
|
||||
|
|
@ -180,8 +181,8 @@ function onTick()
|
|||
{
|
||||
Engine.PopGuiPage();
|
||||
Engine.SwitchGuiPage("page_lobby.xml");
|
||||
Engine.ConfigDB_CreateValue("user", "playername.multiplayer", sanitizePlayerName(username, true, true));
|
||||
Engine.ConfigDB_WriteValueToFile("user", "playername.multiplayer", sanitizePlayerName(username, true, true), "config/user.cfg");
|
||||
Engine.ConfigDB_CreateValue("user", "playername.multiplayer", username);
|
||||
Engine.ConfigDB_WriteValueToFile("user", "playername.multiplayer", username, "config/user.cfg");
|
||||
Engine.ConfigDB_CreateValue("user", "lobby.login", username);
|
||||
Engine.ConfigDB_WriteValueToFile("user", "lobby.login", username, "config/user.cfg");
|
||||
// We only store the encrypted password, so make sure to re-encrypt it if changed before saving.
|
||||
|
|
@ -264,6 +265,8 @@ function prelobbyCancel()
|
|||
{
|
||||
lobbyStop();
|
||||
|
||||
Engine.GetGUIObjectByName("feedback").caption = "";
|
||||
|
||||
if (Engine.GetGUIObjectByName("pageWelcome").hidden)
|
||||
switchPage("welcome");
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue