X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fchannel.c;h=aafb8bc0d91ddc249f1bca19265cbefd880f645f;hp=43b07e0f95c3fbaede51e80b2da087280abf4a48;hb=2e88dd72d1776695fa223cea65953ba4642992f4;hpb=d645ce86e9440a891b80bfd2907617e16aa799e8 diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 43b07e0f..aafb8bc0 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -2,16 +2,13 @@ * 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.29 2002/08/26 23:39:22 alex Exp $ - * - * channel.c: Management der Channels + * Channel management */ @@ -20,6 +17,8 @@ #include "portab.h" +static char UNUSED id[] = "$Id: channel.c,v 1.38 2002/12/16 23:05:24 alex Exp $"; + #include "imp.h" #include #include @@ -52,7 +51,6 @@ LOCAL CHANNEL *My_Channels; 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 )); @@ -81,7 +79,7 @@ Channel_InitPredefined( VOID ) 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 )) @@ -89,14 +87,19 @@ Channel_InitPredefined( VOID ) 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; @@ -159,12 +162,8 @@ Channel_Join( CLIENT *Client, CHAR *Name ) 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 */ @@ -257,11 +256,11 @@ Channel_Quit( CLIENT *Client, CHAR *Reason ) } /* Channel_Quit */ -GLOBAL INT +GLOBAL LONG Channel_Count( VOID ) { CHANNEL *c; - INT count; + LONG count; count = 0; c = My_Channels; @@ -274,11 +273,11 @@ Channel_Count( VOID ) } /* Channel_Count */ -GLOBAL INT +GLOBAL LONG Channel_MemberCount( CHANNEL *Chan ) { CL2CHAN *cl2chan; - INT count; + LONG count; assert( Chan != NULL ); @@ -293,6 +292,48 @@ Channel_MemberCount( CHANNEL *Chan ) } /* 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 ) { @@ -309,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 ) { @@ -454,7 +511,6 @@ Channel_ModeDel( CHANNEL *Chan, CHAR Mode ) CHAR x[2], *p; assert( Chan != NULL ); - assert( Mode > ' ' ); x[0] = Mode; x[1] = '\0'; @@ -483,7 +539,6 @@ Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, CHAR Mode ) assert( Chan != NULL ); assert( Client != NULL ); - assert( Mode > ' ' ); cl2chan = Get_Cl2Chan( Chan, Client ); assert( cl2chan != NULL ); @@ -579,6 +634,39 @@ Channel_SetTopic( CHANNEL *Chan, CHAR *Topic ) } /* Channel_SetTopic */ +GLOBAL VOID +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'; +} /* Channel_SetModes */ + + +GLOBAL VOID +Channel_SetKey( CHANNEL *Chan, CHAR *Key ) +{ + assert( Chan != NULL ); + assert( Key != NULL ); + + strncpy( Chan->key, Key, CLIENT_PASS_LEN - 1 ); + Chan->key[CLIENT_PASS_LEN - 1] = '\0'; + 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 ) { @@ -606,9 +694,8 @@ Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, CHAR *Text ) } /* Channel_Write */ - -LOCAL CHANNEL * -New_Chan( CHAR *Name ) +GLOBAL CHANNEL * +Channel_Create( CHAR *Name ) { /* Neue Channel-Struktur anlegen */ @@ -628,11 +715,17 @@ New_Chan( CHAR *Name ) 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 *