Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12065) Numeric username rejected on win32 beta client.
Home

[Freeciv-Dev] (PR#12065) Numeric username rejected on win32 beta client.

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: lawndart@xxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#12065) Numeric username rejected on win32 beta client.
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 1 Feb 2005 19:38:38 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12065 >

This patch adds a function is_valid_username.  If the result of
user_username isn't valid, a different name is chosen.

-jason

? patch.diff
? win32.diff
Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.197.2.8
diff -u -r1.197.2.8 civclient.c
--- client/civclient.c  21 Jan 2005 00:02:41 -0000      1.197.2.8
+++ client/civclient.c  2 Feb 2005 03:38:05 -0000
@@ -281,6 +281,17 @@
   /* after log_init: */
 
   sz_strlcpy(default_user_name, user_username());
+  if (!is_valid_username(default_user_name)) {
+    char buf[sizeof(default_user_name)];
+
+    my_snprintf(buf, sizeof(buf), "_%s", default_user_name);
+    if (is_valid_username(default_user_name)) {
+      sz_strlcpy(default_user_name, buf);
+    } else {
+      my_snprintf(default_user_name, sizeof(default_user_name),
+                 "player%d", myrand(10000));
+    }
+  }
 
   /* initialization */
 
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.157.2.2
diff -u -r1.157.2.2 player.c
--- common/player.c     23 Oct 2004 20:02:55 -0000      1.157.2.2
+++ common/player.c     2 Feb 2005 03:38:05 -0000
@@ -742,3 +742,16 @@
 
   return in_territory;
 }
+
+/****************************************************************************
+  Returns whether this is a valid username.  This is used by the server to
+  validate usernames and should be used by the client to avoid invalid
+  ones.
+****************************************************************************/
+bool is_valid_username(const char *name)
+{
+  return (strlen(name) > 0
+         && !my_isdigit(name[0])
+         && is_ascii_name(name)
+         && mystrcasecmp(name, ANON_USER_NAME) != 0);
+}
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.130.2.2
diff -u -r1.130.2.2 player.h
--- common/player.h     1 Jan 2005 22:12:44 -0000       1.130.2.2
+++ common/player.h     2 Feb 2005 03:38:06 -0000
@@ -307,4 +307,9 @@
 /* ai love values should be in range [-MAX_AI_LOVE..MAX_AI_LOVE] */
 #define MAX_AI_LOVE 1000
 
+
+/* User functions. */
+bool is_valid_username(const char *name);
+
+
 #endif  /* FC__PLAYER_H */
Index: server/connecthand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/connecthand.c,v
retrieving revision 1.34.2.3
diff -u -r1.34.2.3 connecthand.c
--- server/connecthand.c        9 Dec 2004 16:28:10 -0000       1.34.2.3
+++ server/connecthand.c        2 Feb 2005 03:38:06 -0000
@@ -255,10 +255,7 @@
   remove_leading_trailing_spaces(req->username);
 
   /* Name-sanity check: could add more checks? */
-  if (strlen(req->username) == 0
-      || my_isdigit(req->username[0])
-      || !is_ascii_name(req->username)
-      || mystrcasecmp(req->username, ANON_USER_NAME) == 0) {
+  if (!is_valid_username(req->username)) {
     my_snprintf(msg, sizeof(msg), _("Invalid username '%s'"), req->username);
     reject_new_connection(msg, pconn);
     freelog(LOG_NORMAL, _("Rejected connection from %s with invalid name."),

[Prev in Thread] Current Thread [Next in Thread]