* ngIRCd -- The Next Generation IRC Daemon
* Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
*
- * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
- * der GNU General Public License (GPL), wie von der Free Software Foundation
- * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
- * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
- * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
- * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * Please read the file COPYING, README and AUTHORS for more information.
*
- * $Id: channel.c,v 1.25 2002/06/01 14:35:39 alex Exp $
- *
- * channel.c: Management der Channels
+ * Channel management
*/
#include "portab.h"
+static char UNUSED id[] = "$Id: channel.c,v 1.43 2003/11/06 01:07:44 alex Exp $";
+
#include "imp.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include "conn.h"
+#include "conn-func.h"
#include "client.h"
#include "exp.h"
#include "resolve.h"
#include "conf.h"
#include "hash.h"
+#include "lists.h"
#include "log.h"
#include "messages.h"
LOCAL CL2CHAN *My_Cl2Chan;
-LOCAL CHANNEL *New_Chan PARAMS(( CHAR *Name ));
LOCAL CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
LOCAL CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
LOCAL BOOLEAN Remove_Client PARAMS(( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer ));
GLOBAL VOID
Channel_Init( VOID )
{
- CHANNEL *chan;
- CHAR *c;
- INT i;
-
My_Channels = NULL;
My_Cl2Chan = NULL;
+} /* Channel_Init */
+
+GLOBAL VOID
+Channel_InitPredefined( VOID )
+{
/* Vordefinierte persistente Channels erzeugen */
+
+ CHANNEL *chan;
+ CHAR *c;
+ INT i;
+
for( i = 0; i < Conf_Channel_Count; i++ )
{
/* Ist ein Name konfiguriert? */
- if( ! Conf_Channel[i].name ) continue;
+ if( ! Conf_Channel[i].name[0] ) continue;
/* Gueltiger Channel-Name? */
if( ! Channel_IsValidName( Conf_Channel[i].name ))
Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", Conf_Channel[i].name );
continue;
}
+
+ /* Gibt es den Channel bereits? */
+ chan = Channel_Search( Conf_Channel[i].name );
+ if( chan )
+ {
+ Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name );
+ continue;
+ }
/* Channel anlegen */
- chan = New_Chan( Conf_Channel[i].name );
+ chan = Channel_Create( Conf_Channel[i].name );
if( chan )
{
- /* Verketten */
- chan->next = My_Channels;
- My_Channels = chan;
Channel_ModeAdd( chan, 'P' );
Channel_SetTopic( chan, Conf_Channel[i].topic );
c = Conf_Channel[i].modes;
}
else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name );
}
-} /* Channel_Init */
+} /* Channel_InitPredefined */
GLOBAL VOID
else
{
/* Gibt es noch nicht? Dann neu anlegen: */
- chan = New_Chan( Name );
+ chan = Channel_Create( Name );
if( ! chan ) return FALSE;
-
- /* Verketten */
- chan->next = My_Channels;
- My_Channels = chan;
}
/* User dem Channel hinzufuegen */
while( c )
{
next_c = c->next;
- Remove_Client( REMOVE_QUIT, c, Client, Client_ThisServer( ), Reason, FALSE );
+ Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, FALSE );
c = next_c;
}
} /* Channel_Quit */
-GLOBAL INT
+GLOBAL LONG
Channel_Count( VOID )
{
CHANNEL *c;
- INT count;
+ LONG count;
count = 0;
c = My_Channels;
} /* Channel_Count */
-GLOBAL INT
+GLOBAL LONG
Channel_MemberCount( CHANNEL *Chan )
{
CL2CHAN *cl2chan;
- INT count;
+ LONG count;
assert( Chan != NULL );
} /* 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 */
+GLOBAL VOID
+Channel_SetModes( CHANNEL *Chan, CHAR *Modes )
+{
+ assert( Chan != NULL );
+ assert( Modes != NULL );
+
+ 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 */
-
-LOCAL CHANNEL *
-New_Chan( CHAR *Name )
+GLOBAL CHANNEL *
+Channel_Create( CHAR *Name )
{
/* Neue Channel-Struktur anlegen */
c = malloc( sizeof( CHANNEL ));
if( ! c )
{
- Log( LOG_EMERG, "Can't allocate memory!" );
+ 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;
+ My_Channels = c;
+
Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
return c;
-} /* New_Chan */
+} /* Channel_Create */
LOCAL CL2CHAN *
cl2chan = malloc( sizeof( CL2CHAN ));
if( ! cl2chan )
{
- Log( LOG_EMERG, "Can't allocate memory!" );
+ Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
return NULL;
}
cl2chan->channel = Chan;
switch( Type )
{
case REMOVE_QUIT:
+ /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
+ * hier also "nur" noch alle User in betroffenen Channeln infomieren */
assert( InformServer == FALSE );
IRC_WriteStrChannelPrefix( Origin, c, Origin, FALSE, "QUIT :%s", Reason );
Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
break;
case REMOVE_KICK:
+ /* User wurde geKICKed: ggf. andere Server sowie alle betroffenen User
+ * im entsprechenden Channel informieren */
if( InformServer ) IRC_WriteStrServersPrefix( Client_NextHop( Origin ), Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
IRC_WriteStrChannelPrefix( Client, c, Origin, FALSE, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
if(( Client_Conn( Client ) > NONE ) && ( Client_Type( Client ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Client, Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
Log( LOG_DEBUG, "User \"%s\" has been kicked of \"%s\" by \"%s\": %s.", Client_Mask( Client ), c->name, Client_ID( Origin ), Reason );
break;
default:
+ /* PART */
if( InformServer ) IRC_WriteStrServersPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
IRC_WriteStrChannelPrefix( Origin, c, Client, FALSE, "PART %s :%s", c->name, Reason );
if(( Client_Conn( Origin ) > NONE ) && ( Client_Type( Origin ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
+ /* Invite- und Ban-Lists aufraeumen */
+ Lists_DeleteChannel( chan );
+
/* Neu verketten und freigeben */
if( last_chan ) last_chan->next = chan->next;
else My_Channels = chan->next;