5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2000 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
23 * Revision 1.2 2001/01/30 21:40:21 priikone
26 * Revision 1.1 2000/09/13 17:47:54 priikone
27 * Created SILC Client Libary by moving stuff from silc/ directory.
28 * SILC client library is SILC client without UI. Old UI still exists
29 * in silc/ directory and uses the new client.
31 * Bug fixes and several new functions, structures and functions
32 * naming changes during the change was made.
36 #include "clientincludes.h"
39 SilcClientCommand silc_local_command_list[] =
41 SILC_CLIENT_LCMD(help, HELP, "HELP", 0, 2),
42 SILC_CLIENT_LCMD(clear, CLEAR, "CLEAR", 0, 1),
43 SILC_CLIENT_LCMD(version, VERSION, "VERSION", 0, 1),
44 SILC_CLIENT_LCMD(server, SERVER, "SERVER", 0, 2),
45 SILC_CLIENT_LCMD(msg, MSG, "MSG", 0, 3),
46 SILC_CLIENT_LCMD(away, AWAY, "AWAY", 0, 2),
48 { NULL, 0, NULL, 0, 0 },
51 /* Finds and returns a pointer to the command list. Return NULL if the
52 command is not found. */
54 SilcClientCommand *silc_client_local_command_find(const char *name)
56 SilcClientCommand *cmd;
58 for (cmd = silc_local_command_list; cmd->name; cmd++) {
59 if (!strcmp(cmd->name, name))
66 /* HELP command. This is local command and shows help on SILC */
68 SILC_CLIENT_LCMD_FUNC(help)
73 /* CLEAR command. This is local command and clears current output window */
75 SILC_CLIENT_LCMD_FUNC(clear)
77 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
78 SilcClient client = cmd->client;
79 SilcClientInternal app = (SilcClientInternal)client->application;
82 wclear((WINDOW *)app->screen);
83 wrefresh((WINDOW *)app->screen);
86 silc_client_command_free(cmd);
89 /* VERSION command. This is local command and shows version of the client */
91 SILC_CLIENT_LCMD_FUNC(version)
93 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
94 SilcClient client = cmd->client;
95 extern char *silc_version;
96 extern char *silc_name;
97 extern char *silc_fullname;
99 silc_say(client, cmd->conn,
100 "%s (%s) version %s", silc_name, silc_fullname,
103 silc_client_command_free(cmd);
106 /* Command MSG. Sends private message to user or list of users. Note that
107 private messages are not really commands, they are message packets,
108 however, on user interface it is convenient to show them as commands
109 as that is the common way of sending private messages (like in IRC). */
110 /* XXX supports only one destination */
112 SILC_CLIENT_LCMD_FUNC(msg)
114 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
115 SilcClientConnection conn = cmd->conn;
116 SilcClient client = cmd->client;
117 SilcClientEntry client_entry = NULL;
118 unsigned int num = 0;
119 char *nickname = NULL, *server = NULL;
122 silc_say(client, conn,
123 "You are not connected to a server, use /SERVER to connect");
128 silc_say(client, conn, "Usage: /MSG <nickname> <message>");
132 /* Parse the typed nickname. */
133 if (!silc_parse_nickname(cmd->argv[1], &nickname, &server, &num)) {
134 silc_say(client, conn, "Bad nickname");
138 /* Find client entry */
139 client_entry = silc_idlist_get_client(client, conn, nickname, server, num);
141 /* Client entry not found, it was requested thus mark this to be
143 silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, 0,
144 silc_client_local_command_msg, context);
148 /* Display the message for our eyes. */
149 silc_print(client, "-> *%s* %s", cmd->argv[1], cmd->argv[2]);
151 /* Send the private message */
152 silc_client_packet_send_private_message(client, conn->sock, client_entry,
153 cmd->argv[2], cmd->argv_lens[2],
157 silc_client_command_free(cmd);
161 /* Command SERVER. Connects to remote SILC server. This is local command. */
163 SILC_CLIENT_LCMD_FUNC(server)
165 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
166 SilcClient client = cmd->client;
167 SilcClientConnection conn = cmd->conn;
168 int i = 0, len, port;
172 /* Show current servers */
175 silc_say(client, conn, "You are not connected to any server");
176 silc_say(client, conn, "Usage: /SERVER [<server>[:<port>]]");
180 silc_say(client, conn, "Current server: %s on %d %s",
181 conn->remote_host, conn->remote_port,
182 conn->remote_info ? conn->remote_info : "");
184 silc_say(client, conn, "Server list:");
185 for (i = 0; i < client->conns_count; i++) {
186 silc_say(client, conn, " [%d] %s on %d %s", i + 1,
187 client->conns[i]->remote_host,
188 client->conns[i]->remote_port,
189 client->conns[i]->remote_info ?
190 client->conns[i]->remote_info : "");
196 /* See if port is included and then extract it */
197 if (strchr(cmd->argv[1], ':')) {
198 len = strcspn(cmd->argv[1], ":");
199 hostname = silc_calloc(len + 1, sizeof(char));
200 memcpy(hostname, cmd->argv[1], len);
201 port = atoi(cmd->argv[1] + 1 + len);
203 hostname = cmd->argv[1];
207 /* Connect asynchronously to not to block user interface */
208 silc_client_connect_to_server(cmd->client, port, hostname, NULL);
211 silc_client_command_free(cmd);
214 /* Local command AWAY. Client replies with away message to whomever sends
215 private message to the client if the away message is set. If this is
216 given without arguments the away message is removed. */
218 SILC_CLIENT_LCMD_FUNC(away)
220 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
221 SilcClientConnection conn = cmd->conn;
222 SilcClient client = cmd->client;
223 SilcClientInternal app = (SilcClientInternal)client->application;
226 silc_say(client, conn,
227 "You are not connected to a server, use /SERVER to connect");
231 if (cmd->argc == 1) {
233 silc_free(conn->away->away);
234 silc_free(conn->away);
236 app->screen->bottom_line->away = FALSE;
238 silc_say(client, conn, "Away message removed");
239 silc_screen_print_bottom_line(app->screen, 0);
244 silc_free(conn->away->away);
246 conn->away = silc_calloc(1, sizeof(*conn->away));
248 app->screen->bottom_line->away = TRUE;
249 conn->away->away = strdup(cmd->argv[1]);
251 silc_say(client, conn, "Away message set: %s", conn->away->away);
252 silc_screen_print_bottom_line(app->screen, 0);
256 silc_client_command_free(cmd);