updates.
[silc.git] / apps / silc / client_ops.c
index 1a0947609fbc62bbde6a26dbd0fc3ee6874195ea..647aa5b1473311c82d1738c4b09e2c3a9f87875f 100644 (file)
@@ -56,7 +56,7 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
       silc_print(client, "* %s %s", sender ? sender->nickname : "[<unknown>]", 
                 msg);
     else if (flags & SILC_MESSAGE_FLAG_NOTICE)
-      silc_print(client, "-%s- %s", sender ? sender->nickname : "[<unknown>]", 
+      silc_print(client, "- %s %s", sender ? sender->nickname : "[<unknown>]", 
                 msg);
     else
       silc_print(client, "<%s> %s", sender ? sender->nickname : "[<unknown>]", 
@@ -67,7 +67,7 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
                 "[<unknown>]",
                 channel->channel_name, msg);
     else if (flags & SILC_MESSAGE_FLAG_NOTICE)
-      silc_print(client, "-%s:%s- %s", sender ? sender->nickname : 
+      silc_print(client, "- %s:%s %s", sender ? sender->nickname : 
                 "[<unknown>]",
                 channel->channel_name, msg);
     else
@@ -208,12 +208,25 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     
     tmp = silc_client_chmode(tmp_int, channel_entry);
     
-    if (tmp)
-      snprintf(message, sizeof(message), "%s changed channel mode to +%s",
-              client_entry->nickname, tmp);
-    else
-      snprintf(message, sizeof(message), "%s removed all channel modes", 
-              client_entry->nickname);
+    if (tmp) {
+      if (client_entry) {
+       snprintf(message, sizeof(message), "%s changed channel mode to +%s",
+                client_entry->nickname, tmp);
+      } else {
+       snprintf(message, sizeof(message), 
+                "channel mode was changed to +%s (forced by router)",
+                tmp);
+      }
+    } else {
+      if (client_entry) {
+       snprintf(message, sizeof(message), "%s removed all channel modes", 
+                client_entry->nickname);
+      } else {
+       snprintf(message, sizeof(message), 
+                "Removed all channel modes (forced by router)");
+      }
+    }
+
     if (app->screen->bottom_line->channel_mode)
       silc_free(app->screen->bottom_line->channel_mode);
     app->screen->bottom_line->channel_mode = tmp;
@@ -265,6 +278,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     return;
 
   case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
+    return;
     break;
 
   case SILC_NOTIFY_TYPE_KICKED:
@@ -307,6 +321,31 @@ void silc_notify(SilcClient client, SilcClientConnection conn,
     }
     break;
 
+  case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
+    {
+      SilcClientEntry *clients;
+      unsigned int clients_count;
+      int i;
+
+      (void)va_arg(vp, void *);
+      clients = va_arg(vp, SilcClientEntry *);
+      clients_count = va_arg(vp, unsigned int);
+
+      for (i = 0; i < clients_count; i++) {
+       if (clients[i]->server)
+         snprintf(message, sizeof(message), "Server signoff: %s@%s %s%s%s", 
+                  clients[i]->nickname, clients[i]->server,
+                  tmp ? "(" : "", tmp ? tmp : "", tmp ? ")" : "");
+       else
+         snprintf(message, sizeof(message), "Server signoff: %s %s%s%s", 
+                  clients[i]->nickname,
+                  tmp ? "(" : "", tmp ? tmp : "", tmp ? ")" : "");
+       silc_print(client, "*** %s", message);
+       memset(message, 0, sizeof(message));
+      }
+      return;
+    }
+
   default:
     break;
   }
@@ -508,12 +547,18 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
          }
        }
 
