#include "window-item-def.h"
#include "fe-common/core/printtext.h"
+#include "fe-common/silc/module-formats.h"
void silc_servers_reconnect_init(void);
void silc_servers_reconnect_deinit(void);
SILC_CHANNEL_REC *rec;
rec = silc_channel_find(server, channel);
- if (rec == NULL)
+ if (rec == NULL || rec->entry == NULL)
return;
silc_client_send_channel_message(silc_client, server->conn, rec->entry,
typedef struct {
char *nick;
char *msg;
+ SILC_SERVER_REC *server;
} PRIVMSG_REC;
+/* Callback function that sends the private message if the client was
+ resolved from the server. */
+
static void silc_send_msg_clients(SilcClient client,
SilcClientConnection conn,
SilcClientEntry *clients,
void *context)
{
PRIVMSG_REC *rec = context;
+ SILC_SERVER_REC *server = rec->server;
SilcClientEntry target;
-
- if (clients_count == 0) {
+ char *nickname = NULL;
+
+ if (!clients_count) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", rec->nick);
} else {
- target = clients[0]; /* FIXME: not a good idea :) */
-
+ if (clients_count > 1) {
+ silc_parse_userfqdn(rec->nick, &nickname, NULL);
+
+ /* Find the correct one. The rec->nick might be a formatted nick
+ so this will find the correct one. */
+ clients = silc_client_get_clients_local(silc_client, server->conn,
+ nickname, rec->nick,
+ &clients_count);
+ if (!clients) {
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
+ rec->nick);
+ silc_free(nickname);
+ goto out;
+ }
+ silc_free(nickname);
+ }
+
+ target = clients[0];
+
+ /* Send the private message */
silc_client_send_private_message(client, conn, target, 0,
rec->msg, strlen(rec->msg),
TRUE);
}
+ out:
g_free(rec->nick);
g_free(rec->msg);
g_free(rec);
static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
{
PRIVMSG_REC *rec;
-
- rec = g_new0(PRIVMSG_REC, 1);
- rec->nick = g_strdup(nick);
- rec->msg = g_strdup(msg);
-
- silc_client_get_clients(silc_client, server->conn,
- nick, "", silc_send_msg_clients, rec);
+ SilcClientEntry *clients;
+ uint32 clients_count;
+ char *nickname = NULL;
+
+ if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
+ return;
+ }
+
+ /* Find client entry */
+ clients = silc_client_get_clients_local(silc_client, server->conn,
+ nickname, nick, &clients_count);
+ silc_free(nickname);
+
+ if (!clients) {
+ rec = g_new0(PRIVMSG_REC, 1);
+ rec->nick = g_strdup(nick);
+ rec->msg = g_strdup(msg);
+ rec->server = server;
+
+ /* Could not find client with that nick, resolve it from server. */
+ silc_client_get_clients(silc_client, server->conn,
+ nickname, NULL, silc_send_msg_clients, rec);
+ return;
+ }
+
+ /* Send the private message directly */
+ silc_client_send_private_message(silc_client, server->conn,
+ clients[0], 0, msg, strlen(msg), TRUE);
}
static int isnickflag_func(char flag)
return ret;
}
+/* Syntaxes of all SILC commands for HELP files (the help file generation
+ will snoop these from here). */
+
+/* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
+/* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
+/* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
+/* SYNTAX: GETKEY <nickname or server name> */
+/* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
+/* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
+/* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
+/* SYNTAX: KEY CHANNEL <channel> set|unset|list|agreement|negotiate [<arguments>] */
+/* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: KILL <channel> <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: OPER <username> [-pubkey] */
+/* SYNTAX: SILCOPER <username> [-pubkey] */
+/* SYNTAX: TOPIC <channel> [<topic>] */
+/* SYNTAX: UMODE +|-<modes> */
+/* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
+/* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
+/* SYNTAX: CLOSE <server> [<port>] */
+/* SYNTAX: SHUTDOWN */
+/* SYNTAX: MOTD [<server>] */
+/* SYNTAX: LIST [<channel>] */
+/* SYNTAX: ME <message> */
+/* SYNTAX: ACTION <channel> <message> */
+/* SYNTAX: AWAY [<message>] */
+/* SYNTAX: INFO [<server>] */
+/* SYNTAX: NICK <nickname> */
+/* SYNTAX: NOTICE <message> */
+/* SYNTAX: PART [<channel>] */
+/* SYNTAX: PING */
+/* SYNTAX: SCONNECT <server> [<port>] */
+/* SYNTAX: USERS <channel> */
+
void silc_command_exec(SILC_SERVER_REC *server,
const char *command, const char *args)
{
g_return_if_fail(server != NULL);
- tmpcmd = g_strdup(command); g_strup(tmpcmd);
+ tmpcmd = g_strdup(command);
+ g_strup(tmpcmd);
cmd = silc_client_command_find(tmpcmd);
g_free(tmpcmd);
if (cmd == NULL)
ctx->argv_types = argv_types;
/* Execute command */
- (*cmd->cb)(ctx);
+ (*cmd->cb)(ctx, NULL);
}
-static void command_users(const char *data, SILC_SERVER_REC *server,
- WI_ITEM_REC *item)
+/* Generic command function to call any SILC command directly. */
+
+static void command_self(const char *data, SILC_SERVER_REC *server,
+ WI_ITEM_REC *item)
{
- signal_emit("command names", 3, data, server, item);
+ if (!IS_SILC_SERVER(server) || !server->connected) {
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
+ return;
+ }
+
+ if (IS_SILC_CHANNEL(item)) {
+ SILC_CHANNEL_REC *chanrec;
+ chanrec = silc_channel_find(server, item->name);
+ if (chanrec)
+ server->conn->current_channel = chanrec->entry;
+ }
+
+ silc_command_exec(server, current_command, data);
+ signal_stop();
}
-static void command_self(const char *data, SILC_SERVER_REC *server)
+/* SCONNECT command. Calls actually SILC's CONNECT command since Irssi
+ has CONNECT command for other purposes. */
+
+static void command_sconnect(const char *data, SILC_SERVER_REC *server)
{
if (!IS_SILC_SERVER(server) || !server->connected) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
return;
}
- silc_command_exec(server, current_command, data);
+ silc_command_exec(server, "CONNECT", data);
signal_stop();
}
command_bind("users", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("list", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("ban", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind("oper", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("silcoper", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("umode", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("invite", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("kill", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("kick", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("info", MODULE_NAME, (SIGNAL_FUNC) command_self);
- command_bind("connect", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("ping", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("motd", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("close", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
+ command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
command_set_options("connect", "+silcnet");
}
command_unbind("cumode", (SIGNAL_FUNC) command_self);
command_unbind("users", (SIGNAL_FUNC) command_self);
command_unbind("list", (SIGNAL_FUNC) command_self);
+ command_unbind("oper", (SIGNAL_FUNC) command_self);
command_unbind("silcoper", (SIGNAL_FUNC) command_self);
command_unbind("umode", (SIGNAL_FUNC) command_self);
command_unbind("invite", (SIGNAL_FUNC) command_self);
command_unbind("kill", (SIGNAL_FUNC) command_self);
command_unbind("kick", (SIGNAL_FUNC) command_self);
command_unbind("info", (SIGNAL_FUNC) command_self);
- command_unbind("connect", (SIGNAL_FUNC) command_self);
command_unbind("ping", (SIGNAL_FUNC) command_self);
command_unbind("motd", (SIGNAL_FUNC) command_self);
command_unbind("ban", (SIGNAL_FUNC) command_self);
command_unbind("close", (SIGNAL_FUNC) command_self);
command_unbind("shutdown", (SIGNAL_FUNC) command_self);
command_unbind("getkey", (SIGNAL_FUNC) command_self);
+ command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
}