using channel entry named 'default' as default values
[NeonServV5.git] / DBHelper.c
index ce43cc025699f779d03c8c09b967afe0b61b94ad..f0897d25f03e4a657b534374f58b194e67ad46e6 100644 (file)
@@ -56,6 +56,15 @@ 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;
@@ -64,7 +73,7 @@ int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *chann
     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 = (row[0] ? atoi(row[0]) : getChanDefault(channel_setting));
     if(require_access == 0) return 1;
     if(!(user->flags & USERFLAG_ISAUTHED)) return 0;
     int caccess = 0;