-       if (mode)
-         client->ops->say(client, conn, "%s is %s", nickname,
-                          (mode & SILC_UMODE_SERVER_OPERATOR) ?
-                          "Server Operator" :
-                          (mode & SILC_UMODE_ROUTER_OPERATOR) ?
-                          "SILC Operator" : "[Unknown mode]");
+       if (mode) {
+         if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
+             (mode & SILC_UMODE_ROUTER_OPERATOR))
+           client->ops->say(client, conn, "%s is %s", nickname,
+                            (mode & SILC_UMODE_SERVER_OPERATOR) ?
+                            "Server Operator" :
+                            (mode & SILC_UMODE_ROUTER_OPERATOR) ?
+                            "SILC Operator" : "[Unknown mode]");
+
+         if (mode & SILC_UMODE_GONE)
+           client->ops->say(client, conn, "%s is gone", nickname);
+       }
 
        if (idle && nickname)
          client->ops->say(client, conn, "%s has been idle %d %s",
@@ -744,19 +789,88 @@ void silc_command_reply(SilcClient client, SilcClientConnection conn,
       break;
 
     case SILC_COMMAND_USERS:
-      if (!success)
-       return;
+      {
+       SilcChannelEntry channel;
+       int line_len;
+       char *line;
+       
+       if (!success)
+         return;
 
-      silc_list_start(conn->current_channel->clients);
-      while ((chu = silc_list_get(conn->current_channel->clients)) 
-            != SILC_LIST_END) {
-       if (chu->client == conn->local_entry) {
-         if (app->screen->bottom_line->mode)
-           silc_free(app->screen->bottom_line->mode);
-         app->screen->bottom_line->mode = silc_client_chumode_char(chu->mode);
-         silc_screen_print_bottom_line(app->screen, 0);
-         break;
+       channel = va_arg(vp, SilcChannelEntry);
+
+       /* There are two ways to do this, either parse the list (that
+          the command_reply sends (just take it with va_arg())) or just
+          traverse the channel'c client list.  I'll do the latter.  See
+          JOIN command reply for example for the list. */
+
+       silc_say(client, conn, "Users on %s", channel->channel_name);
+       
+       line = silc_calloc(1024, sizeof(*line));
+       line_len = 1024;
+       silc_list_start(channel->clients);
+       while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
+         SilcClientEntry e = chu->client;
+         int i, len1;
+         char *m, tmp[80];
+
+         memset(line, 0, line_len);
+
+         if (chu->client == conn->local_entry) {
+           /* Update status line */
+           if (app->screen->bottom_line->mode)
+             silc_free(app->screen->bottom_line->mode);
+           app->screen->bottom_line->mode = 
+             silc_client_chumode_char(chu->mode);
+           silc_screen_print_bottom_line(app->screen, 0);
+         }
+
+         if (strlen(e->nickname) + strlen(e->server) + 100 > line_len) {
+           silc_free(line);
+           line_len += strlen(e->nickname) + strlen(e->server) + 100;
+           line = silc_calloc(line_len, sizeof(*line));
+         }
+
+         memset(tmp, 0, sizeof(tmp));
+         m = silc_client_chumode_char(chu->mode);
+
+         strncat(line, " ", 1);
+         strncat(line, e->nickname, strlen(e->nickname));
+         strncat(line, e->server ? "@" : "", 1);
+         
+         len1 = 0;
+         if (e->server)
+           len1 = strlen(e->server);
+         strncat(line, e->server ? e->server : "", len1 > 30 ? 30 : len1);
+         
+         len1 = strlen(line);
+         if (len1 >= 30) {
+           memset(&line[29], 0, len1 - 29);
+         } else {
+           for (i = 0; i < 30 - len1 - 1; i++)
+             strcat(line, " ");
+         }
+         
+         if (e->mode & SILC_UMODE_GONE)
+           strcat(line, "  G");
+         else
+           strcat(line, "  H");
+         strcat(tmp, m ? m : "");
+         strncat(line, tmp, strlen(tmp));
+         
+         if (strlen(tmp) < 5)
+           for (i = 0; i < 5 - strlen(tmp); i++)
+             strcat(line, " ");
+         
+         strcat(line, e->username ? e->username : "");
+         
+         silc_say(client, conn, "%s", line);
+         
+         if (m)
+           silc_free(m);
        }
+       
+       silc_free(line);
       }
       break;