diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-27 08:30:00 -0400 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-03-27 08:30:00 -0400 | 
| commit | 83e92bf7487623c10567502936ca727f3a4c104c (patch) | |
| tree | 35e853f3a2e26582c0dc4938599a85518a41b5b0 | |
| parent | b95932eb5a897fd264f3762493285dd7037dccba (diff) | |
Topic handling changes.
| -rw-r--r-- | irc.c | 2 | ||||
| -rw-r--r-- | irc.h | 7 | ||||
| -rw-r--r-- | irc_channel.c | 12 | ||||
| -rw-r--r-- | irc_send.c | 16 | 
4 files changed, 29 insertions, 8 deletions
| @@ -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; @@ -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;  } @@ -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 );  } | 
