]>
jfr.im git - irc/evilnet/x3.git/blob - src/mod-webtv.c
1 /* mod-webtv.c - WebTV Module for X3
2 * Copyright 2007 X3 Development Team
4 * This file is part of x3.
6 * x3 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with srvx; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 * /msg opserv bind opserv service *modcmd.joiner
24 * /msg opserv bind opserv service\ add *modcmd.service\ add
25 * /msg opserv bind opserv service\ rename *modcmd.service\ rename
26 * /msg opserv bind opserv service\ trigger *modcmd.service\ trigger
27 * /msg opserv bind opserv service\ remove *modcmd.service\ remove
29 * /msg opserv service add IRC WebTV Service Bot
30 * /msg opserv bind IRC help *modcmd.help
31 * Restart X3 with the updated conf file (as above, butwith "bot"
32 * "IRC"), and bind the commands to it:
33 * /msg opserv bind IRC * *webtv.*
44 #define MAX_CHANNELS_WHOIS 50
46 static const struct message_entry msgtab
[] = {
47 { "WBMSG_NOT_MARKED", "You are not a WebTV client." },
49 { "WBMSG_NICK_PARAMS", "You need to specify a nickname." },
50 { "WBMSG_NICK_SAME", "You are already $b%s$b." },
51 { "WBMSG_NICK_INVALID", "The nickname $b%s$b is invalid." },
52 { "WBMSG_NICK_IN_USE", "The nickname $b%s$b is in use, please choose another." },
54 { "WBMSG_WHOIS_NICKIDENT", "[%s] (%s@%s): %s" },
55 { "WBMSG_WHOIS_CHANNELS", "On %s" },
56 { "WBMSG_WHOIS_SERVER", "[%s] %s : %s" },
57 { "WBMSG_WHOIS_OPER", "[%s] is an IRC Operator" },
58 { "WBMSG_WHOIS_SERVICE", "[%s] is an IRC Service" },
59 { "WBMSG_WHOIS_ACCOUNT", "[%s] is logged in as %s" },
60 { "WBMSG_WHOIS_REALHOST", "[%s] realhost %s@%s %s" },
61 { "WBMSG_WHOIS_SWHOIS", "[%s] %s" },
62 { "WBMSG_WHOIS_DNSBL", "[%s] is DNSBL listed on %s" },
63 { "WBMSG_WHOIS_CONNECTED", "[%s] %s" },
64 { "WBMSG_WHOIS_END", "[%s] End of WHOIS list." },
69 struct userNode
*webtv
;
71 #define WEBTV_FUNC(NAME) MODCMD_FUNC(NAME)
72 #define WEBTV_SYNTAX() svccmd_send_help_brief(user, webtv, cmd)
73 #define WEBTV_MIN_PARAMS(N) if(argc < (N)) { \
74 reply("MSG_MISSING_PARAMS", argv[0]); \
81 struct string_list
*valid_marks
;
84 #define OPTION_FUNC(NAME) int NAME(struct svccmd *cmd, struct userNode *user, struct handle_info *hi, UNUSED_ARG(unsigned int override), unsigned int argc, char *argv[])
85 typedef OPTION_FUNC(option_func_t
);
87 extern struct string_list
*autojoin_channels
;
88 const char *webtv_module_deps
[] = { NULL
};
89 static struct module *webtv_module
;
90 static struct log_type
*WB_LOG
;
91 static char *his_servername
;
92 static char *his_servercomment
;
95 int check_mark(struct svccmd
*cmd
, struct userNode
*user
, UNUSED_ARG(struct handle_info
*hi
), UNUSED_ARG(unsigned int override
), UNUSED_ARG(unsigned int argc
), UNUSED_ARG(char *argv
[]))
99 if (webtv_conf
.required_mark
== 0)
103 reply("WBMSG_NOT_MARKED");
106 for (y
= 0; y
< webtv_conf
.valid_marks
->used
; y
++) {
107 if (!strcasecmp(webtv_conf
.valid_marks
->list
[y
], user
->mark
))
110 reply("WBMSG_NOT_MARKED");
115 static MODCMD_FUNC(cmd_nick
)
117 struct userNode
*nick
;
119 if (!check_mark(cmd
, user
, NULL
, 0, 0, NULL
))
123 reply("WBMSG_NICK_PARAMS");
127 if (!strcasecmp(argv
[1], user
->nick
)) {
128 reply("WBMSG_NICK_SAME", argv
[1]);
132 if (!is_valid_nick(argv
[1])) {
133 reply("WBMSG_NICK_INVALID", argv
[1]);
137 nick
= GetUserH(argv
[1]);
139 reply("WBMSG_NICK_IN_USE", argv
[1]);
143 irc_svsnick(webtv
, user
, argv
[1]);
148 webtv_ison(struct userNode
*bot
, struct userNode
*tell
, struct userNode
*target
, const char *message
)
151 unsigned int count
, here_len
, n
, maxlen
;
154 maxlen
= tell
->handle_info
? tell
->handle_info
->screen_width
: 0;
156 maxlen
= MAX_LINE_SIZE
;
157 for (n
=count
=0; n
<target
->channels
.used
; n
++) {
158 mn
= target
->channels
.list
[n
];
159 if ((mn
->channel
->modes
& (MODE_PRIVATE
|MODE_SECRET
)))
162 here_len
= strlen(mn
->channel
->name
);
163 if ((count
+ here_len
+ 4) > maxlen
) {
165 send_message(tell
, bot
, message
, buff
);
168 if (mn
->modes
& MODE_CHANOP
)
170 if (mn
->modes
& MODE_HALFOP
)
172 if (mn
->modes
& MODE_VOICE
)
174 memcpy(buff
+count
, mn
->channel
->name
, here_len
);
180 send_message(tell
, bot
, message
, buff
);
184 static MODCMD_FUNC(cmd_whois
)
186 struct userNode
*target
;
188 if (!check_mark(cmd
, user
, NULL
, 0, 0, NULL
))
192 reply("WBMSG_NICK_PARAMS");
196 target
= GetUserH(argv
[1]);
198 reply("WBMSG_WHOIS_NICKIDENT", target
->nick
, target
->ident
,
199 IsFakeHost(target
) ? target
->fakehost
: target
->hostname
, target
->info
);
201 if ((target
->channels
.used
<= MAX_CHANNELS_WHOIS
) && !IsService(target
))
202 webtv_ison(cmd
->parent
->bot
, user
, target
, "WBMSG_WHOIS_CHANNELS");
205 reply("WBMSG_WHOIS_SERVER", target
->nick
, target
->uplink
->name
, target
->uplink
->description
);
207 reply("WBMSG_WHOIS_SERVER", target
->nick
, his_servername
? his_servername
: target
->uplink
->name
,
208 his_servercomment
? his_servercomment
: target
->uplink
->description
);
212 reply("WBMSG_WHOIS_OPER", target
->nick
);
214 if (IsService(target
))
215 reply("WBMSG_WHOIS_SERVICE", target
->nick
);
217 if (target
->handle_info
)
218 reply("WBMSG_WHOIS_ACCOUNT", target
->nick
, target
->handle_info
->handle
);
220 if ((target
== user
) && (target
->fakehost
|| IsHiddenHost(target
)))
221 reply("WBMSG_WHOIS_REALHOST", target
->nick
, target
->ident
, target
->hostname
, irc_ntoa(&target
->ip
));
223 if (target
->handle_info
) {
224 if (target
->handle_info
->epithet
)
225 reply("WBMSG_WHOIS_SWHOIS", target
->nick
, target
->handle_info
->epithet
);
229 reply("WBMSG_WHOIS_DNSBL", target
->nick
, target
->mark
);
231 reply("WBMSG_WHOIS_END", target
->nick
);
233 reply("MSG_NICK_UNKNOWN", argv
[1]);
241 webtv_conf_read(void)
245 struct string_list
*strlist
;
247 str
= "modules/webtv";
248 if (!(conf_node
= conf_get_data(str
, RECDB_OBJECT
))) {
249 log_module(WB_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", str
);
253 str
= database_get_data(conf_node
, "required_mark", RECDB_QSTRING
);
254 webtv_conf
.required_mark
= str
? atoi(str
) : 0;
256 free_string_list(webtv_conf
.valid_marks
);
257 strlist
= database_get_data(conf_node
, "valid_marks", RECDB_STRING_LIST
);
259 strlist
= string_list_copy(strlist
);
261 strlist
= alloc_string_list(4);
262 webtv_conf
.valid_marks
= strlist
;
264 str
= conf_get_data("server/his_servername", RECDB_QSTRING
);
265 his_servername
= str
? strdup(str
) : NULL
;
266 str
= conf_get_data("server/his_servercomment", RECDB_QSTRING
);
267 his_servercomment
= str
? strdup(str
) : NULL
;
278 WB_LOG
= log_register_type("WebTV", "file:webtv.log");
280 conf_register_reload(webtv_conf_read
);
281 reg_exit_func(webtv_cleanup
);
283 webtv_module
= module_register("WebTV", WB_LOG
, "mod-webtv.help", NULL
);
284 modcmd_register(webtv_module
, "nick", cmd_nick
, 1, 0, NULL
);
285 modcmd_register(webtv_module
, "whois", cmd_whois
, 1, 0, NULL
);
287 message_register_table(msgtab
);
292 webtv_finalize(void) {
293 struct chanNode
*chan
;
298 str
= "modules/webtv";
299 if (!(conf_node
= conf_get_data(str
, RECDB_OBJECT
))) {
300 log_module(WB_LOG
, LOG_ERROR
, "config node `%s' is missing or has wrong type.", str
);
304 str
= database_get_data(conf_node
, "bot", RECDB_QSTRING
);
306 webtv
= webtv_conf
.bot
;
307 const char *modes
= conf_get_data("modules/webtv/modes", RECDB_QSTRING
);
308 webtv
= AddService(str
, modes
? modes
: NULL
, "WebTV IRC Service", NULL
);
310 log_module(WB_LOG
, LOG_ERROR
, "database_get_data for webtv_conf.bot failed!");
314 if (autojoin_channels
&& webtv
) {
315 for (i
= 0; i
< autojoin_channels
->used
; i
++) {
316 chan
= AddChannel(autojoin_channels
->list
[i
], now
, "+nt", NULL
, NULL
);
317 AddChannelUser(webtv
, chan
)->modes
|= MODE_CHANOP
;