changed Makefile; build all commands as an own file
[NeonServV5.git] / cmd_neonserv_suspend.c
index 37d205e9bc11f1a1e1b7711e73ba5dcab65ffecc..4db9a50d1468fa7d17d215e42b4154453c383b1e 100644 (file)
@@ -1,24 +1,25 @@
 
+#include "cmd_neonserv.h"
+
 /*
 * argv[0] - nick / *auth
 */
 static USERAUTH_CALLBACK(neonserv_cmd_suspend_nick_lookup);
-static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *nick, char *auth);
+static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth);
 
 struct neonserv_cmd_suspend_cache {
     struct ClientSocket *client, *textclient;
     struct UserNode *user;
     struct ChanNode *chan;
+    struct Event *event;
     char *nick;
 };
 
-static CMD_BIND(neonserv_cmd_suspend) {
-    check_mysql();
-    checkChannelAccess(user, chan, "channel_cansuspend", 1, 0);
+CMD_BIND(neonserv_cmd_suspend) {
     if(argv[0][0] == '*') {
         //we've got an auth
         argv[0]++;
-        neonserv_cmd_suspend_async1(client, getTextBot(), user, chan, argv[0], argv[0]);
+        neonserv_cmd_suspend_async1(client, getTextBot(), user, chan, event, argv[0], argv[0]);
     } else {
         struct UserNode *cuser = getUserByNick(argv[0]);
         if(!cuser) {
@@ -26,7 +27,7 @@ static CMD_BIND(neonserv_cmd_suspend) {
             cuser->flags |= USERFLAG_ISTMPUSER;
         }
         if(cuser->flags & USERFLAG_ISAUTHED) {
-            neonserv_cmd_suspend_async1(client, getTextBot(), user, chan, argv[0], cuser->auth);
+            neonserv_cmd_suspend_async1(client, getTextBot(), user, chan, event, argv[0], cuser->auth);
         } else {
             struct neonserv_cmd_suspend_cache *cache = malloc(sizeof(*cache));
             if (!cache) {
@@ -37,6 +38,7 @@ static CMD_BIND(neonserv_cmd_suspend) {
             cache->textclient = getTextBot();
             cache->user = user;
             cache->chan = chan;
+            cache->event = event;
             cache->nick = strdup(argv[0]);
             get_userauth(cuser, neonserv_cmd_suspend_nick_lookup, cache);
         }
@@ -54,12 +56,12 @@ static USERAUTH_CALLBACK(neonserv_cmd_suspend_nick_lookup) {
         reply(cache->textclient, cache->user, "NS_USER_NEED_AUTH", cache->nick);
     }
     else
-        neonserv_cmd_suspend_async1(cache->client, cache->textclient, cache->user, cache->chan, user->nick, user->auth);
+        neonserv_cmd_suspend_async1(cache->client, cache->textclient, cache->user, cache->chan, cache->event, user->nick, user->auth);
     free(cache->nick);
     free(cache);
 }
 
-static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *nick, char *auth) {
+static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth) {
     //we've got a valid auth now...
     MYSQL_RES *res;
     MYSQL_ROW row;
@@ -72,9 +74,13 @@ static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct Clie
         printf_mysql_query("SELECT `chanuser_access`, `chanuser_id`, `chanuser_flags` FROM `chanusers` WHERE `chanuser_cid` = '%d' AND `chanuser_uid` = '%d'", chan->channel_id, userid);
         res = mysql_use();
         if ((row = mysql_fetch_row(res)) != NULL) {
-            if(atoi(row[0]) >= getChannelAccess(user, chan, 1)) {
-                reply(textclient, user, "NS_USER_OUTRANKED", nick);
-                return;
+            if(atoi(row[0]) >= getChannelAccess(user, chan, 0)) {
+                if(isGodMode(user)) {
+                    event->flags |= CMDFLAG_OPLOG;
+                } else {
+                    reply(textclient, user, "NS_USER_OUTRANKED", nick);
+                    return;
+                }
             }
             //suspend
             cflags = atoi(row[2]);
@@ -85,6 +91,7 @@ static void neonserv_cmd_suspend_async1(struct ClientSocket *client, struct Clie
             cflags |= DB_CHANUSER_SUSPENDED;
             printf_mysql_query("UPDATE `chanusers` SET `chanuser_flags` = '%d' WHERE `chanuser_id` = '%s'", cflags, row[1]);
             reply(textclient, user, "NS_SUSPEND_DONE", nick, chan->name);
+            logEvent(event);
             return;
         }
     }