mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
/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
This commit is contained in:
parent
e7bfb7fe88
commit
12ec2b86b8
@ -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);
|
||||
|
@ -233,6 +233,9 @@ static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now)
|
||||
return;
|
||||
|
||||
if (!server->cmd_last_split) {
|
||||
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;
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user