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() */
58 extern int current_mem_usage
;
62 static void help (session
*sess
, char *tbuf
, char *helpcmd
, int quiet
);
63 static int cmd_server (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[]);
64 static void handle_say (session
*sess
, char *text
, int check_spch
);
68 notj_msg (struct session
*sess
)
70 PrintText (sess
, _("No channel joined. Try /join #<channel>\n"));
74 notc_msg (struct session
*sess
)
76 PrintText (sess
, _("Not connected. Try /server <host> [<port>]\n"));
80 random_line (char *file_name
)
89 fh
= xchat_fopen_file (file_name
, "r", 0);
93 /* reason is not a file, an actual reason! */
94 return strdup (file_name
);
97 /* count number of lines in file */
99 while (fgets (buf
, sizeof (buf
), fh
))
105 /* go down a random number */
107 ran
= RAND_INT (lines
);
110 fgets (buf
, sizeof (buf
), fh
);
115 buf
[strlen (buf
) - 1] = 0; /* remove the trailing '\n' */
120 server_sendpart (server
* serv
, char *channel
, char *reason
)
124 reason
= random_line (prefs
.partreason
);
125 serv
->p_part (serv
, channel
, reason
);
129 /* reason set by /quit, /close argument */
130 serv
->p_part (serv
, channel
, reason
);
135 server_sendquit (session
* sess
)
139 if (!sess
->quitreason
)
141 colrea
= strdup (prefs
.quitreason
);
142 check_special_chars (colrea
, FALSE
);
143 rea
= random_line (colrea
);
145 sess
->server
->p_quit (sess
->server
, rea
);
149 /* reason set by /quit, /close argument */
150 sess
->server
->p_quit (sess
->server
, sess
->quitreason
);
155 process_data_init (char *buf
, char *cmd
, char *word
[],
156 char *word_eol
[], gboolean handle_quotes
,
157 gboolean allow_escape_quotes
)
165 word
[0] = "\000\000";
166 word_eol
[0] = "\000\000";
167 word
[1] = (char *)buf
;
168 word_eol
[1] = (char *)cmd
;
176 for (j
= wordcount
; j
< PDIWORDS
; j
++)
178 word
[j
] = "\000\000";
179 word_eol
[j
] = "\000\000";
185 /* two quotes turn into 1 */
186 if (allow_escape_quotes
&& cmd
[1] == '\042')
207 if (wordcount
< PDIWORDS
)
209 word
[wordcount
] = &buf
[j
];
210 word_eol
[wordcount
] = cmd
+ 1;
222 len
= g_utf8_skip
[((unsigned char *)cmd
)[0]];
230 /* skip past a multi-byte utf8 char */
231 memcpy (buf
+ j
, cmd
, len
);
240 cmd_addbutton (struct session
*sess
, char *tbuf
, char *word
[],
243 if (*word
[2] && *word_eol
[3])
245 if (sess
->type
== SESS_DIALOG
)
247 list_addentry (&dlgbutton_list
, word_eol
[3], word
[2]);
248 fe_dlgbuttons_update (sess
);
251 list_addentry (&button_list
, word_eol
[3], word
[2]);
252 fe_buttons_update (sess
);
260 cmd_allchannels (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
262 GSList
*list
= sess_list
;
270 if (sess
->type
== SESS_CHANNEL
&& sess
->channel
[0] && sess
->server
->connected
)
272 handle_command (sess
, word_eol
[2], FALSE
);
281 cmd_allchannelslocal (session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
283 GSList
*list
= sess_list
;
284 server
*serv
= sess
->server
;
292 if (sess
->type
== SESS_CHANNEL
&& sess
->channel
[0] &&
293 sess
->server
->connected
&& sess
->server
== serv
)
295 handle_command (sess
, word_eol
[2], FALSE
);
304 cmd_allservers (struct session
*sess
, char *tbuf
, char *word
[],
318 handle_command (serv
->front_session
, word_eol
[2], FALSE
);
326 cmd_away (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
329 char *reason
= word_eol
[2];
333 if (sess
->server
->is_away
)
335 if (sess
->server
->last_away_reason
)
336 PrintTextf (sess
, _("Already marked away: %s\n"), sess
->server
->last_away_reason
);
340 if (sess
->server
->reconnect_away
)
341 reason
= sess
->server
->last_away_reason
;
343 /* must manage memory pointed to by random_line() */
344 reason
= random_line (prefs
.awayreason
);
346 sess
->server
->p_set_away (sess
->server
, reason
);
348 if (prefs
.show_away_message
)
350 snprintf (tbuf
, TBUFSIZE
, "me is away: %s", reason
);
351 for (list
= sess_list
; list
; list
= list
->next
)
353 /* am I the right server and not a dialog box */
354 if (((struct session
*) list
->data
)->server
== sess
->server
355 && ((struct session
*) list
->data
)->type
== SESS_CHANNEL
356 && ((struct session
*) list
->data
)->channel
[0])
358 handle_command ((session
*) list
->data
, tbuf
, TRUE
);
363 if (sess
->server
->last_away_reason
!= reason
)
365 if (sess
->server
->last_away_reason
)
366 free (sess
->server
->last_away_reason
);
368 if (reason
== word_eol
[2])
369 sess
->server
->last_away_reason
= strdup (reason
);
371 sess
->server
->last_away_reason
= reason
;
374 if (!sess
->server
->connected
)
375 sess
->server
->reconnect_away
= 1;
381 cmd_back (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
386 if (sess
->server
->is_away
)
388 sess
->server
->p_set_back (sess
->server
);
390 if (prefs
.show_away_message
)
392 gone
= time (NULL
) - sess
->server
->away_time
;
393 sprintf (tbuf
, "me is back (gone %.2d:%.2d:%.2d)", gone
/ 3600,
394 (gone
/ 60) % 60, gone
% 60);
395 for (list
= sess_list
; list
; list
= list
->next
)
397 /* am I the right server and not a dialog box */
398 if (((struct session
*) list
->data
)->server
== sess
->server
399 && ((struct session
*) list
->data
)->type
== SESS_CHANNEL
400 && ((struct session
*) list
->data
)->channel
[0])
402 handle_command ((session
*) list
->data
, tbuf
, TRUE
);
409 PrintText (sess
, _("Already marked back.\n"));
412 if (sess
->server
->last_away_reason
)
413 free (sess
->server
->last_away_reason
);
414 sess
->server
->last_away_reason
= NULL
;
420 ban (session
* sess
, char *tbuf
, char *mask
, char *bantypestr
, int deop
)
424 char *at
, *dot
, *lastdot
;
425 char username
[64], fullhost
[128], domain
[128], *mode
, *p2
;
426 server
*serv
= sess
->server
;
428 user
= userlist_find (sess
, mask
);
429 if (user
&& user
->hostname
) /* it's a nickname, let's find a proper ban mask */
441 mask
= user
->hostname
;
443 at
= strchr (mask
, '@'); /* FIXME: utf8 */
445 return; /* can't happen? */
448 if (mask
[0] == '~' || mask
[0] == '+' ||
449 mask
[0] == '=' || mask
[0] == '^' || mask
[0] == '-')
451 /* the ident is prefixed with something, we replace that sign with an * */
452 safe_strcpy (username
+1, mask
+1, sizeof (username
)-1);
454 } else if (at
- mask
< USERNAMELEN
)
456 /* we just add an * in the begining of the ident */
457 safe_strcpy (username
+1, mask
, sizeof (username
)-1);
461 /* ident might be too long, we just ban what it gives and add an * in the end */
462 safe_strcpy (username
, mask
, sizeof (username
));
465 safe_strcpy (fullhost
, at
+ 1, sizeof (fullhost
));
467 dot
= strchr (fullhost
, '.');
470 safe_strcpy (domain
, dot
, sizeof (domain
));
473 safe_strcpy (domain
, fullhost
, sizeof (domain
));
477 bantype
= atoi (bantypestr
);
479 bantype
= prefs
.bantype
;
482 if (inet_addr (fullhost
) != -1) /* "fullhost" is really a IP number */
484 lastdot
= strrchr (fullhost
, '.');
486 return; /* can't happen? */
489 strcpy (domain
, fullhost
);
495 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s.*", mode
, p2
, domain
);
499 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s", mode
, p2
, fullhost
);
503 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s.*", mode
, p2
, username
, domain
);
507 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s", mode
, p2
, username
, fullhost
);
515 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@*%s", mode
, p2
, domain
);
519 snprintf (tbuf
, TBUFSIZE
, "%s%s *!*@%s", mode
, p2
, fullhost
);
523 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@*%s", mode
, p2
, username
, domain
);
527 snprintf (tbuf
, TBUFSIZE
, "%s%s *!%s@%s", mode
, p2
, username
, fullhost
);
534 snprintf (tbuf
, TBUFSIZE
, "+b %s", mask
);
536 serv
->p_mode (serv
, sess
->channel
, tbuf
);
540 cmd_ban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
542 char *mask
= word
[2];
546 ban (sess
, tbuf
, mask
, word
[3], 0);
549 sess
->server
->p_mode (sess
->server
, sess
->channel
, "+b"); /* banlist */
556 cmd_unban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
558 /* Allow more than one mask in /unban -- tvk */
567 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'b', 0);
575 cmd_chanopt (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
578 return chanopt_command (sess
, tbuf
, word
, word_eol
);
582 cmd_charset (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
584 server
*serv
= sess
->server
;
585 const char *locale
= NULL
;
588 if (strcmp (word
[2], "-quiet") == 0)
591 if (!word
[2 + offset
][0])
593 g_get_charset (&locale
);
594 PrintTextf (sess
, "Current charset: %s\n",
595 serv
->encoding
? serv
->encoding
: locale
);
599 if (servlist_check_encoding (word
[2 + offset
]))
601 server_set_encoding (serv
, word
[2 + offset
]);
603 PrintTextf (sess
, "Charset changed to: %s\n", word
[2 + offset
]);
606 PrintTextf (sess
, "\0034Unknown charset:\017 %s\n", word
[2 + offset
]);
613 cmd_clear (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
615 GSList
*list
= sess_list
;
616 char *reason
= word_eol
[2];
618 if (strcasecmp (reason
, "HISTORY") == 0)
620 history_free (&sess
->history
);
624 if (strncasecmp (reason
, "all", 3) == 0)
629 if (!sess
->nick_said
)
630 fe_text_clear (list
->data
, 0);
636 if (reason
[0] != '-' && !isdigit (reason
[0]) && reason
[0] != 0)
639 fe_text_clear (sess
, atoi (reason
));
644 cmd_close (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
648 if (strcmp (word
[2], "-m") == 0)
655 if (sess
->type
== SESS_DIALOG
)
656 fe_close_window (sess
);
661 sess
->quitreason
= word_eol
[2];
662 fe_close_window (sess
);
669 cmd_ctcp (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
675 char *msg
= word_eol
[3];
678 unsigned char *cmd
= (unsigned char *)msg
;
680 /* make the first word upper case (as per RFC) */
683 if (*cmd
== ' ' || *cmd
== 0)
685 mbl
= g_utf8_skip
[*cmd
];
687 *cmd
= toupper (*cmd
);
691 sess
->server
->p_ctcp (sess
->server
, to
, msg
);
693 EMIT_SIGNAL (XP_TE_CTCPSEND
, sess
, to
, msg
, NULL
, NULL
, 0);
702 cmd_country (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
704 char *code
= word
[2];
708 if (strcmp (code
, "-s") == 0)
710 country_search (word
[3], sess
, (void *)PrintTextf
);
714 /* search, but forgot the -s */
715 if (strchr (code
, '*'))
717 country_search (code
, sess
, (void *)PrintTextf
);
721 sprintf (tbuf
, "%s = %s\n", code
, country (code
));
722 PrintText (sess
, tbuf
);
729 cmd_cycle (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
731 char *key
= sess
->channelkey
;
732 char *chan
= word
[2];
734 chan
= sess
->channel
;
735 if (*chan
&& sess
->type
== SESS_CHANNEL
)
737 sess
->server
->p_cycle (sess
->server
, chan
, key
);
744 cmd_dcc (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
748 char *type
= word
[2];
751 if (!strcasecmp (type
, "HELP"))
753 if (!strcasecmp (type
, "CLOSE"))
755 if (*word
[3] && *word
[4])
758 if (!strcasecmp (word
[3], "SEND"))
760 dcc
= find_dcc (word
[4], word
[5], TYPE_SEND
);
761 dcc_abort (sess
, dcc
);
764 if (!strcasecmp (word
[3], "GET"))
766 dcc
= find_dcc (word
[4], word
[5], TYPE_RECV
);
767 dcc_abort (sess
, dcc
);
770 if (!strcasecmp (word
[3], "CHAT"))
772 dcc
= find_dcc (word
[4], "", TYPE_CHATRECV
);
774 dcc
= find_dcc (word
[4], "", TYPE_CHATSEND
);
775 dcc_abort (sess
, dcc
);
783 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
790 if ((!strcasecmp (type
, "CHAT")) || (!strcasecmp (type
, "PCHAT")))
792 char *nick
= word
[3];
793 int passive
= (!strcasecmp(type
, "PCHAT")) ? 1 : 0;
795 dcc_chat (sess
, nick
, passive
);
798 if (!strcasecmp (type
, "LIST"))
800 dcc_show_list (sess
);
803 if (!strcasecmp (type
, "GET"))
805 char *nick
= word
[3];
806 char *file
= word
[4];
810 dcc_get_nick (sess
, nick
);
813 dcc
= find_dcc (nick
, file
, TYPE_RECV
);
817 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
821 if ((!strcasecmp (type
, "SEND")) || (!strcasecmp (type
, "PSEND")))
825 int passive
= (!strcasecmp(type
, "PSEND")) ? 1 : 0;
831 maxcps
= prefs
.dcc_max_send_cps
;
832 if (!strncasecmp(nick
, "-maxcps=", 8))
834 maxcps
= atoi(nick
+ 8);
846 fe_dcc_send_filereq (sess
, nick
, maxcps
, passive
);
852 dcc_send (sess
, nick
, file
, maxcps
, passive
);
864 dcc_show_list (sess
);
869 cmd_debug (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
873 GSList
*list
= sess_list
;
875 PrintText (sess
, "Session T Channel WaitChan WillChan Server\n");
878 s
= (struct session
*) list
->data
;
879 sprintf (tbuf
, "%p %1x %-10.10s %-10.10s %-10.10s %p\n",
880 s
, s
->type
, s
->channel
, s
->waitchannel
,
881 s
->willjoinchannel
, s
->server
);
882 PrintText (sess
, tbuf
);
887 PrintText (sess
, "Server Sock Name\n");
890 v
= (struct server
*) list
->data
;
891 sprintf (tbuf
, "%p %-5d %s\n",
892 v
, v
->sok
, v
->servername
);
893 PrintText (sess
, tbuf
);
898 "\nfront_session: %p\n"
899 "current_tab: %p\n\n",
900 sess
->server
->front_session
, current_tab
);
901 PrintText (sess
, tbuf
);
903 sprintf (tbuf
, "current mem: %d\n\n", current_mem_usage
);
904 PrintText (sess
, tbuf
);
905 #endif /* !MEMORY_DEBUG */
911 cmd_delbutton (struct session
*sess
, char *tbuf
, char *word
[],
916 if (sess
->type
== SESS_DIALOG
)
918 if (list_delentry (&dlgbutton_list
, word
[2]))
919 fe_dlgbuttons_update (sess
);
922 if (list_delentry (&button_list
, word
[2]))
923 fe_buttons_update (sess
);
931 cmd_dehop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
941 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'h', 0);
949 cmd_deop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
959 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'o', 0);
976 mdehop_cb (struct User
*user
, multidata
*data
)
978 if (user
->hop
&& !user
->me
)
980 data
->nicks
[data
->i
] = user
->nick
;
987 cmd_mdehop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
989 char **nicks
= malloc (sizeof (char *) * sess
->hops
);
994 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mdehop_cb
, &data
);
995 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '-', 'h', 0);
1002 mdeop_cb (struct User
*user
, multidata
*data
)
1004 if (user
->op
&& !user
->me
)
1006 data
->nicks
[data
->i
] = user
->nick
;
1013 cmd_mdeop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1015 char **nicks
= malloc (sizeof (char *) * sess
->ops
);
1020 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mdeop_cb
, &data
);
1021 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '-', 'o', 0);
1027 GSList
*menu_list
= NULL
;
1030 menu_free (menu_entry
*me
)
1046 /* strings equal? but ignore underscores */
1049 menu_streq (const char *s1
, const char *s2
, int def
)
1051 /* for separators */
1052 if (s1
== NULL
&& s2
== NULL
)
1054 if (s1
== NULL
|| s2
== NULL
)
1073 menu_entry_find (char *path
, char *label
)
1082 if (!strcmp (path
, me
->path
))
1084 if (me
->label
&& label
&& !strcmp (label
, me
->label
))
1093 menu_del_children (char *path
, char *label
)
1095 GSList
*list
, *next
;
1102 snprintf (buf
, sizeof (buf
), "%s/%s", path
, label
);
1104 snprintf (buf
, sizeof (buf
), "%s", label
);
1111 if (!menu_streq (buf
, me
->path
, 0))
1113 menu_list
= g_slist_remove (menu_list
, me
);
1121 menu_del (char *path
, char *label
)
1130 if (!menu_streq (me
->label
, label
, 1) && !menu_streq (me
->path
, path
, 1))
1132 menu_list
= g_slist_remove (menu_list
, me
);
1135 /* delete this item's children, if any */
1136 menu_del_children (path
, label
);
1146 menu_is_mainmenu_root (char *path
, gint16
*offset
)
1148 static const char *menus
[] = {"\x4$TAB","\x5$TRAY","\x4$URL","\x5$NICK","\x5$CHAN"};
1151 for (i
= 0; i
< 5; i
++)
1153 if (!strncmp (path
, menus
[i
] + 1, menus
[i
][0]))
1155 *offset
= menus
[i
][0] + 1; /* number of bytes to offset the root */
1156 return 0; /* is not main menu */
1161 return 1; /* is main menu */
1165 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
)
1169 /* already exists? */
1170 me
= menu_entry_find (path
, label
);
1175 me
->enable
= enable
;
1176 fe_menu_update (me
);
1180 me
= malloc (sizeof (menu_entry
));
1183 me
->is_main
= menu_is_mainmenu_root (path
, &me
->root_offset
);
1185 me
->markup
= markup
;
1186 me
->enable
= enable
;
1188 me
->path
= strdup (path
);
1196 me
->label
= strdup (label
);
1198 me
->cmd
= strdup (cmd
);
1200 me
->ucmd
= strdup (ucmd
);
1202 me
->group
= strdup (group
);
1204 me
->icon
= strdup (icon
);
1206 menu_list
= g_slist_append (menu_list
, me
);
1207 label
= fe_menu_add (me
);
1210 /* FE has given us a stripped label */
1212 me
->label
= strdup (label
);
1213 g_free (label
); /* this is from pango */
1218 cmd_menu (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1233 if (!word
[2][0] || !word
[3][0])
1236 /* -eX enabled or not? */
1237 if (word
[idx
][0] == '-' && word
[idx
][1] == 'e')
1239 enable
= atoi (word
[idx
] + 2);
1244 if (word
[idx
][0] == '-' && word
[idx
][1] == 'i')
1246 icon
= word
[idx
] + 2;
1250 /* -k<mod>,<key> key binding */
1251 if (word
[idx
][0] == '-' && word
[idx
][1] == 'k')
1253 char *comma
= strchr (word
[idx
], ',');
1256 mod
= atoi (word
[idx
] + 2);
1257 key
= atoi (comma
+ 1);
1261 /* -m to specify PangoMarkup language */
1262 if (word
[idx
][0] == '-' && word
[idx
][1] == 'm')
1268 /* -pX to specify menu position */
1269 if (word
[idx
][0] == '-' && word
[idx
][1] == 'p')
1271 pos
= atoi (word
[idx
] + 2);
1275 /* -rSTATE,GROUP to specify a radio item */
1276 if (word
[idx
][0] == '-' && word
[idx
][1] == 'r')
1278 state
= atoi (word
[idx
] + 2);
1279 group
= word
[idx
] + 4;
1283 /* -tX to specify toggle item with default state */
1284 if (word
[idx
][0] == '-' && word
[idx
][1] == 't')
1286 state
= atoi (word
[idx
] + 2);
1291 if (word
[idx
+1][0] == 0)
1295 path_part (word
[idx
+1], tbuf
, 512);
1296 len
= strlen (tbuf
);
1300 /* the name of the item */
1301 label
= file_part (word
[idx
+ 1]);
1302 if (label
[0] == '-' && label
[1] == 0)
1303 label
= NULL
; /* separator */
1307 char *p
; /* to force pango closing tags through */
1308 for (p
= label
; *p
; p
++)
1313 if (!strcasecmp (word
[idx
], "ADD"))
1317 menu_add (tbuf
, label
, word
[idx
+ 2], word
[idx
+ 3], pos
, state
, markup
, enable
, mod
, key
, NULL
, NULL
);
1320 if (word
[idx
+ 2][0])
1321 menu_add (tbuf
, label
, word
[idx
+ 2], NULL
, pos
, state
, markup
, enable
, mod
, key
, group
, icon
);
1323 menu_add (tbuf
, label
, NULL
, NULL
, pos
, state
, markup
, enable
, mod
, key
, group
, icon
);
1328 if (!strcasecmp (word
[idx
], "DEL"))
1330 menu_del (tbuf
, label
);
1338 mkick_cb (struct User
*user
, multidata
*data
)
1340 if (!user
->op
&& !user
->me
)
1341 data
->sess
->server
->p_kick (data
->sess
->server
, data
->sess
->channel
, user
->nick
, data
->reason
);
1346 mkickops_cb (struct User
*user
, multidata
*data
)
1348 if (user
->op
&& !user
->me
)
1349 data
->sess
->server
->p_kick (data
->sess
->server
, data
->sess
->channel
, user
->nick
, data
->reason
);
1354 cmd_mkick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1359 data
.reason
= word_eol
[2];
1360 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mkickops_cb
, &data
);
1361 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mkick_cb
, &data
);
1367 cmd_devoice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1377 send_channel_modes (sess
, tbuf
, word
, 2, i
, '-', 'v', 0);
1385 cmd_discon (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1387 sess
->server
->disconnect (sess
, TRUE
, -1);
1392 cmd_dns (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1394 char *nick
= word
[2];
1399 if (strchr (nick
, '.') == NULL
)
1401 user
= userlist_find (sess
, nick
);
1402 if (user
&& user
->hostname
)
1404 do_dns (sess
, user
->nick
, user
->hostname
);
1407 sess
->server
->p_get_ip (sess
->server
, nick
);
1408 sess
->server
->doing_dns
= TRUE
;
1412 snprintf (tbuf
, TBUFSIZE
, "exec -d %s %s", prefs
.dnsprogram
, nick
);
1413 handle_command (sess
, tbuf
, FALSE
);
1421 cmd_echo (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1423 PrintText (sess
, word_eol
[2]);
1428 exec_check_process (struct session
*sess
)
1432 if (sess
->running_exec
== NULL
)
1434 val
= waitpid (sess
->running_exec
->childpid
, NULL
, WNOHANG
);
1435 if (val
== -1 || val
> 0)
1437 close (sess
->running_exec
->myfd
);
1438 fe_input_remove (sess
->running_exec
->iotag
);
1439 free (sess
->running_exec
);
1440 sess
->running_exec
= NULL
;
1445 cmd_execs (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1449 exec_check_process (sess
);
1450 if (sess
->running_exec
== NULL
)
1452 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1455 r
= kill (sess
->running_exec
->childpid
, SIGSTOP
);
1457 PrintText (sess
, "Error in kill(2)\n");
1463 cmd_execc (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1467 exec_check_process (sess
);
1468 if (sess
->running_exec
== NULL
)
1470 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1473 r
= kill (sess
->running_exec
->childpid
, SIGCONT
);
1475 PrintText (sess
, "Error in kill(2)\n");
1481 cmd_execk (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1485 exec_check_process (sess
);
1486 if (sess
->running_exec
== NULL
)
1488 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1491 if (strcmp (word
[2], "-9") == 0)
1492 r
= kill (sess
->running_exec
->childpid
, SIGKILL
);
1494 r
= kill (sess
->running_exec
->childpid
, SIGTERM
);
1496 PrintText (sess
, "Error in kill(2)\n");
1501 /* OS/2 Can't have the /EXECW command because it uses pipe(2) not socketpair
1502 and thus it is simplex --AGL */
1504 cmd_execw (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1508 exec_check_process (sess
);
1509 if (sess
->running_exec
== NULL
)
1511 EMIT_SIGNAL (XP_TE_NOCHILD
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1514 len
= strlen(word_eol
[2]);
1515 temp
= malloc(len
+ 2);
1516 sprintf(temp
, "%s\n", word_eol
[2]);
1517 PrintText(sess
, temp
);
1518 write(sess
->running_exec
->myfd
, temp
, len
+ 1);
1524 /* convert ANSI escape color codes to mIRC codes */
1526 static short escconv
[] =
1527 /* 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 */
1528 { 1,4,3,5,2,10,6,1, 1,7,9,8,12,11,13,1 };
1531 exec_handle_colors (char *buf
, int len
)
1535 int i
= 0, j
= 0, k
= 0, firstn
= 0, col
, colf
= 0, colb
= 0;
1536 int esc
= FALSE
, backc
= FALSE
, bold
= FALSE
;
1538 /* any escape codes in this text? */
1539 if (strchr (buf
, 27) == 0)
1542 nbuf
= malloc (len
+ 1);
1558 firstn
= atoi (numb
);
1568 if (buf
[i
] >= 'A' && buf
[i
] <= 'z')
1573 if (k
== 0 || (numb
[0] == '0' && k
== 1))
1588 if (firstn
>= 30 && firstn
<= 37)
1597 if (col
>= 30 && col
<= 37)
1605 colb
= escconv
[colb
% 14];
1606 colf
= escconv
[colf
% 14];
1607 j
+= sprintf (&nbuf
[j
], "\003%d,%02d", colf
, colb
);
1610 colf
= escconv
[colf
% 14];
1611 j
+= sprintf (&nbuf
[j
], "\003%02d", colf
);
1619 if (isdigit ((unsigned char) buf
[i
]) && k
< (sizeof (numb
) - 1))
1627 norm
: nbuf
[j
] = buf
[i
];
1635 memcpy (buf
, nbuf
, j
+ 1);
1640 exec_data (GIOChannel
*source
, GIOCondition condition
, struct nbexec
*s
)
1642 char *buf
, *readpos
, *rest
;
1648 /* append new data to buffered incomplete line */
1649 buf
= malloc(len
+ 2050);
1650 memcpy(buf
, s
->linebuf
, len
);
1651 readpos
= buf
+ len
;
1656 readpos
= buf
= malloc(2050);
1658 rd
= read (sok
, readpos
, 2048);
1661 /* The process has died */
1662 kill(s
->childpid
, SIGKILL
);
1665 exec_handle_colors(buf
, len
);
1668 /* must turn off auto-completion temporarily */
1669 unsigned int old
= prefs
.nickcompletion
;
1670 prefs
.nickcompletion
= 0;
1671 handle_multiline (s
->sess
, buf
, FALSE
, TRUE
);
1672 prefs
.nickcompletion
= old
;
1675 PrintText (s
->sess
, buf
);
1678 waitpid (s
->childpid
, NULL
, 0);
1679 s
->sess
->running_exec
= NULL
;
1680 fe_input_remove (s
->iotag
);
1688 rest
= memrchr(buf
, '\n', len
);
1694 s
->buffill
= len
- (rest
- buf
); /* = strlen(rest) */
1695 s
->linebuf
= malloc(s
->buffill
+ 1);
1696 memcpy(s
->linebuf
, rest
, s
->buffill
);
1698 len
-= s
->buffill
; /* possibly 0 */
1704 exec_handle_colors (buf
, len
);
1706 handle_multiline (s
->sess
, buf
, FALSE
, TRUE
);
1708 PrintText (s
->sess
, buf
);
1716 cmd_exec (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1718 int tochannel
= FALSE
;
1719 char *cmd
= word_eol
[2];
1720 int fds
[2], pid
= 0;
1727 exec_check_process (sess
);
1728 if (sess
->running_exec
!= NULL
)
1730 EMIT_SIGNAL (XP_TE_ALREADYPROCESS
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
1734 if (!strcmp (word
[2], "-d"))
1741 else if (!strcmp (word
[2], "-o"))
1751 if (access ("/bin/sh", X_OK
) != 0)
1753 fe_message (_("I need /bin/sh to run!\n"), FE_MSG_ERROR
);
1758 if (socketpair (PF_UNIX
, SOCK_STREAM
, 0, fds
) == -1)
1760 PrintText (sess
, "socketpair(2) failed\n");
1763 s
= (struct nbexec
*) malloc (sizeof (struct nbexec
));
1764 memset(s
, 0, sizeof(*s
));
1766 s
->tochannel
= tochannel
;
1772 /* This is the child's context */
1776 /* Close parent's end of pipe */
1778 /* Copy the child end of the pipe to stdout and stderr */
1781 /* Also copy it to stdin so we can write to it */
1783 /* Now close all open file descriptors except stdin, stdout and stderr */
1784 for (fd
= 3; fd
< 1024; fd
++) close(fd
);
1785 /* Now we call /bin/sh to run our cmd ; made it more friendly -DC1 */
1788 execl ("/bin/sh", "sh", "-c", cmd
, NULL
);
1794 my_poptParseArgvString (cmd
, &argc
, &argv
);
1795 execvp (argv
[0], argv
);
1797 /* not reached unless error */
1798 /*printf("exec error\n");*/
1805 /* Parent context, fork() failed */
1807 PrintText (sess
, "Error in fork(2)\n");
1815 s
->iotag
= fe_input_add (s
->myfd
, FIA_READ
|FIA_EX
, exec_data
, s
);
1816 sess
->running_exec
= s
;
1824 cmd_flushq (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1826 sprintf (tbuf
, "Flushing server send queue, %d bytes.\n", sess
->server
->sendq_len
);
1827 PrintText (sess
, tbuf
);
1828 sess
->server
->flush_queue (sess
->server
);
1833 cmd_quit (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1836 sess
->quitreason
= word_eol
[2];
1837 sess
->server
->disconnect (sess
, TRUE
, -1);
1838 sess
->quitreason
= NULL
;
1843 cmd_gate (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1845 char *server_name
= word
[2];
1846 server
*serv
= sess
->server
;
1849 char *port
= word
[3];
1851 serv
->use_ssl
= FALSE
;
1853 server_fill_her_up (serv
);
1855 serv
->connect (serv
, server_name
, atoi (port
), TRUE
);
1857 serv
->connect (serv
, server_name
, 23, TRUE
);
1870 get_int_cb (int cancel
, int val
, getvalinfo
*info
)
1876 snprintf (buf
, sizeof (buf
), "%s %d", info
->cmd
, val
);
1877 if (is_session (info
->sess
))
1878 handle_command (info
->sess
, buf
, FALSE
);
1886 cmd_getint (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1893 info
= malloc (sizeof (*info
));
1894 info
->cmd
= strdup (word
[3]);
1897 fe_get_int (word
[4], atoi (word
[2]), get_int_cb
, info
);
1903 get_file_cb (char *cmd
, char *file
)
1905 char buf
[1024 + 128];
1907 /* execute the command once per file, then once more with
1911 snprintf (buf
, sizeof (buf
), "%s %s", cmd
, file
);
1912 handle_command (current_sess
, buf
, FALSE
);
1916 handle_command (current_sess
, cmd
, FALSE
);
1922 cmd_getfile (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1930 if (!strcmp (word
[2], "-folder"))
1932 flags
|= FRF_CHOOSEFOLDER
;
1936 if (!strcmp (word
[idx
], "-multi"))
1938 flags
|= FRF_MULTIPLE
;
1942 if (!strcmp (word
[idx
], "-save"))
1948 fe_get_file (word
[idx
+1], word
[idx
+2], (void *)get_file_cb
, strdup (word
[idx
]), flags
);
1954 get_str_cb (int cancel
, char *val
, getvalinfo
*info
)
1960 snprintf (buf
, sizeof (buf
), "%s %s", info
->cmd
, val
);
1961 if (is_session (info
->sess
))
1962 handle_command (info
->sess
, buf
, FALSE
);
1970 cmd_getstr (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1977 info
= malloc (sizeof (*info
));
1978 info
->cmd
= strdup (word
[3]);
1981 fe_get_str (word
[4], word
[2], get_str_cb
, info
);
1987 cmd_ghost (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1992 sess
->server
->p_ns_ghost (sess
->server
, word
[2], word
[3]);
1997 cmd_gui (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
1999 switch (str_ihash (word
[2]))
2001 case 0x058b836e: fe_ctrl_gui (sess
, 8, 0); break; /* APPLY */
2002 case 0xac1eee45: fe_ctrl_gui (sess
, 7, 2); break; /* ATTACH */
2003 case 0x05a72f63: fe_ctrl_gui (sess
, 4, atoi (word
[3])); break; /* COLOR */
2004 case 0xb06a1793: fe_ctrl_gui (sess
, 7, 1); break; /* DETACH */
2005 case 0x05cfeff0: fe_ctrl_gui (sess
, 3, 0); break; /* FLASH */
2006 case 0x05d154d8: fe_ctrl_gui (sess
, 2, 0); break; /* FOCUS */
2007 case 0x0030dd42: fe_ctrl_gui (sess
, 0, 0); break; /* HIDE */
2008 case 0x61addbe3: fe_ctrl_gui (sess
, 5, 0); break; /* ICONIFY */
2009 case 0xc0851aaa: fe_message (word
[3], FE_MSG_INFO
|FE_MSG_MARKUP
); break; /* MSGBOX */
2010 case 0x0035dafd: fe_ctrl_gui (sess
, 1, 0); break; /* SHOW */
2011 case 0x0033155f: /* MENU */
2012 if (!strcasecmp (word
[3], "TOGGLE"))
2013 fe_ctrl_gui (sess
, 6, 0);
2032 show_help_line (session
*sess
, help_list
*hl
, char *name
, char *usage
)
2037 if (name
[0] == '.') /* hidden command? */
2040 if (hl
->longfmt
) /* long format for /HELP -l */
2042 if (!usage
|| usage
[0] == 0)
2043 PrintTextf (sess
, " \0034%s\003 :\n", name
);
2045 PrintTextf (sess
, " \0034%s\003 : %s\n", name
, _(usage
));
2049 /* append the name into buffer, but convert to uppercase */
2050 len
= strlen (hl
->buf
);
2054 hl
->buf
[len
] = toupper ((unsigned char) *p
);
2064 strcat (hl
->buf
, "\n");
2065 PrintText (sess
, hl
->buf
);
2071 /* append some spaces after the command name */
2072 max
= strlen (name
);
2076 for (j
= 0; j
< max
; j
++)
2087 cmd_help (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2089 int i
= 0, longfmt
= 0;
2095 if (*helpcmd
&& strcmp (helpcmd
, "-l") == 0)
2098 if (*helpcmd
&& !longfmt
)
2100 help (sess
, tbuf
, helpcmd
, FALSE
);
2104 char *buf
= malloc (4096);
2107 hl
.longfmt
= longfmt
;
2110 PrintTextf (sess
, "\n%s\n\n", _("Commands Available:"));
2116 while (xc_cmds
[i
].name
)
2118 show_help_line (sess
, &hl
, xc_cmds
[i
].name
, xc_cmds
[i
].help
);
2122 PrintText (sess
, buf
);
2124 PrintTextf (sess
, "\n%s\n\n", _("User defined commands:"));
2130 list
= command_list
;
2134 show_help_line (sess
, &hl
, pop
->name
, pop
->cmd
);
2138 PrintText (sess
, buf
);
2140 PrintTextf (sess
, "\n%s\n\n", _("Plugin defined commands:"));
2146 plugin_command_foreach (sess
, &hl
, (void *)show_help_line
);
2148 PrintText (sess
, buf
);
2151 PrintTextf (sess
, "\n%s\n\n", _("Type /HELP <command> for more information, or /HELP -l"));
2157 cmd_id (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2161 sess
->server
->p_ns_identify (sess
->server
, word
[2]);
2169 cmd_ignore (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2178 ignore_showlist (sess
);
2193 if (strchr (mask
, '?') == NULL
&&
2194 strchr (mask
, '*') == NULL
)
2197 snprintf (tbuf
, TBUFSIZE
, "%s!*@*", word
[2]);
2200 i
= ignore_add (mask
, type
);
2206 EMIT_SIGNAL (XP_TE_IGNOREADD
, sess
, mask
, NULL
, NULL
, NULL
, 0);
2208 case 2: /* old ignore changed */
2209 EMIT_SIGNAL (XP_TE_IGNORECHANGE
, sess
, mask
, NULL
, NULL
, NULL
, 0);
2213 if (!strcasecmp (word
[i
], "UNIGNORE"))
2215 else if (!strcasecmp (word
[i
], "ALL"))
2216 type
|= IG_PRIV
| IG_NOTI
| IG_CHAN
| IG_CTCP
| IG_INVI
| IG_DCC
;
2217 else if (!strcasecmp (word
[i
], "PRIV"))
2219 else if (!strcasecmp (word
[i
], "NOTI"))
2221 else if (!strcasecmp (word
[i
], "CHAN"))
2223 else if (!strcasecmp (word
[i
], "CTCP"))
2225 else if (!strcasecmp (word
[i
], "INVI"))
2227 else if (!strcasecmp (word
[i
], "QUIET"))
2229 else if (!strcasecmp (word
[i
], "NOSAVE"))
2231 else if (!strcasecmp (word
[i
], "DCC"))
2235 sprintf (tbuf
, _("Unknown arg '%s' ignored."), word
[i
]);
2236 PrintText (sess
, tbuf
);
2243 cmd_invite (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2248 sess
->server
->p_invite (sess
->server
, word
[3], word
[2]);
2250 sess
->server
->p_invite (sess
->server
, sess
->channel
, word
[2]);
2255 cmd_join (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2257 char *chan
= word
[2];
2260 char *po
, *pass
= word
[3];
2261 sess
->server
->p_join (sess
->server
, chan
, pass
);
2262 if (sess
->channel
[0] == 0 && sess
->waitchannel
[0])
2264 po
= strchr (chan
, ',');
2267 safe_strcpy (sess
->waitchannel
, chan
, CHANLEN
);
2275 cmd_kick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2277 char *nick
= word
[2];
2278 char *reason
= word_eol
[3];
2281 sess
->server
->p_kick (sess
->server
, sess
->channel
, nick
, reason
);
2288 cmd_kickban (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2290 char *nick
= word
[2];
2291 char *reason
= word_eol
[3];
2296 /* if the reason is a 1 digit number, treat it as a bantype */
2298 user
= userlist_find (sess
, nick
);
2300 if (isdigit ((unsigned char) reason
[0]) && reason
[1] == 0)
2302 ban (sess
, tbuf
, nick
, reason
, (user
&& user
->op
));
2305 ban (sess
, tbuf
, nick
, "", (user
&& user
->op
));
2307 sess
->server
->p_kick (sess
->server
, sess
->channel
, nick
, reason
);
2315 cmd_killall (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2322 cmd_lagcheck (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2329 lastlog (session
*sess
, char *search
, gboolean regexp
)
2331 session
*lastlog_sess
;
2333 if (!is_session (sess
))
2336 lastlog_sess
= find_dialog (sess
->server
, "(lastlog)");
2338 lastlog_sess
= new_ircwindow (sess
->server
, "(lastlog)", SESS_DIALOG
, 0);
2340 lastlog_sess
->lastlog_sess
= sess
;
2341 lastlog_sess
->lastlog_regexp
= regexp
; /* remember the search type */
2343 fe_text_clear (lastlog_sess
, 0);
2344 fe_lastlog (sess
, lastlog_sess
, search
, regexp
);
2348 cmd_lastlog (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2352 if (!strcmp (word
[2], "-r"))
2353 lastlog (sess
, word_eol
[3], TRUE
);
2355 lastlog (sess
, word_eol
[2], FALSE
);
2363 cmd_list (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2365 sess
->server
->p_list_channels (sess
->server
, word_eol
[2], 1);
2371 load_perform_file (session
*sess
, char *file
)
2373 char tbuf
[1024 + 4];
2377 fp
= xchat_fopen_file (file
, "r", XOF_FULLPATH
);
2382 while (fgets (tbuf
, 1024, fp
))
2384 nl
= strchr (tbuf
, '\n');
2385 if (nl
== tbuf
) /* skip empty commands */
2389 if (tbuf
[0] == prefs
.cmdchar
[0])
2390 handle_command (sess
, tbuf
+ 1, TRUE
);
2392 handle_command (sess
, tbuf
, TRUE
);
2399 cmd_load (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2401 char *error
, *arg
, *file
;
2407 if (strcmp (word
[2], "-e") == 0)
2409 file
= expand_homedir (word
[3]);
2410 if (!load_perform_file (sess
, file
))
2412 PrintTextf (sess
, _("Cannot access %s\n"), file
);
2413 PrintText (sess
, errorstring (errno
));
2420 len
= strlen (word
[2]);
2421 if (len
> 3 && strcasecmp (".so", word
[2] + len
- 3) == 0)
2427 file
= expand_homedir (word
[2]);
2428 error
= plugin_load (sess
, file
, arg
);
2432 PrintText (sess
, error
);
2438 sprintf (tbuf
, "Unknown file type %s. Maybe you need to install the Perl or Python plugin?\n", word
[2]);
2439 PrintText (sess
, tbuf
);
2445 cmd_me (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2447 char *act
= word_eol
[2];
2452 if (sess
->type
== SESS_SERVER
)
2458 snprintf (tbuf
, TBUFSIZE
, "\001ACTION %s\001\r", act
);
2459 /* first try through DCC CHAT */
2460 if (dcc_write_chat (sess
->channel
, tbuf
))
2462 /* print it to screen */
2463 inbound_action (sess
, sess
->channel
, sess
->server
->nick
, "", act
, TRUE
, FALSE
);
2466 /* DCC CHAT failed, try through server */
2467 if (sess
->server
->connected
)
2469 sess
->server
->p_action (sess
->server
, sess
->channel
, act
);
2470 /* print it to screen */
2471 inbound_action (sess
, sess
->channel
, sess
->server
->nick
, "", act
, TRUE
, FALSE
);
2482 cmd_mode (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2484 /* +channel channels are dying, let those servers whine about modes.
2485 * return info about current channel if available and no info is given */
2486 if ((*word
[2] == '+') || (*word
[2] == 0) || (!is_channel(sess
->server
, word
[2]) &&
2487 !(rfc_casecmp(sess
->server
->nick
, word
[2]) == 0)))
2489 if(sess
->channel
[0] == 0)
2491 sess
->server
->p_mode (sess
->server
, sess
->channel
, word_eol
[2]);
2494 sess
->server
->p_mode (sess
->server
, word
[2], word_eol
[3]);
2499 mop_cb (struct User
*user
, multidata
*data
)
2503 data
->nicks
[data
->i
] = user
->nick
;
2510 cmd_mop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2512 char **nicks
= malloc (sizeof (char *) * (sess
->total
- sess
->ops
));
2517 tree_foreach (sess
->usertree
, (tree_traverse_func
*)mop_cb
, &data
);
2518 send_channel_modes (sess
, tbuf
, nicks
, 0, data
.i
, '+', 'o', 0);
2526 cmd_msg (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2528 char *nick
= word
[2];
2529 char *msg
= word_eol
[3];
2530 struct session
*newsess
;
2536 if (strcmp (nick
, ".") == 0)
2537 { /* /msg the last nick /msg'ed */
2538 if (sess
->lastnick
[0])
2539 nick
= sess
->lastnick
;
2542 safe_strcpy (sess
->lastnick
, nick
, NICKLEN
); /* prime the last nick memory */
2548 if (!dcc_write_chat (nick
, msg
))
2550 EMIT_SIGNAL (XP_TE_NODCC
, sess
, NULL
, NULL
, NULL
, NULL
, 0);
2555 if (!sess
->server
->connected
)
2560 sess
->server
->p_message (sess
->server
, nick
, msg
);
2562 newsess
= find_dialog (sess
->server
, nick
);
2564 newsess
= find_channel (sess
->server
, nick
);
2566 inbound_chanmsg (newsess
->server
, NULL
, newsess
->channel
,
2567 newsess
->server
->nick
, msg
, TRUE
, FALSE
);
2570 /* mask out passwords */
2571 if (strcasecmp (nick
, "nickserv") == 0 &&
2572 strncasecmp (msg
, "identify ", 9) == 0)
2573 msg
= "identify ****";
2574 EMIT_SIGNAL (XP_TE_MSGSEND
, sess
, nick
, msg
, NULL
, NULL
, 0);
2584 cmd_names (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2587 sess
->server
->p_names (sess
->server
, word
[2]);
2589 sess
->server
->p_names (sess
->server
, sess
->channel
);
2594 cmd_nctcp (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2598 sess
->server
->p_nctcp (sess
->server
, word
[2], word_eol
[3]);
2605 cmd_newserver (struct session
*sess
, char *tbuf
, char *word
[],
2608 if (strcmp (word
[2], "-noconnect") == 0)
2610 new_ircwindow (NULL
, word
[3], SESS_SERVER
, 0);
2614 sess
= new_ircwindow (NULL
, NULL
, SESS_SERVER
, 0);
2615 cmd_server (sess
, tbuf
, word
, word_eol
);
2620 cmd_nick (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2622 char *nick
= word
[2];
2625 if (sess
->server
->connected
)
2626 sess
->server
->p_change_nick (sess
->server
, nick
);
2628 inbound_newnick (sess
->server
, sess
->server
->nick
, nick
, TRUE
);
2635 cmd_notice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2637 if (*word
[2] && *word_eol
[3])
2639 sess
->server
->p_notice (sess
->server
, word
[2], word_eol
[3]);
2640 EMIT_SIGNAL (XP_TE_NOTICESEND
, sess
, word
[2], word_eol
[3], NULL
, NULL
, 0);
2647 cmd_notify (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2654 if (strcmp (word
[2], "-n") == 0) /* comma sep network list */
2665 if (notify_deluser (word
[i
]))
2667 EMIT_SIGNAL (XP_TE_DELNOTIFY
, sess
, word
[i
], NULL
, NULL
, NULL
, 0);
2671 if (net
&& strcmp (net
, "ASK") == 0)
2672 fe_notify_ask (word
[i
], NULL
);
2675 notify_adduser (word
[i
], net
);
2676 EMIT_SIGNAL (XP_TE_ADDNOTIFY
, sess
, word
[i
], NULL
, NULL
, NULL
, 0);
2680 notify_showlist (sess
);
2685 cmd_op (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2695 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'o', 0);
2703 cmd_part (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2705 char *chan
= word
[2];
2706 char *reason
= word_eol
[3];
2708 chan
= sess
->channel
;
2709 if ((*chan
) && is_channel (sess
->server
, chan
))
2713 server_sendpart (sess
->server
, chan
, reason
);
2720 cmd_ping (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2722 char timestring
[64];
2726 tim
= make_ping_time ();
2728 snprintf (timestring
, sizeof (timestring
), "%lu", tim
);
2729 sess
->server
->p_ping (sess
->server
, to
, timestring
);
2735 open_query (server
*serv
, char *nick
, gboolean focus_existing
)
2739 sess
= find_dialog (serv
, nick
);
2741 new_ircwindow (serv
, nick
, SESS_DIALOG
, 1);
2742 else if (focus_existing
)
2743 fe_ctrl_gui (sess
, 2, 0); /* bring-to-front */
2747 cmd_query (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2749 char *nick
= word
[2];
2750 gboolean focus
= TRUE
;
2752 if (strcmp (word
[2], "-nofocus") == 0)
2758 if (*nick
&& !is_channel (sess
->server
, nick
))
2760 open_query (sess
->server
, nick
, focus
);
2767 cmd_quote (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2769 char *raw
= word_eol
[2];
2771 return sess
->server
->p_raw (sess
->server
, raw
);
2775 cmd_reconnect (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2777 int tmp
= prefs
.recon_delay
;
2779 server
*serv
= sess
->server
;
2781 prefs
.recon_delay
= 0;
2783 if (!strcasecmp (word
[2], "ALL"))
2789 if (serv
->connected
)
2790 serv
->auto_reconnect (serv
, TRUE
, -1);
2794 /* If it isn't "ALL" and there is something
2795 there it *should* be a server they are trying to connect to*/
2800 int use_ssl
= FALSE
;
2802 if (strcmp (word
[2], "-ssl") == 0)
2805 offset
++; /* args move up by 1 word */
2807 serv
->use_ssl
= use_ssl
;
2808 serv
->accept_invalid_cert
= TRUE
;
2811 if (*word
[4+offset
])
2812 safe_strcpy (serv
->password
, word
[4+offset
], sizeof (serv
->password
));
2813 if (*word
[3+offset
])
2814 serv
->port
= atoi (word
[3+offset
]);
2815 safe_strcpy (serv
->hostname
, word
[2+offset
], sizeof (serv
->hostname
));
2816 serv
->auto_reconnect (serv
, TRUE
, -1);
2820 serv
->auto_reconnect (serv
, TRUE
, -1);
2822 prefs
.recon_delay
= tmp
;
2828 cmd_recv (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2832 sess
->server
->p_inline (sess
->server
, word_eol
[2], strlen (word_eol
[2]));
2840 cmd_say (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2842 char *speech
= word_eol
[2];
2845 handle_say (sess
, speech
, FALSE
);
2852 cmd_send (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2856 struct sockaddr_in SAddr
;
2861 addr
= dcc_get_my_address ();
2864 /* use the one from our connected server socket */
2865 memset (&SAddr
, 0, sizeof (struct sockaddr_in
));
2866 len
= sizeof (SAddr
);
2867 getsockname (sess
->server
->sok
, (struct sockaddr
*) &SAddr
, &len
);
2868 addr
= SAddr
.sin_addr
.s_addr
;
2870 addr
= ntohl (addr
);
2872 if ((addr
& 0xffff0000) == 0xc0a80000 || /* 192.168.x.x */
2873 (addr
& 0xff000000) == 0x0a000000) /* 10.x.x.x */
2874 /* we got a private net address, let's PSEND or it'll fail */
2875 snprintf (tbuf
, 512, "DCC PSEND %s", word_eol
[2]);
2877 snprintf (tbuf
, 512, "DCC SEND %s", word_eol
[2]);
2879 handle_command (sess
, tbuf
, FALSE
);
2885 cmd_setcursor (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2891 if (word
[2][0] == '-' || word
[2][0] == '+')
2893 fe_set_inputbox_cursor (sess
, delta
, atoi (word
[2]));
2901 cmd_settab (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2905 strcpy (tbuf
, sess
->channel
);
2906 safe_strcpy (sess
->channel
, word_eol
[2], CHANLEN
);
2907 fe_set_channel (sess
);
2908 strcpy (sess
->channel
, tbuf
);
2915 cmd_settext (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2917 fe_set_inputbox_contents (sess
, word_eol
[2]);
2922 cmd_splay (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2926 sound_play (word
[2], FALSE
);
2934 parse_irc_url (char *url
, char *server_name
[], char *port
[], char *channel
[], int *use_ssl
)
2938 if (strncasecmp ("ircs://", url
, 7) == 0)
2941 *server_name
= url
+ 7;
2946 if (strncasecmp ("irc://", url
, 6) == 0)
2948 *server_name
= url
+ 6;
2952 /* check for port */
2953 co
= strchr (*server_name
, ':');
2960 /* check for channel - mirc style */
2961 co
= strchr (co
+ 1, '/');
2978 cmd_server (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
2981 char *server_name
= NULL
;
2984 char *channel
= NULL
;
2985 int use_ssl
= FALSE
;
2987 server
*serv
= sess
->server
;
2990 /* BitchX uses -ssl, mIRC uses -e, let's support both */
2991 if (strcmp (word
[2], "-ssl") == 0 || strcmp (word
[2], "-e") == 0)
2994 offset
++; /* args move up by 1 word */
2998 if (!parse_irc_url (word
[2 + offset
], &server_name
, &port
, &channel
, &use_ssl
))
3001 server_name
= word
[2 + offset
];
3004 pass
= word
[3 + offset
];
3007 port
= word
[3 + offset
];
3008 pass
= word
[4 + offset
];
3011 if (!(*server_name
))
3014 sess
->server
->network
= NULL
;
3016 /* dont clear it for /servchan */
3017 if (strncasecmp (word_eol
[1], "SERVCHAN ", 9))
3018 sess
->willjoinchannel
[0] = 0;
3022 sess
->willjoinchannel
[0] = '#';
3023 safe_strcpy ((sess
->willjoinchannel
+ 1), channel
, (CHANLEN
- 1));
3026 /* support +7000 style ports like mIRC */
3037 safe_strcpy (serv
->password
, pass
, sizeof (serv
->password
));
3040 serv
->use_ssl
= use_ssl
;
3041 serv
->accept_invalid_cert
= TRUE
;
3044 /* try to connect by Network name */
3045 if (servlist_connect_by_netname (sess
, server_name
, !is_url
))
3050 serv
->connect (serv
, server_name
, atoi (port
), FALSE
);
3053 /* -1 for default port */
3054 serv
->connect (serv
, server_name
, -1, FALSE
);
3057 /* try to associate this connection with a listed network */
3059 /* search for this hostname in the entire server list */
3060 serv
->network
= servlist_net_find_from_server (server_name
);
3061 /* may return NULL, but that's OK */
3067 cmd_servchan (struct session
*sess
, char *tbuf
, char *word
[],
3073 if (strcmp (word
[2], "-ssl") == 0)
3077 if (*word
[4 + offset
])
3079 safe_strcpy (sess
->willjoinchannel
, word
[4 + offset
], CHANLEN
);
3080 return cmd_server (sess
, tbuf
, word
, word_eol
);
3087 cmd_topic (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3089 if (word
[2][0] && is_channel (sess
->server
, word
[2]))
3090 sess
->server
->p_topic (sess
->server
, word
[2], word_eol
[3]);
3092 sess
->server
->p_topic (sess
->server
, sess
->channel
, word_eol
[2]);
3097 cmd_tray (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3099 if (strcmp (word
[2], "-b") == 0)
3101 fe_tray_set_balloon (word
[3], word
[4][0] ? word
[4] : NULL
);
3105 if (strcmp (word
[2], "-t") == 0)
3107 fe_tray_set_tooltip (word
[3][0] ? word
[3] : NULL
);
3111 if (strcmp (word
[2], "-i") == 0)
3113 fe_tray_set_icon (atoi (word
[3]));
3117 if (strcmp (word
[2], "-f") != 0)
3122 fe_tray_set_file (NULL
); /* default xchat icon */
3128 fe_tray_set_file (word
[3]); /* fixed custom icon */
3132 /* flash between 2 icons */
3133 fe_tray_set_flash (word
[4], word
[5][0] ? word
[5] : NULL
, atoi (word
[3]));
3138 cmd_unignore (struct session
*sess
, char *tbuf
, char *word
[],
3141 char *mask
= word
[2];
3142 char *arg
= word
[3];
3145 if (ignore_del (mask
, NULL
))
3147 if (strcasecmp (arg
, "QUIET"))
3148 EMIT_SIGNAL (XP_TE_IGNOREREMOVE
, sess
, mask
, NULL
, NULL
, NULL
, 0);
3156 cmd_unload (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3159 int len
, by_file
= FALSE
;
3161 len
= strlen (word
[2]);
3162 if (len
> 3 && strcasecmp (word
[2] + len
- 3, ".so") == 0)
3165 switch (plugin_kill (word
[2], by_file
))
3168 PrintText (sess
, _("No such plugin found.\n"));
3173 PrintText (sess
, _("That plugin is refusing to unload.\n"));
3182 find_server_from_hostname (char *hostname
)
3184 GSList
*list
= serv_list
;
3190 if (!strcasecmp (hostname
, serv
->hostname
) && serv
->connected
)
3199 find_server_from_net (void *net
)
3201 GSList
*list
= serv_list
;
3207 if (serv
->network
== net
&& serv
->connected
)
3216 url_join_only (server
*serv
, char *tbuf
, char *channel
)
3218 /* already connected, JOIN only. FIXME: support keys? */
3221 safe_strcpy ((tbuf
+ 1), channel
, 256);
3222 serv
->p_join (serv
, tbuf
, "");
3226 cmd_url (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3230 char *server_name
= NULL
;
3232 char *channel
= NULL
;
3233 char *url
= g_strdup (word
[2]);
3234 int use_ssl
= FALSE
;
3238 if (parse_irc_url (url
, &server_name
, &port
, &channel
, &use_ssl
))
3240 /* maybe we're already connected to this net */
3242 /* check for "FreeNode" */
3243 net
= servlist_net_find (server_name
, NULL
, strcasecmp
);
3244 /* check for "irc.eu.freenode.net" */
3246 net
= servlist_net_find_from_server (server_name
);
3250 /* found the network, but are we connected? */
3251 serv
= find_server_from_net (net
);
3254 url_join_only (serv
, tbuf
, channel
);
3261 /* an un-listed connection */
3262 serv
= find_server_from_hostname (server_name
);
3265 url_join_only (serv
, tbuf
, channel
);
3271 /* not connected to this net, open new window */
3272 cmd_newserver (sess
, tbuf
, word
, word_eol
);
3275 fe_open_url (word
[2]);
3284 userlist_cb (struct User
*user
, session
*sess
)
3288 if (!user
->lasttalk
)
3291 lt
= time (0) - user
->lasttalk
;
3293 "\00306%s\t\00314[\00310%-38s\00314] \017ov\0033=\017%d%d away=%u lt\0033=\017%d\n",
3294 user
->nick
, user
->hostname
, user
->op
, user
->voice
, user
->away
, lt
);
3300 cmd_uselect (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3306 if (strcmp (word
[2], "-a") == 0) /* ADD (don't clear selections) */
3311 if (strcmp (word
[idx
], "-s") == 0) /* SCROLL TO */
3316 /* always valid, no args means clear the selection list */
3317 fe_uselect (sess
, word
+ idx
, clear
, scroll
);
3322 cmd_userlist (struct session
*sess
, char *tbuf
, char *word
[],
3325 tree_foreach (sess
->usertree
, (tree_traverse_func
*)userlist_cb
, sess
);
3330 wallchop_cb (struct User
*user
, multidata
*data
)
3335 strcat (data
->tbuf
, ",");
3336 strcat (data
->tbuf
, user
->nick
);
3342 sprintf (data
->tbuf
+ strlen (data
->tbuf
),
3343 " :[@%s] %s", data
->sess
->channel
, data
->reason
);
3344 data
->sess
->server
->p_raw (data
->sess
->server
, data
->tbuf
);
3345 strcpy (data
->tbuf
, "NOTICE ");
3352 cmd_wallchop (struct session
*sess
, char *tbuf
, char *word
[],
3357 if (!(*word_eol
[2]))
3360 strcpy (tbuf
, "NOTICE ");
3362 data
.reason
= word_eol
[2];
3366 tree_foreach (sess
->usertree
, (tree_traverse_func
*)wallchop_cb
, &data
);
3370 sprintf (tbuf
+ strlen (tbuf
),
3371 " :[@%s] %s", sess
->channel
, word_eol
[2]);
3372 sess
->server
->p_raw (sess
->server
, tbuf
);
3379 cmd_wallchan (struct session
*sess
, char *tbuf
, char *word
[],
3390 if (sess
->type
== SESS_CHANNEL
)
3392 inbound_chanmsg (sess
->server
, NULL
, sess
->channel
,
3393 sess
->server
->nick
, word_eol
[2], TRUE
, FALSE
);
3394 sess
->server
->p_message (sess
->server
, sess
->channel
, word_eol
[2]);
3404 cmd_hop (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3414 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'h', 0);
3422 cmd_voice (struct session
*sess
, char *tbuf
, char *word
[], char *word_eol
[])
3432 send_channel_modes (sess
, tbuf
, word
, 2, i
, '+', 'v', 0);
3439 /* *MUST* be kept perfectly sorted for the bsearch to work */
3440 const struct commands xc_cmds
[] = {
3441 {"ADDBUTTON", cmd_addbutton
, 0, 0, 1,
3442 N_("ADDBUTTON <name> <action>, adds a button under the user-list")},
3443 {"ALLCHAN", cmd_allchannels
, 0, 0, 1,
3444 N_("ALLCHAN <cmd>, sends a command to all channels you're in")},
3445 {"ALLCHANL", cmd_allchannelslocal
, 0, 0, 1,
3446 N_("ALLCHANL <cmd>, sends a command to all channels on the current server")},
3447 {"ALLSERV", cmd_allservers
, 0, 0, 1,
3448 N_("ALLSERV <cmd>, sends a command to all servers you're in")},
3449 {"AWAY", cmd_away
, 1, 0, 1, N_("AWAY [<reason>], sets you away")},
3450 {"BACK", cmd_back
, 1, 0, 1, N_("BACK, sets you back (not away)")},
3451 {"BAN", cmd_ban
, 1, 1, 1,
3452 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)")},
3453 {"CHANOPT", cmd_chanopt
, 0, 0, 1, N_("CHANOPT [-quiet] <variable> [<value>]")},
3454 {"CHARSET", cmd_charset
, 0, 0, 1, N_("CHARSET [<encoding>], get or set the encoding used for the current connection")},
3455 {"CLEAR", cmd_clear
, 0, 0, 1, N_("CLEAR [ALL|HISTORY], Clears the current text window or command history")},
3456 {"CLOSE", cmd_close
, 0, 0, 1, N_("CLOSE, Closes the current window/tab")},
3458 {"COUNTRY", cmd_country
, 0, 0, 1,
3459 N_("COUNTRY [-s] <code|wildcard>, finds a country code, eg: au = australia")},
3460 {"CTCP", cmd_ctcp
, 1, 0, 1,
3461 N_("CTCP <nick> <message>, send the CTCP message to nick, common messages are VERSION and USERINFO")},
3462 {"CYCLE", cmd_cycle
, 1, 1, 1,
3463 N_("CYCLE [<channel>], parts the current or given channel and immediately rejoins")},
3464 {"DCC", cmd_dcc
, 0, 0, 1,
3466 "DCC GET <nick> - accept an offered file\n"
3467 "DCC SEND [-maxcps=#] <nick> [file] - send a file to someone\n"
3468 "DCC PSEND [-maxcps=#] <nick> [file] - send a file using passive mode\n"
3469 "DCC LIST - show DCC list\n"
3470 "DCC CHAT <nick> - offer DCC CHAT to someone\n"
3471 "DCC PCHAT <nick> - offer DCC CHAT using passive mode\n"
3472 "DCC CLOSE <type> <nick> <file> example:\n"
3473 " /dcc close send johnsmith file.tar.gz")},
3474 {"DEBUG", cmd_debug
, 0, 0, 1, 0},
3476 {"DEHOP", cmd_dehop
, 1, 1, 1,
3477 N_("DEHOP <nick>, removes chanhalf-op status from the nick on the current channel (needs chanop)")},
3478 {"DELBUTTON", cmd_delbutton
, 0, 0, 1,
3479 N_("DELBUTTON <name>, deletes a button from under the user-list")},
3480 {"DEOP", cmd_deop
, 1, 1, 1,
3481 N_("DEOP <nick>, removes chanop status from the nick on the current channel (needs chanop)")},
3482 {"DEVOICE", cmd_devoice
, 1, 1, 1,
3483 N_("DEVOICE <nick>, removes voice status from the nick on the current channel (needs chanop)")},
3484 {"DISCON", cmd_discon
, 0, 0, 1, N_("DISCON, Disconnects from server")},
3485 {"DNS", cmd_dns
, 0, 0, 1, N_("DNS <nick|host|ip>, Finds a users IP number")},
3486 {"ECHO", cmd_echo
, 0, 0, 1, N_("ECHO <text>, Prints text locally")},
3487 {"EXEC", cmd_exec
, 0, 0, 1,
3488 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")},
3489 {"EXECCONT", cmd_execc
, 0, 0, 1, N_("EXECCONT, sends the process SIGCONT")},
3490 {"EXECKILL", cmd_execk
, 0, 0, 1,
3491 N_("EXECKILL [-9], kills a running exec in the current session. If -9 is given the process is SIGKILL'ed")},
3492 {"EXECSTOP", cmd_execs
, 0, 0, 1, N_("EXECSTOP, sends the process SIGSTOP")},
3493 {"EXECWRITE", cmd_execw
, 0, 0, 1, N_("EXECWRITE, sends data to the processes stdin")},
3494 {"FLUSHQ", cmd_flushq
, 0, 0, 1,
3495 N_("FLUSHQ, flushes the current server's send queue")},
3496 {"GATE", cmd_gate
, 0, 0, 1,
3497 N_("GATE <host> [<port>], proxies through a host, port defaults to 23")},
3498 {"GETFILE", cmd_getfile
, 0, 0, 1, "GETFILE [-folder] [-multi] [-save] <command> <title> [<initial>]"},
3499 {"GETINT", cmd_getint
, 0, 0, 1, "GETINT <default> <command> <prompt>"},
3500 {"GETSTR", cmd_getstr
, 0, 0, 1, "GETSTR <default> <command> <prompt>"},
3501 {"GHOST", cmd_ghost
, 1, 0, 1, N_("GHOST <nick> [password], Kills a ghosted nickname")},
3502 {"GUI", cmd_gui
, 0, 0, 1, "GUI [APPLY|ATTACH|DETACH|SHOW|HIDE|FOCUS|FLASH|ICONIFY|COLOR <n>]\n"
3503 " GUI [MSGBOX <text>|MENU TOGGLE]"},
3504 {"HELP", cmd_help
, 0, 0, 1, 0},
3505 {"HOP", cmd_hop
, 1, 1, 1,
3506 N_("HOP <nick>, gives chanhalf-op status to the nick (needs chanop)")},
3507 {"ID", cmd_id
, 1, 0, 1, N_("ID <password>, identifies yourself to nickserv")},
3508 {"IGNORE", cmd_ignore
, 0, 0, 1,
3509 N_("IGNORE <mask> <types..> <options..>\n"
3510 " mask - host mask to ignore, eg: *!*@*.aol.com\n"
3511 " types - types of data to ignore, one or all of:\n"
3512 " PRIV, CHAN, NOTI, CTCP, DCC, INVI, ALL\n"
3513 " options - NOSAVE, QUIET")},
3515 {"INVITE", cmd_invite
, 1, 0, 1,
3516 N_("INVITE <nick> [<channel>], invites someone to a channel, by default the current channel (needs chanop)")},
3517 {"JOIN", cmd_join
, 1, 0, 0, N_("JOIN <channel>, joins the channel")},
3518 {"KICK", cmd_kick
, 1, 1, 1,
3519 N_("KICK <nick>, kicks the nick from the current channel (needs chanop)")},
3520 {"KICKBAN", cmd_kickban
, 1, 1, 1,
3521 N_("KICKBAN <nick>, bans then kicks the nick from the current channel (needs chanop)")},
3522 {"KILLALL", cmd_killall
, 0, 0, 1, "KILLALL, immediately exit"},
3523 {"LAGCHECK", cmd_lagcheck
, 0, 0, 1,
3524 N_("LAGCHECK, forces a new lag check")},
3525 {"LASTLOG", cmd_lastlog
, 0, 0, 1,
3526 N_("LASTLOG <string>, searches for a string in the buffer")},
3527 {"LIST", cmd_list
, 1, 0, 1, 0},
3528 {"LOAD", cmd_load
, 0, 0, 1, N_("LOAD [-e] <file>, loads a plugin or script")},
3530 {"MDEHOP", cmd_mdehop
, 1, 1, 1,
3531 N_("MDEHOP, Mass deop's all chanhalf-ops in the current channel (needs chanop)")},
3532 {"MDEOP", cmd_mdeop
, 1, 1, 1,
3533 N_("MDEOP, Mass deop's all chanops in the current channel (needs chanop)")},
3534 {"ME", cmd_me
, 0, 0, 1,
3535 N_("ME <action>, sends the action to the current channel (actions are written in the 3rd person, like /me jumps)")},
3536 {"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"
3537 " See http://xchat.org/docs/menu/ for more details."},
3538 {"MKICK", cmd_mkick
, 1, 1, 1,
3539 N_("MKICK, Mass kicks everyone except you in the current channel (needs chanop)")},
3540 {"MODE", cmd_mode
, 1, 0, 1, 0},
3541 {"MOP", cmd_mop
, 1, 1, 1,
3542 N_("MOP, Mass op's all users in the current channel (needs chanop)")},
3543 {"MSG", cmd_msg
, 0, 0, 1, N_("MSG <nick> <message>, sends a private message")},
3545 {"NAMES", cmd_names
, 1, 0, 1,
3546 N_("NAMES, Lists the nicks on the current channel")},
3547 {"NCTCP", cmd_nctcp
, 1, 0, 1,
3548 N_("NCTCP <nick> <message>, Sends a CTCP notice")},
3549 {"NEWSERVER", cmd_newserver
, 0, 0, 1, N_("NEWSERVER [-noconnect] <hostname> [<port>]")},
3550 {"NICK", cmd_nick
, 0, 0, 1, N_("NICK <nickname>, sets your nick")},
3552 {"NOTICE", cmd_notice
, 1, 0, 1,
3553 N_("NOTICE <nick/channel> <message>, sends a notice. Notices are a type of message that should be auto reacted to")},
3554 {"NOTIFY", cmd_notify
, 0, 0, 1,
3555 N_("NOTIFY [-n network1[,network2,...]] [<nick>], displays your notify list or adds someone to it")},
3556 {"OP", cmd_op
, 1, 1, 1,
3557 N_("OP <nick>, gives chanop status to the nick (needs chanop)")},
3558 {"PART", cmd_part
, 1, 1, 0,
3559 N_("PART [<channel>] [<reason>], leaves the channel, by default the current one")},
3560 {"PING", cmd_ping
, 1, 0, 1,
3561 N_("PING <nick | channel>, CTCP pings nick or channel")},
3562 {"QUERY", cmd_query
, 0, 0, 1,
3563 N_("QUERY [-nofocus] <nick>, opens up a new privmsg window to someone")},
3564 {"QUIT", cmd_quit
, 0, 0, 1,
3565 N_("QUIT [<reason>], disconnects from the current server")},
3566 {"QUOTE", cmd_quote
, 1, 0, 1,
3567 N_("QUOTE <text>, sends the text in raw form to the server")},
3569 {"RECONNECT", cmd_reconnect
, 0, 0, 1,
3570 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")},
3572 {"RECONNECT", cmd_reconnect
, 0, 0, 1,
3573 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")},
3575 {"RECV", cmd_recv
, 1, 0, 1, N_("RECV <text>, send raw data to xchat, as if it was received from the irc server")},
3577 {"SAY", cmd_say
, 0, 0, 1,
3578 N_("SAY <text>, sends the text to the object in the current window")},
3579 {"SEND", cmd_send
, 0, 0, 1, N_("SEND <nick> [<file>]")},
3581 {"SERVCHAN", cmd_servchan
, 0, 0, 1,
3582 N_("SERVCHAN [-ssl] <host> <port> <channel>, connects and joins a channel")},
3584 {"SERVCHAN", cmd_servchan
, 0, 0, 1,
3585 N_("SERVCHAN <host> <port> <channel>, connects and joins a channel")},
3588 {"SERVER", cmd_server
, 0, 0, 1,
3589 N_("SERVER [-ssl] <host> [<port>] [<password>], connects to a server, the default port is 6667 for normal connections, and 9999 for ssl connections")},
3591 {"SERVER", cmd_server
, 0, 0, 1,
3592 N_("SERVER <host> [<port>] [<password>], connects to a server, the default port is 6667")},
3594 {"SET", cmd_set
, 0, 0, 1, N_("SET [-e] [-off|-on] [-quiet] <variable> [<value>]")},
3595 {"SETCURSOR", cmd_setcursor
, 0, 0, 1, N_("SETCURSOR [-|+]<position>, reposition the cursor in the inputbox")},
3596 {"SETTAB", cmd_settab
, 0, 0, 1, N_("SETTAB <new name>, change a tab's name, tab_trunc limit still applies")},
3597 {"SETTEXT", cmd_settext
, 0, 0, 1, N_("SETTEXT <new text>, replace the text in the input box")},
3598 {"SPLAY", cmd_splay
, 0, 0, 1, "SPLAY <soundfile>"},
3599 {"TOPIC", cmd_topic
, 1, 1, 1,
3600 N_("TOPIC [<topic>], sets the topic if one is given, else shows the current topic")},
3601 {"TRAY", cmd_tray
, 0, 0, 1,
3602 N_("\nTRAY -f <timeout> <file1> [<file2>] Blink tray between two icons.\n"
3603 "TRAY -f <filename> Set tray to a fixed icon.\n"
3604 "TRAY -i <number> Blink tray with an internal icon.\n"
3605 "TRAY -t <text> Set the tray tooltip.\n"
3606 "TRAY -b <title> <text> Set the tray balloon."
3608 {"UNBAN", cmd_unban
, 1, 1, 1,
3609 N_("UNBAN <mask> [<mask>...], unbans the specified masks.")},
3610 {"UNIGNORE", cmd_unignore
, 0, 0, 1, N_("UNIGNORE <mask> [QUIET]")},
3611 {"UNLOAD", cmd_unload
, 0, 0, 1, N_("UNLOAD <name>, unloads a plugin or script")},
3612 {"URL", cmd_url
, 0, 0, 1, N_("URL <url>, opens a URL in your browser")},
3613 {"USELECT", cmd_uselect
, 0, 1, 0,
3614 N_("USELECT [-a] [-s] <nick1> <nick2> etc, highlights nick(s) in channel userlist")},
3615 {"USERLIST", cmd_userlist
, 1, 1, 1, 0},
3616 {"VOICE", cmd_voice
, 1, 1, 1,
3617 N_("VOICE <nick>, gives voice status to someone (needs chanop)")},
3618 {"WALLCHAN", cmd_wallchan
, 1, 1, 1,
3619 N_("WALLCHAN <message>, writes the message to all channels")},
3620 {"WALLCHOP", cmd_wallchop
, 1, 1, 1,
3621 N_("WALLCHOP <message>, sends the message to all chanops on the current channel")},
3627 command_compare (const void *a
, const void *b
)
3629 return strcasecmp (a
, ((struct commands
*)b
)->name
);
3632 static struct commands
*
3633 find_internal_command (char *name
)
3635 /* the "-1" is to skip the NULL terminator */
3636 return bsearch (name
, xc_cmds
, (sizeof (xc_cmds
) /
3637 sizeof (xc_cmds
[0])) - 1, sizeof (xc_cmds
[0]), command_compare
);
3641 help (session
*sess
, char *tbuf
, char *helpcmd
, int quiet
)
3643 struct commands
*cmd
;
3645 if (plugin_show_help (sess
, helpcmd
))
3648 cmd
= find_internal_command (helpcmd
);
3654 snprintf (tbuf
, TBUFSIZE
, _("Usage: %s\n"), _(cmd
->help
));
3655 PrintText (sess
, tbuf
);
3659 PrintText (sess
, _("\nNo help available on that command.\n"));
3665 PrintText (sess
, _("No such command.\n"));
3668 /* inserts %a, %c, %d etc into buffer. Also handles &x %x for word/word_eol. *
3669 * returns 2 on buffer overflow
3670 * returns 1 on success *
3671 * returns 0 on bad-args-for-user-command *
3672 * - word/word_eol args might be NULL *
3673 * - this beast is used for UserCommands, UserlistButtons and CTCP replies */
3676 auto_insert (char *dest
, int destlen
, unsigned char *src
, char *word
[],
3677 char *word_eol
[], char *a
, char *c
, char *d
, char *e
, char *h
,
3692 if (src
[0] == '%' || src
[0] == '&')
3694 if (isdigit ((unsigned char) src
[1]))
3696 if (isdigit ((unsigned char) src
[2]) && isdigit ((unsigned char) src
[3]))
3702 dest
[0] = atoi (buf
);
3703 utf
= g_locale_to_utf8 (dest
, 1, 0, &utf_len
, 0);
3706 if ((dest
- orig
) + utf_len
>= destlen
)
3712 memcpy (dest
, utf
, utf_len
);
3722 num
= src
[0] - '0'; /* ascii to decimal */
3723 if (*word
[num
] == 0)
3729 utf
= word_eol
[num
];
3731 /* avoid recusive usercommand overflow */
3732 if ((dest
- orig
) + strlen (utf
) >= destlen
)
3736 dest
+= strlen (dest
);
3748 if ((dest
- orig
) + 2 >= destlen
)
3765 utf
= get_cpu_str (); break;
3776 utf
= PACKAGE_VERSION
; break;
3780 tm_ptr
= localtime (&now
);
3781 snprintf (buf
, sizeof (buf
), "%4d%02d%02d", 1900 +
3782 tm_ptr
->tm_year
, 1 + tm_ptr
->tm_mon
, tm_ptr
->tm_mday
);
3792 if ((dest
- orig
) + strlen (utf
) >= destlen
)
3795 dest
+= strlen (dest
);
3802 utf_len
= g_utf8_skip
[src
[0]];
3804 if ((dest
- orig
) + utf_len
>= destlen
)
3815 memcpy (dest
, src
, utf_len
);
3828 check_special_chars (char *cmd
, int do_ascii
) /* check for %X */
3831 int len
= strlen (cmd
);
3840 buf
= malloc (len
+ 1);
3852 (isdigit ((unsigned char) cmd
[j
+ 1]) && isdigit ((unsigned char) cmd
[j
+ 2]) &&
3853 isdigit ((unsigned char) cmd
[j
+ 3])))
3855 tbuf
[0] = cmd
[j
+ 1];
3856 tbuf
[1] = cmd
[j
+ 2];
3857 tbuf
[2] = cmd
[j
+ 3];
3859 buf
[i
] = atoi (tbuf
);
3860 utf
= g_locale_to_utf8 (buf
+ i
, 1, 0, &utf_len
, 0);
3863 memcpy (buf
+ i
, utf
, utf_len
);
3887 case 'H': /* CL: invisible text code */
3888 buf
[i
] = HIDDEN_CHAR
;
3925 nick_comp_cb (struct User
*user
, nickdata
*data
)
3929 if (!rfc_ncasecmp (user
->nick
, data
->nick
, data
->len
))
3931 lenu
= strlen (user
->nick
);
3932 if (lenu
== data
->len
)
3934 snprintf (data
->tbuf
, TBUFSIZE
, "%s%s", user
->nick
, data
->space
);
3937 } else if (lenu
< data
->bestlen
)
3939 data
->bestlen
= lenu
;
3948 perform_nick_completion (struct session
*sess
, char *cmd
, char *tbuf
)
3951 char *space
= strchr (cmd
, ' ');
3952 if (space
&& space
!= cmd
)
3954 if (space
[-1] == prefs
.nick_suffix
[0] && space
- 1 != cmd
)
3956 len
= space
- cmd
- 1;
3962 memcpy (nick
, cmd
, len
);
3967 data
.bestlen
= INT_MAX
;
3970 data
.space
= space
- 1;
3971 tree_foreach (sess
->usertree
, (tree_traverse_func
*)nick_comp_cb
, &data
);
3978 snprintf (tbuf
, TBUFSIZE
, "%s%s", data
.best
->nick
, space
- 1);
3989 user_command (session
* sess
, char *tbuf
, char *cmd
, char *word
[],
3992 if (!auto_insert (tbuf
, 2048, cmd
, word
, word_eol
, "", sess
->channel
, "",
3993 server_get_network (sess
->server
, TRUE
), "",
3994 sess
->server
->nick
, ""))
3996 PrintText (sess
, _("Bad arguments for user command.\n"));
4000 handle_command (sess
, tbuf
, TRUE
);
4003 /* handle text entered without a CMDchar prefix */
4006 handle_say (session
*sess
, char *text
, int check_spch
)
4009 char *word
[PDIWORDS
+1];
4010 char *word_eol
[PDIWORDS
+1];
4011 char pdibuf_static
[1024];
4012 char newcmd_static
[1024];
4013 char *pdibuf
= pdibuf_static
;
4014 char *newcmd
= newcmd_static
;
4016 int newcmdlen
= sizeof newcmd_static
;
4018 if (strcmp (sess
->channel
, "(lastlog)") == 0)
4020 lastlog (sess
->lastlog_sess
, text
, sess
->lastlog_regexp
);
4024 len
= strlen (text
);
4025 if (len
>= sizeof pdibuf_static
)
4026 pdibuf
= malloc (len
+ 1);
4028 if (len
+ NICKLEN
>= newcmdlen
)
4029 newcmd
= malloc (newcmdlen
= len
+ NICKLEN
+ 1);
4031 if (check_spch
&& prefs
.perc_color
)
4032 check_special_chars (text
, prefs
.perc_ascii
);
4034 /* Python relies on this */
4035 word
[PDIWORDS
] = NULL
;
4036 word_eol
[PDIWORDS
] = NULL
;
4038 /* split the text into words and word_eol */
4039 process_data_init (pdibuf
, text
, word
, word_eol
, TRUE
, FALSE
);
4041 /* a command of "" can be hooked for non-commands */
4042 if (plugin_emit_command (sess
, "", word
, word_eol
))
4045 /* incase a plugin did /close */
4046 if (!is_session (sess
))
4049 if (!sess
->channel
[0] || sess
->type
== SESS_SERVER
|| sess
->type
== SESS_NOTICES
|| sess
->type
== SESS_SNOTICES
)
4055 if (prefs
.nickcompletion
)
4056 perform_nick_completion (sess
, text
, newcmd
);
4058 safe_strcpy (newcmd
, text
, newcmdlen
);
4062 if (sess
->type
== SESS_DIALOG
)
4064 /* try it via dcc, if possible */
4065 dcc
= dcc_write_chat (sess
->channel
, text
);
4068 inbound_chanmsg (sess
->server
, NULL
, sess
->channel
,
4069 sess
->server
->nick
, text
, TRUE
, FALSE
);
4070 set_topic (sess
, net_ip (dcc
->addr
), net_ip (dcc
->addr
));
4075 if (sess
->server
->connected
)
4078 unsigned char t
= 0;
4080 /* maximum allowed message text */
4081 /* :nickname!username@host.com PRIVMSG #channel :text\r\n */
4083 max
-= 16; /* :, !, @, " PRIVMSG ", " ", :, \r, \n */
4084 max
-= strlen (sess
->server
->nick
);
4085 max
-= strlen (sess
->channel
);
4086 if (sess
->me
&& sess
->me
->hostname
)
4087 max
-= strlen (sess
->me
->hostname
);
4090 max
-= 9; /* username */
4091 max
-= 65; /* max possible hostname and '@' */
4094 if (strlen (text
) > max
)
4098 /* traverse the utf8 string and find the nearest cut point that
4099 doesn't split 1 char in half */
4102 size
= g_utf8_skip
[((unsigned char *)text
)[i
]];
4103 if ((i
+ size
) >= max
)
4109 text
[max
] = 0; /* insert a NULL terminator to shorten it */
4112 inbound_chanmsg (sess
->server
, sess
, sess
->channel
, sess
->server
->nick
,
4114 sess
->server
->p_message (sess
->server
, sess
->channel
, text
);
4119 handle_say (sess
, text
+ max
, FALSE
);
4128 if (pdibuf
!= pdibuf_static
)
4131 if (newcmd
!= newcmd_static
)
4135 /* handle a command, without the '/' prefix */
4138 handle_command (session
*sess
, char *cmd
, int check_spch
)
4141 int user_cmd
= FALSE
;
4143 char *word
[PDIWORDS
+1];
4144 char *word_eol
[PDIWORDS
+1];
4145 static int command_level
= 0;
4146 struct commands
*int_cmd
;
4147 char pdibuf_static
[1024];
4148 char tbuf_static
[TBUFSIZE
];
4154 if (command_level
> 99)
4156 fe_message (_("Too many recursive usercommands, aborting."), FE_MSG_ERROR
);
4160 /* anything below MUST DEC command_level before returning */
4163 if (len
>= sizeof (pdibuf_static
))
4164 pdibuf
= malloc (len
+ 1);
4166 pdibuf
= pdibuf_static
;
4168 if ((len
* 2) >= sizeof (tbuf_static
))
4169 tbuf
= malloc ((len
* 2) + 1);
4173 /* split the text into words and word_eol */
4174 process_data_init (pdibuf
, cmd
, word
, word_eol
, TRUE
, TRUE
);
4176 /* ensure an empty string at index 32 for cmd_deop etc */
4177 /* (internal use only, plugins can still only read 1-31). */
4178 word
[PDIWORDS
] = "\000\000";
4179 word_eol
[PDIWORDS
] = "\000\000";
4181 int_cmd
= find_internal_command (word
[1]);
4182 /* redo it without quotes processing, for some commands like /JOIN */
4183 if (int_cmd
&& !int_cmd
->handle_quotes
)
4184 process_data_init (pdibuf
, cmd
, word
, word_eol
, FALSE
, FALSE
);
4186 if (check_spch
&& prefs
.perc_color
)
4187 check_special_chars (cmd
, prefs
.perc_ascii
);
4189 if (plugin_emit_command (sess
, word
[1], word
, word_eol
))
4192 /* incase a plugin did /close */
4193 if (!is_session (sess
))
4196 /* first see if it's a userCommand */
4197 list
= command_list
;
4200 pop
= (struct popup
*) list
->data
;
4201 if (!strcasecmp (pop
->name
, word
[1]))
4203 user_command (sess
, tbuf
, pop
->cmd
, word
, word_eol
);
4212 /* now check internal commands */
4213 int_cmd
= find_internal_command (word
[1]);
4217 if (int_cmd
->needserver
&& !sess
->server
->connected
)
4220 } else if (int_cmd
->needchannel
&& !sess
->channel
[0])
4225 switch (int_cmd
->callback (sess
, tbuf
, word
, word_eol
))
4228 help (sess
, tbuf
, int_cmd
->name
, TRUE
);
4237 /* unknown command, just send it to the server and hope */
4238 if (!sess
->server
->connected
)
4239 PrintText (sess
, _("Unknown Command. Try /help\n"));
4241 sess
->server
->p_raw (sess
->server
, cmd
);
4247 if (pdibuf
!= pdibuf_static
)
4250 if (tbuf
!= tbuf_static
)
4256 /* handle one line entered into the input box */
4259 handle_user_input (session
*sess
, char *text
, int history
, int nocommand
)
4265 history_add (&sess
->history
, text
);
4267 /* is it NOT a command, just text? */
4268 if (nocommand
|| text
[0] != prefs
.cmdchar
[0])
4270 handle_say (sess
, text
, TRUE
);
4275 if (text
[0] == prefs
.cmdchar
[0] && text
[1] == prefs
.cmdchar
[0])
4277 handle_say (sess
, text
+ 1, TRUE
);
4281 if (prefs
.cmdchar
[0] == '/')
4284 const char *unix_dirs
[] = {
4285 "/bin/", "/boot/", "/dev/",
4286 "/etc/", "/home/", "/lib/",
4287 "/lost+found/", "/mnt/", "/opt/",
4288 "/proc/", "/root/", "/sbin/",
4289 "/tmp/", "/usr/", "/var/",
4291 for (i
= 0; unix_dirs
[i
] != NULL
; i
++)
4292 if (strncmp (text
, unix_dirs
[i
], strlen (unix_dirs
[i
]))==0)
4294 handle_say (sess
, text
, TRUE
);
4299 return handle_command (sess
, text
+ 1, TRUE
);
4302 /* changed by Steve Green. Macs sometimes paste with imbedded \r */
4304 handle_multiline (session
*sess
, char *cmd
, int history
, int nocommand
)
4308 char *cr
= cmd
+ strcspn (cmd
, "\n\r");
4309 int end_of_string
= *cr
== 0;
4311 if (!handle_user_input (sess
, cmd
, history
, nocommand
))
4320 handle_multiline (session *sess, char *cmd, int history, int nocommand)
4324 cr = strchr (cmd, '\n');
4331 if (!handle_user_input (sess, cmd, history, nocommand))
4338 cr = strchr (cmd, '\n');
4342 handle_user_input (sess, cmd, history, nocommand);