1 /* cmd_neonserv_deluser.c - NeonServ v5.3
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_neonserv.h"
21 * argv[0] - nick / *auth
23 static USERAUTH_CALLBACK(neonserv_cmd_deluser_nick_lookup);
24 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);
26 struct neonserv_cmd_deluser_cache {
27 struct ClientSocket *client, *textclient;
28 struct UserNode *user;
29 struct ChanNode *chan;
34 CMD_BIND(neonserv_cmd_deluser) {
35 if(argv[0][0] == '*') {
38 neonserv_cmd_deluser_async1(client, getTextBot(), user, chan, event, argv[0], argv[0]);
40 struct UserNode *cuser = getUserByNick(argv[0]);
42 cuser = createTempUser(argv[0]);
44 reply(getTextBot(), user, "NS_USER_UNKNOWN", argv[0]);
47 cuser->flags |= USERFLAG_ISTMPUSER;
49 if(cuser->flags & USERFLAG_ISAUTHED) {
50 neonserv_cmd_deluser_async1(client, getTextBot(), user, chan, event, argv[0], cuser->auth);
52 struct neonserv_cmd_deluser_cache *cache = malloc(sizeof(*cache));
54 perror("malloc() failed");
57 cache->client = client;
58 cache->textclient = getTextBot();
62 cache->nick = strdup(argv[0]);
63 get_userauth(cuser, neonserv_cmd_deluser_nick_lookup, cache);
68 static USERAUTH_CALLBACK(neonserv_cmd_deluser_nick_lookup) {
69 struct neonserv_cmd_deluser_cache *cache = data;
72 reply(cache->textclient, cache->user, "NS_USER_UNKNOWN", cache->nick);
74 else if(!(user->flags & USERFLAG_ISAUTHED)) {
76 reply(cache->textclient, cache->user, "NS_USER_NEED_AUTH", cache->nick);
79 neonserv_cmd_deluser_async1(cache->client, cache->textclient, cache->user, cache->chan, cache->event, user->nick, user->auth);
84 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) {
85 //we've got a valid auth now...
89 printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(auth));
91 if ((row = mysql_fetch_row(res)) != NULL) {
92 userid = atoi(row[0]);
93 //check if the user is already added
94 printf_mysql_query("SELECT `chanuser_access`, `chanuser_id` FROM `chanusers` WHERE `chanuser_cid` = '%d' AND `chanuser_uid` = '%d'", chan->channel_id, userid);
96 if ((row = mysql_fetch_row(res)) != NULL) {
97 if(atoi(row[0]) >= getChannelAccess(user, chan)) {
99 event->flags |= CMDFLAG_OPLOG;
101 reply(textclient, user, "NS_USER_OUTRANKED", nick);
106 printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_id` = '%s'", row[1]);
107 reply(textclient, user, "NS_DELUSER_DONE", nick, atoi(row[0]), chan->name);
112 reply(textclient, user, "NS_NOT_ON_USERLIST", nick, chan->name);