From: pk910 Date: Thu, 6 Oct 2011 13:57:35 +0000 (+0200) Subject: added cmd_unvisited X-Git-Tag: v5.3~298 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=4276c6c55cd57154d8a2c680e88fdea81a8c6e58 added cmd_unvisited --- diff --git a/Makefile.am b/Makefile.am index 44f64fb..2970dee 100644 --- a/Makefile.am +++ b/Makefile.am @@ -104,6 +104,7 @@ neonserv_SOURCES = src/version.c \ src/cmd_neonserv_setrank.c \ src/cmd_neonserv_info.c \ src/cmd_neonserv_rename.c \ + src/cmd_neonserv_unvisited.c \ src/lib/ini.c neonserv_LDADD = $(MYSQL_LIBS) $(WINSOCK_LIBS) diff --git a/database.upgrade_v4_v5.sql b/database.upgrade_v4_v5.sql index 089c6bb..3aee182 100644 --- a/database.upgrade_v4_v5.sql +++ b/database.upgrade_v4_v5.sql @@ -41,7 +41,7 @@ ALTER TABLE `bots` ADD `max_channels` INT( 5 ) NOT NULL ; ALTER TABLE `bot_binds` CHANGE `botid` `botclass` INT( 11 ) NOT NULL; ALTER TABLE `bots` DROP `whoisbot` ; ALTER TABLE `bots` DROP `bindFrom` ; -ALTER TABLE `bots` ADD `register_order` INT( 2 ) NOT NULL; +ALTER TABLE `bots` ADD `register_priority` INT( 2 ) NOT NULL; CREATE TABLE IF NOT EXISTS `help` ( `id` int(11) NOT NULL AUTO_INCREMENT, diff --git a/src/bot_NeonServ.c b/src/bot_NeonServ.c index 8b8866e..f81228e 100644 --- a/src/bot_NeonServ.c +++ b/src/bot_NeonServ.c @@ -537,6 +537,7 @@ void init_NeonServ() { OPER_COMMAND("assignrank", neonserv_cmd_assignrank,2, 1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); OPER_COMMAND("listrank", neonserv_cmd_listrank, 0, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); OPER_COMMAND("rename", neonserv_cmd_rename, 2, 300, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); + OPER_COMMAND("unvisited", neonserv_cmd_unvisited, 0, 400, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG); #undef OPER_COMMAND start_bots(); diff --git a/src/cmd_neonserv.h b/src/cmd_neonserv.h index 2debd39..658751c 100644 --- a/src/cmd_neonserv.h +++ b/src/cmd_neonserv.h @@ -103,6 +103,7 @@ CMD_BIND(neonserv_cmd_unbanme); CMD_BIND(neonserv_cmd_unbind); CMD_BIND(neonserv_cmd_unregister); CMD_BIND(neonserv_cmd_unsuspend); +CMD_BIND(neonserv_cmd_unvisited); CMD_BIND(neonserv_cmd_up); CMD_BIND(neonserv_cmd_upall); CMD_BIND(neonserv_cmd_users); diff --git a/src/cmd_neonserv_unvisited.c b/src/cmd_neonserv_unvisited.c new file mode 100644 index 0000000..3cfaed9 --- /dev/null +++ b/src/cmd_neonserv_unvisited.c @@ -0,0 +1,107 @@ +/* cmd_neonserv_unvisited.c - NeonServ v5.1 + * Copyright (C) 2011 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 . + */ + +#include "cmd_neonserv.h" + +struct neonserv_cmd_unvisited_cache { + struct ClientSocket *client, *textclient; + struct UserNode *user; + int duration; + int who_count, matches; +}; + +static USERLIST_CALLBACK(neonserv_cmd_unvisited_userlist_lookup); +static int neonserv_cmd_unvisited_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, int duration); +static void neonserv_cmd_unvisited_async2(struct neonserv_cmd_unvisited_cache *cache); + +CMD_BIND(neonserv_cmd_unvisited) { + int duration = (argc ? strToTime(user, argv[0]) : 60*60*24*7*3); + reply(getTextBot(), user, "NS_SEARCH_HEADER"); + MYSQL_RES *res, *res2; + MYSQL_ROW row, row2; + struct ChanNode *channel; + struct neonserv_cmd_unvisited_cache *cache = malloc(sizeof(*cache)); + if (!cache) { + perror("malloc() failed"); + return; + } + cache->client = client; + cache->textclient = getTextBot(); + cache->user = user; + cache->duration = duration; + cache->who_count = 0; + cache->matches = 0; + printf_mysql_query("SELECT `channel_id`, `channel_name`, `channel_nodelete` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` LEFT JOIN `users` ON `channel_registrator` = `user_id` WHERE `botid` = '%d'", client->botid); + res = mysql_use(); + while ((row = mysql_fetch_row(res)) != NULL) { + if(!strcmp(row[2], "1")) continue; + printf_mysql_query("SELECT `chanuser_seen` FROM `chanusers` WHERE `chanuser_cid` = '%s' AND `chanuser_access` >= 300 ORDER BY `chanuser_seen` DESC LIMIT 1", row[0]); + res2 = mysql_use(); + row2 = mysql_fetch_row(res); + if(row2 && (time(0) - atoi(row2[0])) < duration) continue; + channel = getChanByName(row[1]); + if(channel) { + cache->who_count++; + channel->channel_id = atoi(row[0]); + get_userlist_with_invisible(channel, neonserv_cmd_unvisited_userlist_lookup, cache); + } else { + reply(getTextBot(), user, "%s", row[1]); + cache->matches++; + } + } + if(cache->who_count == 0) { + neonserv_cmd_unvisited_async2(cache); + } +} + +static USERLIST_CALLBACK(neonserv_cmd_unvisited_userlist_lookup) { + struct neonserv_cmd_unvisited_cache *cache = data; + if(neonserv_cmd_unvisited_async1(cache->client, cache->textclient, cache->user, chan, cache->duration)) + cache->matches++; + cache->who_count--; + if(cache->who_count == 0) { + neonserv_cmd_unvisited_async2(cache); + } +} + +static int neonserv_cmd_unvisited_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, int duration) { + struct ChanUser *chanuser; + MYSQL_RES *res2; + MYSQL_ROW row2; + int active = 0; + for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) { + if(isBot(chanuser->user)) continue; + if((chanuser->user->flags & USERFLAG_ISAUTHED)) { + printf_mysql_query("SELECT `chanuser_id`, `chanuser_access` FROM `chanusers` LEFT JOIN `users` ON `user_id` = `chanuser_uid` WHERE `chanuser_cid` = '%d' AND `user_user` = '%s'", chan->channel_id, escape_string(chanuser->user->auth)); + res2 = mysql_use(); + row2 = mysql_fetch_row(res2); + if(row2 && atoi(row2[1]) >= 300) { + printf_mysql_query("UPDATE `chanusers` SET `chanuser_seen` = UNIX_TIMESTAMP() WHERE `chanuser_id` = '%s'", row2[0]); + active = 1; + } + } + } + if(!active) { + reply(textclient, user, "%s", chan->name); + } + return !active; +} + +static void neonserv_cmd_unvisited_async2(struct neonserv_cmd_unvisited_cache *cache) { + reply(cache->textclient, cache->user, "NS_TABLE_COUNT", cache->matches); + free(cache); +}