X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fchannel.c;h=971fe2f9c4cd28830c4bcdde0015865fff8907c1;hp=5cd24128fe1e5449ad8ef258887ff24c80a2112d;hb=6626395c88fc46eeb110942b17eb9245a1d0021b;hpb=b7eb5f66dc93647d502572b5289ce3c6ba129463 diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 5cd24128..971fe2f9 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.36 2002/12/13 17:22:57 alex Exp $"; +static char UNUSED id[] = "$Id: channel.c,v 1.41 2002/12/26 16:48:14 alex Exp $"; #include "imp.h" #include @@ -293,14 +293,13 @@ Channel_MemberCount( CHANNEL *Chan ) GLOBAL INT -Channel_CountForUser( CHANNEL *Chan, CLIENT *Client ) +Channel_CountForUser( CLIENT *Client ) { /* Count number of channels a user is member of. */ CL2CHAN *cl2chan; INT count; - assert( Chan != NULL ); assert( Client != NULL ); count = 0; @@ -315,6 +314,25 @@ Channel_CountForUser( CHANNEL *Chan, CLIENT *Client ) } /* Channel_CountForUser */ +GLOBAL INT +Channel_PCount( VOID ) +{ + /* Count the number of persistent (mode 'P') channels */ + + CHANNEL *chan; + INT count; + + count = 0; + chan = My_Channels; + while( chan ) + { + if( strchr( chan->modes, 'P' )) count++; + chan = chan->next; + } + + return count; +} /* Channel_PCount */ + GLOBAL CHAR * Channel_Name( CHANNEL *Chan ) @@ -332,6 +350,22 @@ Channel_Modes( CHANNEL *Chan ) } /* Channel_Modes */ +GLOBAL CHAR * +Channel_Key( CHANNEL *Chan ) +{ + assert( Chan != NULL ); + return Chan->key; +} /* Channel_Key */ + + +GLOBAL LONG +Channel_MaxUsers( CHANNEL *Chan ) +{ + assert( Chan != NULL ); + return Chan->maxusers; +} /* Channel_MaxUsers */ + + GLOBAL CHANNEL * Channel_First( VOID ) { @@ -434,7 +468,7 @@ Channel_IsValidName( CHAR *Name ) if(( Name[0] != '#' ) || ( strlen( Name ) >= CHANNEL_NAME_LEN )) return FALSE; ptr = Name; - strcpy( badchars, " ,:\x07" ); + strcpy( badchars, " ,:\007" ); while( *ptr ) { if( strchr( badchars, *ptr )) return FALSE; @@ -460,7 +494,7 @@ Channel_ModeAdd( CHANNEL *Chan, CHAR Mode ) if( ! strchr( Chan->modes, x[0] )) { /* Client hat den Mode noch nicht -> setzen */ - strcat( Chan->modes, x ); + strlcat( Chan->modes, x, sizeof( Chan->modes )); return TRUE; } else return FALSE; @@ -513,7 +547,7 @@ Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, CHAR Mode ) if( ! strchr( cl2chan->modes, x[0] )) { /* Client hat den Mode noch nicht -> setzen */ - strcat( cl2chan->modes, x ); + strlcat( cl2chan->modes, x, sizeof( cl2chan->modes )); return TRUE; } else return FALSE; @@ -595,8 +629,7 @@ Channel_SetTopic( CHANNEL *Chan, CHAR *Topic ) assert( Chan != NULL ); assert( Topic != NULL ); - strncpy( Chan->topic, Topic, CHANNEL_TOPIC_LEN - 1 ); - Chan->topic[CHANNEL_TOPIC_LEN - 1] = '\0'; + strlcpy( Chan->topic, Topic, sizeof( Chan->topic )); } /* Channel_SetTopic */ @@ -606,11 +639,30 @@ Channel_SetModes( CHANNEL *Chan, CHAR *Modes ) assert( Chan != NULL ); assert( Modes != NULL ); - strncpy( Chan->modes, Modes, CHANNEL_MODE_LEN - 1 ); - Chan->topic[CHANNEL_MODE_LEN - 1] = '\0'; + strlcpy( Chan->modes, Modes, sizeof( Chan->modes )); } /* Channel_SetModes */ +GLOBAL VOID +Channel_SetKey( CHANNEL *Chan, CHAR *Key ) +{ + assert( Chan != NULL ); + assert( Key != NULL ); + + strlcpy( Chan->key, Key, sizeof( Chan->key )); + Log( LOG_DEBUG, "Channel %s: Key is now \"%s\".", Chan->name, Chan->key ); +} /* Channel_SetKey */ + + +GLOBAL VOID +Channel_SetMaxUsers( CHANNEL *Chan, LONG Count ) +{ + assert( Chan != NULL ); + + Chan->maxusers = Count; + Log( LOG_DEBUG, "Channel %s: Member limit is now %ld.", Chan->name, Chan->maxusers ); +} /* Channel_SetMaxUsers */ + GLOBAL BOOLEAN Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, CHAR *Text ) @@ -655,11 +707,13 @@ Channel_Create( CHAR *Name ) return NULL; } c->next = NULL; - strncpy( c->name, Name, CHANNEL_NAME_LEN - 1 ); + strlcpy( c->name, Name, sizeof( c->name )); c->name[CHANNEL_NAME_LEN - 1] = '\0'; strcpy( c->modes, "" ); strcpy( c->topic, "" ); c->hash = Hash( c->name ); + strcpy( c->key, "" ); + c->maxusers = 0; /* Verketten */ c->next = My_Channels;