aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2010-01-21 12:42:33 +0000
committerNatanael Copa <natanael.copa@gmail.com>2010-01-21 12:42:33 +0000
commit4695fd8cadfd500e1aad7f0a4fde9111d8d995db (patch)
treebb58e41daf645a84d95f992ef382eb442d94d75a
parent0e91325e164b609f78e5454c85ec93860448ed1a (diff)
downloadsircbot-4695fd8cadfd500e1aad7f0a4fde9111d8d995db.tar.bz2
sircbot-4695fd8cadfd500e1aad7f0a4fde9111d8d995db.tar.xz
implement -r <flushrate> option to set the rate the data is flushed
This is to avoid getting kicked out for flooding the channel.
-rw-r--r--sircbot.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/sircbot.c b/sircbot.c
index 7341cc2..4321638 100644
--- a/sircbot.c
+++ b/sircbot.c
@@ -45,6 +45,7 @@ struct sircbot_channel {
static int foreground = 0;
static int sigterm = 0;
+static int flush_rate = 2;
static int write_pid(const char *file)
@@ -259,10 +260,11 @@ static int send_fifo_queue(struct irc_session *sess,
{
int r;
struct tq_string *item = TAILQ_FIRST(&chan->queue_head);
- if (item == NULL || chan->last_data_sent == now)
+ if (item == NULL || (now - chan->last_data_sent) < flush_rate)
return 0; /* nothing in queue, or too early to send */
r = irc_send_chan(sess, chan->name, item->value);
+ chan->last_data_sent = now;
/* remove from FIFO queue */
TAILQ_REMOVE(&chan->queue_head, item, entries);
free(item->value);
@@ -351,7 +353,7 @@ void sighandler(int signal)
static void usage_exit(int exitcode)
{
- printf("usage: sircbot [-f] [-n nick] [-s server] [-p port] CHANNEL\n");
+ printf("usage: sircbot [-f] [-n nick] [-r flushrate] [-s server] [-p port] CHANNEL\n");
exit(exitcode);
}
@@ -366,7 +368,7 @@ int main(int argc, char *argv[])
struct sircbot_channel *chan;
int i, c, port = 6667;
- while ((c = getopt(argc, argv, "fn:p:P:s:")) != -1) {
+ while ((c = getopt(argc, argv, "fn:p:P:r:s:")) != -1) {
switch (c) {
case 'f':
foreground = 1;
@@ -380,6 +382,9 @@ int main(int argc, char *argv[])
case 'p':
port = atoi(optarg);
break;
+ case 'r':
+ flush_rate = atoi(optarg);
+ break;
case 's':
server = optarg;
break;