1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
bot-irc-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-servers.h"
#include "channels.h"
#include "nicklist.h"
#include "irc-masks.h"
#include "bot-users.h"
#include "botnet-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 (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);
botcmd_user_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 */
botcmd_user_set_password(user, user->password == NULL ? pass : newpass);
irc_send_cmdv(server, "NOTICE %s :Password changed", nick);
g_free(params);
}
void bot_irc_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_irc_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);
}
|