From: Alexander Barton Date: Fri, 2 Sep 2005 12:50:25 +0000 (+0000) Subject: Implementec numeric "333": Time and user name who set a channel topic. X-Git-Tag: rel-0-10-0-pre1~93 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd.git;a=commitdiff_plain;h=ca32c1b311379445d1c8bee5705a9371cf2fa1a7 Implementec numeric "333": Time and user name who set a channel topic. --- diff --git a/ChangeLog b/ChangeLog index f1634ae3..155bae99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ ngIRCd CVSHEAD + - Implementec numeric "333": Time and user name who set a channel topic. - Fixed server NOTICEs to users with "s" mode ("server messages"). - Enhanced the handler for PING and PONG commands: fix forwarding and enable back-passing of a client supplied additional argument of PING. @@ -637,4 +638,4 @@ ngIRCd 0.0.1, 31.12.2001 -- -$Id: ChangeLog,v 1.291 2005/08/29 10:58:00 alex Exp $ +$Id: ChangeLog,v 1.292 2005/09/02 12:50:25 alex Exp $ diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 3659b19f..ac5eb5c4 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -17,7 +17,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: channel.c,v 1.53 2005/07/31 20:13:08 alex Exp $"; +static char UNUSED id[] = "$Id: channel.c,v 1.54 2005/09/02 12:50:25 alex Exp $"; #include "imp.h" #include @@ -100,22 +100,25 @@ Channel_InitPredefined( void ) array_free(&Conf_Channel[i].topic); continue; } - - /* Channel anlegen */ - chan = Channel_Create( Conf_Channel[i].name ); - if( chan ) - { - Channel_ModeAdd( chan, 'P' ); - if (!array_copy(&chan->topic, &Conf_Channel[i].topic)) { - Log( LOG_WARNING, "Could not set topic for new pre-defined channel: %s", - strerror(errno)); - } + + /* Create channel */ + chan = Channel_Create(Conf_Channel[i].name); + if (chan) { + Channel_ModeAdd(chan, 'P'); + + Channel_SetTopic(chan, NULL, + array_start(&Conf_Channel[i].topic)); array_free(&Conf_Channel[i].topic); + c = Conf_Channel[i].modes; - while( *c ) Channel_ModeAdd( chan, *c++ ); - Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name ); + while (*c) + Channel_ModeAdd(chan, *c++); + + Log(LOG_INFO, "Created pre-defined channel \"%s\".", + Conf_Channel[i].name ); } - else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name ); + else Log(LOG_ERR, "Can't create pre-defined channel \"%s\"!", + Conf_Channel[i].name ); } } /* Channel_InitPredefined */ @@ -635,9 +638,29 @@ Channel_Topic( CHANNEL *Chan ) return ret ? ret : ""; } /* Channel_Topic */ + +#ifndef STRICT_RFC + +GLOBAL unsigned int +Channel_TopicTime(CHANNEL *Chan) +{ + assert(Chan != NULL); + return (unsigned int) Chan->topic_time; +} /* Channel_TopicTime */ + + +GLOBAL char * +Channel_TopicWho(CHANNEL *Chan) +{ + assert(Chan != NULL); + return Chan->topic_who; +} /* Channel_TopicWho */ + +#endif + GLOBAL void -Channel_SetTopic( CHANNEL *Chan, char *Topic ) +Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, char *Topic) { size_t len; assert( Chan != NULL ); @@ -648,9 +671,22 @@ Channel_SetTopic( CHANNEL *Chan, char *Topic ) array_free(&Chan->topic); if (!array_copyb(&Chan->topic, Topic, len)) - Log(LOG_WARNING, "could not set new Topic %s: %s", Topic, strerror(errno)); + Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s", + Topic, Chan->name, strerror(errno)); array_cat0(&Chan->topic); + +#ifndef STRICT_RFC + Chan->topic_time = time(NULL); + if (Client != NULL && Client_Type(Client) != CLIENT_SERVER) + strlcpy(Chan->topic_who, Client_ID(Client), + sizeof Chan->topic_who); + else + strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID, + sizeof Chan->topic_who); +#else + (void) Client; +#endif } /* Channel_SetTopic */ diff --git a/src/ngircd/channel.h b/src/ngircd/channel.h index 493161b0..2f6e3251 100644 --- a/src/ngircd/channel.h +++ b/src/ngircd/channel.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: channel.h,v 1.28 2005/07/28 16:23:55 fw Exp $ + * $Id: channel.h,v 1.29 2005/09/02 12:50:25 alex Exp $ * * Channel management (header) */ @@ -30,6 +30,10 @@ typedef struct _CHANNEL UINT32 hash; /* Hash of the (lowecase!) name */ char modes[CHANNEL_MODE_LEN]; /* Channel modes */ array topic; /* Topic of the channel */ +#ifndef STRICT_RFC + time_t topic_time; /* Time when topic was set */ + char topic_who[CLIENT_NICK_LEN];/* Nickname of user that set topic */ +#endif char key[CLIENT_PASS_LEN]; /* Channel key ("password", mode "k" ) */ long maxusers; /* Maximum number of members (mode "l") */ } CHANNEL; @@ -72,7 +76,7 @@ GLOBAL char *Channel_Topic PARAMS(( CHANNEL *Chan )); GLOBAL char *Channel_Key PARAMS(( CHANNEL *Chan )); GLOBAL long Channel_MaxUsers PARAMS(( CHANNEL *Chan )); -GLOBAL void Channel_SetTopic PARAMS(( CHANNEL *Chan, char *Topic )); +GLOBAL void Channel_SetTopic PARAMS(( CHANNEL *Chan, CLIENT *Client, char *Topic )); GLOBAL void Channel_SetModes PARAMS(( CHANNEL *Chan, char *Modes )); GLOBAL void Channel_SetKey PARAMS(( CHANNEL *Chan, char *Key )); GLOBAL void Channel_SetMaxUsers PARAMS(( CHANNEL *Chan, long Count )); @@ -105,6 +109,11 @@ GLOBAL bool Channel_Write PARAMS(( CHANNEL *Chan, CLIENT *From, CLIENT *Client, GLOBAL CHANNEL *Channel_Create PARAMS(( char *Name )); +#ifndef STRICT_RFC +GLOBAL unsigned int Channel_TopicTime PARAMS(( CHANNEL *Chan )); +GLOBAL char *Channel_TopicWho PARAMS(( CHANNEL *Chan )); +#endif + #endif diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 70800c3d..d314f1a9 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: defines.h,v 1.56 2005/07/28 16:23:55 fw Exp $ + * $Id: defines.h,v 1.57 2005/09/02 12:50:25 alex Exp $ */ @@ -103,6 +103,8 @@ #define DEFAULT_AWAY_MSG "Away" /* Away message for users connected to linked servers. */ +#define DEFAULT_TOPIC_ID "-Server-" /* Default ID for "topic owner". */ + #define CONFIG_FILE "/ngircd.conf" /* Configuration file name. */ #define MOTD_FILE "/ngircd.motd" /* Name of the MOTD file. */ #define MOTD_PHRASE "" /* Default MOTD phrase string. */ diff --git a/src/ngircd/irc-channel.c b/src/ngircd/irc-channel.c index 4708af1d..dbf26fe2 100644 --- a/src/ngircd/irc-channel.c +++ b/src/ngircd/irc-channel.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-channel.c,v 1.30 2005/06/12 18:23:59 alex Exp $"; +static char UNUSED id[] = "$Id: irc-channel.c,v 1.31 2005/09/02 12:50:25 alex Exp $"; #include "imp.h" #include @@ -47,7 +47,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) bool is_new_chan, is_invited, is_banned; CLIENT *target; CHANNEL *chan; - + assert( Client != NULL ); assert( Req != NULL ); @@ -211,9 +211,18 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) /* an Client bestaetigen */ IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame ); - /* Topic an Client schicken */ - topic = Channel_Topic( chan ); - if( *topic ) IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), channame, topic ); + /* Send topic to client, if any */ + topic = Channel_Topic(chan); + if (*topic) { + IRC_WriteStrClient(Client, RPL_TOPIC_MSG, + Client_ID(Client), channame, topic); +#ifndef STRICT_RFC + IRC_WriteStrClient(Client, RPL_TOPICSETBY_MSG, + Client_ID(Client), channame, + Channel_TopicWho(chan), + Channel_TopicTime(chan)); +#endif + } /* Mitglieder an Client Melden */ IRC_Send_NAMES( Client, chan ); @@ -268,6 +277,7 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) CHANNEL *chan; CLIENT *from; char *topic; + bool r; assert( Client != NULL ); assert( Req != NULL ); @@ -288,10 +298,22 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) if( Req->argc == 1 ) { - /* Topic erfragen */ - topic = Channel_Topic( chan ); - if( *topic ) return IRC_WriteStrClient( from, RPL_TOPIC_MSG, Client_ID( from ), Channel_Name( chan ), topic ); - else return IRC_WriteStrClient( from, RPL_NOTOPIC_MSG, Client_ID( from ), Channel_Name( chan )); + /* Request actual topic */ + topic = Channel_Topic(chan); + if (*topic) { + r = IRC_WriteStrClient(from, RPL_TOPIC_MSG, + Client_ID(Client), Channel_Name(chan), topic); +#ifndef STRICT_RFC + r = IRC_WriteStrClient(from, RPL_TOPICSETBY_MSG, + Client_ID(Client), Channel_Name(chan), + Channel_TopicWho(chan), + Channel_TopicTime(chan)); +#endif + return r; + } + else + return IRC_WriteStrClient(from, RPL_NOTOPIC_MSG, + Client_ID(from), Channel_Name(chan)); } if( strchr( Channel_Modes( chan ), 't' )) @@ -300,9 +322,11 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req ) if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan )); } - /* Topic setzen */ - Channel_SetTopic( chan, Req->argv[1] ); - Log( LOG_DEBUG, "User \"%s\" set topic on \"%s\": %s", Client_Mask( from ), Channel_Name( chan ), Req->argv[1][0] ? Req->argv[1] : "" ); + /* Set new topic */ + Channel_SetTopic(chan, from, Req->argv[1]); + Log(LOG_DEBUG, "User \"%s\" set topic on \"%s\": %s", + Client_Mask(from), Channel_Name(chan), + Req->argv[1][0] ? Req->argv[1] : ""); /* im Channel bekannt machen und an Server weiterleiten */ IRC_WriteStrServersPrefix( Client, from, "TOPIC %s :%s", Req->argv[0], Req->argv[1] ); @@ -478,8 +502,9 @@ IRC_CHANINFO( CLIENT *Client, REQUEST *Req ) if(( ! *ptr ) && ( Req->argv[arg_topic][0] )) { /* OK, there is no topic jet */ - Channel_SetTopic( chan, Req->argv[arg_topic] ); - IRC_WriteStrChannelPrefix( Client, chan, from, false, "TOPIC %s :%s", Req->argv[0], Channel_Topic( chan )); + Channel_SetTopic(chan, Client, Req->argv[arg_topic]); + IRC_WriteStrChannelPrefix(Client, chan, from, false, + "TOPIC %s :%s", Req->argv[0], Channel_Topic(chan)); } } diff --git a/src/ngircd/messages.h b/src/ngircd/messages.h index c6847cf4..ee1eff67 100644 --- a/src/ngircd/messages.h +++ b/src/ngircd/messages.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: messages.h,v 1.66 2004/02/28 02:18:16 alex Exp $ + * $Id: messages.h,v 1.67 2005/09/02 12:50:25 alex Exp $ * * IRC numerics (Header) */ @@ -62,6 +62,7 @@ #define RPL_CHANNELMODEIS_MSG "324 %s %s +%s" #define RPL_NOTOPIC_MSG "331 %s %s :No topic is set" #define RPL_TOPIC_MSG "332 %s %s :%s" +#define RPL_TOPICSETBY_MSG "333 %s %s %s %u" #define RPL_INVITING_MSG "341 %s %s %s" #define RPL_INVITELIST_MSG "346 %s %s %s" #define RPL_ENDOFINVITELIST_MSG "347 %s %s :End of channel invite list"