X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fsilc-servers.c;h=4afc351790fa9bd65f574b910c5af4782d70bade;hp=8e9089361203a1c1ff850200471b4d8aa3fd8770;hb=017dec75a98209fbef49eb496c2269b0c49e736d;hpb=fbb6b73744494d8a908d9cfff2e4dbf882bf5ccf diff --git a/apps/irssi/src/silc/core/silc-servers.c b/apps/irssi/src/silc/core/silc-servers.c index 8e908936..4afc3517 100644 --- a/apps/irssi/src/silc/core/silc-servers.c +++ b/apps/irssi/src/silc/core/silc-servers.c @@ -40,6 +40,7 @@ #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); @@ -50,7 +51,7 @@ static void silc_send_channel(SILC_SERVER_REC *server, 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, @@ -60,8 +61,12 @@ static void silc_send_channel(SILC_SERVER_REC *server, 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, @@ -69,18 +74,39 @@ static void silc_send_msg_clients(SilcClient client, 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); @@ -89,13 +115,36 @@ static void silc_send_msg_clients(SilcClient client, 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) @@ -223,6 +272,40 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) return ret; } +/* Syntaxes of all SILC commands for HELP files (the help file generation + will snoop these from here). */ + +/* SYNTAX: BAN [+|-[[@[![@hostname>]]]]] */ +/* SYNTAX: CMODE +|- [{ }] */ +/* SYNTAX: CUMODE +|- [@] [-pubkey|] */ +/* SYNTAX: GETKEY */ +/* SYNTAX: INVITE [[@hostname>] */ +/* SYNTAX: INVITE [+|-[[@[![@hostname>]]]]] */ +/* SYNTAX: KEY MSG set|unset|list|agreement|negotiate [] */ +/* SYNTAX: KEY CHANNEL set|unset|list|agreement|negotiate [] */ +/* SYNTAX: KICK [@] [] */ +/* SYNTAX: KILL [@] [] */ +/* SYNTAX: OPER [-pubkey] */ +/* SYNTAX: SILCOPER [-pubkey] */ +/* SYNTAX: TOPIC [] */ +/* SYNTAX: UMODE +|- */ +/* SYNTAX: WHOIS [@] [] */ +/* SYNTAX: WHOWAS [@] [] */ +/* SYNTAX: CLOSE [] */ +/* SYNTAX: SHUTDOWN */ +/* SYNTAX: MOTD [] */ +/* SYNTAX: LIST [] */ +/* SYNTAX: ME */ +/* SYNTAX: ACTION */ +/* SYNTAX: AWAY [] */ +/* SYNTAX: INFO [] */ +/* SYNTAX: NICK */ +/* SYNTAX: NOTICE */ +/* SYNTAX: PART [] */ +/* SYNTAX: PING */ +/* SYNTAX: SCONNECT [] */ +/* SYNTAX: USERS */ + void silc_command_exec(SILC_SERVER_REC *server, const char *command, const char *args) { @@ -260,23 +343,41 @@ void silc_command_exec(SILC_SERVER_REC *server, 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(); } @@ -313,22 +414,21 @@ void silc_server_init(void) 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"); - - settings_add_bool("server", "skip_motd", FALSE); } void silc_server_deinit(void) @@ -346,17 +446,18 @@ void silc_server_deinit(void) 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); }