summaryrefslogtreecommitdiff
path: root/src/irc/core/irc-chatnets.c
blob: d757bf8d820383e32680ba76b1725d543ad8e477 (plain)
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
/*
 irc-chatnets.c : 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.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "module.h"
#include "signals.h"
#include "lib-config/iconfig.h"
#include "settings.h"

#include "irc-chatnets.h"

void ircnet_create(IRC_CHATNET_REC *rec)
{
	g_return_if_fail(rec != NULL);

	rec->chat_type = IRC_PROTOCOL;
        chatnet_create((CHATNET_REC *) rec);
}

static void sig_chatnet_read(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
{
	if (!IS_IRC_CHATNET(rec))
		return;

	rec->usermode = g_strdup(config_node_get_str(node, "usermode", NULL));

	rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
	rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
	rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0);

	rec->max_kicks = config_node_get_int(node, "max_kicks", 0);
	rec->max_msgs = config_node_get_int(node, "max_msgs", 0);
	rec->max_modes = config_node_get_int(node, "max_modes", 0);
	rec->max_whois = config_node_get_int(node, "max_whois", 0);
}

static void sig_chatnet_saved(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
{
	if (!IS_IRC_CHATNET(rec))
		return;

	if (rec->usermode != NULL)
                iconfig_node_set_str(node, "usermode", rec->usermode);

	if (rec->max_cmds_at_once > 0)
		iconfig_node_set_int(node, "cmdmax", rec->max_cmds_at_once);
	if (rec->cmd_queue_speed > 0)
		iconfig_node_set_int(node, "cmdspeed", rec->cmd_queue_speed);
	if (rec->max_query_chans > 0)
		iconfig_node_set_int(node, "max_query_chans", rec->max_query_chans);

	if (rec->max_kicks > 0)
		iconfig_node_set_int(node, "max_kicks", rec->max_kicks);
	if (rec->max_msgs > 0)
		iconfig_node_set_int(node, "max_msgs", rec->max_msgs);
	if (rec->max_modes > 0)
		iconfig_node_set_int(node, "max_modes", rec->max_modes);
	if (rec->max_whois > 0)
		iconfig_node_set_int(node, "max_whois", rec->max_whois);
}

static void sig_chatnet_destroyed(IRC_CHATNET_REC *rec)
{
	if (IS_IRC_CHATNET(rec))
                g_free(rec->usermode);
}


void irc_chatnets_init(void)
{
	signal_add("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
	signal_add("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
	signal_add("chatnet destroyed", (SIGNAL_FUNC) sig_chatnet_destroyed);
}

void irc_chatnets_deinit(void)
{
	GSList *tmp, *next;

	for (tmp = chatnets; tmp != NULL; tmp = next) {
		CHATNET_REC *rec = tmp->data;

		next = tmp->next;
		if (IS_IRC_CHATNET(rec))
                        chatnet_destroy(rec);
	}

	signal_remove("chatnet read", (SIGNAL_FUNC) sig_chatnet_read);
	signal_remove("chatnet saved", (SIGNAL_FUNC) sig_chatnet_saved);
	signal_remove("chatnet destroyed", (SIGNAL_FUNC) sig_chatnet_destroyed);
}