2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #define _GNU_SOURCE /* for memrchr */
44 #include "cfgfiles.h" /* xchat_fopen_file() */
45 #include "network.h" /* net_ip() */
59 extern int current_mem_usage
;
63 static void help (session
*sess
, char *tbuf
, char *helpcmd
, int quiet
);
64 static int cmd_server (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[]);
65 static void handle_say (session
*sess
, char *text
, int check_spch
);
69 notj_msg (struct session
*sess
)
71 PrintText (sess
, _("No channel joined. Try /join #<channel>\n"));
75 notc_msg (struct session
*sess
)
77 PrintText (sess
, _("Not connected. Try /server <host> [<port>]\n"));
81 random_line (char *file_name
)
90 fh
= xchat_fopen_file (file_name
, "r", 0);
94 /* reason is not a file, an actual reason! */
95 return strdup (file_name
);
98 /* count number of lines in file */
100 while (fgets (buf
, sizeof (buf
), fh
))
106 /* go down a random number */
108 ran
= RAND_INT (lines
);
111 fgets (buf
, sizeof (buf
), fh
);
116 buf
[strlen (buf
) - 1] = 0; /* remove the trailing '\n' */
121 server_sendpart (server
* serv
, char *channel
, char *reason
)
125 reason
= random_line (prefs
.partreason
);
126 serv
->p_part (serv
, channel
, reason
);
130 /* reason set by /quit, /close argument */
131 serv
->p_part (serv
, channel
, reason
);
136 server_sendquit (session
* sess
)
140 if (!sess
->quitreason
)
142 colrea
= strdup (prefs
.quitreason
);
143 check_special_chars (colrea
, FALSE
);
144 rea
= random_line (colrea
);
146 sess
->server
->p_quit (sess
->server
, rea
);
150 /* reason set by /quit, /close argument */
151 sess
->server
->p_quit (sess
->server
, sess
->quitreason
);
156 process_data_init (char *buf
, char *cmd
, char *word
[],
157 char *word_eol
[], gboolean handle_quotes
,
158 gboolean allow_escape_quotes
)
166 word
[0] = "\000\000";
167 word_eol
[0] = "\000\000";
168 word
[1] = (char *)buf
;
169 word_eol
[1] = (char *)cmd
;
177 for (j
= wordcount
; j
< PDIWORDS
; j
++)
179 word
[j
] = "\000\000";
180 word_eol
[j
] = "\000\000";
186 /* two quotes turn into 1 */
187 if (allow_escape_quotes
&& cmd
[1] == '\042')
208 if (wordcount
< PDIWORDS
)
210 word
[wordcount
] = &buf
[j
];
211 word_eol
[wordcount
] = cmd
+ 1;
223 len
= g_utf8_skip
[((unsigned char *)cmd
)[0]];
231 /* skip past a multi-byte utf8 char */
232 memcpy (buf
+ j
, cmd
, len
);
241 cmd_addbutton (struct session
*sess
, char *tbuf
, char *word
[],
244 if (*word
[2] && *word_eol
[3])
246 if (sess
->type
== SESS_DIALOG
)
248 list_addentry (&dlgbutton_list
, word_eol
[3], word
[2]);
249 fe_dlgbuttons_update (sess
);
252 list_addentry (&button_list
, word_eol
[3], word
[2]);
253 fe_buttons_update (sess
);
261 cmd_allchannels (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
263 GSList
*list
= sess_list
;
271 if (sess
->type
== SESS_CHANNEL
&& sess
->channel
[0] && sess
->server
->connected
)
273 handle_command (sess
, word_eol
[2], FALSE
);
282 cmd_allchannelslocal (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
284 GSList
*list
= sess_list
;
285 server
*serv
= sess
->server
;
293 if (sess
->type
== SESS_CHANNEL
&& sess
->channel
[0] &&
294 sess
->server
->connected
&& sess
->server
== serv
)
296 handle_command (sess
, word_eol
[2], FALSE
);
305 cmd_allservers (struct session
*sess
, char *tbuf
, char *word
[],
319 handle_command (serv
->front_session
, word_eol
[2], FALSE
);
327 cmd_away (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
330 char *reason
= word_eol
[2];
334 if (sess
->server
->is_away
)
336 if (sess
->server
->last_away_reason
)
337 PrintTextf (sess
, _("Already marked away: %s\n"), sess
->server
->last_away_reason
);
341 if (sess
->server
->reconnect_away
)
342 reason
= sess
->server
->last_away_reason
;
344 /* must manage memory pointed to by random_line() */
345 reason
= random_line (prefs
.awayreason
);
347 sess
->server
->p_set_away (sess
->server
, reason
);
349 if (prefs
.show_away_message
)
351 snprintf (tbuf
, TBUFSIZE
, "me is away: %s", reason
);
352 for (list
= sess_list
; list
; list
= list
->next
)
354 /* am I the right server and not a dialog box */
355 if (((struct session
*) list
->data
)->server
== sess
->server
356 && ((struct session
*) list
->data
)->type
== SESS_CHANNEL
357 && ((struct session
*) list
->data
)->channel
[0])
359 handle_command ((session
*) list
->data
, tbuf
, TRUE
);
364 if (sess
->server
->last_away_reason
!= reason
)
366 if (sess
->server
->last_away_reason
)
367 free (sess
->server
->last_away_reason
);
369 if (reason
== word_eol
[2])
370 sess
->server
->last_away_reason
= strdup (reason
);
372 sess
->server
->last_away_reason
= reason
;
375 if (!sess
->server
->connected
)
376 sess
->server
->reconnect_away
= 1;
382 cmd_back (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
387 if (sess
->server
->is_away
)
389 sess
->server
->p_set_back (sess
->server
);
391 if (prefs
.show_away_message
)
393 gone
= time (NULL
) - sess
->server
->away_time
;
394 sprintf (tbuf
, "me is back (gone %.2d:%.2d:%.2d)", gone
/ 3600,
395 (gone
/ 60) % 60, gone
% 60);
396 for (list
= sess_list
; list
; list
= list
->next
)
398 /* am I the right server and not a dialog box */
399 if (((struct session
*) list
->data
)->server
== sess
->server
400 && ((struct session
*) list
->data
)->type
== SESS_CHANNEL
401 && ((struct session
*) list
->data
)->channel
[0])
403 handle_command ((session
*) list
->data
, tbuf
, TRUE
);
410 PrintText (sess
, _("Already marked back.\n"));
413 if (sess
->server
->last_away_reason
)
414 free (sess
->server
->last_away_reason
);
415 sess
->server
->last_away_reason
= NULL
;
421 ban (session
* sess
, char *tbuf
, char *mask
, char *bantypestr
, int deop
)
425 char *at
, *dot
, *lastdot
;
426 char username
[64], fullhost
[128], domain
[128], *mode
, *p2
;
427 server
*serv
= sess
->server
;
429 user
= userlist_find (sess
, mask
);
430 if (user
&& user
->hostname
) /* it's a nickname, let's find a proper ban mask */
442 mask
= user
->hostname
;
444 at
= strchr (mask
, '@'); /* FIXME: utf8 */
446 return; /* can't happen? */
449 if (mask
[0] == '~' || mask
[0] == '+' ||
450 mask
[0] == '=' || mask
[0] == '^' || mask
[0] == '-')
452 /* the ident is prefixed with something, we replace that sign with an * */
453 safe_strcpy (username
+1, mask
+1, sizeof (username
)-1);
455 } else if (at
- mask
< USERNAMELEN
)
457 /* we just add an * in the begining of the ident */
458 safe_strcpy (username
+1, mask
, sizeof (username
)-1);
462 /* ident might be too long, we just ban what it gives and add an * in the end */
463 safe_strcpy (username
, mask
, sizeof (username
));
466 safe_strcpy (fullhost
, at
+ 1, sizeof (fullhost
));
468 dot
= strchr (fullhost
, '.');
471 safe_strcpy (domain
, dot
, sizeof (domain
));
474 safe_strcpy (domain
, fullhost
, sizeof (domain
));
478 bantype
= atoi (bantypestr
);
480 bantype
= prefs
.bantype
;
483 if (inet_addr (fullhost
) != -1) /* "fullhost" is really a IP number */
485 lastdot
= strrchr (fullhost
, '.');
487 return; /* can't happen? */
490 strcpy (domain
, fullhost
);
496 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s.*", mode
, p2
, domain
);
500 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s", mode
, p2
, fullhost
);
504 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s.*", mode
, p2
, username
, domain
);
508 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s", mode
, p2
, username
, fullhost
);
516 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@*%s", mode
, p2
, domain
);
520 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s", mode
, p2
, fullhost
);
524 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@*%s", mode
, p2
, username
, domain
);
528 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s", mode
, p2
, username
, fullhost
);
535 snprintf (tbuf
, TBUFSIZE
, "+b %s", mask
);
537 serv
->p_mode (serv
, sess
->channel
, tbuf
);
541 cmd_ban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
543 char *mask
= word
[2];
547 ban (sess
, tbuf
, mask
, word
[3], 0);
550 sess
->server
->p_mode (sess
->server
, sess
->channel
, "+b"); /* banlist */
557 cmd_unban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
559 /* Allow more than one mask in /unban -- tvk */
568 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'b', 0);
576 cmd_chanopt (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
579 return chanopt_command (sess
, tbuf
, word
, word_eol
);
583 cmd_charset (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
585 server
*serv
= sess
->server
;
586 const char *locale
= NULL
;
589 if (strcmp (word
[2], "-quiet") == 0)
592 if (!word
[2 + offset
][0])
594 g_get_charset (&locale
);
595 PrintTextf (sess
, "Current charset: %s\n",
596 serv
->encoding
? serv
->encoding
: locale
);
600 if (servlist_check_encoding (word
[2 + offset
]))
602 server_set_encoding (serv
, word
[2 + offset
]);
604 PrintTextf (sess
, "Charset changed to: %s\n", word
[2 + offset
]);
607 PrintTextf (sess
, "\0034Unknown charset:\017 %s\n", word
[2 + offset
]);
614 cmd_clear (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
616 GSList
*list
= sess_list
;
617 char *reason
= word_eol
[2];
619 if (strcasecmp (reason
, "HISTORY") == 0)
621 history_free (&sess
->history
);
625 if (strncasecmp (reason
, "all", 3) == 0)
630 if (!sess
->nick_said
)
631 fe_text_clear (list
->data
, 0);
637 if (reason
[0] != '-' && !isdigit (reason
[0]) && reason
[0] != 0)
640 fe_text_clear (sess
, atoi (reason
));
645 cmd_close (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
649 if (strcmp (word
[2], "-m") == 0)
656 if (sess
->type
== SESS_DIALOG
)
657 fe_close_window (sess
);
662 sess
->quitreason
= word_eol
[2];
663 fe_close_window (sess
);
670 cmd_ctcp (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
676 char *msg
= word_eol
[3];
679 unsigned char *cmd
= (unsigned char *)msg
;
681 /* make the first word upper case (as per RFC) */
684 if (*cmd
== ' ' || *cmd
== 0)
686 mbl
= g_utf8_skip
[*cmd
];
688 *cmd
= toupper (*cmd
);
692 sess
->server
->p_ctcp (sess
->server
, to
, msg
);
694 EMIT_SIGNAL (XP_TE_CTCPSEND
, sess
, to
, msg
, NULL
, NULL
, 0);
703 cmd_country (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
705 char *code
= word
[2];
709 if (strcmp (code
, "-s") == 0)
711 country_search (word
[3], sess
, (void *)PrintTextf
);
715 /* search, but forgot the -s */
716 if (strchr (code
, '*'))
718 country_search (code
, sess
, (void *)PrintTextf
);
722 sprintf (tbuf
, "%s = %s\n", code
, country (code
));
723 PrintText (sess
, tbuf
);
730 cmd_cycle (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
732 char *key
= sess
->channelkey
;
733 char *chan
= word
[2];
735 chan
= sess
->channel
;
736 if (*chan
&& sess
->type
== SESS_CHANNEL
)
738 sess
->server
->p_cycle (sess
->server
, chan
, key
);
745 cmd_dcc (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
749 char *type
= word
[2];
752 if (!strcasecmp (type
, "HELP"))
754 if (!strcasecmp (type
, "CLOSE"))
756 if (*word
[3] && *word
[4])
759 if (!strcasecmp (word
[3], "SEND"))
761 dcc
= find_dcc (word
[4], word
[5], TYPE_SEND
);
762 dcc_abort (sess
, dcc
);
765 if (!strcasecmp (word
[3], "GET"))
767 dcc
= find_dcc (word
[4], word
[5], TYPE_RECV
);
768 dcc_abort (sess
, dcc
);
771 if (!strcasecmp (word
[3], "CHAT"))
773 dcc
= find_dcc (word
[4], "", TYPE_CHATRECV
);
775 dcc
= find_dcc (word
[4], "", TYPE_CHATSEND
);
776 dcc_abort (sess
, dcc
);
784 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
791 if ((!strcasecmp (type
, "CHAT")) || (!strcasecmp (type
, "PCHAT")))
793 char *nick
= word
[3];
794 int passive
= (!strcasecmp(type
, "PCHAT")) ? 1 : 0;
796 dcc_chat (sess
, nick
, passive
);
799 if (!strcasecmp (type
, "LIST"))
801 dcc_show_list (sess
);
804 if (!strcasecmp (type
, "GET"))
806 char *nick
= word
[3];
807 char *file
= word
[4];
811 dcc_get_nick (sess
, nick
);
814 dcc
= find_dcc (nick
, file
, TYPE_RECV
);
818 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
822 if ((!strcasecmp (type
, "SEND")) || (!strcasecmp (type
, "PSEND")))
826 int passive
= (!strcasecmp(type
, "PSEND")) ? 1 : 0;
832 maxcps
= prefs
.dcc_max_send_cps
;
833 if (!strncasecmp(nick
, "-maxcps=", 8))
835 maxcps
= atoi(nick
+ 8);
847 fe_dcc_send_filereq (sess
, nick
, maxcps
, passive
);
853 dcc_send (sess
, nick
, file
, maxcps
, passive
);
865 dcc_show_list (sess
);
870 cmd_debug (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
874 GSList
*list
= sess_list
;
876 PrintText (sess
, "Session T Channel WaitChan WillChan Server\n");
879 s
= (struct session
*) list
->data
;
880 sprintf (tbuf
, "%p %1x %-10.10s %-10.10s %-10.10s %p\n",
881 s
, s
->type
, s
->channel
, s
->waitchannel
,
882 s
->willjoinchannel
, s
->server
);
883 PrintText (sess
, tbuf
);
888 PrintText (sess
, "Server Sock Name\n");
891 v
= (struct server
*) list
->data
;
892 sprintf (tbuf
, "%p %-5d %s\n",
893 v
, v
->sok
, v
->servername
);
894 PrintText (sess
, tbuf
);
899 "\nfront_session: %p\n"
900 "current_tab: %p\n\n",
901 sess
->server
->front_session
, current_tab
);
902 PrintText (sess
, tbuf
);
904 sprintf (tbuf
, "current mem: %d\n\n", current_mem_usage
);
905 PrintText (sess
, tbuf
);
906 #endif /* !MEMORY_DEBUG */
912 cmd_delbutton (struct session
*sess
, char *tbuf
, char *word
[],
917 if (sess
->type
== SESS_DIALOG
)
919 if (list_delentry (&dlgbutton_list
, word
[2]))
920 fe_dlgbuttons_update (sess
);
923 if (list_delentry (&button_list
, word
[2]))
924 fe_buttons_update (sess
);
932 cmd_dehop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
942 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'h', 0);
950 cmd_deop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
960 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'o', 0);
977 mdehop_cb (struct User
*user
, multidata
*data
)
979 if (user
->hop
&& !user
->me
)
981 data
->nicks
[data
->i
] = user
->nick
;
988 cmd_mdehop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
990 char **nicks
= malloc (sizeof (char *) * sess
->hops
);
995 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mdehop_cb
, &data
);
996 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '-', 'h', 0);
1003 mdeop_cb (struct User
*user
, multidata
*data
)
1005 if (user
->op
&& !user
->me
)
1007 data
->nicks
[data
->i
] = user
->nick
;
1014 cmd_mdeop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1016 char **nicks
= malloc (sizeof (char *) * sess
->ops
);
1021 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mdeop_cb
, &data
);
1022 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '-', 'o', 0);
1028 GSList
*menu_list
= NULL
;
1031 menu_free (menu_entry
*me
)
1047 /* strings equal? but ignore underscores */
1050 menu_streq (const char *s1
, const char *s2
, int def
)
1052 /* for separators */
1053 if (s1
== NULL
&& s2
== NULL
)
1055 if (s1
== NULL
|| s2
== NULL
)
1074 menu_entry_find (char *path
, char *label
)
1083 if (!strcmp (path
, me
->path
))
1085 if (me
->label
&& label
&& !strcmp (label
, me
->label
))
1094 menu_del_children (char *path
, char *label
)
1096 GSList
*list
, *next
;
1103 snprintf (buf
, sizeof (buf
), "%s/%s", path
, label
);
1105 snprintf (buf
, sizeof (buf
), "%s", label
);
1112 if (!menu_streq (buf
, me
->path
, 0))
1114 menu_list
= g_slist_remove (menu_list
, me
);
1122 menu_del (char *path
, char *label
)
1131 if (!menu_streq (me
->label
, label
, 1) && !menu_streq (me
->path
, path
, 1))
1133 menu_list
= g_slist_remove (menu_list
, me
);
1136 /* delete this item's children, if any */
1137 menu_del_children (path
, label
);
1147 menu_is_mainmenu_root (char *path
, gint16
*offset
)
1149 static const char *menus
[] = {"\x4$TAB","\x5$TRAY","\x4$URL","\x5$NICK","\x5$CHAN"};
1152 for (i
= 0; i
< 5; i
++)
1154 if (!strncmp (path
, menus
[i
] + 1, menus
[i
][0]))
1156 *offset
= menus
[i
][0] + 1; /* number of bytes to offset the root */
1157 return 0; /* is not main menu */
1162 return 1; /* is main menu */
1166 menu_add (char *path
, char *label
, char *cmd
, char *ucmd
, int pos
, int state
, int markup
, int enable
, int mod
, int key
, char *group
, char *icon
)
1170 /* already exists? */
1171 me
= menu_entry_find (path
, label
);
1176 me
->enable
= enable
;
1177 fe_menu_update (me
);
1181 me
= malloc (sizeof (menu_entry
));
1184 me
->is_main
= menu_is_mainmenu_root (path
, &me
->root_offset
);
1186 me
->markup
= markup
;
1187 me
->enable
= enable
;
1189 me
->path
= strdup (path
);
1197 me
->label
= strdup (label
);
1199 me
->cmd
= strdup (cmd
);
1201 me
->ucmd
= strdup (ucmd
);
1203 me
->group
= strdup (group
);
1205 me
->icon
= strdup (icon
);
1207 menu_list
= g_slist_append (menu_list
, me
);
1208 label
= fe_menu_add (me
);
1211 /* FE has given us a stripped label */
1213 me
->label
= strdup (label
);
1214 g_free (label
); /* this is from pango */
1219 cmd_menu (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1234 if (!word
[2][0] || !word
[3][0])
1237 /* -eX enabled or not? */
1238 if (word
[idx
][0] == '-' && word
[idx
][1] == 'e')
1240 enable
= atoi (word
[idx
] + 2);
1245 if (word
[idx
][0] == '-' && word
[idx
][1] == 'i')
1247 icon
= word
[idx
] + 2;
1251 /* -k<mod>,<key> key binding */
1252 if (word
[idx
][0] == '-' && word
[idx
][1] == 'k')
1254 char *comma
= strchr (word
[idx
], ',');
1257 mod
= atoi (word
[idx
] + 2);
1258 key
= atoi (comma
+ 1);
1262 /* -m to specify PangoMarkup language */
1263 if (word
[idx
][0] == '-' && word
[idx
][1] == 'm')
1269 /* -pX to specify menu position */
1270 if (word
[idx
][0] == '-' && word
[idx
][1] == 'p')
1272 pos
= atoi (word
[idx
] + 2);
1276 /* -rSTATE,GROUP to specify a radio item */
1277 if (word
[idx
][0] == '-' && word
[idx
][1] == 'r')
1279 state
= atoi (word
[idx
] + 2);
1280 group
= word
[idx
] + 4;
1284 /* -tX to specify toggle item with default state */
1285 if (word
[idx
][0] == '-' && word
[idx
][1] == 't')
1287 state
= atoi (word
[idx
] + 2);
1292 if (word
[idx
+1][0] == 0)
1296 path_part (word
[idx
+1], tbuf
, 512);
1297 len
= strlen (tbuf
);
1301 /* the name of the item */
1302 label
= file_part (word
[idx
+ 1]);
1303 if (label
[0] == '-' && label
[1] == 0)
1304 label
= NULL
; /* separator */
1308 char *p
; /* to force pango closing tags through */
1309 for (p
= label
; *p
; p
++)
1314 if (!strcasecmp (word
[idx
], "ADD"))
1318 menu_add (tbuf
, label
, word
[idx
+ 2], word
[idx
+ 3], pos
, state
, markup
, enable
, mod
, key
, NULL
, NULL
);
1321 if (word
[idx
+ 2][0])
1322 menu_add (tbuf
, label
, word
[idx
+ 2], NULL
, pos
, state
, markup
, enable
, mod
, key
, group
, icon
);
1324 menu_add (tbuf
, label
, NULL
, NULL
, pos
, state
, markup
, enable
, mod
, key
, group
, icon
);
1329 if (!strcasecmp (word
[idx
], "DEL"))
1331 menu_del (tbuf
, label
);
1339 mkick_cb (struct User
*user
, multidata
*data
)
1341 if (!user
->op
&& !user
->me
)
1342 data
->sess
->server
->p_kick (data
->sess
->server
, data
->sess
->channel
, user
->nick
, data
->reason
);
1347 mkickops_cb (struct User
*user
, multidata
*data
)
1349 if (user
->op
&& !user
->me
)
1350 data
->sess
->server
->p_kick (data
->sess
->server
, data
->sess
->channel
, user
->nick
, data
->reason
);
1355 cmd_mkick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1360 data
.reason
= word_eol
[2];
1361 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mkickops_cb
, &data
);
1362 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mkick_cb
, &data
);
1368 cmd_devoice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1378 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'v', 0);
1386 cmd_discon (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1388 sess
->server
->disconnect (sess
, TRUE
, -1);
1393 cmd_dns (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1395 char *nick
= word
[2];
1400 if (strchr (nick
, '.') == NULL
)
1402 user
= userlist_find (sess
, nick
);
1403 if (user
&& user
->hostname
)
1405 do_dns (sess
, user
->nick
, user
->hostname
);
1408 sess
->server
->p_get_ip (sess
->server
, nick
);
1409 sess
->server
->doing_dns
= TRUE
;
1413 snprintf (tbuf
, TBUFSIZE
, "exec -d %s %s", prefs
.dnsprogram
, nick
);
1414 handle_command (sess
, tbuf
, FALSE
);
1422 cmd_echo (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1424 PrintText (sess
, word_eol
[2]);
1429 exec_check_process (struct session
*sess
)
1433 if (sess
->running_exec
== NULL
)
1435 val
= waitpid (sess
->running_exec
->childpid
, NULL
, WNOHANG
);
1436 if (val
== -1 || val
> 0)
1438 close (sess
->running_exec
->myfd
);
1439 fe_input_remove (sess
->running_exec
->iotag
);
1440 free (sess
->running_exec
);
1441 sess
->running_exec
= NULL
;
1446 cmd_execs (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1450 exec_check_process (sess
);
1451 if (sess
->running_exec
== NULL
)
1453 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1456 r
= kill (sess
->running_exec
->childpid
, SIGSTOP
);
1458 PrintText (sess
, "Error in kill(2)\n");
1464 cmd_execc (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1468 exec_check_process (sess
);
1469 if (sess
->running_exec
== NULL
)
1471 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1474 r
= kill (sess
->running_exec
->childpid
, SIGCONT
);
1476 PrintText (sess
, "Error in kill(2)\n");
1482 cmd_execk (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1486 exec_check_process (sess
);
1487 if (sess
->running_exec
== NULL
)
1489 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1492 if (strcmp (word
[2], "-9") == 0)
1493 r
= kill (sess
->running_exec
->childpid
, SIGKILL
);
1495 r
= kill (sess
->running_exec
->childpid
, SIGTERM
);
1497 PrintText (sess
, "Error in kill(2)\n");
1502 /* OS/2 Can't have the /EXECW command because it uses pipe(2) not socketpair
1503 and thus it is simplex --AGL */
1505 cmd_execw (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1509 exec_check_process (sess
);
1510 if (sess
->running_exec
== NULL
)
1512 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1515 len
= strlen(word_eol
[2]);
1516 temp
= malloc(len
+ 2);
1517 sprintf(temp
, "%s\n", word_eol
[2]);
1518 PrintText(sess
, temp
);
1519 write(sess
->running_exec
->myfd
, temp
, len
+ 1);
1525 /* convert ANSI escape color codes to mIRC codes */
1527 static short escconv
[] =
1528 /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 */
1529 { 1,4,3,5,2,10,6,1, 1,7,9,8,12,11,13,1 };
1532 exec_handle_colors (char *buf
, int len
)
1536 int i
= 0, j
= 0, k
= 0, firstn
= 0, col
, colf
= 0, colb
= 0;
1537 int esc
= FALSE
, backc
= FALSE
, bold
= FALSE
;
1539 /* any escape codes in this text? */
1540 if (strchr (buf
, 27) == 0)
1543 nbuf
= malloc (len
+ 1);
1559 firstn
= atoi (numb
);
1569 if (buf
[i
] >= 'A' && buf
[i
] <= 'z')
1574 if (k
== 0 || (numb
[0] == '0' && k
== 1))
1589 if (firstn
>= 30 && firstn
<= 37)
1598 if (col
>= 30 && col
<= 37)
1606 colb
= escconv
[colb
% 14];
1607 colf
= escconv
[colf
% 14];
1608 j
+= sprintf (&nbuf
[j
], "\003%d,%02d", colf
, colb
);
1611 colf
= escconv
[colf
% 14];
1612 j
+= sprintf (&nbuf
[j
], "\003%02d", colf
);
1620 if (isdigit ((unsigned char) buf
[i
]) && k
< (sizeof (numb
) - 1))
1628 norm
: nbuf
[j
] = buf
[i
];
1636 memcpy (buf
, nbuf
, j
+ 1);
1641 exec_data (GIOChannel
*source
, GIOCondition condition
, struct nbexec
*s
)
1643 char *buf
, *readpos
, *rest
;
1649 /* append new data to buffered incomplete line */
1650 buf
= malloc(len
+ 2050);
1651 memcpy(buf
, s
->linebuf
, len
);
1652 readpos
= buf
+ len
;
1657 readpos
= buf
= malloc(2050);
1659 rd
= read (sok
, readpos
, 2048);
1662 /* The process has died */
1663 kill(s
->childpid
, SIGKILL
);
1666 exec_handle_colors(buf
, len
);
1669 /* must turn off auto-completion temporarily */
1670 unsigned int old
= prefs
.nickcompletion
;
1671 prefs
.nickcompletion
= 0;
1672 handle_multiline (s
->sess
, buf
, FALSE
, TRUE
);
1673 prefs
.nickcompletion
= old
;
1676 PrintText (s
->sess
, buf
);
1679 waitpid (s
->childpid
, NULL
, 0);
1680 s
->sess
->running_exec
= NULL
;
1681 fe_input_remove (s
->iotag
);
1689 rest
= memrchr(buf
, '\n', len
);
1695 s
->buffill
= len
- (rest
- buf
); /* = strlen(rest) */
1696 s
->linebuf
= malloc(s
->buffill
+ 1);
1697 memcpy(s
->linebuf
, rest
, s
->buffill
);
1699 len
-= s
->buffill
; /* possibly 0 */
1705 exec_handle_colors (buf
, len
);
1707 handle_multiline (s
->sess
, buf
, FALSE
, TRUE
);
1709 PrintText (s
->sess
, buf
);
1717 cmd_exec (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1719 int tochannel
= FALSE
;
1720 char *cmd
= word_eol
[2];
1721 int fds
[2], pid
= 0;
1728 exec_check_process (sess
);
1729 if (sess
->running_exec
!= NULL
)
1731 EMIT_SIGNAL (XP_TE_ALREADYPROCESS
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1735 if (!strcmp (word
[2], "-d"))
1742 else if (!strcmp (word
[2], "-o"))
1752 if (access ("/bin/sh", X_OK
) != 0)
1754 fe_message (_("I need /bin/sh to run!\n"), FE_MSG_ERROR
);
1759 if (socketpair (PF_UNIX
, SOCK_STREAM
, 0, fds
) == -1)
1761 PrintText (sess
, "socketpair(2) failed\n");
1764 s
= (struct nbexec
*) malloc (sizeof (struct nbexec
));
1765 memset(s
, 0, sizeof(*s
));
1767 s
->tochannel
= tochannel
;
1773 /* This is the child's context */
1777 /* Close parent's end of pipe */
1779 /* Copy the child end of the pipe to stdout and stderr */
1782 /* Also copy it to stdin so we can write to it */
1784 /* Now close all open file descriptors except stdin, stdout and stderr */
1785 for (fd
= 3; fd
< 1024; fd
++) close(fd
);
1786 /* Now we call /bin/sh to run our cmd ; made it more friendly -DC1 */
1789 execl ("/bin/sh", "sh", "-c", cmd
, NULL
);
1795 my_poptParseArgvString (cmd
, &argc
, &argv
);
1796 execvp (argv
[0], argv
);
1798 /* not reached unless error */
1799 /*printf("exec error\n");*/
1806 /* Parent context, fork() failed */
1808 PrintText (sess
, "Error in fork(2)\n");
1816 s
->iotag
= fe_input_add (s
->myfd
, FIA_READ
|FIA_EX
, exec_data
, s
);
1817 sess
->running_exec
= s
;
1825 cmd_flushq (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1827 sprintf (tbuf
, "Flushing server send queue, %d bytes.\n", sess
->server
->sendq_len
);
1828 PrintText (sess
, tbuf
);
1829 sess
->server
->flush_queue (sess
->server
);
1834 cmd_quit (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1837 sess
->quitreason
= word_eol
[2];
1838 sess
->server
->disconnect (sess
, TRUE
, -1);
1839 sess
->quitreason
= NULL
;
1844 cmd_gate (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1846 char *server_name
= word
[2];
1847 server
*serv
= sess
->server
;
1850 char *port
= word
[3];
1852 serv
->use_ssl
= FALSE
;
1854 server_fill_her_up (serv
);
1856 serv
->connect (serv
, server_name
, atoi (port
), TRUE
);
1858 serv
->connect (serv
, server_name
, 23, TRUE
);
1871 get_int_cb (int cancel
, int val
, getvalinfo
*info
)
1877 snprintf (buf
, sizeof (buf
), "%s %d", info
->cmd
, val
);
1878 if (is_session (info
->sess
))
1879 handle_command (info
->sess
, buf
, FALSE
);
1887 cmd_getint (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1894 info
= malloc (sizeof (*info
));
1895 info
->cmd
= strdup (word
[3]);
1898 fe_get_int (word
[4], atoi (word
[2]), get_int_cb
, info
);
1904 get_file_cb (char *cmd
, char *file
)
1906 char buf
[1024 + 128];
1908 /* execute the command once per file, then once more with
1912 snprintf (buf
, sizeof (buf
), "%s %s", cmd
, file
);
1913 handle_command (current_sess
, buf
, FALSE
);
1917 handle_command (current_sess
, cmd
, FALSE
);
1923 cmd_getfile (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1931 if (!strcmp (word
[2], "-folder"))
1933 flags
|= FRF_CHOOSEFOLDER
;
1937 if (!strcmp (word
[idx
], "-multi"))
1939 flags
|= FRF_MULTIPLE
;
1943 if (!strcmp (word
[idx
], "-save"))
1949 fe_get_file (word
[idx
+1], word
[idx
+2], (void *)get_file_cb
, strdup (word
[idx
]), flags
);
1955 get_str_cb (int cancel
, char *val
, getvalinfo
*info
)
1961 snprintf (buf
, sizeof (buf
), "%s %s", info
->cmd
, val
);
1962 if (is_session (info
->sess
))
1963 handle_command (info
->sess
, buf
, FALSE
);
1971 cmd_getstr (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1978 info
= malloc (sizeof (*info
));
1979 info
->cmd
= strdup (word
[3]);
1982 fe_get_str (word
[4], word
[2], get_str_cb
, info
);
1988 cmd_ghost (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1993 sess
->server
->p_ns_ghost (sess
->server
, word
[2], word
[3]);
1998 cmd_gui (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2000 switch (str_ihash (word
[2]))
2002 case 0x058b836e: fe_ctrl_gui (sess
, 8, 0); break; /* APPLY */
2003 case 0xac1eee45: fe_ctrl_gui (sess
, 7, 2); break; /* ATTACH */
2004 case 0x05a72f63: fe_ctrl_gui (sess
, 4, atoi (word
[3])); break; /* COLOR */
2005 case 0xb06a1793: fe_ctrl_gui (sess
, 7, 1); break; /* DETACH */
2006 case 0x05cfeff0: fe_ctrl_gui (sess
, 3, 0); break; /* FLASH */
2007 case 0x05d154d8: fe_ctrl_gui (sess
, 2, 0); break; /* FOCUS */
2008 case 0x0030dd42: fe_ctrl_gui (sess
, 0, 0); break; /* HIDE */
2009 case 0x61addbe3: fe_ctrl_gui (sess
, 5, 0); break; /* ICONIFY */
2010 case 0xc0851aaa: fe_message (word
[3], FE_MSG_INFO
|FE_MSG_MARKUP
); break; /* MSGBOX */
2011 case 0x0035dafd: fe_ctrl_gui (sess
, 1, 0); break; /* SHOW */
2012 case 0x0033155f: /* MENU */
2013 if (!strcasecmp (word
[3], "TOGGLE"))
2014 fe_ctrl_gui (sess
, 6, 0);
2033 show_help_line (session
*sess
, help_list
*hl
, char *name
, char *usage
)
2038 if (name
[0] == '.') /* hidden command? */
2041 if (hl
->longfmt
) /* long format for /HELP -l */
2043 if (!usage
|| usage
[0] == 0)
2044 PrintTextf (sess
, " \0034%s\003 :\n", name
);
2046 PrintTextf (sess
, " \0034%s\003 : %s\n", name
, _(usage
));
2050 /* append the name into buffer, but convert to uppercase */
2051 len
= strlen (hl
->buf
);
2055 hl
->buf
[len
] = toupper ((unsigned char) *p
);
2065 strcat (hl
->buf
, "\n");
2066 PrintText (sess
, hl
->buf
);
2072 /* append some spaces after the command name */
2073 max
= strlen (name
);
2077 for (j
= 0; j
< max
; j
++)
2088 cmd_help (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2090 int i
= 0, longfmt
= 0;
2096 if (*helpcmd
&& strcmp (helpcmd
, "-l") == 0)
2099 if (*helpcmd
&& !longfmt
)
2101 help (sess
, tbuf
, helpcmd
, FALSE
);
2105 char *buf
= malloc (4096);
2108 hl
.longfmt
= longfmt
;
2111 PrintTextf (sess
, "\n%s\n\n", _("Commands Available:"));
2117 while (xc_cmds
[i
].name
)
2119 show_help_line (sess
, &hl
, xc_cmds
[i
].name
, xc_cmds
[i
].help
);
2123 PrintText (sess
, buf
);
2125 PrintTextf (sess
, "\n%s\n\n", _("User defined commands:"));
2131 list
= command_list
;
2135 show_help_line (sess
, &hl
, pop
->name
, pop
->cmd
);
2139 PrintText (sess
, buf
);
2141 PrintTextf (sess
, "\n%s\n\n", _("Plugin defined commands:"));
2147 plugin_command_foreach (sess
, &hl
, (void *)show_help_line
);
2149 PrintText (sess
, buf
);
2152 PrintTextf (sess
, "\n%s\n\n", _("Type /HELP <command> for more information, or /HELP -l"));
2158 cmd_id (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2162 sess
->server
->p_ns_identify (sess
->server
, word
[2]);
2170 cmd_ignore (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2179 ignore_showlist (sess
);
2194 if (strchr (mask
, '?') == NULL
&&
2195 strchr (mask
, '*') == NULL
)
2198 snprintf (tbuf
, TBUFSIZE
, "%s!*@*", word
[2]);
2201 i
= ignore_add (mask
, type
);
2207 EMIT_SIGNAL (XP_TE_IGNOREADD
, sess
, mask
, NULL
, NULL
, NULL
, 0);
2209 case 2: /* old ignore changed */
2210 EMIT_SIGNAL (XP_TE_IGNORECHANGE
, sess
, mask
, NULL
, NULL
, NULL
, 0);
2214 if (!strcasecmp (word
[i
], "UNIGNORE"))
2216 else if (!strcasecmp (word
[i
], "ALL"))
2217 type
|= IG_PRIV
| IG_NOTI
| IG_CHAN
| IG_CTCP
| IG_INVI
| IG_DCC
;
2218 else if (!strcasecmp (word
[i
], "PRIV"))
2220 else if (!strcasecmp (word
[i
], "NOTI"))
2222 else if (!strcasecmp (word
[i
], "CHAN"))
2224 else if (!strcasecmp (word
[i
], "CTCP"))
2226 else if (!strcasecmp (word
[i
], "INVI"))
2228 else if (!strcasecmp (word
[i
], "QUIET"))
2230 else if (!strcasecmp (word
[i
], "NOSAVE"))
2232 else if (!strcasecmp (word
[i
], "DCC"))
2236 sprintf (tbuf
, _("Unknown arg '%s' ignored."), word
[i
]);
2237 PrintText (sess
, tbuf
);
2244 cmd_invite (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2249 sess
->server
->p_invite (sess
->server
, word
[3], word
[2]);
2251 sess
->server
->p_invite (sess
->server
, sess
->channel
, word
[2]);
2256 cmd_join (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2258 char *chan
= word
[2];
2261 char *po
, *pass
= word
[3];
2262 sess
->server
->p_join (sess
->server
, chan
, pass
);
2263 if (sess
->channel
[0] == 0 && sess
->waitchannel
[0])
2265 po
= strchr (chan
, ',');
2268 safe_strcpy (sess
->waitchannel
, chan
, CHANLEN
);
2276 cmd_kick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2278 char *nick
= word
[2];
2279 char *reason
= word_eol
[3];
2282 sess
->server
->p_kick (sess
->server
, sess
->channel
, nick
, reason
);
2289 cmd_kickban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2291 char *nick
= word
[2];
2292 char *reason
= word_eol
[3];
2297 /* if the reason is a 1 digit number, treat it as a bantype */
2299 user
= userlist_find (sess
, nick
);
2301 if (isdigit ((unsigned char) reason
[0]) && reason
[1] == 0)
2303 ban (sess
, tbuf
, nick
, reason
, (user
&& user
->op
));
2306 ban (sess
, tbuf
, nick
, "", (user
&& user
->op
));
2308 sess
->server
->p_kick (sess
->server
, sess
->channel
, nick
, reason
);
2316 cmd_killall (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2323 cmd_lagcheck (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2330 lastlog (session
*sess
, char *search
, gboolean regexp
)
2332 session
*lastlog_sess
;
2334 if (!is_session (sess
))
2337 lastlog_sess
= find_dialog (sess
->server
, "(lastlog)");
2339 lastlog_sess
= new_ircwindow (sess
->server
, "(lastlog)", SESS_DIALOG
, 0);
2341 lastlog_sess
->lastlog_sess
= sess
;
2342 lastlog_sess
->lastlog_regexp
= regexp
; /* remember the search type */
2344 fe_text_clear (lastlog_sess
, 0);
2345 fe_lastlog (sess
, lastlog_sess
, search
, regexp
);
2349 cmd_lastlog (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2353 if (!strcmp (word
[2], "-r"))
2354 lastlog (sess
, word_eol
[3], TRUE
);
2356 lastlog (sess
, word_eol
[2], FALSE
);
2364 cmd_list (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2366 sess
->server
->p_list_channels (sess
->server
, word_eol
[2], 1);
2372 load_perform_file (session
*sess
, char *file
)
2374 char tbuf
[1024 + 4];
2378 fp
= xchat_fopen_file (file
, "r", XOF_FULLPATH
);
2383 while (fgets (tbuf
, 1024, fp
))
2385 nl
= strchr (tbuf
, '\n');
2386 if (nl
== tbuf
) /* skip empty commands */
2390 if (tbuf
[0] == prefs
.cmdchar
[0])
2391 handle_command (sess
, tbuf
+ 1, TRUE
);
2393 handle_command (sess
, tbuf
, TRUE
);
2400 cmd_load (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2402 char *error
, *arg
, *file
;
2408 if (strcmp (word
[2], "-e") == 0)
2410 file
= expand_homedir (word
[3]);
2411 if (!load_perform_file (sess
, file
))
2413 PrintTextf (sess
, _("Cannot access %s\n"), file
);
2414 PrintText (sess
, errorstring (errno
));
2421 len
= strlen (word
[2]);
2422 if (len
> 3 && strcasecmp (".so", word
[2] + len
- 3) == 0)
2428 file
= expand_homedir (word
[2]);
2429 error
= plugin_load (sess
, file
, arg
);
2433 PrintText (sess
, error
);
2439 sprintf (tbuf
, "Unknown file type %s. Maybe you need to install the Perl or Python plugin?\n", word
[2]);
2440 PrintText (sess
, tbuf
);
2446 cmd_me (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2448 char *act
= word_eol
[2];
2453 if (sess
->type
== SESS_SERVER
)
2459 snprintf (tbuf
, TBUFSIZE
, "\001ACTION %s\001\r", act
);
2460 /* first try through DCC CHAT */
2461 if (dcc_write_chat (sess
->channel
, tbuf
))
2463 /* print it to screen */
2464 inbound_action (sess
, sess
->channel
, sess
->server
->nick
, "", act
, TRUE
, FALSE
);
2467 /* DCC CHAT failed, try through server */
2468 if (sess
->server
->connected
)
2470 sess
->server
->p_action (sess
->server
, sess
->channel
, act
);
2471 /* print it to screen */
2472 inbound_action (sess
, sess
->channel
, sess
->server
->nick
, "", act
, TRUE
, FALSE
);
2483 cmd_mode (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2485 /* +channel channels are dying, let those servers whine about modes.
2486 * return info about current channel if available and no info is given */
2487 if ((*word
[2] == '+') || (*word
[2] == 0) || (!is_channel(sess
->server
, word
[2]) &&
2488 !(rfc_casecmp(sess
->server
->nick
, word
[2]) == 0)))
2490 if(sess
->channel
[0] == 0)
2492 sess
->server
->p_mode (sess
->server
, sess
->channel
, word_eol
[2]);
2495 sess
->server
->p_mode (sess
->server
, word
[2], word_eol
[3]);
2500 mop_cb (struct User
*user
, multidata
*data
)
2504 data
->nicks
[data
->i
] = user
->nick
;
2511 cmd_mop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2513 char **nicks
= malloc (sizeof (char *) * (sess
->total
- sess
->ops
));
2518 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mop_cb
, &data
);
2519 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '+', 'o', 0);
2527 cmd_msg (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2529 char *nick
= word
[2];
2530 char *msg
= word_eol
[3];
2531 struct session
*newsess
;
2537 if (strcmp (nick
, ".") == 0)
2538 { /* /msg the last nick /msg'ed */
2539 if (sess
->lastnick
[0])
2540 nick
= sess
->lastnick
;
2543 safe_strcpy (sess
->lastnick
, nick
, NICKLEN
); /* prime the last nick memory */
2549 if (!dcc_write_chat (nick
, msg
))
2551 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
2556 if (!sess
->server
->connected
)
2561 sess
->server
->p_message (sess
->server
, nick
, msg
);
2563 newsess
= find_dialog (sess
->server
, nick
);
2565 newsess
= find_channel (sess
->server
, nick
);
2567 inbound_chanmsg (newsess
->server
, NULL
, newsess
->channel
,
2568 newsess
->server
->nick
, msg
, TRUE
, FALSE
);
2571 /* mask out passwords */
2572 if (strcasecmp (nick
, "nickserv") == 0 &&
2573 strncasecmp (msg
, "identify ", 9) == 0)
2574 msg
= "identify ****";
2575 EMIT_SIGNAL (XP_TE_MSGSEND
, sess
, nick
, msg
, NULL
, NULL
, 0);
2585 cmd_names (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2588 sess
->server
->p_names (sess
->server
, word
[2]);
2590 sess
->server
->p_names (sess
->server
, sess
->channel
);
2595 cmd_nctcp (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2599 sess
->server
->p_nctcp (sess
->server
, word
[2], word_eol
[3]);
2606 cmd_newserver (struct session
*sess
, char *tbuf
, char *word
[],
2609 if (strcmp (word
[2], "-noconnect") == 0)
2611 new_ircwindow (NULL
, word
[3], SESS_SERVER
, 0);
2615 sess
= new_ircwindow (NULL
, NULL
, SESS_SERVER
, 0);
2616 cmd_server (sess
, tbuf
, word
, word_eol
);
2621 cmd_nick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2623 char *nick
= word
[2];
2626 if (sess
->server
->connected
)
2627 sess
->server
->p_change_nick (sess
->server
, nick
);
2629 inbound_newnick (sess
->server
, sess
->server
->nick
, nick
, TRUE
);
2636 cmd_notice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2638 if (*word
[2] && *word_eol
[3])
2640 sess
->server
->p_notice (sess
->server
, word
[2], word_eol
[3]);
2641 EMIT_SIGNAL (XP_TE_NOTICESEND
, sess
, word
[2], word_eol
[3], NULL
, NULL
, 0);
2648 cmd_notify (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2655 if (strcmp (word
[2], "-n") == 0) /* comma sep network list */
2666 if (notify_deluser (word
[i
]))
2668 EMIT_SIGNAL (XP_TE_DELNOTIFY
, sess
, word
[i
], NULL
, NULL
, NULL
, 0);
2672 if (net
&& strcmp (net
, "ASK") == 0)
2673 fe_notify_ask (word
[i
], NULL
);
2676 notify_adduser (word
[i
], net
);
2677 EMIT_SIGNAL (XP_TE_ADDNOTIFY
, sess
, word
[i
], NULL
, NULL
, NULL
, 0);
2681 notify_showlist (sess
);
2686 cmd_op (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2696 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'o', 0);
2704 cmd_part (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2706 char *chan
= word
[2];
2707 char *reason
= word_eol
[3];
2709 chan
= sess
->channel
;
2710 if ((*chan
) && is_channel (sess
->server
, chan
))
2714 server_sendpart (sess
->server
, chan
, reason
);
2721 cmd_ping (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2723 char timestring
[64];
2727 tim
= make_ping_time ();
2729 snprintf (timestring
, sizeof (timestring
), "%lu", tim
);
2730 sess
->server
->p_ping (sess
->server
, to
, timestring
);
2736 open_query (server
*serv
, char *nick
, gboolean focus_existing
)
2740 sess
= find_dialog (serv
, nick
);
2742 new_ircwindow (serv
, nick
, SESS_DIALOG
, 1);
2743 else if (focus_existing
)
2744 fe_ctrl_gui (sess
, 2, 0); /* bring-to-front */
2748 cmd_query (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2750 char *nick
= word
[2];
2751 gboolean focus
= TRUE
;
2753 if (strcmp (word
[2], "-nofocus") == 0)
2759 if (*nick
&& !is_channel (sess
->server
, nick
))
2761 open_query (sess
->server
, nick
, focus
);
2768 cmd_quote (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2770 char *raw
= word_eol
[2];
2772 return sess
->server
->p_raw (sess
->server
, raw
);
2776 cmd_reconnect (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2778 int tmp
= prefs
.recon_delay
;
2780 server
*serv
= sess
->server
;
2782 prefs
.recon_delay
= 0;
2784 if (!strcasecmp (word
[2], "ALL"))
2790 if (serv
->connected
)
2791 serv
->auto_reconnect (serv
, TRUE
, -1);
2795 /* If it isn't "ALL" and there is something
2796 there it *should* be a server they are trying to connect to*/
2801 int use_ssl
= FALSE
;
2803 if (strcmp (word
[2], "-ssl") == 0)
2806 offset
++; /* args move up by 1 word */
2808 serv
->use_ssl
= use_ssl
;
2809 serv
->accept_invalid_cert
= TRUE
;
2812 if (*word
[4+offset
])
2813 safe_strcpy (serv
->password
, word
[4+offset
], sizeof (serv
->password
));
2814 if (*word
[3+offset
])
2815 serv
->port
= atoi (word
[3+offset
]);
2816 safe_strcpy (serv
->hostname
, word
[2+offset
], sizeof (serv
->hostname
));
2817 serv
->auto_reconnect (serv
, TRUE
, -1);
2821 serv
->auto_reconnect (serv
, TRUE
, -1);
2823 prefs
.recon_delay
= tmp
;
2829 cmd_recv (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2833 sess
->server
->p_inline (sess
->server
, word_eol
[2], strlen (word_eol
[2]));
2841 cmd_say (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2843 char *speech
= word_eol
[2];
2846 handle_say (sess
, speech
, FALSE
);
2853 cmd_send (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2857 struct sockaddr_in SAddr
;
2862 addr
= dcc_get_my_address ();
2865 /* use the one from our connected server socket */
2866 memset (&SAddr
, 0, sizeof (struct sockaddr_in
));
2867 len
= sizeof (SAddr
);
2868 getsockname (sess
->server
->sok
, (struct sockaddr
*) &SAddr
, &len
);
2869 addr
= SAddr
.sin_addr
.s_addr
;
2871 addr
= ntohl (addr
);
2873 if ((addr
& 0xffff0000) == 0xc0a80000 || /* 192.168.x.x */
2874 (addr
& 0xff000000) == 0x0a000000) /* 10.x.x.x */
2875 /* we got a private net address, let's PSEND or it'll fail */
2876 snprintf (tbuf
, 512, "DCC PSEND %s", word_eol
[2]);
2878 snprintf (tbuf
, 512, "DCC SEND %s", word_eol
[2]);
2880 handle_command (sess
, tbuf
, FALSE
);
2886 cmd_setcursor (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2892 if (word
[2][0] == '-' || word
[2][0] == '+')
2894 fe_set_inputbox_cursor (sess
, delta
, atoi (word
[2]));
2902 cmd_settab (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2906 strcpy (tbuf
, sess
->channel
);
2907 safe_strcpy (sess
->channel
, word_eol
[2], CHANLEN
);
2908 fe_set_channel (sess
);
2909 strcpy (sess
->channel
, tbuf
);
2916 cmd_settext (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2918 fe_set_inputbox_contents (sess
, word_eol
[2]);
2923 cmd_splay (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2927 sound_play (word
[2], FALSE
);
2935 parse_irc_url (char *url
, char *server_name
[], char *port
[], char *channel
[], int *use_ssl
)
2939 if (strncasecmp ("ircs://", url
, 7) == 0)
2942 *server_name
= url
+ 7;
2947 if (strncasecmp ("irc://", url
, 6) == 0)
2949 *server_name
= url
+ 6;
2953 /* check for port */
2954 co
= strchr (*server_name
, ':');
2961 /* check for channel - mirc style */
2962 co
= strchr (co
+ 1, '/');
2979 cmd_server (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2982 char *server_name
= NULL
;
2985 char *channel
= NULL
;
2986 int use_ssl
= FALSE
;
2988 server
*serv
= sess
->server
;
2991 /* BitchX uses -ssl, mIRC uses -e, let's support both */
2992 if (strcmp (word
[2], "-ssl") == 0 || strcmp (word
[2], "-e") == 0)
2995 offset
++; /* args move up by 1 word */
2999 if (!parse_irc_url (word
[2 + offset
], &server_name
, &port
, &channel
, &use_ssl
))
3002 server_name
= word
[2 + offset
];
3005 pass
= word
[3 + offset
];
3008 port
= word
[3 + offset
];
3009 pass
= word
[4 + offset
];
3012 if (!(*server_name
))
3015 sess
->server
->network
= NULL
;
3017 /* dont clear it for /servchan */
3018 if (strncasecmp (word_eol
[1], "SERVCHAN ", 9))
3019 sess
->willjoinchannel
[0] = 0;
3023 sess
->willjoinchannel
[0] = '#';
3024 safe_strcpy ((sess
->willjoinchannel
+ 1), channel
, (CHANLEN
- 1));
3027 /* support +7000 style ports like mIRC */
3038 safe_strcpy (serv
->password
, pass
, sizeof (serv
->password
));
3039 serv
->loginmethod
= LOGIN_PASS
;
3043 serv
->password
[0] = 0;
3047 serv
->use_ssl
= use_ssl
;
3048 serv
->accept_invalid_cert
= TRUE
;
3051 /* try to connect by Network name */
3052 if (servlist_connect_by_netname (sess
, server_name
, !is_url
))
3057 serv
->connect (serv
, server_name
, atoi (port
), FALSE
);
3060 /* -1 for default port */
3061 serv
->connect (serv
, server_name
, -1, FALSE
);
3064 /* try to associate this connection with a listed network */
3066 /* search for this hostname in the entire server list */
3067 serv
->network
= servlist_net_find_from_server (server_name
);
3068 /* may return NULL, but that's OK */
3074 cmd_servchan (struct session
*sess
, char *tbuf
, char *word
[],
3080 if (strcmp (word
[2], "-ssl") == 0)
3084 if (*word
[4 + offset
])
3086 safe_strcpy (sess
->willjoinchannel
, word
[4 + offset
], CHANLEN
);
3087 return cmd_server (sess
, tbuf
, word
, word_eol
);
3094 cmd_topic (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3096 if (word
[2][0] && is_channel (sess
->server
, word
[2]))
3097 sess
->server
->p_topic (sess
->server
, word
[2], word_eol
[3]);
3099 sess
->server
->p_topic (sess
->server
, sess
->channel
, word_eol
[2]);
3104 cmd_tray (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3106 if (strcmp (word
[2], "-b") == 0)
3108 fe_tray_set_balloon (word
[3], word
[4][0] ? word
[4] : NULL
);
3112 if (strcmp (word
[2], "-t") == 0)
3114 fe_tray_set_tooltip (word
[3][0] ? word
[3] : NULL
);
3118 if (strcmp (word
[2], "-i") == 0)
3120 fe_tray_set_icon (atoi (word
[3]));
3124 if (strcmp (word
[2], "-f") != 0)
3129 fe_tray_set_file (NULL
); /* default xchat icon */
3135 fe_tray_set_file (word
[3]); /* fixed custom icon */
3139 /* flash between 2 icons */
3140 fe_tray_set_flash (word
[4], word
[5][0] ? word
[5] : NULL
, atoi (word
[3]));
3145 cmd_unignore (struct session
*sess
, char *tbuf
, char *word
[],
3148 char *mask
= word
[2];
3149 char *arg
= word
[3];
3152 if (ignore_del (mask
, NULL
))
3154 if (strcasecmp (arg
, "QUIET"))
3155 EMIT_SIGNAL (XP_TE_IGNOREREMOVE
, sess
, mask
, NULL
, NULL
, NULL
, 0);
3163 cmd_unload (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3166 int len
, by_file
= FALSE
;
3168 len
= strlen (word
[2]);
3169 if (len
> 3 && strcasecmp (word
[2] + len
- 3, ".so") == 0)
3172 switch (plugin_kill (word
[2], by_file
))
3175 PrintText (sess
, _("No such plugin found.\n"));
3180 PrintText (sess
, _("That plugin is refusing to unload.\n"));
3189 find_server_from_hostname (char *hostname
)
3191 GSList
*list
= serv_list
;
3197 if (!strcasecmp (hostname
, serv
->hostname
) && serv
->connected
)
3206 find_server_from_net (void *net
)
3208 GSList
*list
= serv_list
;
3214 if (serv
->network
== net
&& serv
->connected
)
3223 url_join_only (server
*serv
, char *tbuf
, char *channel
)
3225 /* already connected, JOIN only. FIXME: support keys? */
3228 safe_strcpy ((tbuf
+ 1), channel
, 256);
3229 serv
->p_join (serv
, tbuf
, "");
3233 cmd_url (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3237 char *server_name
= NULL
;
3239 char *channel
= NULL
;
3240 char *url
= g_strdup (word
[2]);
3241 int use_ssl
= FALSE
;
3245 if (parse_irc_url (url
, &server_name
, &port
, &channel
, &use_ssl
))
3247 /* maybe we're already connected to this net */
3249 /* check for "FreeNode" */
3250 net
= servlist_net_find (server_name
, NULL
, strcasecmp
);
3251 /* check for "irc.eu.freenode.net" */
3253 net
= servlist_net_find_from_server (server_name
);
3257 /* found the network, but are we connected? */
3258 serv
= find_server_from_net (net
);
3261 url_join_only (serv
, tbuf
, channel
);
3268 /* an un-listed connection */
3269 serv
= find_server_from_hostname (server_name
);
3272 url_join_only (serv
, tbuf
, channel
);
3278 /* not connected to this net, open new window */
3279 cmd_newserver (sess
, tbuf
, word
, word_eol
);
3282 fe_open_url (word
[2]);
3291 userlist_cb (struct User
*user
, session
*sess
)
3295 if (!user
->lasttalk
)
3298 lt
= time (0) - user
->lasttalk
;
3300 "\00306%s\t\00314[\00310%-38s\00314] \017ov\0033=\017%d%d away=%u lt\0033=\017%d\n",
3301 user
->nick
, user
->hostname
, user
->op
, user
->voice
, user
->away
, lt
);
3307 cmd_uselect (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3313 if (strcmp (word
[2], "-a") == 0) /* ADD (don't clear selections) */
3318 if (strcmp (word
[idx
], "-s") == 0) /* SCROLL TO */
3323 /* always valid, no args means clear the selection list */
3324 fe_uselect (sess
, word
+ idx
, clear
, scroll
);
3329 cmd_userlist (struct session
*sess
, char *tbuf
, char *word
[],
3332 tree_foreach (sess
->usertree
, (tree_traverse_func
*)userlist_cb
, sess
);
3337 wallchop_cb (struct User
*user
, multidata
*data
)
3342 strcat (data
->tbuf
, ",");
3343 strcat (data
->tbuf
, user
->nick
);
3349 sprintf (data
->tbuf
+ strlen (data
->tbuf
),
3350 " :[@%s] %s", data
->sess
->channel
, data
->reason
);
3351 data
->sess
->server
->p_raw (data
->sess
->server
, data
->tbuf
);
3352 strcpy (data
->tbuf
, "NOTICE ");
3359 cmd_wallchop (struct session
*sess
, char *tbuf
, char *word
[],
3364 if (!(*word_eol
[2]))
3367 strcpy (tbuf
, "NOTICE ");
3369 data
.reason
= word_eol
[2];
3373 tree_foreach (sess
->usertree
, (tree_traverse_func
*)wallchop_cb
, &data
);
3377 sprintf (tbuf
+ strlen (tbuf
),
3378 " :[@%s] %s", sess
->channel
, word_eol
[2]);
3379 sess
->server
->p_raw (sess
->server
, tbuf
);
3386 cmd_wallchan (struct session
*sess
, char *tbuf
, char *word
[],
3397 if (sess
->type
== SESS_CHANNEL
)
3399 inbound_chanmsg (sess
->server
, NULL
, sess
->channel
,
3400 sess
->server
->nick
, word_eol
[2], TRUE
, FALSE
);
3401 sess
->server
->p_message (sess
->server
, sess
->channel
, word_eol
[2]);
3411 cmd_hop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3421 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'h', 0);
3429 cmd_voice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3439 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'v', 0);
3446 /* *MUST* be kept perfectly sorted for the bsearch to work */
3447 const struct commands xc_cmds
[] = {
3448 {"ADDBUTTON", cmd_addbutton
, 0, 0, 1,
3449 N_("ADDBUTTON <name> <action>, adds a button under the user-list")},
3450 {"ALLCHAN", cmd_allchannels
, 0, 0, 1,
3451 N_("ALLCHAN <cmd>, sends a command to all channels you're in")},
3452 {"ALLCHANL", cmd_allchannelslocal
, 0, 0, 1,
3453 N_("ALLCHANL <cmd>, sends a command to all channels on the current server")},
3454 {"ALLSERV", cmd_allservers
, 0, 0, 1,
3455 N_("ALLSERV <cmd>, sends a command to all servers you're in")},
3456 {"AWAY", cmd_away
, 1, 0, 1, N_("AWAY [<reason>], sets you away")},
3457 {"BACK", cmd_back
, 1, 0, 1, N_("BACK, sets you back (not away)")},
3458 {"BAN", cmd_ban
, 1, 1, 1,
3459 N_("BAN <mask> [<bantype>], bans everyone matching the mask from the current channel. If they are already on the channel this doesn't kick them (needs chanop)")},
3460 {"CHANOPT", cmd_chanopt
, 0, 0, 1, N_("CHANOPT [-quiet] <variable> [<value>]")},
3461 {"CHARSET", cmd_charset
, 0, 0, 1, N_("CHARSET [<encoding>], get or set the encoding used for the current connection")},
3462 {"CLEAR", cmd_clear
, 0, 0, 1, N_("CLEAR [ALL|HISTORY], Clears the current text window or command history")},
3463 {"CLOSE", cmd_close
, 0, 0, 1, N_("CLOSE, Closes the current window/tab")},
3465 {"COUNTRY", cmd_country
, 0, 0, 1,
3466 N_("COUNTRY [-s] <code|wildcard>, finds a country code, eg: au = australia")},
3467 {"CTCP", cmd_ctcp
, 1, 0, 1,
3468 N_("CTCP <nick> <message>, send the CTCP message to nick, common messages are VERSION and USERINFO")},
3469 {"CYCLE", cmd_cycle
, 1, 1, 1,
3470 N_("CYCLE [<channel>], parts the current or given channel and immediately rejoins")},
3471 {"DCC", cmd_dcc
, 0, 0, 1,
3473 "DCC GET <nick> - accept an offered file\n"
3474 "DCC SEND [-maxcps=#] <nick> [file] - send a file to someone\n"
3475 "DCC PSEND [-maxcps=#] <nick> [file] - send a file using passive mode\n"
3476 "DCC LIST - show DCC list\n"
3477 "DCC CHAT <nick> - offer DCC CHAT to someone\n"
3478 "DCC PCHAT <nick> - offer DCC CHAT using passive mode\n"
3479 "DCC CLOSE <type> <nick> <file> example:\n"
3480 " /dcc close send johnsmith file.tar.gz")},
3481 {"DEBUG", cmd_debug
, 0, 0, 1, 0},
3483 {"DEHOP", cmd_dehop
, 1, 1, 1,
3484 N_("DEHOP <nick>, removes chanhalf-op status from the nick on the current channel (needs chanop)")},
3485 {"DELBUTTON", cmd_delbutton
, 0, 0, 1,
3486 N_("DELBUTTON <name>, deletes a button from under the user-list")},
3487 {"DEOP", cmd_deop
, 1, 1, 1,
3488 N_("DEOP <nick>, removes chanop status from the nick on the current channel (needs chanop)")},
3489 {"DEVOICE", cmd_devoice
, 1, 1, 1,
3490 N_("DEVOICE <nick>, removes voice status from the nick on the current channel (needs chanop)")},
3491 {"DISCON", cmd_discon
, 0, 0, 1, N_("DISCON, Disconnects from server")},
3492 {"DNS", cmd_dns
, 0, 0, 1, N_("DNS <nick|host|ip>, Finds a users IP number")},
3493 {"ECHO", cmd_echo
, 0, 0, 1, N_("ECHO <text>, Prints text locally")},
3494 {"EXEC", cmd_exec
, 0, 0, 1,
3495 N_("EXEC [-o] <command>, runs the command. If -o flag is used then output is sent to current channel, else is printed to current text box")},
3496 {"EXECCONT", cmd_execc
, 0, 0, 1, N_("EXECCONT, sends the process SIGCONT")},
3497 {"EXECKILL", cmd_execk
, 0, 0, 1,
3498 N_("EXECKILL [-9], kills a running exec in the current session. If -9 is given the process is SIGKILL'ed")},
3499 {"EXECSTOP", cmd_execs
, 0, 0, 1, N_("EXECSTOP, sends the process SIGSTOP")},
3500 {"EXECWRITE", cmd_execw
, 0, 0, 1, N_("EXECWRITE, sends data to the processes stdin")},
3501 {"FLUSHQ", cmd_flushq
, 0, 0, 1,
3502 N_("FLUSHQ, flushes the current server's send queue")},
3503 {"GATE", cmd_gate
, 0, 0, 1,
3504 N_("GATE <host> [<port>], proxies through a host, port defaults to 23")},
3505 {"GETFILE", cmd_getfile
, 0, 0, 1, "GETFILE [-folder] [-multi] [-save] <command> <title> [<initial>]"},
3506 {"GETINT", cmd_getint
, 0, 0, 1, "GETINT <default> <command> <prompt>"},
3507 {"GETSTR", cmd_getstr
, 0, 0, 1, "GETSTR <default> <command> <prompt>"},
3508 {"GHOST", cmd_ghost
, 1, 0, 1, N_("GHOST <nick> [password], Kills a ghosted nickname")},
3509 {"GUI", cmd_gui
, 0, 0, 1, "GUI [APPLY|ATTACH|DETACH|SHOW|HIDE|FOCUS|FLASH|ICONIFY|COLOR <n>]\n"
3510 " GUI [MSGBOX <text>|MENU TOGGLE]"},
3511 {"HELP", cmd_help
, 0, 0, 1, 0},
3512 {"HOP", cmd_hop
, 1, 1, 1,
3513 N_("HOP <nick>, gives chanhalf-op status to the nick (needs chanop)")},
3514 {"ID", cmd_id
, 1, 0, 1, N_("ID <password>, identifies yourself to nickserv")},
3515 {"IGNORE", cmd_ignore
, 0, 0, 1,
3516 N_("IGNORE <mask> <types..> <options..>\n"
3517 " mask - host mask to ignore, eg: *!*@*.aol.com\n"
3518 " types - types of data to ignore, one or all of:\n"
3519 " PRIV, CHAN, NOTI, CTCP, DCC, INVI, ALL\n"
3520 " options - NOSAVE, QUIET")},
3522 {"INVITE", cmd_invite
, 1, 0, 1,
3523 N_("INVITE <nick> [<channel>], invites someone to a channel, by default the current channel (needs chanop)")},
3524 {"JOIN", cmd_join
, 1, 0, 0, N_("JOIN <channel>, joins the channel")},
3525 {"KICK", cmd_kick
, 1, 1, 1,
3526 N_("KICK <nick>, kicks the nick from the current channel (needs chanop)")},
3527 {"KICKBAN", cmd_kickban
, 1, 1, 1,
3528 N_("KICKBAN <nick>, bans then kicks the nick from the current channel (needs chanop)")},
3529 {"KILLALL", cmd_killall
, 0, 0, 1, "KILLALL, immediately exit"},
3530 {"LAGCHECK", cmd_lagcheck
, 0, 0, 1,
3531 N_("LAGCHECK, forces a new lag check")},
3532 {"LASTLOG", cmd_lastlog
, 0, 0, 1,
3533 N_("LASTLOG <string>, searches for a string in the buffer")},
3534 {"LIST", cmd_list
, 1, 0, 1, 0},
3535 {"LOAD", cmd_load
, 0, 0, 1, N_("LOAD [-e] <file>, loads a plugin or script")},
3537 {"MDEHOP", cmd_mdehop
, 1, 1, 1,
3538 N_("MDEHOP, Mass deop's all chanhalf-ops in the current channel (needs chanop)")},
3539 {"MDEOP", cmd_mdeop
, 1, 1, 1,
3540 N_("MDEOP, Mass deop's all chanops in the current channel (needs chanop)")},
3541 {"ME", cmd_me
, 0, 0, 1,
3542 N_("ME <action>, sends the action to the current channel (actions are written in the 3rd person, like /me jumps)")},
3543 {"MENU", cmd_menu
, 0, 0, 1, "MENU [-eX] [-i<ICONFILE>] [-k<mod>,<key>] [-m] [-pX] [-r<X,group>] [-tX] {ADD|DEL} <path> [command] [unselect command]\n"
3544 " See http://xchat.org/docs/menu/ for more details."},
3545 {"MKICK", cmd_mkick
, 1, 1, 1,
3546 N_("MKICK, Mass kicks everyone except you in the current channel (needs chanop)")},
3547 {"MODE", cmd_mode
, 1, 0, 1, 0},
3548 {"MOP", cmd_mop
, 1, 1, 1,
3549 N_("MOP, Mass op's all users in the current channel (needs chanop)")},
3550 {"MSG", cmd_msg
, 0, 0, 1, N_("MSG <nick> <message>, sends a private message")},
3552 {"NAMES", cmd_names
, 1, 0, 1,
3553 N_("NAMES, Lists the nicks on the current channel")},
3554 {"NCTCP", cmd_nctcp
, 1, 0, 1,
3555 N_("NCTCP <nick> <message>, Sends a CTCP notice")},
3556 {"NEWSERVER", cmd_newserver
, 0, 0, 1, N_("NEWSERVER [-noconnect] <hostname> [<port>]")},
3557 {"NICK", cmd_nick
, 0, 0, 1, N_("NICK <nickname>, sets your nick")},
3559 {"NOTICE", cmd_notice
, 1, 0, 1,
3560 N_("NOTICE <nick/channel> <message>, sends a notice. Notices are a type of message that should be auto reacted to")},
3561 {"NOTIFY", cmd_notify
, 0, 0, 1,
3562 N_("NOTIFY [-n network1[,network2,...]] [<nick>], displays your notify list or adds someone to it")},
3563 {"OP", cmd_op
, 1, 1, 1,
3564 N_("OP <nick>, gives chanop status to the nick (needs chanop)")},
3565 {"PART", cmd_part
, 1, 1, 0,
3566 N_("PART [<channel>] [<reason>], leaves the channel, by default the current one")},
3567 {"PING", cmd_ping
, 1, 0, 1,
3568 N_("PING <nick | channel>, CTCP pings nick or channel")},
3569 {"QUERY", cmd_query
, 0, 0, 1,
3570 N_("QUERY [-nofocus] <nick>, opens up a new privmsg window to someone")},
3571 {"QUIT", cmd_quit
, 0, 0, 1,
3572 N_("QUIT [<reason>], disconnects from the current server")},
3573 {"QUOTE", cmd_quote
, 1, 0, 1,
3574 N_("QUOTE <text>, sends the text in raw form to the server")},
3576 {"RECONNECT", cmd_reconnect
, 0, 0, 1,
3577 N_("RECONNECT [-ssl] [<host>] [<port>] [<password>], Can be called just as /RECONNECT to reconnect to the current server or with /RECONNECT ALL to reconnect to all the open servers")},
3579 {"RECONNECT", cmd_reconnect
, 0, 0, 1,
3580 N_("RECONNECT [<host>] [<port>] [<password>], Can be called just as /RECONNECT to reconnect to the current server or with /RECONNECT ALL to reconnect to all the open servers")},
3582 {"RECV", cmd_recv
, 1, 0, 1, N_("RECV <text>, send raw data to xchat, as if it was received from the irc server")},
3584 {"SAY", cmd_say
, 0, 0, 1,
3585 N_("SAY <text>, sends the text to the object in the current window")},
3586 {"SEND", cmd_send
, 0, 0, 1, N_("SEND <nick> [<file>]")},
3588 {"SERVCHAN", cmd_servchan
, 0, 0, 1,
3589 N_("SERVCHAN [-ssl] <host> <port> <channel>, connects and joins a channel")},
3591 {"SERVCHAN", cmd_servchan
, 0, 0, 1,
3592 N_("SERVCHAN <host> <port> <channel>, connects and joins a channel")},
3595 {"SERVER", cmd_server
, 0, 0, 1,
3596 N_("SERVER [-ssl] <host> [<port>] [<password>], connects to a server, the default port is 6667 for normal connections, and 9999 for ssl connections")},
3598 {"SERVER", cmd_server
, 0, 0, 1,
3599 N_("SERVER <host> [<port>] [<password>], connects to a server, the default port is 6667")},
3601 {"SET", cmd_set
, 0, 0, 1, N_("SET [-e] [-off|-on] [-quiet] <variable> [<value>]")},
3602 {"SETCURSOR", cmd_setcursor
, 0, 0, 1, N_("SETCURSOR [-|+]<position>, reposition the cursor in the inputbox")},
3603 {"SETTAB", cmd_settab
, 0, 0, 1, N_("SETTAB <new name>, change a tab's name, tab_trunc limit still applies")},
3604 {"SETTEXT", cmd_settext
, 0, 0, 1, N_("SETTEXT <new text>, replace the text in the input box")},
3605 {"SPLAY", cmd_splay
, 0, 0, 1, "SPLAY <soundfile>"},
3606 {"TOPIC", cmd_topic
, 1, 1, 1,
3607 N_("TOPIC [<topic>], sets the topic if one is given, else shows the current topic")},
3608 {"TRAY", cmd_tray
, 0, 0, 1,
3609 N_("\nTRAY -f <timeout> <file1> [<file2>] Blink tray between two icons.\n"
3610 "TRAY -f <filename> Set tray to a fixed icon.\n"
3611 "TRAY -i <number> Blink tray with an internal icon.\n"
3612 "TRAY -t <text> Set the tray tooltip.\n"
3613 "TRAY -b <title> <text> Set the tray balloon."
3615 {"UNBAN", cmd_unban
, 1, 1, 1,
3616 N_("UNBAN <mask> [<mask>...], unbans the specified masks.")},
3617 {"UNIGNORE", cmd_unignore
, 0, 0, 1, N_("UNIGNORE <mask> [QUIET]")},
3618 {"UNLOAD", cmd_unload
, 0, 0, 1, N_("UNLOAD <name>, unloads a plugin or script")},
3619 {"URL", cmd_url
, 0, 0, 1, N_("URL <url>, opens a URL in your browser")},
3620 {"USELECT", cmd_uselect
, 0, 1, 0,
3621 N_("USELECT [-a] [-s] <nick1> <nick2> etc, highlights nick(s) in channel userlist")},
3622 {"USERLIST", cmd_userlist
, 1, 1, 1, 0},
3623 {"VOICE", cmd_voice
, 1, 1, 1,
3624 N_("VOICE <nick>, gives voice status to someone (needs chanop)")},
3625 {"WALLCHAN", cmd_wallchan
, 1, 1, 1,
3626 N_("WALLCHAN <message>, writes the message to all channels")},
3627 {"WALLCHOP", cmd_wallchop
, 1, 1, 1,
3628 N_("WALLCHOP <message>, sends the message to all chanops on the current channel")},
3634 command_compare (const void *a
, const void *b
)
3636 return strcasecmp (a
, ((struct commands
*)b
)->name
);
3639 static struct commands
*
3640 find_internal_command (char *name
)
3642 /* the "-1" is to skip the NULL terminator */
3643 return bsearch (name
, xc_cmds
, (sizeof (xc_cmds
) /
3644 sizeof (xc_cmds
[0])) - 1, sizeof (xc_cmds
[0]), command_compare
);
3648 help (session
*sess
, char *tbuf
, char *helpcmd
, int quiet
)
3650 struct commands
*cmd
;
3652 if (plugin_show_help (sess
, helpcmd
))
3655 cmd
= find_internal_command (helpcmd
);
3661 snprintf (tbuf
, TBUFSIZE
, _("Usage: %s\n"), _(cmd
->help
));
3662 PrintText (sess
, tbuf
);
3666 PrintText (sess
, _("\nNo help available on that command.\n"));
3672 PrintText (sess
, _("No such command.\n"));
3675 /* inserts %a, %c, %d etc into buffer. Also handles &x %x for word/word_eol. *
3676 * returns 2 on buffer overflow
3677 * returns 1 on success *
3678 * returns 0 on bad-args-for-user-command *
3679 * - word/word_eol args might be NULL *
3680 * - this beast is used for UserCommands, UserlistButtons and CTCP replies */
3683 auto_insert (char *dest
, int destlen
, unsigned char *src
, char *word
[],
3684 char *word_eol
[], char *a
, char *c
, char *d
, char *e
, char *h
,
3699 if (src
[0] == '%' || src
[0] == '&')
3701 if (isdigit ((unsigned char) src
[1]))
3703 if (isdigit ((unsigned char) src
[2]) && isdigit ((unsigned char) src
[3]))
3709 dest
[0] = atoi (buf
);
3710 utf
= g_locale_to_utf8 (dest
, 1, 0, &utf_len
, 0);
3713 if ((dest
- orig
) + utf_len
>= destlen
)
3719 memcpy (dest
, utf
, utf_len
);
3729 num
= src
[0] - '0'; /* ascii to decimal */
3730 if (*word
[num
] == 0)
3736 utf
= word_eol
[num
];
3738 /* avoid recusive usercommand overflow */
3739 if ((dest
- orig
) + strlen (utf
) >= destlen
)
3743 dest
+= strlen (dest
);
3755 if ((dest
- orig
) + 2 >= destlen
)
3772 utf
= get_cpu_str (); break;
3783 utf
= PACKAGE_VERSION
; break;
3787 tm_ptr
= localtime (&now
);
3788 snprintf (buf
, sizeof (buf
), "%4d%02d%02d", 1900 +
3789 tm_ptr
->tm_year
, 1 + tm_ptr
->tm_mon
, tm_ptr
->tm_mday
);
3799 if ((dest
- orig
) + strlen (utf
) >= destlen
)
3802 dest
+= strlen (dest
);
3809 utf_len
= g_utf8_skip
[src
[0]];
3811 if ((dest
- orig
) + utf_len
>= destlen
)
3822 memcpy (dest
, src
, utf_len
);
3835 check_special_chars (char *cmd
, int do_ascii
) /* check for %X */
3838 int len
= strlen (cmd
);
3847 buf
= malloc (len
+ 1);
3859 (isdigit ((unsigned char) cmd
[j
+ 1]) && isdigit ((unsigned char) cmd
[j
+ 2]) &&
3860 isdigit ((unsigned char) cmd
[j
+ 3])))
3862 tbuf
[0] = cmd
[j
+ 1];
3863 tbuf
[1] = cmd
[j
+ 2];
3864 tbuf
[2] = cmd
[j
+ 3];
3866 buf
[i
] = atoi (tbuf
);
3867 utf
= g_locale_to_utf8 (buf
+ i
, 1, 0, &utf_len
, 0);
3870 memcpy (buf
+ i
, utf
, utf_len
);
3894 case 'H': /* CL: invisible text code */
3895 buf
[i
] = HIDDEN_CHAR
;
3932 nick_comp_cb (struct User
*user
, nickdata
*data
)
3936 if (!rfc_ncasecmp (user
->nick
, data
->nick
, data
->len
))
3938 lenu
= strlen (user
->nick
);
3939 if (lenu
== data
->len
)
3941 snprintf (data
->tbuf
, TBUFSIZE
, "%s%s", user
->nick
, data
->space
);
3944 } else if (lenu
< data
->bestlen
)
3946 data
->bestlen
= lenu
;
3955 perform_nick_completion (struct session
*sess
, char *cmd
, char *tbuf
)
3958 char *space
= strchr (cmd
, ' ');
3959 if (space
&& space
!= cmd
)
3961 if (space
[-1] == prefs
.nick_suffix
[0] && space
- 1 != cmd
)
3963 len
= space
- cmd
- 1;
3969 memcpy (nick
, cmd
, len
);
3974 data
.bestlen
= INT_MAX
;
3977 data
.space
= space
- 1;
3978 tree_foreach (sess
->usertree
, (tree_traverse_func
*)nick_comp_cb
, &data
);
3985 snprintf (tbuf
, TBUFSIZE
, "%s%s", data
.best
->nick
, space
- 1);
3996 user_command (session
* sess
, char *tbuf
, char *cmd
, char *word
[],
3999 if (!auto_insert (tbuf
, 2048, cmd
, word
, word_eol
, "", sess
->channel
, "",
4000 server_get_network (sess
->server
, TRUE
), "",
4001 sess
->server
->nick
, ""))
4003 PrintText (sess
, _("Bad arguments for user command.\n"));
4007 handle_command (sess
, tbuf
, TRUE
);
4010 /* handle text entered without a CMDchar prefix */
4013 handle_say (session
*sess
, char *text
, int check_spch
)
4016 char *word
[PDIWORDS
+1];
4017 char *word_eol
[PDIWORDS
+1];
4018 char pdibuf_static
[1024];
4019 char newcmd_static
[1024];
4020 char *pdibuf
= pdibuf_static
;
4021 char *newcmd
= newcmd_static
;
4023 int newcmdlen
= sizeof newcmd_static
;
4025 if (strcmp (sess
->channel
, "(lastlog)") == 0)
4027 lastlog (sess
->lastlog_sess
, text
, sess
->lastlog_regexp
);
4031 len
= strlen (text
);
4032 if (len
>= sizeof pdibuf_static
)
4033 pdibuf
= malloc (len
+ 1);
4035 if (len
+ NICKLEN
>= newcmdlen
)
4036 newcmd
= malloc (newcmdlen
= len
+ NICKLEN
+ 1);
4038 if (check_spch
&& prefs
.perc_color
)
4039 check_special_chars (text
, prefs
.perc_ascii
);
4041 /* Python relies on this */
4042 word
[PDIWORDS
] = NULL
;
4043 word_eol
[PDIWORDS
] = NULL
;
4045 /* split the text into words and word_eol */
4046 process_data_init (pdibuf
, text
, word
, word_eol
, TRUE
, FALSE
);
4048 /* a command of "" can be hooked for non-commands */
4049 if (plugin_emit_command (sess
, "", word
, word_eol
))
4052 /* incase a plugin did /close */
4053 if (!is_session (sess
))
4056 if (!sess
->channel
[0] || sess
->type
== SESS_SERVER
|| sess
->type
== SESS_NOTICES
|| sess
->type
== SESS_SNOTICES
)
4062 if (prefs
.nickcompletion
)
4063 perform_nick_completion (sess
, text
, newcmd
);
4065 safe_strcpy (newcmd
, text
, newcmdlen
);
4069 if (sess
->type
== SESS_DIALOG
)
4071 /* try it via dcc, if possible */
4072 dcc
= dcc_write_chat (sess
->channel
, text
);
4075 inbound_chanmsg (sess
->server
, NULL
, sess
->channel
,
4076 sess
->server
->nick
, text
, TRUE
, FALSE
);
4077 set_topic (sess
, net_ip (dcc
->addr
), net_ip (dcc
->addr
));
4082 if (sess
->server
->connected
)
4085 unsigned char t
= 0;
4087 /* maximum allowed message text */
4088 /* :nickname!username@host.com PRIVMSG #channel :text\r\n */
4090 max
-= 16; /* :, !, @, " PRIVMSG ", " ", :, \r, \n */
4091 max
-= strlen (sess
->server
->nick
);
4092 max
-= strlen (sess
->channel
);
4093 if (sess
->me
&& sess
->me
->hostname
)
4094 max
-= strlen (sess
->me
->hostname
);
4097 max
-= 9; /* username */
4098 max
-= 65; /* max possible hostname and '@' */
4101 if (strlen (text
) > max
)
4105 /* traverse the utf8 string and find the nearest cut point that
4106 doesn't split 1 char in half */
4109 size
= g_utf8_skip
[((unsigned char *)text
)[i
]];
4110 if ((i
+ size
) >= max
)
4116 text
[max
] = 0; /* insert a NULL terminator to shorten it */
4119 inbound_chanmsg (sess
->server
, sess
, sess
->channel
, sess
->server
->nick
,
4121 sess
->server
->p_message (sess
->server
, sess
->channel
, text
);
4126 handle_say (sess
, text
+ max
, FALSE
);
4135 if (pdibuf
!= pdibuf_static
)
4138 if (newcmd
!= newcmd_static
)
4142 /* handle a command, without the '/' prefix */
4145 handle_command (session
*sess
, char *cmd
, int check_spch
)
4148 int user_cmd
= FALSE
;
4150 char *word
[PDIWORDS
+1];
4151 char *word_eol
[PDIWORDS
+1];
4152 static int command_level
= 0;
4153 struct commands
*int_cmd
;
4154 char pdibuf_static
[1024];
4155 char tbuf_static
[TBUFSIZE
];
4161 if (command_level
> 99)
4163 fe_message (_("Too many recursive usercommands, aborting."), FE_MSG_ERROR
);
4167 /* anything below MUST DEC command_level before returning */
4170 if (len
>= sizeof (pdibuf_static
))
4171 pdibuf
= malloc (len
+ 1);
4173 pdibuf
= pdibuf_static
;
4175 if ((len
* 2) >= sizeof (tbuf_static
))
4176 tbuf
= malloc ((len
* 2) + 1);
4180 /* split the text into words and word_eol */
4181 process_data_init (pdibuf
, cmd
, word
, word_eol
, TRUE
, TRUE
);
4183 /* ensure an empty string at index 32 for cmd_deop etc */
4184 /* (internal use only, plugins can still only read 1-31). */
4185 word
[PDIWORDS
] = "\000\000";
4186 word_eol
[PDIWORDS
] = "\000\000";
4188 int_cmd
= find_internal_command (word
[1]);
4189 /* redo it without quotes processing, for some commands like /JOIN */
4190 if (int_cmd
&& !int_cmd
->handle_quotes
)
4191 process_data_init (pdibuf
, cmd
, word
, word_eol
, FALSE
, FALSE
);
4193 if (check_spch
&& prefs
.perc_color
)
4194 check_special_chars (cmd
, prefs
.perc_ascii
);
4196 if (plugin_emit_command (sess
, word
[1], word
, word_eol
))
4199 /* incase a plugin did /close */
4200 if (!is_session (sess
))
4203 /* first see if it's a userCommand */
4204 list
= command_list
;
4207 pop
= (struct popup
*) list
->data
;
4208 if (!strcasecmp (pop
->name
, word
[1]))
4210 user_command (sess
, tbuf
, pop
->cmd
, word
, word_eol
);
4219 /* now check internal commands */
4220 int_cmd
= find_internal_command (word
[1]);
4224 if (int_cmd
->needserver
&& !sess
->server
->connected
)
4227 } else if (int_cmd
->needchannel
&& !sess
->channel
[0])
4232 switch (int_cmd
->callback (sess
, tbuf
, word
, word_eol
))
4235 help (sess
, tbuf
, int_cmd
->name
, TRUE
);
4244 /* unknown command, just send it to the server and hope */
4245 if (!sess
->server
->connected
)
4246 PrintText (sess
, _("Unknown Command. Try /help\n"));
4248 sess
->server
->p_raw (sess
->server
, cmd
);
4254 if (pdibuf
!= pdibuf_static
)
4257 if (tbuf
!= tbuf_static
)
4263 /* handle one line entered into the input box */
4266 handle_user_input (session
*sess
, char *text
, int history
, int nocommand
)
4272 history_add (&sess
->history
, text
);
4274 /* is it NOT a command, just text? */
4275 if (nocommand
|| text
[0] != prefs
.cmdchar
[0])
4277 handle_say (sess
, text
, TRUE
);
4282 if (text
[0] == prefs
.cmdchar
[0] && text
[1] == prefs
.cmdchar
[0])
4284 handle_say (sess
, text
+ 1, TRUE
);
4288 if (prefs
.cmdchar
[0] == '/')
4291 const char *unix_dirs
[] = {
4292 "/bin/", "/boot/", "/dev/",
4293 "/etc/", "/home/", "/lib/",
4294 "/lost+found/", "/mnt/", "/opt/",
4295 "/proc/", "/root/", "/sbin/",
4296 "/tmp/", "/usr/", "/var/",
4298 for (i
= 0; unix_dirs
[i
] != NULL
; i
++)
4299 if (strncmp (text
, unix_dirs
[i
], strlen (unix_dirs
[i
]))==0)
4301 handle_say (sess
, text
, TRUE
);
4306 return handle_command (sess
, text
+ 1, TRUE
);
4309 /* changed by Steve Green. Macs sometimes paste with imbedded \r */
4311 handle_multiline (session
*sess
, char *cmd
, int history
, int nocommand
)
4315 char *cr
= cmd
+ strcspn (cmd
, "\n\r");
4316 int end_of_string
= *cr
== 0;
4318 if (!handle_user_input (sess
, cmd
, history
, nocommand
))
4327 handle_multiline (session *sess, char *cmd, int history, int nocommand)
4331 cr = strchr (cmd, '\n');
4338 if (!handle_user_input (sess, cmd, history, nocommand))
4345 cr = strchr (cmd, '\n');
4349 handle_user_input (sess, cmd, history, nocommand);