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 void silcnet_create(SILC_CHATNET_REC *rec)
36 g_return_if_fail(rec != NULL);
38 rec->chat_type = SILC_PROTOCOL;
39 chatnet_create((CHATNET_REC *) rec);
42 static void cmd_silcnet_list(void)
47 str = g_string_new(NULL);
48 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_HEADER);
49 for (tmp = chatnets; tmp != NULL; tmp = tmp->next) {
50 SILC_CHATNET_REC *rec = tmp->data;
55 g_string_truncate(str, 0);
56 if (rec->nick != NULL)
57 g_string_sprintfa(str, "nick: %s, ", rec->nick);
58 if (rec->username != NULL)
59 g_string_sprintfa(str, "username: %s, ", rec->username);
60 if (rec->realname != NULL)
61 g_string_sprintfa(str, "realname: %s, ", rec->realname);
62 if (rec->own_host != NULL)
63 g_string_sprintfa(str, "host: %s, ", rec->own_host);
65 if (str->len > 1) g_string_truncate(str, str->len-2);
66 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
67 SILCTXT_SILCNET_LINE, rec->name, str->str);
69 g_string_free(str, TRUE);
70 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, SILCTXT_SILCNET_FOOTER);
73 /* SYNTAX: SILCNET ADD [-nick <nick>] [-user <user>] [-realname <name>]
74 [-host <host>] <name> */
75 static void cmd_silcnet_add(const char *data)
80 SILC_CHATNET_REC *rec;
82 if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
83 "silcnet add", &optlist, &name))
85 if (*name == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
87 rec = silcnet_find(name);
89 rec = g_new0(SILC_CHATNET_REC, 1);
90 rec->name = g_strdup(name);
92 if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
93 if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
94 if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
95 if (g_hash_table_lookup(optlist, "host")) {
96 g_free_and_null(rec->own_host);
97 rec->own_ip4 = rec->own_ip6 = NULL;
102 value = g_hash_table_lookup(optlist, "nick");
103 if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
104 value = g_hash_table_lookup(optlist, "user");
105 if (value != NULL && *value != '\0') rec->username = g_strdup(value);
106 value = g_hash_table_lookup(optlist, "realname");
107 if (value != NULL && *value != '\0') rec->realname = g_strdup(value);
109 value = g_hash_table_lookup(optlist, "host");
110 if (value != NULL && *value != '\0') {
111 rec->own_host = g_strdup(value);
112 rec->own_ip4 = rec->own_ip6 = NULL;
116 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_ADDED, name);
118 cmd_params_free(free_arg);
121 /* SYNTAX: SILCNET REMOVE <silcnet> */
122 static void cmd_silcnet_remove(const char *data)
124 SILC_CHATNET_REC *rec;
126 if (*data == '\0') cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
128 rec = silcnet_find(data);
130 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_NOT_FOUND, data);
132 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, SILCTXT_SILCNET_REMOVED, data);
133 chatnet_remove(CHATNET(rec));
137 static void cmd_silcnet(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
142 command_runsub("silcnet", data, server, item);
145 void fe_silcnet_init(void)
147 command_bind("silcnet", NULL, (SIGNAL_FUNC) cmd_silcnet);
148 command_bind("silcnet list", NULL, (SIGNAL_FUNC) cmd_silcnet_list);
149 command_bind("silcnet add", NULL, (SIGNAL_FUNC) cmd_silcnet_add);
150 command_bind("silcnet remove", NULL, (SIGNAL_FUNC) cmd_silcnet_remove);
152 command_set_options("silcnet add", "-nick -user -realname -host");
155 void fe_silcnet_deinit(void)
157 command_unbind("silcnet", (SIGNAL_FUNC) cmd_silcnet);
158 command_unbind("silcnet list", (SIGNAL_FUNC) cmd_silcnet_list);
159 command_unbind("silcnet add", (SIGNAL_FUNC) cmd_silcnet_add);
160 command_unbind("silcnet remove", (SIGNAL_FUNC) cmd_silcnet_remove);