updates.
[silc.git] / apps / irssi / src / silc / core / silc-servers.c
index 062b6049fb221fc66095b5e939a0160a002d3018..a810b8eed7bc4475c31e2e76fd73c169ef271045 100644 (file)
@@ -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, 
@@ -62,6 +63,9 @@ typedef struct {
   char *msg;
 } 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,
@@ -89,13 +93,33 @@ static void silc_send_msg_clients(SilcClient client,
 static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
 {
   PRIVMSG_REC *rec;
+  SilcClientEntry client_entry;
+  uint32 num = 0;
+  char *nickname = NULL, *serv = NULL;
   
-  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);
+  if (!silc_parse_nickname(nick, &nickname, &serv, &num)) {
+    printformat_module("fe-common/silc", server, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
+    return;
+  }
+
+  /* Find client entry */
+  client_entry = silc_idlist_get_client(silc_client, server->conn, 
+                                       nickname, serv, num, FALSE);
+  if (!client_entry) {
+    rec = g_new0(PRIVMSG_REC, 1);
+    rec->nick = g_strdup(nick);
+    rec->msg = g_strdup(msg);
+
+    /* Could not find client with that nick, resolve it from server. */
+    silc_client_get_clients(silc_client, server->conn,
+                           nickname, serv, silc_send_msg_clients, rec);
+    return;
+  }
+
+  /* Send the private message directly */
+  silc_client_send_private_message(silc_client, server->conn, client_entry, 0,
+                                  msg, strlen(msg), TRUE);
 }
 
 static int isnickflag_func(char flag)
@@ -223,6 +247,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 <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
+/* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
+/* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<server>] [-pubkey|<passwd>] */
+/* SYNTAX: GETKEY <nickname or server name> */
+/* SYNTAX: INVITE <channel> [<nickname>[@server>] */
+/* 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>[@<server>] [<comment>] */
+/* SYNTAX: KILL <channel> <nickname>[@<server>] [<comment>] */
+/* SYNTAX: OPER <username> [-pubkey] */
+/* SYNTAX: SILCOPER <username> [-pubkey] */
+/* SYNTAX: TOPIC <channel> [<topic>] */
+/* SYNTAX: UMODE +|-<modes> */
+/* SYNTAX: WHOIS <nickname>[@<server>] [<count>] */
+/* SYNTAX: WHOWAS <nickname>[@<server>] [<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)
 {
@@ -260,23 +318,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,18 +389,19 @@ 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");
 }
@@ -344,17 +421,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);
 }