commit 0e38d10bcd336afa9c28c69b6fad04a4669f2e4c from: Alexander Barton date: Mon Mar 25 16:54:26 2002 UTC - New_Chan() berechnet Hash-Werte ueber den Namen. - Channel_Search() verwendet nun Hash-Werte. - Neue Funktion Channel_Write(). commit - 7bb2c6b012bfa3595477ac3502480357b89271c7 commit + 0e38d10bcd336afa9c28c69b6fad04a4669f2e4c blob - 139e9b184e00b25246121de5d864c4a474e4c6d5 blob + 3e1e710bad885417c6c22a0bf59f682150ef788f --- src/ngircd/channel.c +++ src/ngircd/channel.c @@ -9,7 +9,7 @@ * 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.19 2002/03/12 14:37:52 alex Exp $ + * $Id: channel.c,v 1.20 2002/03/25 16:54:26 alex Exp $ * * channel.c: Management der Channels */ @@ -26,6 +26,7 @@ #include #include "client.h" +#include "hash.h" #include "irc-write.h" #include "log.h" #include "messages.h" @@ -202,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; @@ -424,12 +432,39 @@ GLOBAL VOID Channel_SetTopic( CHANNEL *Chan, CHAR *Top 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 ); @@ -445,6 +480,7 @@ LOCAL CHANNEL *New_Chan( CHAR *Name ) 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 );