]> skyeroc.xyz Git - dgamelaunch/commitdiff
Change max. length of player name from magic number to a define.
authorPasi Kallinen <paxed@alt.org>
Fri, 27 Nov 2009 18:41:35 +0000 (18:41 +0000)
committerPasi Kallinen <paxed@alt.org>
Fri, 27 Nov 2009 18:41:35 +0000 (18:41 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@516 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

TODO
config.y
dgamelaunch.c
dgamelaunch.h
dgl-common.c

diff --git a/TODO b/TODO
index 5392530287c262f687bf3ba017c8671803bb9a11..589731d8f7f8d9d07c29da9db817a0bbf7b3e0bf 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,4 @@
+-update README
 -maybe allow something like changed_menu="[Updated %d]" config option  and
  $CHANGED in the menu banner.
  the $CHANGED will be replaced with the changed_menu value.
index 56fbbba4975c1e0f332372f0f06a446987cb00e9..66947961d26da3f92c1adfbcce76702dcaab1b88 100644 (file)
--- a/config.y
+++ b/config.y
@@ -245,6 +245,10 @@ KeyPair: TYPE_CMDQUEUE '[' TYPE_CMDQUEUENAME ']'
 
   case TYPE_MAXNICKLEN:
       globalconfig.max_newnick_len = $3;
+      if (globalconfig.max_newnick_len > DGL_PLAYERNAMELEN) {
+         fprintf(stderr, "%s:%d: max_newnick_len > DGL_PLAYERNAMELEN\n", config, line);
+         globalconfig.max_newnick_len = DGL_PLAYERNAMELEN;
+      }
       break;
 
     default:
index ef2934f99f370a206ea5ca31269fc78c558aa912..77b7e9a230d763c7721ff5f1844233fdc44f1763 100644 (file)
@@ -513,12 +513,12 @@ inprogressmenu (int gameid)
                int match = -1;
               int firstmatch = -1;
               int nmatches = 0;
-               char findname[21];
+               char findname[DGL_PLAYERNAMELEN+1];
               if (len <= 0) break;
                findname[0] = '\0';
               mvprintw ((btm+2+top_banner_hei), 1, "Watch which player? =>                 "); /* stupid... */
               mvaddstr ((btm+2+top_banner_hei), 1, "Watch which player? => ");
-               if ((mygetnstr(findname, 20, 1) == OK) && (strlen(findname) > 1)) {
+               if ((mygetnstr(findname, DGL_PLAYERNAMELEN, 1) == OK) && (strlen(findname) > 1)) {
                   int mlen = strlen(findname);
                    for (i = 0; i < len; i++)
                        if (!strncasecmp(games[i]->name, findname, mlen)) {
@@ -1024,7 +1024,7 @@ autologin (char* user, char *pass)
 void
 loginprompt (int from_ttyplay)
 {
-  char user_buf[22], pw_buf[22];
+  char user_buf[DGL_PLAYERNAMELEN+1], pw_buf[22];
   int error = 2;
 
   loggedin = 0;
@@ -1050,8 +1050,7 @@ loginprompt (int from_ttyplay)
 
       refresh ();
 
-      /* keep this at 20 chars for hysterical raisins */
-      if (mygetnstr (user_buf, 20, 1) != OK)
+      if (mygetnstr (user_buf, DGL_PLAYERNAMELEN, 1) != OK)
          return;
 
       if (*user_buf == '\0')
@@ -1416,7 +1415,7 @@ userexist (char *cname, int isnew)
 
   for (i = 0; i < f_num; i++)
     {
-       if (!strncasecmp (cname, users[i]->username, (isnew ? globalconfig.max_newnick_len : 20))) {
+       if (!strncasecmp (cname, users[i]->username, (isnew ? globalconfig.max_newnick_len : DGL_PLAYERNAMELEN))) {
            userexist_tmp_me = cpy_me(users[i]);
            return userexist_tmp_me;
        }
@@ -1462,8 +1461,8 @@ userexist (char *cname, int isnew)
 
     char *qbuf;
 
-    char tmpbuf[32];
-    strncpy(tmpbuf, cname, (isnew ? globalconfig.max_newnick_len : 20));
+    char tmpbuf[DGL_PLAYERNAMELEN+2];
+    strncpy(tmpbuf, cname, (isnew ? globalconfig.max_newnick_len : DGL_PLAYERNAMELEN));
 
     /* Check that the nick doesn't interfere with already registered nicks */
     if (isnew && (strlen(cname) >= globalconfig.max_newnick_len))
@@ -1645,7 +1644,7 @@ writefile (int requirenew)
 
   for (i = 0; i < f_num; i++)
     {
-      if (loggedin && !strncmp (me->username, users[i]->username, 20))
+      if (loggedin && !strncmp (me->username, users[i]->username, DGL_PLAYERNAMELEN))
         {
           if (requirenew)
             {
@@ -1922,7 +1921,7 @@ int
 authenticate ()
 {
   int i, len, me_index;
-  char user_buf[22], pw_buf[22];
+  char user_buf[DGL_PLAYERNAMELEN+1], pw_buf[22];
   struct dg_game **games = NULL;
 
   /* We use simple password authentication, rather than challenge/response. */
@@ -1935,7 +1934,7 @@ authenticate ()
     user_buf[--len] = '\0';
   else
     {
-      fprintf (stderr, "Username too long (max 20 chars).\n");
+       fprintf (stderr, "Username too long (max %i chars).\n", DGL_PLAYERNAMELEN);
       return 1;
     }
 
index 738a8d01a58330c9d453e58fb933032b8f15ef9d..9ceb433c3c278a328eca52a088ebb5277ca5d2ea 100644 (file)
@@ -15,6 +15,8 @@
 
 #define dglsign(x) (x < 0 ? -1 : (x > 0 ? 1 : 0))
 
+#define DGL_PLAYERNAMELEN 30 /* max. length of player name */
+
 typedef enum
 {
     DGLTIME_DGLSTART = 0,      /* when someone telnets in */
index 6158dac305c9275c38a8d4342f94990d7c5144ca..9c52c01076b42d7e711ef6f166910e14a1e35b61 100644 (file)
@@ -465,7 +465,7 @@ populate_games (int xgame, int *l, struct dg_user *me)
   DIR *pdir;
   struct dirent *pdirent;
   struct stat pstat;
-  char fullname[130], ttyrecname[130], pidws[80], playername[30];
+  char fullname[130], ttyrecname[130], pidws[80], playername[DGL_PLAYERNAMELEN+1];
   char *replacestr, *dir, *p;
   struct dg_game **games = NULL;
   struct flock fl = { 0 };
@@ -514,8 +514,8 @@ populate_games (int xgame, int *l, struct dg_user *me)
          if (!is_nhext)
            {
                char *ttrecdir = NULL;
-               strncpy(playername, pdirent->d_name, 29);
-               playername[29] = '\0';
+               strncpy(playername, pdirent->d_name, DGL_PLAYERNAMELEN);
+               playername[DGL_PLAYERNAMELEN] = '\0';
                if ((replacestr = strchr(playername, ':')))
                    *replacestr = '\0';
 
@@ -700,7 +700,7 @@ create_config ()
   if (!globalconfig.chroot) globalconfig.chroot = "/var/lib/dgamelaunch/";
 
   if (globalconfig.max == 0) globalconfig.max = 64000;
-  if (globalconfig.max_newnick_len == 0) globalconfig.max_newnick_len = 20;
+  if (globalconfig.max_newnick_len == 0) globalconfig.max_newnick_len = DGL_PLAYERNAMELEN;
   if (!globalconfig.dglroot) globalconfig.dglroot = "/dgldir/";
   if (!globalconfig.banner)  globalconfig.banner = "/dgl-banner";