X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fmodules%2FDummyServ.mod%2Fbot_DummyServ.c;h=ade73ac809aca5a1ebbe9db5bc704260a662f992;hb=4b9de3472bf8bb35214bd3c31289b7c601304686;hp=9d9d7207ad24d64a4bc81865a16cd307ca71236b;hpb=706e48b1e666054030c491d864f740071e390038;p=NeonServV5.git diff --git a/src/modules/DummyServ.mod/bot_DummyServ.c b/src/modules/DummyServ.mod/bot_DummyServ.c index 9d9d720..ade73ac 100644 --- a/src/modules/DummyServ.mod/bot_DummyServ.c +++ b/src/modules/DummyServ.mod/bot_DummyServ.c @@ -1,4 +1,4 @@ -/* bot_DummyServ.c - NeonServ v5.3 +/* bot_DummyServ.c - NeonServ v5.5 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -15,40 +15,44 @@ * along with this program. If not, see . */ #include "../module.h" +#include "../botid.h" #include "bot_DummyServ.h" -#include "modcmd.h" -#include "IRCParser.h" -#include "IRCEvents.h" -#include "UserNode.h" -#include "ChanNode.h" -#include "ChanUser.h" -#include "ModeNode.h" -#include "BanNode.h" -#include "ClientSocket.h" -#include "mysqlConn.h" -#include "lang.h" -#include "HandleInfoHandler.h" -#include "WHOHandler.h" -#include "DBHelper.h" -#include "tools.h" -#include "timeq.h" -#include "version.h" -#include "EventLogger.h" -#include "bots.h" -#include "cmd_neonserv.h" -#include "cmd_neonspam.h" +#include "../../modcmd.h" +#include "../../IRCParser.h" +#include "../../IRCEvents.h" +#include "../../UserNode.h" +#include "../../ChanNode.h" +#include "../../ChanUser.h" +#include "../../ModeNode.h" +#include "../../BanNode.h" +#include "../../ClientSocket.h" +#include "../../mysqlConn.h" +#include "../../lang.h" +#include "../../HandleInfoHandler.h" +#include "../../WHOHandler.h" +#include "../../DBHelper.h" +#include "../../tools.h" +#include "../../timeq.h" +#include "../../version.h" +#include "../../EventLogger.h" +#include "../../bots.h" -#define BOTID 3 +#define BOTID DUMMYSERV_BOTID #define BOTALIAS "DummyServ" static void dummyserv_bot_ready(struct ClientSocket *client) { + if(client->botid != BOTID) + return; MYSQL_RES *res; MYSQL_ROW row; - printf_mysql_query("SELECT `automodes` FROM `bots` WHERE `id` = '%d'", client->clientid); + printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid); res = mysql_use(); if ((row = mysql_fetch_row(res)) != NULL) { + if(row[1] && row[2]) { + putsock(client, "OPER %s %s", row[1], row[2]); + } putsock(client, "MODE %s +%s", client->user->nick, row[0]); } @@ -71,7 +75,7 @@ static void start_bots(int type) { MYSQL_ROW row; if(type == MODSTATE_STARTSTOP) { - printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID); + printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind`, `secret` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID); res = mysql_use(); while ((row = mysql_fetch_row(res)) != NULL) { @@ -79,6 +83,7 @@ static void start_bots(int type) { client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0); client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0); client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0); + client->flags |= (strcmp(row[11], "0") ? SOCKET_FLAG_SECRET_BOT : 0); client->flags |= SOCKET_FLAG_SILENT; client->botid = BOTID; client->clientid = atoi(row[7]); @@ -106,6 +111,33 @@ static void start_bots(int type) { bind_unbound_required_functions(BOTID); } +static void dummyserv_event_invite(struct ClientSocket *client, struct UserNode *user, char *channel) { + if(client->botid != BOTID) + return; + MYSQL_RES *res; + MYSQL_ROW row; + printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `channel_name` = '%s' AND `botclass` = '%d'", escape_string(channel), client->botid); + res = mysql_use(); + if ((row = mysql_fetch_row(res)) == NULL) { + reply(client, user, "NS_INVITE_FAIL", channel, client->user->nick); + return; + } + if(!strcmp(row[2], "1")) { + return; + } + int botid = atoi(row[0]); + struct ClientSocket *bot; + for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) { + if(bot->clientid == botid) + break; + } + if(bot) { + struct ChanNode *chan = getChanByName(channel); + if(!(chan && isUserOnChan(bot->user, chan))) + putsock(bot, "JOIN %s", channel); + } +} + void init_DummyServ(int type) { set_bot_alias(BOTID, BOTALIAS); start_bots(type); @@ -113,13 +145,10 @@ void init_DummyServ(int type) { if(type == MODSTATE_REBIND) return; //register events - bind_bot_ready(dummyserv_bot_ready); - - set_trigger_callback(BOTID, dummyserv_trigger_callback); -} - -void loop_DummyServ() { + bind_bot_ready(dummyserv_bot_ready, module_id); + bind_invite(dummyserv_event_invite, module_id); + set_trigger_callback(BOTID, module_id, dummyserv_trigger_callback); } void free_DummyServ(int type) {