Navigation Menu

Skip to content

Commit

Permalink
Allow numbers in players names
Browse files Browse the repository at this point in the history
Note that freeciv doesn't allow names starting with a number. This
patch doesn't lift that restriction.

Closes #183
  • Loading branch information
lonemadmax committed Sep 8, 2018
1 parent 4395576 commit 7707ed5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
9 changes: 3 additions & 6 deletions freeciv-proxy/freeciv-proxy.py
Expand Up @@ -188,13 +188,10 @@ def get_civcom(self, username, civserverport, ws_connection):


def validate_username(name):
if (name is None
or len(name) <= 2 or len(name) >= 32
or name.lower() == "pbem"
or re.search('[^a-zA-Z]', name) is not None):
if (name is None or len(name) <= 2 or len(name) >= 32):
return False
else:
return True
name = name.lower()
return name != "pbem" and re.fullmatch('[a-z][a-z0-9]*', name) is not None


if __name__ == "__main__":
Expand Down
Expand Up @@ -21,15 +21,15 @@

public class Validation {

private static final Pattern usernameInvalidPattern = Pattern.compile("[^a-z]");
private static final Pattern usernamePattern = Pattern.compile("[a-z][a-z0-9]*");

public boolean isValidUsername(String name) {

if (name == null || name.length() <= 2 || name.length() >= 32) {
return false;
}
name = name.toLowerCase();
if (usernameInvalidPattern.matcher(name).find()) {
if (!usernamePattern.matcher(name).matches()) {
return false;
}
if (name.equals("pbem")) {
Expand Down
2 changes: 1 addition & 1 deletion freeciv-web/src/main/webapp/javascript/pbem.js
Expand Up @@ -31,7 +31,7 @@ function show_pbem_dialog()
var message = "";

if ($.getUrlVar('invited_by') != null) {
var invited = $.getUrlVar('invited_by').replace(/[^a-zA-Z]/g,'');
var invited = $.getUrlVar('invited_by').replace(/[^a-zA-Z0-9]/g,'');
message = "You have been invited by " + invited + " for a Play-by-Email game of Freeciv-web. "
+ "You and " + invited + " will play alternating turns, and you will get an e-mail every time "
+ "it is your turn to play. First you can create a new user or log-in, then you will play "
Expand Down
4 changes: 2 additions & 2 deletions freeciv-web/src/main/webapp/javascript/player.js
Expand Up @@ -264,8 +264,8 @@ function get_invalid_username_reason(username)
username = username.toLowerCase();
if (username == "pbem") {
return "not available";
} else if (username.search(/^[a-z]+$/g) != 0) {
return "invalid, only the English alphabet is allowed";
} else if (username.search(/^[a-z][a-z0-9]*$/g) != 0) {
return "invalid: only English letters and numbers are allowed, and must start with a letter";
} else if (!check_text_with_banlist_exact(username)) {
return "banned";
}
Expand Down

0 comments on commit 7707ed5

Please sign in to comment.