diff options
author | Timo Sirainen <cras@irssi.org> | 2000-11-30 23:13:15 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-11-30 23:13:15 +0000 |
commit | 12ec2b86b8eeca24e01f648a5a75f0e942da61a0 (patch) | |
tree | 677eae1b03982bb9d1669aaf8f43d072462a1083 /src | |
parent | e7bfb7fe88bdab5e0d68a1a1036f5cb32306a311 (diff) | |
download | irssi-12ec2b86b8eeca24e01f648a5a75f0e942da61a0.zip |
/WAIT [-<server tag>] <milliseconds> - wait for <milliseconds> before
sending anything else to server
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@905 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/core/irc-commands.c | 39 | ||||
-rw-r--r-- | src/irc/core/irc-servers.c | 6 | ||||
-rw-r--r-- | src/irc/core/irc-servers.h | 1 | ||||
-rw-r--r-- | src/irc/core/irc.c | 6 |
4 files changed, 50 insertions, 2 deletions
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index 38fc8bc2..951ce1bb 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -709,6 +709,43 @@ static void cmd_wall_hash(gpointer key, NICK_REC *nick, GSList **nicks) if (nick->op) *nicks = g_slist_append(*nicks, nick); } +/* SYNTAX: WAIT [-<server tag>] <milliseconds> */ +static void cmd_wait(const char *data, IRC_SERVER_REC *server) +{ + GHashTable *optlist; + char *msecs; + void *free_arg; + int n; + + g_return_if_fail(data != NULL); + if (!IS_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | + PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, + NULL, &optlist, &msecs)) + return; + + if (*msecs == '\0') + cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); + + /* -<server tag> */ + server = IRC_SERVER(cmd_options_get_server(NULL, optlist, + SERVER(server))); + + n = atoi(msecs); + if (server != NULL && n > 0) { + g_get_current_time(&server->wait_cmd); + server->wait_cmd.tv_sec += n/1000; + server->wait_cmd.tv_usec += n%1000; + if (server->wait_cmd.tv_usec >= 1000) { + server->wait_cmd.tv_sec++; + server->wait_cmd.tv_usec -= 1000; + } + } + cmd_params_free(free_arg); +} + /* SYNTAX: WALL [<channel>] <message> */ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { @@ -1106,6 +1143,7 @@ void irc_commands_init(void) command_bind("userhost", NULL, (SIGNAL_FUNC) command_self); command_bind("quote", NULL, (SIGNAL_FUNC) cmd_quote); command_bind("wall", NULL, (SIGNAL_FUNC) cmd_wall); + command_bind("wait", NULL, (SIGNAL_FUNC) cmd_wait); /* SYNTAX: WALLOPS <message> */ command_bind("wallops", NULL, (SIGNAL_FUNC) command_1self); /* SYNTAX: WALLCHOPS <channel> <message> */ @@ -1180,6 +1218,7 @@ void irc_commands_deinit(void) command_unbind("userhost", (SIGNAL_FUNC) command_self); command_unbind("quote", (SIGNAL_FUNC) cmd_quote); command_unbind("wall", (SIGNAL_FUNC) cmd_wall); + command_unbind("wait", (SIGNAL_FUNC) cmd_wait); command_unbind("wallops", (SIGNAL_FUNC) command_1self); command_unbind("wallchops", (SIGNAL_FUNC) command_2self); command_unbind("cycle", (SIGNAL_FUNC) cmd_cycle); diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 84b40c76..fb2c97a3 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -233,7 +233,10 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) return; if (!server->cmd_last_split) { - usecs = get_timeval_diff(now, &server->last_cmd); + if (g_timeval_cmp(now, &server->wait_cmd) == -1) + return; + + usecs = get_timeval_diff(now, &server->last_cmd); if (usecs < server->cmd_queue_speed) return; } @@ -253,6 +256,7 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) return; } + server->wait_cmd.tv_sec = 0; memcpy(&server->last_cmd, now, sizeof(GTimeVal)); if (server->cmd_last_split) server->cmd_last_split = FALSE; diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index ab6b63e9..598f5a6b 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -61,6 +61,7 @@ typedef struct { int cmd_last_split; /* Last command wasn't sent entirely to server. First item in `cmdqueue' should be re-sent. */ GSList *cmdqueue; + GTimeVal wait_cmd; /* don't send anything to server before this */ GTimeVal last_cmd; /* last time command was sent to server */ int max_cmds_at_once; /* How many messages can be sent immediately before timeouting starts */ diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index efb9a8cd..607335b1 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -24,6 +24,7 @@ #include "net-sendbuffer.h" #include "line-split.h" #include "rawlog.h" +#include "misc.h" #include "irc.h" #include "irc-servers.h" @@ -75,14 +76,17 @@ static void cmd_send(IRC_SERVER_REC *server, const char *cmd, int send_now, int /* Send command to IRC server */ void irc_send_cmd(IRC_SERVER_REC *server, const char *cmd) { + GTimeVal now; int send_now; g_return_if_fail(cmd != NULL); if (server == NULL) return; + g_get_current_time(&now); send_now = !server->cmd_last_split && (server->cmdcount < server->max_cmds_at_once || - server->cmd_queue_speed <= 0); + server->cmd_queue_speed <= 0) && + g_timeval_cmp(&now, &server->wait_cmd) >= 0; cmd_send(server, cmd, send_now, FALSE); } |