2
ctrlproxy: A modular IRC proxy
3
(c) 2002-2003 Jelmer Vernooij <jelmer@nl.linux.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#include "ctrlproxy.h"
24
static GHashTable *files = NULL;
26
void replicate_data(struct network *s, struct transport_context *io) {
27
GSList *l = g_hash_table_lookup(files, s);
28
if(!l) { default_replicate_function(s, io); return; }
30
struct line *rl = (struct line *)l->data;
32
irc_send_line(io, rl);
38
g_hash_table_replace(files, s, NULL);
41
static gboolean log_data(struct line *l) {
42
GSList *gl = g_hash_table_lookup(files, l->network);
45
if(l->argc < 1)return TRUE;
47
if(l->direction == TO_SERVER &&
48
(!strcasecmp(l->args[0], "PRIVMSG") || !strcasecmp(l->args[0], "NOTICE"))) {
51
if(gs->data)free_line((struct line *)gs->data);
52
gs = g_slist_next(gs);
56
g_hash_table_replace(files, l->network, NULL);
60
if(l->direction == TO_SERVER)return TRUE;
62
if(!gl) gl = gen_replication(l->network);
64
if(!strcasecmp(l->args[0], "PRIVMSG") ||
65
!strcasecmp(l->args[0], "NOTICE") ||
66
!strcasecmp(l->args[0], "MODE") ||
67
!strcasecmp(l->args[0], "JOIN") ||
68
!strcasecmp(l->args[0], "PART") ||
69
!strcasecmp(l->args[0], "KICK") ||
70
!strcasecmp(l->args[0], "QUIT") ||
71
!strcasecmp(l->args[0], "TOPIC") ||
72
!strcasecmp(l->args[0], "NICK")) {
73
gl = g_slist_append(gl, linedup(l));
74
} else if(!strcasecmp(l->args[0], "353")) {
75
c = find_channel(l->network, l->args[3]);
76
if(c && !(c->introduced & 2)) {
77
gl = g_slist_append(gl, linedup(l));
79
/* Only do 366 if not & 2. Set | 2 */
80
} else if(!strcasecmp(l->args[0], "366")) {
81
c = find_channel(l->network, l->args[2]);
82
if(c && !(c->introduced & 2)) {
83
gl = g_slist_append(gl, linedup(l));
86
/* Only do 331 or 332 if not & 1. Set | 1 */
87
} else if(!strcasecmp(l->args[0], "331") || !strcasecmp(l->args[0], "332")) {
88
c = find_channel(l->network, l->args[2]);
89
if(c && !(c->introduced & 1)) {
90
gl = g_slist_append(gl, linedup(l));
95
g_hash_table_replace(files, l->network, gl);
99
gboolean fini_plugin(struct plugin *p) {
100
del_filter(log_data);
101
replicate_function = default_replicate_function;
105
gboolean init_plugin(struct plugin *p) {
106
files = g_hash_table_new(NULL, NULL);
107
replicate_function = replicate_data;
108
add_filter("repl_memory", log_data);