Added bot plugin, it also has almost-functional botnet.

Changed configure.in's functionality so that you could tell what modules you
want to build in main irssi binary and it will create automatically the .c
files that need to call the module_init()/deinit() functions.

Fixed several minor things..


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@230 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-05-25 11:30:47 +00:00 committed by cras
commit 76605ad0ae
41 changed files with 2809 additions and 246 deletions

165
src/irc/bot/bot-commands.c Normal file
View file

@ -0,0 +1,165 @@
/*
bot-commands.c : IRC bot plugin for irssi
Copyright (C) 1999-2000 Timo Sirainen
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "signals.h"
#include "commands.h"
#include "irc.h"
#include "irc-server.h"
#include "channels.h"
#include "nicklist.h"
#include "masks.h"
#include "bot-users.h"
static void event_privmsg(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
char *params, *target, *msg, *args, *str;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
if (nick == NULL) nick = server->real_address;
if (*msg == 1 || ischannel(*target)) {
g_free(params);
return;
}
/* private message for us */
str = g_strconcat("bot command ", msg, NULL);
args = strchr(str+12, ' ');
if (args != NULL) *args++ = '\0'; else args = "";
g_strdown(str);
if (signal_emit(str, 4, args, server, nick, address)) {
/* msg was a command - the msg event. */
signal_stop();
}
g_free(str);
g_free(params);
}
static void botcmd_op(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
CHANNEL_REC *channel;
USER_REC *user;
USER_CHAN_REC *userchan;
GSList *tmp;
g_return_if_fail(data != NULL);
if (*data == '\0') {
/* no password given? .. */
return;
}
user = botuser_find(nick, address);
if (user == NULL || (user->not_flags & USER_OP) ||
!botuser_verify_password(user, data)) {
/* not found, can't op with this mask or failed password */
return;
}
/* find the channels where to op.. */
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
channel = tmp->data;
userchan = g_hash_table_lookup(user->channels, channel->name);
if ((user->flags & USER_OP) || (userchan->flags & USER_OP))
signal_emit("command op", 3, nick, server, channel);
}
}
static void botcmd_ident(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
USER_REC *user;
char *mask;
g_return_if_fail(data != NULL);
user = botuser_find(nick, address);
if (user != NULL) {
/* Already know this host */
return;
}
user = botuser_find(nick, NULL);
if (user == NULL || !botuser_verify_password(user, data)) {
/* failed password */
return;
}
/* add the new mask */
mask = irc_get_mask(nick, address, IRC_MASK_USER | IRC_MASK_DOMAIN);
botuser_add_mask(user, mask);
irc_send_cmdv(server, "NOTICE %s :Added new mask %s", nick, mask);
g_free(mask);
}
static void botcmd_pass(const char *data, IRC_SERVER_REC *server,
const char *nick, const char *address)
{
USER_REC *user;
char *params, *pass, *newpass;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2, &pass, &newpass);
user = botuser_find(nick, address);
if (user == NULL || *pass == '\0') {
g_free(params);
return;
}
if (user->password != NULL &&
(*newpass == '\0' || !botuser_verify_password(user, pass))) {
g_free(params);
return;
}
/* change the password */
botuser_set_password(user, user->password == NULL ? pass : newpass);
irc_send_cmdv(server, "NOTICE %s :Password changed", nick);
g_free(params);
}
void bot_commands_init(void)
{
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add_last("bot command op", (SIGNAL_FUNC) botcmd_op);
signal_add_last("bot command ident", (SIGNAL_FUNC) botcmd_ident);
signal_add_last("bot command pass", (SIGNAL_FUNC) botcmd_pass);
}
void bot_commands_deinit(void)
{
signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_remove("bot command op", (SIGNAL_FUNC) botcmd_op);
signal_remove("bot command ident", (SIGNAL_FUNC) botcmd_ident);
signal_remove("bot command pass", (SIGNAL_FUNC) botcmd_pass);
}