get default value if channel_getop or channel_getvoice is NULL
authorpk910 <philipp@zoelle1.de>
Mon, 22 Aug 2011 21:43:37 +0000 (23:43 +0200)
committerpk910 <philipp@zoelle1.de>
Mon, 22 Aug 2011 21:43:37 +0000 (23:43 +0200)
cmd_neonserv_myaccess.c

index 16a718ba21385fd8fdcb4b27d5064403776fbc84..281e7a161d7bfa6ab4d772f3dbbc83348549ecc7 100644 (file)
@@ -93,8 +93,8 @@ static USERAUTH_CALLBACK(neonserv_cmd_myaccess_nick_lookup) {
 
 static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *nick, char *auth, char *chanmatch) {
     //we've got a valid auth now...
-    MYSQL_RES *res;
-    MYSQL_ROW user_row, chanuser_row;
+    MYSQL_RES *res, *default_res;
+    MYSQL_ROW user_row, chanuser_row, default_chan = NULL;
     char flagBuf[5];
     int userid, cflags, caccess, flagPos;
     int i, total_count, match_count = 0, owner_count = 0;
@@ -122,6 +122,11 @@ static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct Cli
             if(!strcmp(chanuser_row[0], "500")) owner_count++;
             if(chanmatch && match(chanmatch, chanuser_row[0])) continue;
             match_count++;
+            if((!chanuser_row[4] || !chanuser_row[5]) && !default_chan) {
+                printf_mysql_query("SELECT `channel_getop`, `channel_getvoice` FROM `channels` WHERE `channel_name` = 'defaults'");
+                default_res = mysql_use();
+                default_chan = mysql_fetch_row(default_res);
+            }
             flagPos = 0;
             content[0] = chanuser_row[3];
             content[1] = chanuser_row[0];
@@ -129,9 +134,9 @@ static void neonserv_cmd_myaccess_async1(struct ClientSocket *client, struct Cli
             caccess = atoi(chanuser_row[0]);
             if((cflags & DB_CHANUSER_SUSPENDED))
                 flagPos += sprintf(flagBuf + flagPos, "s");
-            if(caccess >= atoi(chanuser_row[4]))
+            if(caccess >= (chanuser_row[4] ? atoi(chanuser_row[4]) : atoi(default_chan[0])))
                 flagPos += sprintf(flagBuf + flagPos, "o");
-            if(caccess >= atoi(chanuser_row[5]))
+            if(caccess >= (chanuser_row[5] ? atoi(chanuser_row[5]) : atoi(default_chan[1])))
                 flagPos += sprintf(flagBuf + flagPos, "v");
             if((cflags & DB_CHANUSER_AUTOINVITE))
                 flagPos += sprintf(flagBuf + flagPos, "i");