rearranged NeonServ code to be modular
[NeonServV5.git] / src / cmd_neonserv_deluser.c
diff --git a/src/cmd_neonserv_deluser.c b/src/cmd_neonserv_deluser.c
deleted file mode 100644 (file)
index 5188f01..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/* cmd_neonserv_deluser.c - NeonServ v5.3
- * Copyright (C) 2011-2012  Philipp Kreil (pk910)
- * 
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License 
- * along with this program. If not, see <http://www.gnu.org/licenses/>. 
- */
-
-#include "cmd_neonserv.h"
-
-/*
-* argv[0] - nick / *auth
-*/
-static USERAUTH_CALLBACK(neonserv_cmd_deluser_nick_lookup);
-static void neonserv_cmd_deluser_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, struct Event *event, char *nick, char *auth);
-
-struct neonserv_cmd_deluser_cache {
-    struct ClientSocket *client, *textclient;
-    struct UserNode *user;
-    struct ChanNode *chan;
-    struct Event *event;
-    char *nick;
-};
-
-CMD_BIND(neonserv_cmd_deluser) {
-    if(argv[0][0] == '*') {
-        //we've got an auth
-        argv[0]++;
-        neonserv_cmd_deluser_async1(client, getTextBot(), user, chan, event, argv[0], argv[0]);
-    } else {
-        struct UserNode *cuser = getUserByNick(argv[0]);
-        if(!cuser) {
-            cuser = createTempUser(argv[0]);
-                       if(!cuser) {
-                reply(getTextBot(), user, "NS_USER_UNKNOWN", argv[0]);
-                return;
-            }
-            cuser->flags |= USERFLAG_ISTMPUSER;
-        }
-        if(cuser->flags & USERFLAG_ISAUTHED) {
-            neonserv_cmd_deluser_async1(client, getTextBot(), user, chan, event, argv[0], cuser->auth);
-        } else {
-            struct neonserv_cmd_deluser_cache *cache = malloc(sizeof(*cache));
-            if (!cache) {
-                perror("malloc() failed");
-                return;
-            }
-            cache->client = client;
-            cache->textclient = getTextBot();
-            cache->user = user;
-            cache->chan = chan;
-            cache->event = event;
-            cache->nick = strdup(argv[0]);
-            get_userauth(cuser, neonserv_cmd_deluser_nick_lookup, cache);
-        }
-    }
-}
-
-static USERAUTH_CALLBACK(neonserv_cmd_deluser_nick_lookup) {
-    struct neonserv_cmd_deluser_cache *cache = data;
-    if(!user) {
-        //USER_DOES_NOT_EXIST
-        reply(cache->textclient, cache->user, "NS_USER_UNKNOWN", cache->nick);
-    }
-    else if(!(user->flags & USERFLAG_ISAUTHED)) {
-        //USER_NOT_AUTHED
-        reply(cache->textclient, cache->user, "NS_USER_NEED_AUTH", cache->nick);
-    }
-    else
-        neonserv_cmd_deluser_async1(cache->client, cache->textclient, cache->user, cache->chan, cache->event, user->nick, user->auth);
-    free(cache->nick);
-    free(cache);
-}
-
-static void neonserv_cmd_deluser_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;
-    int userid;
-    printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
-    res = mysql_use();
-    if ((row = mysql_fetch_row(res)) != NULL) {
-        userid = atoi(row[0]);
-        //check if the user is already added
-        printf_mysql_query("SELECT `chanuser_access`, `chanuser_id` 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)) {
-                if(isGodMode(user)) {
-                    event->flags |= CMDFLAG_OPLOG;
-                } else {
-                    reply(textclient, user, "NS_USER_OUTRANKED", nick);
-                    return;
-                }
-            }
-            //delete
-            printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_id` = '%s'", row[1]);
-            reply(textclient, user, "NS_DELUSER_DONE", nick, atoi(row[0]), chan->name);
-            logEvent(event);
-            return;
-        }
-    }
-    reply(textclient, user, "NS_NOT_ON_USERLIST", nick, chan->name);
-}