aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--irc.c2
-rw-r--r--irc.h7
-rw-r--r--irc_channel.c12
-rw-r--r--irc_send.c16
4 files changed, 29 insertions, 8 deletions
diff --git a/irc.c b/irc.c
index 6e4ba157..bf84f66d 100644
--- a/irc.c
+++ b/irc.c
@@ -619,7 +619,7 @@ int irc_check_login( irc_t *irc )
irc_send_login( irc );
ic = irc_channel_new( irc, ROOT_CHAN );
- irc_channel_set_topic( ic, CONTROL_TOPIC );
+ irc_channel_set_topic( ic, CONTROL_TOPIC, irc->root );
irc_channel_add_user( ic, irc->user );
return 1;
diff --git a/irc.h b/irc.h
index 646281ff..48cba879 100644
--- a/irc.h
+++ b/irc.h
@@ -117,6 +117,8 @@ typedef struct irc_channel
int flags;
char *name;
char *topic;
+ char *topic_who;
+ time_t topic_time;
char mode[8];
GSList *users;
struct set *set;
@@ -144,9 +146,10 @@ int irc_check_login( irc_t *irc );
/* irc_channel.c */
irc_channel_t *irc_channel_new( irc_t *irc, const char *name );
irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name );
+int irc_channel_free( irc_channel_t *ic );
int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
-int irc_channel_set_topic( irc_channel_t *ic, const char *topic );
+int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );
/* irc_commands.c */
void irc_exec( irc_t *irc, char **cmd );
@@ -159,7 +162,7 @@ void irc_usermsg( irc_t *irc, char *format, ... );
void irc_send_join( irc_channel_t *ic, irc_user_t *iu );
void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason );
void irc_send_names( irc_channel_t *ic );
-void irc_send_topic( irc_channel_t *ic );
+void irc_send_topic( irc_channel_t *ic, gboolean topic_change );
void irc_send_whois( irc_user_t *iu );
/* irc_user.c */
diff --git a/irc_channel.c b/irc_channel.c
index c58d6b1c..d15b73eb 100644
--- a/irc_channel.c
+++ b/irc_channel.c
@@ -108,13 +108,21 @@ int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
return 1;
}
-int irc_channel_set_topic( irc_channel_t *ic, const char *topic )
+int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *iu )
{
g_free( ic->topic );
ic->topic = g_strdup( topic );
+ g_free( ic->topic_who );
+ if( iu )
+ ic->topic_who = g_strdup_printf( "%s!%s@%s", iu->nick, iu->user, iu->host );
+ else
+ ic->topic_who = NULL;
+
+ ic->topic_time = time( NULL );
+
if( ic->flags & IRC_CHANNEL_JOINED )
- irc_send_topic( ic );
+ irc_send_topic( ic, TRUE );
return 1;
}
diff --git a/irc_send.c b/irc_send.c
index b19d6a0f..f0c3958c 100644
--- a/irc_send.c
+++ b/irc_send.c
@@ -134,7 +134,7 @@ void irc_send_join( irc_channel_t *ic, irc_user_t *iu )
{
irc_write( irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode );
irc_send_names( ic );
- irc_send_topic( ic );
+ irc_send_topic( ic, FALSE );
}
}
@@ -181,10 +181,20 @@ void irc_send_names( irc_channel_t *ic )
irc_send_num( ic->irc, 366, "%s :End of /NAMES list", ic->name );
}
-void irc_send_topic( irc_channel_t *ic )
+void irc_send_topic( irc_channel_t *ic, gboolean topic_change )
{
- if( ic->topic )
+ if( topic_change && ic->topic_who )
+ {
+ irc_write( ic->irc, ":%s TOPIC %s :%s", ic->topic_who,
+ ic->name, ic->topic && *ic->topic ? ic->topic : "" );
+ }
+ else if( ic->topic )
+ {
irc_send_num( ic->irc, 332, "%s :%s", ic->name, ic->topic );
+ if( ic->topic_who )
+ irc_send_num( ic->irc, 333, "%s %s %d",
+ ic->name, ic->topic_who, (int) ic->topic_time );
+ }
else
irc_send_num( ic->irc, 331, "%s :No topic for this channel", ic->name );
}