aboutsummaryrefslogtreecommitdiffstats
path: root/irc_send.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2010-03-27 22:44:19 -0400
committerWilmer van der Gaast <wilmer@gaast.net>2010-03-27 22:44:19 -0400
commit6761a40af82d8134ee9fa2ac1d2b34475d297ad8 (patch)
tree8bea6d627548db7fa9950d0c9c0fd0cf6aafe967 /irc_send.c
parent410bf6d47436e83a09378aac2a8de24709b83422 (diff)
Restored multi-line message support.
Diffstat (limited to 'irc_send.c')
-rw-r--r--irc_send.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/irc_send.c b/irc_send.c
index d9b7f8d2..80d9b466 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -123,17 +123,17 @@ void irc_usermsg( irc_t *irc, char *format, ... )
irc_channel_name_ok( irc->last_root_cmd ) &&
( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) &&
ic->flags & IRC_CHANNEL_JOINED )
- irc_send_msg( irc->root, "PRIVMSG", irc->last_root_cmd, text );
+ irc_send_msg( irc->root, "PRIVMSG", irc->last_root_cmd, text, NULL );
else if( irc->last_root_cmd &&
( iu = irc_user_by_name( irc, irc->last_root_cmd ) ) &&
iu->f == &irc_user_root_funcs )
- irc_send_msg( iu, "PRIVMSG", irc->user->nick, text );
+ irc_send_msg( iu, "PRIVMSG", irc->user->nick, text, NULL );
else
{
g_free( irc->last_root_cmd );
irc->last_root_cmd = NULL;
- irc_send_msg( irc->root, "PRIVMSG", irc->user->nick, text );
+ irc_send_msg( irc->root, "PRIVMSG", irc->user->nick, text, NULL );
}
/*return( irc_msgfrom( irc, u->nick, text ) );*/
@@ -253,7 +253,49 @@ void irc_send_who( irc_t *irc, GSList *l, const char *channel )
irc_send_num( irc, 315, "%s :End of /WHO list", channel );
}
-void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg )
+void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix )
+{
+ char last = 0;
+ const char *s = msg, *line = msg;
+ char raw_msg[strlen(msg)+1024];
+
+ while( !last )
+ {
+ if( *s == '\r' && *(s+1) == '\n' )
+ s++;
+ if( *s == '\n' )
+ {
+ last = s[1] == 0;
+ }
+ else
+ {
+ last = s[0] == 0;
+ }
+ if( *s == 0 || *s == '\n' )
+ {
+ if( g_strncasecmp( line, "/me ", 4 ) == 0 && ( !prefix || !*prefix ) &&
+ g_strcasecmp( type, "PRIVMSG" ) == 0 )
+ {
+ strcpy( raw_msg, "\001ACTION " );
+ strncat( raw_msg, line + 4, s - line - 4 );
+ strcat( raw_msg, "\001" );
+ irc_send_msg_raw( iu, type, dst, raw_msg );
+ }
+ else
+ {
+ *raw_msg = '\0';
+ if( prefix && *prefix )
+ strcpy( raw_msg, prefix );
+ strncat( raw_msg, line, s - line );
+ irc_send_msg_raw( iu, type, dst, raw_msg );
+ }
+ line = s + 1;
+ }
+ s ++;
+ }
+}
+
+void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg )
{
irc_write( iu->irc, ":%s!%s@%s %s %s :%s",
iu->nick, iu->user, iu->host, type, dst, msg );