0ee9f2a21baa16ad09ebbf5b392637b757d6abf3
[NeonServV5.git] / src / cmd_neonserv_delme.c
1 /* cmd_neonserv_delme.c - NeonServ v5.1
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "cmd_neonserv.h"
19
20 /*
21 * argv[0] - key
22 */
23
24 CMD_BIND(neonserv_cmd_delme) {
25     MYSQL_RES *res;
26     MYSQL_ROW row;
27     int userid;
28     printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
29     res = mysql_use();
30     if ((row = mysql_fetch_row(res)) != NULL) {
31         userid = atoi(row[0]);
32         //check if the user is added
33         printf_mysql_query("SELECT `chanuser_access`, `chanuser_id` FROM `chanusers` WHERE `chanuser_cid` = '%d' AND `chanuser_uid` = '%d'", chan->channel_id, userid);
34         res = mysql_use();
35         if ((row = mysql_fetch_row(res)) != NULL) {
36             //check key
37             int seed = 0;
38             char *tmp;
39             static char unregkey[16];
40             for(tmp = user->auth; *tmp; tmp++)
41                 seed = (seed * 0xEECE66DL ^ ((*tmp << 24) | (*tmp << 16) | (*tmp << 8) | *tmp));
42             for(tmp = chan->name; *tmp; tmp++)
43                 seed = (seed * 0xEECE66DL ^ ((*tmp << 24) | (*tmp << 16) | (*tmp << 8) | *tmp));
44             sprintf(unregkey, "%08x", seed);
45             if(argc < 1 || strcmp(argv[0], unregkey)) {
46                 reply(getTextBot(), user, "NS_DELME_KEY", unregkey);
47                 return;
48             } else {
49                 //delete
50                 printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_id` = '%s'", row[1]);
51                 reply(getTextBot(), user, "NS_DELME_DONE", atoi(row[0]), chan->name);
52                 logEvent(event);
53                 return;
54             }
55         }
56     }
57     reply(getTextBot(), user, "NS_NOT_ON_USERLIST_YOU", chan->name);
58 }