fixed last commit
[NeonServV5.git] / DBHelper.c
index eb8953691d5225904fbe898a3bb73ed087fe12ff..7d22a816f2805e79f56f71de1d3050b0a852d8f0 100644 (file)
@@ -47,7 +47,8 @@ int getChannelAccess(struct UserNode *user, struct ChanNode *chan, int override)
         //
         res = mysql_use();
         if ((row = mysql_fetch_row(res)) != NULL) {
-            if(!(atoi(row[1]) & DB_CHANUSER_SUSPENDED) && atoi(row[0]) > caccess)
+            int cflags = atoi(row[1]);
+            if(!(cflags & DB_CHANUSER_SUSPENDED) && atoi(row[0]) > caccess)
                 caccess = atoi(row[0]);
         }
         return caccess;
@@ -55,15 +56,25 @@ int getChannelAccess(struct UserNode *user, struct ChanNode *chan, int override)
     return 0;
 }
 
+char *getChanDefault(char *channel_setting) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_name` = 'defaults'", channel_setting);
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) == NULL) return "";
+    return row[0];
+}
+
 int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *channel_setting, int allow_override, int allow_501) {
     loadChannelSettings(chan);
     if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0;
+    if((user->flags & USERFLAG_ISIRCOP)) return 1;
     MYSQL_RES *res;
     MYSQL_ROW row;
     printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_id` = '%d'", channel_setting, chan->channel_id);
     res = mysql_use();
     if ((row = mysql_fetch_row(res)) == NULL) return 0;
-    int require_access = atoi(row[0]);
+    int require_access = atoi((row[0] ? row[0] : getChanDefault(channel_setting)));
     if(require_access == 0) return 1;
     if(!(user->flags & USERFLAG_ISAUTHED)) return 0;
     int caccess = 0;
@@ -73,7 +84,8 @@ int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *chann
         printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` WHERE `chanuser_uid` = '%s' AND `chanuser_cid` = '%d'", row[0], chan->channel_id);
         res = mysql_use();
         if ((row = mysql_fetch_row(res)) != NULL) {
-            if(!(atoi(row[1]) & DB_CHANUSER_SUSPENDED))
+            int cflags = atoi(row[1]);
+            if(!(cflags & DB_CHANUSER_SUSPENDED))
                 caccess = atoi(row[0]);
         }
     }