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.
22 #include "clientincludes.h"
23 #include "client_internal.h"
26 SilcClientCommand silc_local_command_list[] =
28 SILC_CLIENT_LCMD(help, HELP, "HELP", 0, 2),
29 SILC_CLIENT_LCMD(clear, CLEAR, "CLEAR", 0, 1),
30 SILC_CLIENT_LCMD(version, VERSION, "VERSION", 0, 1),
31 SILC_CLIENT_LCMD(server, SERVER, "SERVER", 0, 2),
32 SILC_CLIENT_LCMD(msg, MSG, "MSG", 0, 3),
33 SILC_CLIENT_LCMD(away, AWAY, "AWAY", 0, 2),
35 { NULL, 0, NULL, 0, 0 },
38 /* Finds and returns a pointer to the command list. Return NULL if the
39 command is not found. */
41 SilcClientCommand *silc_client_local_command_find(const char *name)
43 SilcClientCommand *cmd;
45 for (cmd = silc_local_command_list; cmd->name; cmd++) {
46 if (!strcmp(cmd->name, name))
53 /* HELP command. This is local command and shows help on SILC */
55 SILC_CLIENT_LCMD_FUNC(help)
60 /* CLEAR command. This is local command and clears current output window */
62 SILC_CLIENT_LCMD_FUNC(clear)
64 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
65 SilcClient client = cmd->client;
66 SilcClientInternal app = (SilcClientInternal)client->application;
69 wclear((WINDOW *)app->screen);
70 wrefresh((WINDOW *)app->screen);
73 silc_client_command_free(cmd);
76 /* VERSION command. This is local command and shows version of the client */
78 SILC_CLIENT_LCMD_FUNC(version)
80 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
81 SilcClient client = cmd->client;
82 extern char *silc_version;
83 extern char *silc_name;
84 extern char *silc_fullname;
86 silc_say(client, cmd->conn,
87 "%s (%s) version %s", silc_name, silc_fullname,
90 silc_client_command_free(cmd);
93 /* Command MSG. Sends private message to user or list of users. Note that
94 private messages are not really commands, they are message packets,
95 however, on user interface it is convenient to show them as commands
96 as that is the common way of sending private messages (like in IRC). */
97 /* XXX supports only one destination */
99 SILC_CLIENT_LCMD_FUNC(msg)
101 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
102 SilcClientConnection conn = cmd->conn;
103 SilcClient client = cmd->client;
104 SilcClientEntry client_entry = NULL;
105 unsigned int num = 0;
106 char *nickname = NULL, *server = NULL;
109 silc_say(client, conn,
110 "You are not connected to a server, use /SERVER to connect");
115 silc_say(client, conn, "Usage: /MSG <nickname> <message>");
119 /* Parse the typed nickname. */
120 if (!silc_parse_nickname(cmd->argv[1], &nickname, &server, &num)) {
121 silc_say(client, conn, "Bad nickname");
125 /* Find client entry */
126 client_entry = silc_idlist_get_client(client, conn, nickname, server, num,
129 /* Client entry not found, it was requested thus mark this to be
131 silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, conn->cmd_ident,
132 NULL, silc_client_local_command_msg, context);
136 /* Display the message for our eyes. */
137 silc_print(client, "-> *%s* %s", cmd->argv[1], cmd->argv[2]);
139 /* Send the private message */
140 silc_client_send_private_message(client, conn, client_entry,
141 cmd->argv[2], cmd->argv_lens[2],
145 silc_client_command_free(cmd);
149 /* Command SERVER. Connects to remote SILC server. This is local command. */
151 SILC_CLIENT_LCMD_FUNC(server)
153 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
154 SilcClient client = cmd->client;
155 SilcClientConnection conn = cmd->conn;
156 int i = 0, len, port;
160 /* Show current servers */
163 silc_say(client, conn, "You are not connected to any server");
164 silc_say(client, conn, "Usage: /SERVER [<server>[:<port>]]");
168 silc_say(client, conn, "Current server: %s on %d %s",
169 conn->remote_host, conn->remote_port,
170 conn->remote_info ? conn->remote_info : "");
172 silc_say(client, conn, "Server list:");
173 for (i = 0; i < client->conns_count; i++) {
174 silc_say(client, conn, " [%d] %s on %d %s", i + 1,
175 client->conns[i]->remote_host,
176 client->conns[i]->remote_port,
177 client->conns[i]->remote_info ?
178 client->conns[i]->remote_info : "");
184 /* See if port is included and then extract it */
185 if (strchr(cmd->argv[1], ':')) {
186 len = strcspn(cmd->argv[1], ":");
187 hostname = silc_calloc(len + 1, sizeof(char));
188 memcpy(hostname, cmd->argv[1], len);
189 port = atoi(cmd->argv[1] + 1 + len);
191 hostname = cmd->argv[1];
196 if (conn && conn->remote_host) {
197 if (!strcmp(hostname, conn->remote_host) && port == conn->remote_port) {
198 silc_say(client, conn, "You are already connected to that server");
202 /* Close connection */
203 cmd->client->ops->disconnect(cmd->client, cmd->conn);
204 silc_client_close_connection(cmd->client, cmd->conn->sock);
208 /* Connect asynchronously to not to block user interface */
209 silc_client_connect_to_server(cmd->client, port, hostname, NULL);
212 silc_client_command_free(cmd);
215 /* Local command AWAY. Client replies with away message to whomever sends
216 private message to the client if the away message is set. If this is
217 given without arguments the away message is removed. */
219 SILC_CLIENT_LCMD_FUNC(away)
221 SilcClientCommandContext cmd = (SilcClientCommandContext)context;
222 SilcClientConnection conn = cmd->conn;
223 SilcClient client = cmd->client;
224 SilcClientInternal app = (SilcClientInternal)client->application;
227 silc_say(client, conn,
228 "You are not connected to a server, use /SERVER to connect");
232 if (cmd->argc == 1) {
234 silc_free(conn->away->away);
235 silc_free(conn->away);
237 app->screen->bottom_line->away = FALSE;
239 silc_say(client, conn, "Away message removed");
240 silc_screen_print_bottom_line(app->screen, 0);
245 silc_free(conn->away->away);
247 conn->away = silc_calloc(1, sizeof(*conn->away));
249 app->screen->bottom_line->away = TRUE;
250 conn->away->away = strdup(cmd->argv[1]);
252 silc_say(client, conn, "Away message set: %s", conn->away->away);
253 silc_screen_print_bottom_line(app->screen, 0);
257 silc_client_command_free(cmd);