Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "core.h"
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "line-split.h"
#include "settings.h"
#include "irssi-version.h"
+#include "servers.h"
#include "fe-windows.h"
#include "printtext.h"
TXT_NOT_JOINED,
TXT_CHAN_NOT_FOUND,
TXT_CHAN_NOT_SYNCED,
- TXT_NOT_GOOD_IDEA
+ TXT_ILLEGAL_PROTO,
+ TXT_NOT_GOOD_IDEA,
+ TXT_INVALID_TIME,
+ TXT_INVALID_CHARSET,
+ TXT_EVAL_MAX_RECURSE,
+ TXT_PROGRAM_NOT_FOUND
};
+int command_hide_output;
+
/* keep the whole command line here temporarily. we need it in
"default command" event handler, but there we don't know if the start of
the line had one or two command chars, and which one.. */
static const char *current_cmdline;
-static int hide_output;
static GTimeVal time_command_last, time_command_now;
static int last_command_cmd, command_cmd;
/* SYNTAX: VERSION */
static void cmd_version(char *data)
{
+ char time[10];
+
g_return_if_fail(data != NULL);
if (*data == '\0') {
+ g_snprintf(time, sizeof(time), "%04d", IRSSI_VERSION_TIME);
printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
- "Client: "PACKAGE" " IRSSI_VERSION);
+ "Client: "PACKAGE" " IRSSI_VERSION" (%d %s)",
+ IRSSI_VERSION_DATE, time);
}
}
recvlen = read(f, tmpbuf, sizeof(tmpbuf));
ret = line_split(tmpbuf, recvlen, &str, &buffer);
- if (ret > 0)
- printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s", str);
+ if (ret > 0) {
+ printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP |
+ MSGLEVEL_NEVER, "%s", str);
+ }
} while (ret > 0);
line_split_free(buffer);
signal_emit("beep", 0);
}
+static void cmd_nick(const char *data, SERVER_REC *server)
+{
+ g_return_if_fail(data != NULL);
+
+ if (*data != '\0') return;
+ if (server == NULL || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
+
+ /* display current nick */
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_YOUR_NICK, server->nick);
+ signal_stop();
+}
+
+static void cmd_join(const char *data, SERVER_REC *server)
+{
+ GHashTable *optlist;
+ char *channels;
+ void *free_arg;
+
+ g_return_if_fail(data != NULL);
+
+ if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
+ PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
+ "join", &optlist, &channels))
+ return;
+
+ server = cmd_options_get_server("join", optlist, server);
+ if (g_hash_table_lookup(optlist, "invite") &&
+ server != NULL && server->last_invite == NULL) {
+ /* ..all this trouble just to print this error message */
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_INVITED);
+ signal_stop();
+ }
+
+ cmd_params_free(free_arg);
+}
+
+/* SYNTAX: UPTIME */
+static void cmd_uptime(char *data)
+{
+ time_t uptime;
+
+ g_return_if_fail(data != NULL);
+
+ if (*data == '\0') {
+ uptime = time(NULL) - client_start_time;
+ printtext(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
+ "Uptime: %ldd %ldh %ldm %lds",
+ uptime/3600/24, uptime/3600%24,
+ uptime/60%60, uptime%60);
+ }
+}
+
static void sig_stop(void)
{
signal_stop();
last_command_cmd = command_cmd;
g_get_current_time(&time_command_now);
- command_cmd = strchr(settings_get_str("cmdchars"), *data) != NULL;
+ command_cmd = *data != '\0' &&
+ strchr(settings_get_str("cmdchars"), *data) != NULL;
/* /^command hides the output of the command */
- cmdchar = strchr(settings_get_str("cmdchars"), *data);
+ cmdchar = *data == '\0' ? NULL :
+ strchr(settings_get_str("cmdchars"), *data);
if (cmdchar != NULL && (data[1] == '^' ||
- (data[1] == *cmdchar && data[2] == '^'))) {
- hide_output = TRUE;
+ (data[1] == *cmdchar && data[2] == '^'))
+ && !command_hide_output++) {
signal_add_first("print starting", (SIGNAL_FUNC) sig_stop);
signal_add_first("print format", (SIGNAL_FUNC) sig_stop);
- signal_add_first("print text stripped", (SIGNAL_FUNC) sig_stop);
signal_add_first("print text", (SIGNAL_FUNC) sig_stop);
}
}
static void event_command_last(const char *data)
{
- if (hide_output) {
- hide_output = FALSE;
+ if (command_hide_output && !--command_hide_output) {
signal_remove("print starting", (SIGNAL_FUNC) sig_stop);
signal_remove("print format", (SIGNAL_FUNC) sig_stop);
- signal_remove("print text stripped", (SIGNAL_FUNC) sig_stop);
signal_remove("print text", (SIGNAL_FUNC) sig_stop);
}
}
void fe_core_commands_init(void)
{
- hide_output = FALSE;
+ command_hide_output = 0;
command_cmd = FALSE;
memset(&time_command_now, 0, sizeof(GTimeVal));
command_bind("version", NULL, (SIGNAL_FUNC) cmd_version);
command_bind("cat", NULL, (SIGNAL_FUNC) cmd_cat);
command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep);
+ command_bind("uptime", NULL, (SIGNAL_FUNC) cmd_uptime);
+ command_bind_first("nick", NULL, (SIGNAL_FUNC) cmd_nick);
+ command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_join);
signal_add("send command", (SIGNAL_FUNC) event_command);
signal_add_last("send command", (SIGNAL_FUNC) event_command_last);
command_unbind("version", (SIGNAL_FUNC) cmd_version);
command_unbind("cat", (SIGNAL_FUNC) cmd_cat);
command_unbind("beep", (SIGNAL_FUNC) cmd_beep);
+ command_unbind("uptime", (SIGNAL_FUNC) cmd_uptime);
+ command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
+ command_unbind("join", (SIGNAL_FUNC) cmd_join);
signal_remove("send command", (SIGNAL_FUNC) event_command);
signal_remove("send command", (SIGNAL_FUNC) event_command_last);