changed Makefile; build all commands as an own file
[NeonServV5.git] / DBHelper.c
index 587158635b065e64283c71849adfb479d250cc06..181fff607b542c6262721a4fe973414594ec5d8c 100644 (file)
@@ -5,10 +5,9 @@
 #include "ChanUser.h"
 #include "mysqlConn.h"
 #include "lang.h"
-
+#include "tools.h"
 
 void _loadUserSettings(struct UserNode *user) {
-    check_mysql();
     MYSQL_RES *res;
     MYSQL_ROW row;
     printf_mysql_query("SELECT `user_lang`, `user_reply_privmsg`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
@@ -36,7 +35,6 @@ int getChannelAccess(struct UserNode *user, struct ChanNode *chan, int override)
     if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0;
     MYSQL_RES *res;
     MYSQL_ROW row;
-    check_mysql();
     int caccess = 0;
     printf_mysql_query("SELECT `user_id`, `user_access`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
     res = mysql_use();
@@ -95,7 +93,6 @@ int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *chann
 }
 
 void _loadChannelSettings(struct ChanNode *chan) {
-    check_mysql();
     MYSQL_RES *res;
     MYSQL_ROW row;
     printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(chan->name));
@@ -118,13 +115,13 @@ int isUserProtected(struct ChanNode *chan, struct UserNode *victim, struct UserN
     char protection;
     loadChannelSettings(chan);
     if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0;
-    printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_id` = '%d'");
+    printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id);
     res = mysql_use();
     if(!(row = mysql_fetch_row(res))) return 0;
     if(row[0]) {
         protection = (char) atoi(row[0]);
     } else {
-         printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_name` = 'defaults'", chan->channel_id);
+         printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_name` = 'defaults'");
         res = mysql_use();
         row = mysql_fetch_row(res);
         protection = (char) atoi(row[0]);
@@ -154,4 +151,16 @@ int isUserProtected(struct ChanNode *chan, struct UserNode *victim, struct UserN
     return 0;
 }
 
-
+char *getBanAffectingMask(struct ChanNode *chan, char *mask) {
+    loadChannelSettings(chan);
+    if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0;
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `ban_mask` FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id);
+    res = mysql_use();
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(!match(row[0], mask))
+            return row[0];
+    }
+    return NULL;
+}