added new multi log system
[NeonServV5.git] / src / modules / NeonServ.mod / cmd_neonserv_invite.c
index 70a405cea7fb91038b0fdbe33bdf32d46e6022fc..b9bce2855b8c626af6fa90f9b8f72d95944ea595 100644 (file)
@@ -1,4 +1,4 @@
-/* cmd_neonserv_invite.c - NeonServ v5.4
+/* cmd_neonserv_invite.c - NeonServ v5.6
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -47,19 +47,19 @@ static struct neonserv_cmd_invite_timeout *first_timeout = NULL, *last_timeout =
 
 CMD_BIND(neonserv_cmd_invite) {
     if(neonserv_cmd_invite_is_timeout(argv[0], chan->name)) {
-        reply(getTextBot(), user, "NS_INVITE_TIMEOUT", argv[0], chan->name);
+        reply(textclient, user, "NS_INVITE_TIMEOUT", argv[0], chan->name);
         return;
     }
     struct UserNode *cuser = getUserByNick(argv[0]);
     if(!cuser) {
         cuser = createTempUser(argv[0]);
                if(!cuser) {
-            reply(getTextBot(), user, "NS_USER_UNKNOWN", argv[0]);
+            reply(textclient, user, "NS_USER_UNKNOWN", argv[0]);
             return;
         }
         cuser->flags |= USERFLAG_ISTMPUSER;
     } else if(getChanUser(cuser, chan)) {
-        reply(getTextBot(), user, "NS_INVITE_ON_CHAN", cuser->nick, chan->name);
+        reply(textclient, user, "NS_INVITE_ON_CHAN", cuser->nick, chan->name);
         /* BUG
          This check does not work if the user is invisible (CHMODE +D/+d)
          to fix this we'd need to request the full userlist...
@@ -68,15 +68,15 @@ CMD_BIND(neonserv_cmd_invite) {
         return;
     }
     if(cuser->flags & USERFLAG_ISAUTHED) {
-        neonserv_cmd_invite_async1(client, getTextBot(), user, chan, event, argv[0], cuser->auth);
+        neonserv_cmd_invite_async1(client, textclient, user, chan, event, argv[0], cuser->auth);
     } else {
         struct neonserv_cmd_invite_cache *cache = malloc(sizeof(*cache));
         if (!cache) {
-            perror("malloc() failed");
+            printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
             return;
         }
         cache->client = client;
-        cache->textclient = getTextBot();
+        cache->textclient = textclient;
         cache->user = user;
         cache->chan = chan;
         cache->event = event;
@@ -97,12 +97,17 @@ static USERAUTH_CALLBACK(neonserv_cmd_invite_nick_lookup) {
 }
 
 static void neonserv_cmd_invite_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth) {
-    if(auth) {
+    if(auth && (!(user->flags & USERFLAG_ISAUTHED) || stricmp(auth, user->auth))) {
         MYSQL_RES *res;
         MYSQL_ROW row;
-        printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
+        printf_mysql_query("SELECT `user_id`, `user_block_invites` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
         res = mysql_use();
         if ((row = mysql_fetch_row(res)) != NULL) {
+            //check if the user has blocked invites globally
+            if(!strcmp(row[1], "1")) {
+                reply(textclient, user, "NS_INVITE_GLOBALLY_BLOCKED", nick);
+                return;
+            }
             //check if the user has set noinvite
             printf_mysql_query("SELECT `id` FROM `noinvite` WHERE `uid` = '%s' AND `cid` = '%d'", row[0], chan->channel_id);
             res = mysql_use();
@@ -134,7 +139,7 @@ static TIMEQ_CALLBACK(neonserv_cmd_invite_timeout_timeout) {
 static struct neonserv_cmd_invite_timeout* neonserv_cmd_invite_add_timeout(char *nick, char *chan) {
     struct neonserv_cmd_invite_timeout *entry = malloc(sizeof(*entry));
     if (!entry) {
-        perror("malloc() failed");
+        printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return NULL;
     }
     entry->next = NULL;