summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-22 22:41:01 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-22 22:41:01 +0200
commit53b46482f5cc361c5e725cf50c45234bfe19916e (patch)
tree6986ce9fcf12199b1f509f56a48ce2aa32943809
parentf2a2206e49627f81918df89ef682d56736177ad6 (diff)
downloadxK-53b46482f5cc361c5e725cf50c45234bfe19916e.tar.gz
xK-53b46482f5cc361c5e725cf50c45234bfe19916e.tar.xz
xK-53b46482f5cc361c5e725cf50c45234bfe19916e.zip
degesch: preliminary message autosplitting
-rw-r--r--degesch.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/degesch.c b/degesch.c
index a5443f5..5b10c7b 100644
--- a/degesch.c
+++ b/degesch.c
@@ -2722,10 +2722,28 @@ send_message_to_target (struct app_context *ctx,
return;
}
- // TODO: autosplit
- irc_send (ctx, "PRIVMSG %s :%s", target, message);
- buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
- ctx->irc_user->nickname, NULL, "%s", message);
+ int one_message = 0;
+ if (ctx->irc_user_host)
+ // :<nick>!<user>@<host> PRIVMSG <target> :<message>
+ one_message = 510 - 1 - (int) strlen (ctx->irc_user->nickname)
+ - 1 - (int) strlen (ctx->irc_user_host)
+ - 1 - 7 - 1 - strlen (target) - 1 - 1;
+
+ // FIXME: UTF-8 sequences
+ int left = strlen (message);
+ while (left)
+ {
+ int part = MIN (one_message, left);
+ if (!one_message)
+ part = left;
+
+ irc_send (ctx, "PRIVMSG %s :%.*s", target, part, message);
+ buffer_send (ctx, buffer, BUFFER_LINE_PRIVMSG, 0,
+ ctx->irc_user->nickname, NULL, "%.*s", part, message);
+
+ left -= part;
+ message += part;
+ }
}
static void