rearranged NeonServ code to be modular
[NeonServV5.git] / src / cmd_neonhelp_next.c
diff --git a/src/cmd_neonhelp_next.c b/src/cmd_neonhelp_next.c
deleted file mode 100644 (file)
index 2e2a2d1..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/* cmd_neonhelp_next.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_neonhelp.h"
-
-/*
-* argv[0]   (optional) suppid
-*/
-
-CMD_BIND(neonhelp_cmd_next) {
-    //check permissions
-    MYSQL_RES *res;
-    MYSQL_ROW row, row2;
-    int caccess = 0;
-    int userid;
-    printf_mysql_query("SELECT `helpserv_support`, `helpserv_public`, `helpserv_intern` FROM `helpserv_settings` WHERE `helpserv_botid` = '%d'", client->clientid);
-    res = mysql_use();
-    if (!(row = mysql_fetch_row(res))) return;
-    //check if the user is a supporter (access in the support channel)
-    if((user->flags & USERFLAG_ISAUTHED)) {
-        if(user->flags & USERFLAG_HAS_USERID)
-            userid = user->user_id;
-        else {
-            printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
-            res = mysql_use();
-            if ((row2 = mysql_fetch_row(res)) != NULL) {
-                userid = atoi(row2[0]);
-                user->user_id = userid;
-                user->flags |= USERFLAG_HAS_USERID;
-            } else
-                userid = 0;
-        }
-        printf_mysql_query("SELECT `chanuser_access`, `chanuser_flags` FROM `chanusers` LEFT JOIN `channels` ON `chanuser_cid` = `channel_id` WHERE `chanuser_uid` = '%d' AND `channel_name` = '%s'", userid, escape_string(row[0]));
-        res = mysql_use();
-        if ((row2 = mysql_fetch_row(res)) != NULL) {
-            int cflags = atoi(row2[1]);
-            if(!(cflags & DB_CHANUSER_SUSPENDED))
-                caccess = atoi(row2[0]);
-        }
-    }
-    if(!caccess) {
-        reply(getTextBot(), user, "MODCMD_ACCESS_DENIED");
-        return;
-    }
-    if(!(client->flags & SOCKET_HAVE_HELPNODE) || client->botclass_helpnode == NULL) {
-        reply(getTextBot(), user, "NH_NEXT_NONE");
-        return;
-    }
-    struct NeonHelpNode *helpnode, *next_helpnode = NULL;
-    int lowest_id = -1;
-    for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
-        if(helpnode->status == 0) {
-            if(argc) {
-                if(atoi(argv[0]) == helpnode->suppid) {
-                    next_helpnode = helpnode;
-                    break;
-                }
-            } else {
-                if(helpnode->suppid < lowest_id || lowest_id == -1) {
-                    lowest_id = helpnode->suppid;
-                    next_helpnode = helpnode;
-                }
-            }
-        }
-    }
-    if(!next_helpnode) {
-        reply(getTextBot(), user, "NH_NEXT_NOT_FOUND");
-        return;
-    }
-    printf_mysql_query("SELECT `text` FROM `helpserv_requests` WHERE `id` = '%d'", next_helpnode->suppid);
-    res = mysql_use();
-    if (!(row2 = mysql_fetch_row(res))) return;
-    reply(getTextBot(), user, "NH_NEXT_HEADER", next_helpnode->suppid, next_helpnode->user->nick);
-    char *a, *b = row2[0];
-    do {
-        a = strstr(b, "\n");
-        if(a) *a = '\0';
-        reply(getTextBot(), user, "  %s", b);
-        if(a) {
-            *a = '\n';
-            b = a+1;
-        }
-    } while(a);
-    if(row[1])
-        putsock(client, "INVITE %s %s", next_helpnode->user->nick, row[0]);
-    else
-        putsock(client, "MODE %s +v %s", row[0], next_helpnode->user->nick);
-    char sendbuf1[MAXLEN];
-    char sendbuf2[MAXLEN];
-    char *join_now = (row[1] ? build_language_string(user, sendbuf2, "NH_NEXT_JOIN", row[0]) : "");
-    putsock(client, "PRIVMSG %s :%s %s", next_helpnode->user->nick, build_language_string(user, sendbuf1, "NH_NEXT_HELPER", next_helpnode->suppid, user->auth, user->nick), join_now);
-    next_helpnode->status = 1;
-    printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '1', `supporter` = '%d' WHERE `id` = '%d'", userid, next_helpnode->suppid);
-}