#include "portab.h"
-static char UNUSED id[] = "$Id: channel.c,v 1.35 2002/12/12 12:24:18 alex Exp $";
+static char UNUSED id[] = "$Id: channel.c,v 1.45 2004/03/11 22:16:31 alex Exp $";
#include "imp.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
-#include "conn.h"
+#include "conn-func.h"
#include "client.h"
#include "exp.h"
} /* Channel_MemberCount */
+GLOBAL INT
+Channel_CountForUser( CLIENT *Client )
+{
+ /* Count number of channels a user is member of. */
+
+ CL2CHAN *cl2chan;
+ INT count;
+
+ assert( Client != NULL );
+
+ count = 0;
+ cl2chan = My_Cl2Chan;
+ while( cl2chan )
+ {
+ if( cl2chan->client == Client ) count++;
+ cl2chan = cl2chan->next;
+ }
+
+ return count;
+} /* 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 )
{
} /* 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 )
{
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;
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;
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;
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 */
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 )
{
BOOLEAN is_member, has_voice, is_op, ok;
- /* Okay, Ziel ist ein Channel */
+ /* Okay, target is a channel */
is_member = has_voice = is_op = FALSE;
if( Channel_IsMemberOf( Chan, From ))
{
if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = TRUE;
}
- /* pruefen, ob Client in Channel schreiben darf */
+ /* Check weather client is allowed to write to channel */
ok = TRUE;
if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = FALSE;
if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = FALSE;
+
+ /* Is the client banned? */
+ if( Lists_CheckBanned( From, Chan ))
+ {
+ /* Client is banned, bus is he channel operator or has voice? */
+ if(( ! has_voice ) && ( ! is_op )) ok = FALSE;
+ }
if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan ));
- /* Text senden */
+ /* Send text */
if( Client_Conn( From ) > NONE ) Conn_UpdateIdle( Client_Conn( From ));
return IRC_WriteStrChannelPrefix( Client, Chan, From, TRUE, "PRIVMSG %s :%s", Channel_Name( Chan ), Text );
} /* Channel_Write */
assert( Name != NULL );
- c = malloc( sizeof( CHANNEL ));
+ c = (CHANNEL *)malloc( sizeof( CHANNEL ));
if( ! c )
{
Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
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;
assert( Client != NULL );
/* neue CL2CHAN-Struktur anlegen */
- cl2chan = malloc( sizeof( CL2CHAN ));
+ cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
if( ! cl2chan )
{
Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );