4 Copyright (C) 2000 Timo Sirainen
5 Copyright (C) 2003 Jochen Eisinger
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "module-formats.h"
30 #include "silc-servers.h"
31 #include "silc-chatnets.h"
32 #include "printtext.h"
34 static void cmd_silcnet_list(void)
39 str = g_string_new(NULL);
40 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_HEADER);
41 for (tmp = chatnets; tmp != NULL; tmp = tmp->next) {
42 SILC_CHATNET_REC *rec = tmp->data;
47 g_string_truncate(str, 0);
48 if (rec->nick != NULL)
49 g_string_sprintfa(str, "nick: %s, ", rec->nick);
50 if (rec->username != NULL)
51 g_string_sprintfa(str, "username: %s, ", rec->username);
52 if (rec->realname != NULL)
53 g_string_sprintfa(str, "realname: %s, ", rec->realname);
54 if (rec->own_host != NULL)
55 g_string_sprintfa(str, "host: %s, ", rec->own_host);
57 if (str->len > 1) g_string_truncate(str, str->len-2);
58 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
59 SILCTXT_SILCNET_LINE, rec->name, str->str);
61 g_string_free(str, TRUE);
62 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_FOOTER);
65 /* SYNTAX: SILCNET ADD [-nick <nick>] [-user <user>] [-realname <name>]
66 [-host <host>] <name> */
67 static void cmd_silcnet_add(const char *data)
72 SILC_CHATNET_REC *rec;
74 if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
75 "silcnet add", &optlist, &name))
77 if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
79 rec = silcnet_find(name);
81 rec = g_new0(SILC_CHATNET_REC, 1);
82 rec->name = g_strdup(name);
84 if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
85 if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
86 if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
87 if (g_hash_table_lookup(optlist, "host")) {
88 g_free_and_null(rec->own_host);
89 rec->own_ip4 = rec->own_ip6 = NULL;
94 value = g_hash_table_lookup(optlist, "nick");
95 if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
96 value = g_hash_table_lookup(optlist, "user");
97 if (value != NULL && *value != '\0') rec->username = g_strdup(value);
98 value = g_hash_table_lookup(optlist, "realname");
99 if (value != NULL && *value != '\0') rec->realname = g_strdup(value);
101 value = g_hash_table_lookup(optlist, "host");
102 if (value != NULL && *value != '\0') {
103 rec->own_host = g_strdup(value);
104 rec->own_ip4 = rec->own_ip6 = NULL;
108 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_ADDED, name);
110 cmd_params_free(free_arg);
113 /* SYNTAX: SILCNET REMOVE <silcnet> */
114 static void cmd_silcnet_remove(const char *data)
116 SILC_CHATNET_REC *rec;
118 if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
120 rec = silcnet_find(data);
122 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_NOT_FOUND, data);
124 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_REMOVED, data);
125 chatnet_remove(CHATNET(rec));
129 static void cmd_silcnet(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
134 command_runsub("silcnet", data, server, item);
137 void fe_silcnet_init(void)
139 command_bind("silcnet", NULL, (SIGNAL_FUNC) cmd_silcnet);
140 command_bind("silcnet list", NULL, (SIGNAL_FUNC) cmd_silcnet_list);
141 command_bind("silcnet add", NULL, (SIGNAL_FUNC) cmd_silcnet_add);
142 command_bind("silcnet remove", NULL, (SIGNAL_FUNC) cmd_silcnet_remove);
144 command_set_options("silcnet add", "-nick -user -realname -host");
147 void fe_silcnet_deinit(void)
149 command_unbind("silcnet", (SIGNAL_FUNC) cmd_silcnet);
150 command_unbind("silcnet list", (SIGNAL_FUNC) cmd_silcnet_list);
151 command_unbind("silcnet add", (SIGNAL_FUNC) cmd_silcnet_add);
152 command_unbind("silcnet remove", (SIGNAL_FUNC) cmd_silcnet_remove);