src/cmd_global_modcmd.c \
src/cmd_neonhelp_next.c \
src/cmd_neonhelp_delete.c \
+ src/cmd_neonhelp_requests.c \
src/cmd_funcmds.c \
src/ConfigParser.c
CREATE TABLE IF NOT EXISTS `helpserv_requests` (
`id` int(11) NOT NULL AUTO_INCREMENT,
+ `botid` INT(11) NOT NULL,
`host` varchar(200) NOT NULL,
`hand` varchar(50) NOT NULL,
`nick` varchar(50) NOT NULL,
PRIMARY KEY (`helpserv_botid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--- version: 11
\ No newline at end of file
+-- version: 11
+
+ALTER TABLE `helpserv_requests` ADD `botid` INT( 11 ) NOT NULL AFTER `id`;
+
+-- version: 12
client->botid = BOTID;
client->clientid = atoi(row[7]);
connect_socket(client);
+ //close old, still opened requests
+ printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '2' WHERE `botid` = '%d'", client->clientid);
}
printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
struct NeonHelpNode *helpnode = malloc(sizeof(*helpnode));
if(!helpnode) return;
helpnode->user = user;
+ helpnode->logchan = getChanByName(row[0]);
helpnode->status = 0;
- printf_mysql_query("INSERT INTO `helpserv_requests` (`host`, `hand`, `nick`, `status`, `supporter`, `time`, `text`) VALUES ('%s@%s', '%s', '%s', '0', '-1', UNIX_TIMESTAMP(), '%s')", escape_string(user->ident), escape_string(user->host), ((user->flags & USERFLAG_ISAUTHED) ? escape_string(user->auth) : "*"), escape_string(user->nick), escape_string(message));
+ printf_mysql_query("INSERT INTO `helpserv_requests` (`botid`, `host`, `hand`, `nick`, `status`, `supporter`, `time`, `text`) VALUES ('%d', '%s@%s', '%s', '%s', '0', '-1', UNIX_TIMESTAMP(), '%s')", client->clientid, escape_string(user->ident), escape_string(user->host), ((user->flags & USERFLAG_ISAUTHED) ? escape_string(user->auth) : "*"), escape_string(user->nick), escape_string(message));
helpnode->suppid = (int) mysql_insert_id(mysql_conn);
+ helpnode->log = NULL;
helpnode->next = ((client->flags & SOCKET_HAVE_HELPNODE) ? client->botclass_helpnode : NULL);
client->botclass_helpnode = helpnode;
client->flags |= SOCKET_HAVE_HELPNODE;
}
}
+static void neonhelp_event_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
+ char logline[MAXLEN];
+ sprintf(logline, "<%s> %s", user->nick, message);
+ struct ClientSocket *client;
+ for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
+ if(client->botid == BOTID) {
+ struct NeonHelpNode *helpnode;
+ if(client->flags & SOCKET_HAVE_HELPNODE) {
+ for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
+ if(helpnode->logchan == chan && helpnode->status == 1) {
+ if(!helpnode->log) {
+ helpnode->log = calloc(LOGBUFFERLINES, sizeof(char*));
+ if(!helpnode->log) return;
+ }
+ int i;
+ for(i = 0; i < LOGBUFFERLINES; i++) {
+ if(!helpnode->log[i]) {
+ helpnode->log[i] = strdup(logline);
+ break;
+ }
+ }
+ if(i == LOGBUFFERLINES) {
+ //write buffer to database
+ char logbuff[MAXLEN * LOGBUFFERLINES];
+ int len = 0;
+ for(i = 0; i < LOGBUFFERLINES; i++) {
+ len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
+ free(helpnode->log[i]);
+ helpnode->log[i] = NULL;
+ }
+ printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
static void destroy_support_request(struct ClientSocket *client, struct NeonHelpNode *helpnode, int do_reply) {
- printf_mysql_query("UPDATE `helpserv_requests` SET `status` = '2' WHERE `id` = %d", helpnode->suppid);
+ //write buffer to database
+ char logbuff[MAXLEN * LOGBUFFERLINES];
+ int len = 0;
+ int i;
+ if(helpnode->log) {
+ for(i = 0; i < LOGBUFFERLINES; i++) {
+ if(!helpnode->log[i]) break;
+ len += sprintf(logbuff + len, "%s\n", helpnode->log[i]);
+ free(helpnode->log[i]);
+ helpnode->log[i] = NULL;
+ }
+ free(helpnode->log);
+ }
+ printf_long_mysql_query(1024 + len, "UPDATE `helpserv_requests` SET `status`='2', `log` = CONCAT(`log`, '%s') WHERE `id` = %d", escape_string(logbuff), helpnode->suppid);
if(do_reply) {
reply(client, helpnode->user, "NH_DELETED", helpnode->suppid);
}
//register events
bind_bot_ready(neonhelp_bot_ready);
bind_privmsg(neonhelp_event_privmsg);
+ bind_chanmsg(neonhelp_event_chanmsg);
bind_part(neonhelp_event_part);
bind_kick(neonhelp_event_kick);
bind_quit(neonhelp_event_quit);
#define botclass_helpnode botclassvalue1
#define SOCKET_HAVE_HELPNODE SOCKET_HAVE_BOTCLASSVALUE1
+#define LOGBUFFERLINES 20
+
+struct UserNode;
+struct ChanNode;
+
struct NeonHelpNode {
struct UserNode *user;
int suppid;
char status;
struct NeonHelpNode *next;
+ struct ChanNode *logchan;
+ char **log;
};
void init_NeonHelp();
#include "IRCParser.h"
#include "bot_NeonHelp.h"
#include "lang.h"
+#include "tools.h"
CMD_BIND(neonhelp_cmd_delete);
CMD_BIND(neonhelp_cmd_next);
+CMD_BIND(neonhelp_cmd_requests);
#endif
\ No newline at end of file
--- /dev/null
+/* cmd_neonhelp_requests.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"
+
+/*
+* no args
+*/
+
+CMD_BIND(neonhelp_cmd_requests) {
+ //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;
+ }
+ struct Table *table;
+ printf_mysql_query("SELECT `id`, `time`, `text` FROM `helpserv_requests` WHERE `botid` = '%d' ORDER BY `time` DESC", client->clientid);
+ res = mysql_use();
+ table = table_init(5, mysql_num_rows(res) + 1, 0);
+ char *content[5];
+ content[0] = get_language_string(user, "NH_REQUESTS_HEADER_ID");
+ content[1] = get_language_string(user, "NH_REQUESTS_HEADER_STATUS");
+ content[2] = get_language_string(user, "NH_REQUESTS_HEADER_NICK");
+ content[3] = get_language_string(user, "NH_REQUESTS_HEADER_TIME");
+ content[4] = get_language_string(user, "NH_REQUESTS_HEADER_REQUEST");
+ table_add(table, content);
+ char timestr[MAXLEN];
+ struct NeonHelpNode *helpnode;
+ int suppid;
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ content[0] = row[0];
+ suppid = atoi(row[0]);
+ if(client->flags & SOCKET_HAVE_HELPNODE) {
+ for(helpnode = client->botclass_helpnode; helpnode; helpnode = helpnode->next) {
+ if(helpnode->suppid == suppid) {
+ if(helpnode->status)
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_ACTIVE");
+ else
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_PENDING");
+ content[2] = helpnode->user->nick;
+ break;
+ }
+ }
+ } else {
+ content[1] = get_language_string(user, "NH_REQUESTS_STATE_ERROR");
+ content[2] = NULL;
+ }
+ timeToStr(user, (time(0) - atoi(row[1])), 2, timestr);
+ content[3] = timestr;
+ char *p;
+ if((p = strstr(row[2], "\n")))
+ *p = '\0';
+ content[4] = row[2];
+ table_add(table, content);
+ }
+ //send the table
+ char **table_lines = table_end(table);
+ int i;
+ for(i = 0; i < table->entrys; i++) {
+ reply(getTextBot(), user, table_lines[i]);
+ }
+ if(table->entrys == 1)
+ reply(getTextBot(), user, "NS_TABLE_NONE");
+}
// NAME FUNCTION PARAMS PRIVS FLAGS
USER_COMMAND("next", neonhelp_cmd_next, 0, NULL, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
USER_COMMAND("delete", neonhelp_cmd_delete, 1, NULL, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+ USER_COMMAND("requests", neonhelp_cmd_requests, 0, NULL, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
#undef USER_COMMAND
}
\ No newline at end of file
*/
#include "mysqlConn.h"
-#define DATABASE_VERSION "11"
+#define DATABASE_VERSION "12"
struct used_result {
MYSQL_RES *result;