X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fchannel.c;h=3e1e710bad885417c6c22a0bf59f682150ef788f;hp=0ed2e3fe7bfe9bef248a71fc04149f8b0e2e6e4f;hb=0e38d10bcd336afa9c28c69b6fad04a4669f2e4c;hpb=d72c55a09dd8e87ccdcb1b97ae2306c1957baca9 diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 0ed2e3fe..3e1e710b 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -9,75 +9,29 @@ * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS. * - * $Id: channel.c,v 1.13 2002/02/11 01:00:12 alex Exp $ + * $Id: channel.c,v 1.20 2002/03/25 16:54:26 alex Exp $ * * channel.c: Management der Channels - * - * $Log: channel.c,v $ - * Revision 1.13 2002/02/11 01:00:12 alex - * - neue Funktionen Channel_ModeAdd(), Channel_ModeDel(), Channel_UserModes(), - * Channel_UserModeAdd(), Channel_UserModeDel(). - * - Modes in CL2CHAN-Struktur werden nun korrekt initialisiert. - * - * Revision 1.12 2002/02/06 16:48:48 alex - * - neue Funktion Channel_Modes() und Channel_IsValidName(). - * - Channel-Namen werden (besser) validiert. - * - * Revision 1.11 2002/01/29 00:11:10 alex - * - neue Funktionen Channel_FirstChannelOf() und Channel_NextChannelOf(). - * - * Revision 1.10 2002/01/28 01:16:15 alex - * - neue Funktionen Channel_Name(), Channel_First() und Channel_Next(). - * - * Revision 1.9 2002/01/27 22:47:11 alex - * - PART wird nicht mehr an den Server verschickt, von dem es empfangen wurde. - * - * Revision 1.8 2002/01/27 21:56:54 alex - * - weitere Anpassungen an Chennals, v.a. ueber Server-Links. - * - * Revision 1.7 2002/01/27 17:14:33 alex - * - diverse Aenderungen fuer Channels ueber mehrere Server. - * - * Revision 1.6 2002/01/26 18:41:55 alex - * - CHANNEL- und CL2CHAN-Strukturen in Header verlegt, - * - einige neue Funktionen (Channel_GetChannel(), Channel_FirstMember(), ...) - * - * Revision 1.5 2002/01/21 00:12:29 alex - * - begonnen, Channels zu implementieren :-) - * - * Revision 1.4 2002/01/16 22:09:07 alex - * - neue Funktion Channel_Count(). - * - * Revision 1.3 2002/01/02 02:42:58 alex - * - Copyright-Texte aktualisiert. - * - * Revision 1.2 2001/12/31 02:18:51 alex - * - viele neue Befehle (WHOIS, ISON, OPER, DIE, RESTART), - * - neuen Header "defines.h" mit (fast) allen Konstanten. - * - Code Cleanups und viele "kleine" Aenderungen & Bugfixes. - * - * Revision 1.1 2001/12/14 08:13:43 alex - * - neues Modul begonnen :-) */ #define __channel_c__ -#include -#include "global.h" +#include "portab.h" -#include +#include "imp.h" #include #include #include #include "client.h" -#include "irc.h" +#include "hash.h" +#include "irc-write.h" #include "log.h" #include "messages.h" -#include +#include "exp.h" #include "channel.h" @@ -249,12 +203,19 @@ GLOBAL CHANNEL *Channel_Search( CHAR *Name ) /* Channel-Struktur suchen */ CHANNEL *c; + UINT32 search_hash; assert( Name != NULL ); + + search_hash = Hash( Name ); c = My_Channels; while( c ) { - if( strcasecmp( Name, c->name ) == 0 ) return c; + if( search_hash == c->hash ) + { + /* lt. Hash-Wert: Treffer! */ + if( strcasecmp( Name, c->name ) == 0 ) return c; + } c = c->next; } return NULL; @@ -308,10 +269,20 @@ GLOBAL CHANNEL *Channel_GetChannel( CL2CHAN *Cl2Chan ) GLOBAL BOOLEAN Channel_IsValidName( CHAR *Name ) { /* PrŸfen, ob Name als Channelname gueltig */ + + CHAR *ptr, badchars[] = " ,:\x07"; assert( Name != NULL ); if(( Name[0] != '#' ) || ( strlen( Name ) >= CHANNEL_NAME_LEN )) return FALSE; + + ptr = Name; + while( *ptr ) + { + if( strchr( badchars, *ptr )) return FALSE; + ptr++; + } + return TRUE; } /* Channel_IsValidName */ @@ -434,10 +405,66 @@ GLOBAL CHAR *Channel_UserModes( CHANNEL *Chan, CLIENT *Client ) } /* Channel_UserModes */ +GLOBAL BOOLEAN Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client ) +{ + /* Pruefen, ob Client Mitglied in Channel ist */ + + assert( Chan != NULL ); + assert( Client != NULL ); + + if( Get_Cl2Chan( Chan, Client )) return TRUE; + else return FALSE; +} /* Channel_IsMemberOf */ + + +GLOBAL CHAR *Channel_Topic( CHANNEL *Chan ) +{ + assert( Chan != NULL ); + return Chan->topic; +} /* Channel_Topic */ + + +GLOBAL VOID 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'; +} /* Channel_SetTopic */ + + +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 */ + is_member = has_voice = is_op = FALSE; + if( Channel_IsMemberOf( Chan, From )) + { + is_member = TRUE; + if( strchr( Channel_UserModes( Chan, From ), 'v' )) has_voice = TRUE; + if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = TRUE; + } + + /* pruefen, ob Client in Channel schreiben darf */ + ok = TRUE; + if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = FALSE; + if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = FALSE; + + if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan )); + + /* Text senden */ + 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 ) { /* Neue Channel-Struktur anlegen */ - + CHANNEL *c; assert( Name != NULL ); @@ -449,9 +476,11 @@ LOCAL CHANNEL *New_Chan( CHAR *Name ) return NULL; } c->next = NULL; - strncpy( c->name, Name, CHANNEL_NAME_LEN ); + strncpy( c->name, Name, CHANNEL_NAME_LEN - 1 ); c->name[CHANNEL_NAME_LEN - 1] = '\0'; strcpy( c->modes, "" ); + strcpy( c->topic, "" ); + c->hash = Hash( c->name ); Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );