Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 by Alexander Barton (alex@barton.de)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
10 *
11 * Channel management
12 */
15 #define __channel_c__
18 #include "portab.h"
20 static char UNUSED id[] = "$Id: channel.c,v 1.48 2005/06/04 11:53:25 fw Exp $";
22 #include "imp.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <strings.h>
28 #include "defines.h"
29 #include "conn-func.h"
30 #include "client.h"
32 #include "exp.h"
33 #include "channel.h"
35 #include "imp.h"
36 #include "irc-write.h"
37 #include "resolve.h"
38 #include "conf.h"
39 #include "hash.h"
40 #include "lists.h"
41 #include "log.h"
42 #include "messages.h"
44 #include "exp.h"
47 #define REMOVE_PART 0
48 #define REMOVE_QUIT 1
49 #define REMOVE_KICK 2
52 LOCAL CHANNEL *My_Channels;
53 LOCAL CL2CHAN *My_Cl2Chan;
56 LOCAL CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
57 LOCAL CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
58 LOCAL bool Remove_Client PARAMS(( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, char *Reason, bool InformServer ));
59 LOCAL CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
60 LOCAL CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
61 LOCAL bool Delete_Channel PARAMS(( CHANNEL *Chan ));
64 GLOBAL void
65 Channel_Init( void )
66 {
67 My_Channels = NULL;
68 My_Cl2Chan = NULL;
69 } /* Channel_Init */
72 GLOBAL void
73 Channel_InitPredefined( void )
74 {
75 /* Vordefinierte persistente Channels erzeugen */
77 CHANNEL *chan;
78 char *c;
79 int i;
81 for( i = 0; i < Conf_Channel_Count; i++ )
82 {
83 /* Ist ein Name konfiguriert? */
84 if( ! Conf_Channel[i].name[0] ) continue;
86 /* Gueltiger Channel-Name? */
87 if( ! Channel_IsValidName( Conf_Channel[i].name ))
88 {
89 Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", Conf_Channel[i].name );
90 continue;
91 }
93 /* Gibt es den Channel bereits? */
94 chan = Channel_Search( Conf_Channel[i].name );
95 if( chan )
96 {
97 Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name );
98 continue;
99 }
101 /* Channel anlegen */
102 chan = Channel_Create( Conf_Channel[i].name );
103 if( chan )
105 Channel_ModeAdd( chan, 'P' );
106 Channel_SetTopic( chan, Conf_Channel[i].topic );
107 c = Conf_Channel[i].modes;
108 while( *c ) Channel_ModeAdd( chan, *c++ );
109 Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name );
111 else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name );
113 } /* Channel_InitPredefined */
116 GLOBAL void
117 Channel_Exit( void )
119 CHANNEL *c, *c_next;
120 CL2CHAN *cl2chan, *cl2chan_next;
122 /* Channel-Strukturen freigeben */
123 c = My_Channels;
124 while( c )
126 c_next = c->next;
127 free( c );
128 c = c_next;
131 /* Channel-Zuordnungstabelle freigeben */
132 cl2chan = My_Cl2Chan;
133 while( c )
135 cl2chan_next = cl2chan->next;
136 free( cl2chan );
137 cl2chan = cl2chan_next;
139 } /* Channel_Exit */
142 GLOBAL bool
143 Channel_Join( CLIENT *Client, char *Name )
145 CHANNEL *chan;
147 assert( Client != NULL );
148 assert( Name != NULL );
150 /* Valider Channel-Name? */
151 if( ! Channel_IsValidName( Name ))
153 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
154 return false;
157 /* Channel suchen */
158 chan = Channel_Search( Name );
159 if( chan )
161 /* Ist der Client bereits Mitglied? */
162 if( Get_Cl2Chan( chan, Client )) return false;
164 else
166 /* Gibt es noch nicht? Dann neu anlegen: */
167 chan = Channel_Create( Name );
168 if( ! chan ) return false;
171 /* User dem Channel hinzufuegen */
172 if( ! Add_Client( chan, Client )) return false;
173 else return true;
174 } /* Channel_Join */
177 GLOBAL bool
178 Channel_Part( CLIENT *Client, CLIENT *Origin, char *Name, char *Reason )
180 CHANNEL *chan;
182 assert( Client != NULL );
183 assert( Name != NULL );
184 assert( Reason != NULL );
186 /* Channel suchen */
187 chan = Channel_Search( Name );
188 if(( ! chan ) || ( ! Get_Cl2Chan( chan, Client )))
190 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
191 return false;
194 /* User aus Channel entfernen */
195 if( ! Remove_Client( REMOVE_PART, chan, Client, Origin, Reason, true)) return false;
196 else return true;
197 } /* Channel_Part */
200 GLOBAL void
201 Channel_Kick( CLIENT *Client, CLIENT *Origin, char *Name, char *Reason )
203 CHANNEL *chan;
205 assert( Client != NULL );
206 assert( Origin != NULL );
207 assert( Name != NULL );
208 assert( Reason != NULL );
210 /* Channel suchen */
211 chan = Channel_Search( Name );
212 if( ! chan )
214 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
215 return;
218 /* Ist der User Mitglied in dem Channel? */
219 if( ! Channel_IsMemberOf( chan, Origin ))
221 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Name );
222 return;
225 /* Ist der User Channel-Operator? */
226 if( ! strchr( Channel_UserModes( chan, Origin ), 'o' ))
228 IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Name);
229 return;
232 /* Ist der Ziel-User Mitglied im Channel? */
233 if( ! Channel_IsMemberOf( chan, Client ))
235 IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( Client ), Name );
236 return;
239 Remove_Client( REMOVE_KICK, chan, Client, Origin, Reason, true);
240 } /* Channel_Kick */
243 GLOBAL void
244 Channel_Quit( CLIENT *Client, char *Reason )
246 CHANNEL *c, *next_c;
248 assert( Client != NULL );
249 assert( Reason != NULL );
251 IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
253 c = My_Channels;
254 while( c )
256 next_c = c->next;
257 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false );
258 c = next_c;
260 } /* Channel_Quit */
263 GLOBAL long
264 Channel_Count( void )
266 CHANNEL *c;
267 long count = 0;
269 c = My_Channels;
270 while( c )
272 count++;
273 c = c->next;
275 return count;
276 } /* Channel_Count */
279 GLOBAL long
280 Channel_MemberCount( CHANNEL *Chan )
282 CL2CHAN *cl2chan;
283 long count = 0;
285 assert( Chan != NULL );
287 cl2chan = My_Cl2Chan;
288 while( cl2chan )
290 if( cl2chan->channel == Chan ) count++;
291 cl2chan = cl2chan->next;
293 return count;
294 } /* Channel_MemberCount */
297 GLOBAL int
298 Channel_CountForUser( CLIENT *Client )
300 /* Count number of channels a user is member of. */
302 CL2CHAN *cl2chan;
303 int count = 0;
305 assert( Client != NULL );
307 cl2chan = My_Cl2Chan;
308 while( cl2chan )
310 if( cl2chan->client == Client ) count++;
311 cl2chan = cl2chan->next;
314 return count;
315 } /* Channel_CountForUser */
318 GLOBAL int
319 Channel_PCount( void )
321 /* Count the number of persistent (mode 'P') channels */
323 CHANNEL *chan;
324 int count = 0;
326 chan = My_Channels;
327 while( chan )
329 if( strchr( chan->modes, 'P' )) count++;
330 chan = chan->next;
333 return count;
334 } /* Channel_PCount */
337 GLOBAL char *
338 Channel_Name( CHANNEL *Chan )
340 assert( Chan != NULL );
341 return Chan->name;
342 } /* Channel_Name */
345 GLOBAL char *
346 Channel_Modes( CHANNEL *Chan )
348 assert( Chan != NULL );
349 return Chan->modes;
350 } /* Channel_Modes */
353 GLOBAL char *
354 Channel_Key( CHANNEL *Chan )
356 assert( Chan != NULL );
357 return Chan->key;
358 } /* Channel_Key */
361 GLOBAL long
362 Channel_MaxUsers( CHANNEL *Chan )
364 assert( Chan != NULL );
365 return Chan->maxusers;
366 } /* Channel_MaxUsers */
369 GLOBAL CHANNEL *
370 Channel_First( void )
372 return My_Channels;
373 } /* Channel_First */
376 GLOBAL CHANNEL *
377 Channel_Next( CHANNEL *Chan )
379 assert( Chan != NULL );
380 return Chan->next;
381 } /* Channel_Next */
384 GLOBAL CHANNEL *
385 Channel_Search( char *Name )
387 /* Channel-Struktur suchen */
389 CHANNEL *c;
390 UINT32 search_hash;
392 assert( Name != NULL );
394 search_hash = Hash( Name );
395 c = My_Channels;
396 while( c )
398 if( search_hash == c->hash )
400 /* lt. Hash-Wert: Treffer! */
401 if( strcasecmp( Name, c->name ) == 0 ) return c;
403 c = c->next;
405 return NULL;
406 } /* Channel_Search */
409 GLOBAL CL2CHAN *
410 Channel_FirstMember( CHANNEL *Chan )
412 assert( Chan != NULL );
413 return Get_First_Cl2Chan( NULL, Chan );
414 } /* Channel_FirstMember */
417 GLOBAL CL2CHAN *
418 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
420 assert( Chan != NULL );
421 assert( Cl2Chan != NULL );
422 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
423 } /* Channel_NextMember */
426 GLOBAL CL2CHAN *
427 Channel_FirstChannelOf( CLIENT *Client )
429 assert( Client != NULL );
430 return Get_First_Cl2Chan( Client, NULL );
431 } /* Channel_FirstChannelOf */
434 GLOBAL CL2CHAN *
435 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
437 assert( Client != NULL );
438 assert( Cl2Chan != NULL );
439 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
440 } /* Channel_NextChannelOf */
443 GLOBAL CLIENT *
444 Channel_GetClient( CL2CHAN *Cl2Chan )
446 assert( Cl2Chan != NULL );
447 return Cl2Chan->client;
448 } /* Channel_GetClient */
451 GLOBAL CHANNEL *
452 Channel_GetChannel( CL2CHAN *Cl2Chan )
454 assert( Cl2Chan != NULL );
455 return Cl2Chan->channel;
456 } /* Channel_GetChannel */
459 GLOBAL bool
460 Channel_IsValidName( char *Name )
462 /* Pruefen, ob Name als Channelname gueltig */
464 char *ptr, badchars[10];
466 assert( Name != NULL );
468 if(( Name[0] != '#' ) || ( strlen( Name ) >= CHANNEL_NAME_LEN )) return false;
470 ptr = Name;
471 strcpy( badchars, " ,:\007" );
472 while( *ptr )
474 if( strchr( badchars, *ptr )) return false;
475 ptr++;
478 return true;
479 } /* Channel_IsValidName */
482 GLOBAL bool
483 Channel_ModeAdd( CHANNEL *Chan, char Mode )
485 /* set Mode.
486 * If the channel already had this mode, return false.
487 * If the channel mode was newly set return true.
488 */
490 char x[2];
492 assert( Chan != NULL );
494 x[0] = Mode; x[1] = '\0';
495 if( ! strchr( Chan->modes, x[0] ))
497 /* Channel does not have this mode yet, set it */
498 strlcat( Chan->modes, x, sizeof( Chan->modes ));
499 return true;
501 else return false;
502 } /* Channel_ModeAdd */
505 GLOBAL bool
506 Channel_ModeDel( CHANNEL *Chan, char Mode )
508 /* Delete mode.
509 * if the mode was removed return true.
510 * if the channel did not have the mode, return false.
511 */
512 char x[2], *p;
514 assert( Chan != NULL );
516 x[0] = Mode; x[1] = '\0';
518 p = strchr( Chan->modes, x[0] );
519 if( ! p ) return false;
521 /* Channel has mode -> delete */
522 while( *p )
524 *p = *(p + 1);
525 p++;
527 return true;
528 } /* Channel_ModeDel */
531 GLOBAL bool
532 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, char Mode )
534 /* Set Channel-User-Mode.
535 * if mode was newly set, return true.
536 * if the User already had this channel-mode, return false.
537 */
539 CL2CHAN *cl2chan;
540 char x[2];
542 assert( Chan != NULL );
543 assert( Client != NULL );
545 cl2chan = Get_Cl2Chan( Chan, Client );
546 assert( cl2chan != NULL );
548 x[0] = Mode; x[1] = '\0';
549 if( ! strchr( cl2chan->modes, x[0] ))
551 /* mode not set, -> set it */
552 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
553 return true;
555 else return false;
556 } /* Channel_UserModeAdd */
559 GLOBAL bool
560 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, char Mode )
562 /* Delete Channel-User-Mode.
563 * If Mode was removed, return true.
564 * If User did not have the Channel-Mode, return false.
565 */
567 CL2CHAN *cl2chan;
568 char x[2], *p;
570 assert( Chan != NULL );
571 assert( Client != NULL );
573 cl2chan = Get_Cl2Chan( Chan, Client );
574 assert( cl2chan != NULL );
576 x[0] = Mode; x[1] = '\0';
578 p = strchr( cl2chan->modes, x[0] );
579 if( ! p ) return false;
581 /* Client has Mode -> delete */
582 while( *p )
584 *p = *(p + 1);
585 p++;
587 return true;
588 } /* Channel_UserModeDel */
591 GLOBAL char *
592 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
594 /* return Users' Channel-Modes */
596 CL2CHAN *cl2chan;
598 assert( Chan != NULL );
599 assert( Client != NULL );
601 cl2chan = Get_Cl2Chan( Chan, Client );
602 assert( cl2chan != NULL );
604 return cl2chan->modes;
605 } /* Channel_UserModes */
608 GLOBAL bool
609 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
611 /* Test if Client is on Channel Chan */
613 assert( Chan != NULL );
614 assert( Client != NULL );
616 if( Get_Cl2Chan( Chan, Client )) return true;
617 else return false;
618 } /* Channel_IsMemberOf */
621 GLOBAL char *
622 Channel_Topic( CHANNEL *Chan )
624 assert( Chan != NULL );
625 return Chan->topic;
626 } /* Channel_Topic */
629 GLOBAL void
630 Channel_SetTopic( CHANNEL *Chan, char *Topic )
632 assert( Chan != NULL );
633 assert( Topic != NULL );
635 strlcpy( Chan->topic, Topic, sizeof( Chan->topic ));
636 } /* Channel_SetTopic */
639 GLOBAL void
640 Channel_SetModes( CHANNEL *Chan, char *Modes )
642 assert( Chan != NULL );
643 assert( Modes != NULL );
645 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
646 } /* Channel_SetModes */
649 GLOBAL void
650 Channel_SetKey( CHANNEL *Chan, char *Key )
652 assert( Chan != NULL );
653 assert( Key != NULL );
655 strlcpy( Chan->key, Key, sizeof( Chan->key ));
656 Log( LOG_DEBUG, "Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
657 } /* Channel_SetKey */
660 GLOBAL void
661 Channel_SetMaxUsers( CHANNEL *Chan, long Count )
663 assert( Chan != NULL );
665 Chan->maxusers = Count;
666 Log( LOG_DEBUG, "Channel %s: Member limit is now %ld.", Chan->name, Chan->maxusers );
667 } /* Channel_SetMaxUsers */
670 GLOBAL bool
671 Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, char *Text )
673 bool is_member, has_voice, is_op, ok;
675 /* Okay, target is a channel */
676 is_member = has_voice = is_op = false;
677 if( Channel_IsMemberOf( Chan, From ))
679 is_member = true;
680 if( strchr( Channel_UserModes( Chan, From ), 'v' )) has_voice = true;
681 if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = true;
684 /* Is the client allowed to write to channel? */
685 ok = true;
686 if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = false;
687 if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = false;
689 /* Is the client banned? */
690 if( Lists_CheckBanned( From, Chan ))
692 /* Client is banned, bus is he channel operator or has voice? */
693 if(( ! has_voice ) && ( ! is_op )) ok = false;
696 if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan ));
698 /* Send text */
699 if( Client_Conn( From ) > NONE ) Conn_UpdateIdle( Client_Conn( From ));
700 return IRC_WriteStrChannelPrefix( Client, Chan, From, true, "PRIVMSG %s :%s", Channel_Name( Chan ), Text );
701 } /* Channel_Write */
704 GLOBAL CHANNEL *
705 Channel_Create( char *Name )
707 /* Create new CHANNEL structure and add it to linked list */
708 CHANNEL *c;
710 assert( Name != NULL );
712 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
713 if( ! c )
715 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
716 return NULL;
718 memset( c, 0, sizeof( CHANNEL ));
719 strlcpy( c->name, Name, sizeof( c->name ));
720 c->hash = Hash( c->name );
721 c->next = My_Channels;
722 My_Channels = c;
724 Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
726 return c;
727 } /* Channel_Create */
730 LOCAL CL2CHAN *
731 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
733 CL2CHAN *cl2chan;
735 assert( Chan != NULL );
736 assert( Client != NULL );
738 cl2chan = My_Cl2Chan;
739 while( cl2chan )
741 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
742 cl2chan = cl2chan->next;
744 return NULL;
745 } /* Get_Cl2Chan */
748 LOCAL CL2CHAN *
749 Add_Client( CHANNEL *Chan, CLIENT *Client )
751 CL2CHAN *cl2chan;
753 assert( Chan != NULL );
754 assert( Client != NULL );
756 /* neue CL2CHAN-Struktur anlegen */
757 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
758 if( ! cl2chan )
760 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
761 return NULL;
763 cl2chan->channel = Chan;
764 cl2chan->client = Client;
765 strcpy( cl2chan->modes, "" );
767 /* Verketten */
768 cl2chan->next = My_Cl2Chan;
769 My_Cl2Chan = cl2chan;
771 Log( LOG_DEBUG, "User \"%s\" joined channel \"%s\".", Client_Mask( Client ), Chan->name );
773 return cl2chan;
774 } /* Add_Client */
777 LOCAL bool
778 Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, char *Reason, bool InformServer )
780 CL2CHAN *cl2chan, *last_cl2chan;
781 CHANNEL *c;
783 assert( Chan != NULL );
784 assert( Client != NULL );
785 assert( Origin != NULL );
786 assert( Reason != NULL );
788 last_cl2chan = NULL;
789 cl2chan = My_Cl2Chan;
790 while( cl2chan )
792 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
793 last_cl2chan = cl2chan;
794 cl2chan = cl2chan->next;
796 if( ! cl2chan ) return false;
798 c = cl2chan->channel;
799 assert( c != NULL );
801 /* Aus Verkettung loesen und freigeben */
802 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
803 else My_Cl2Chan = cl2chan->next;
804 free( cl2chan );
806 switch( Type )
808 case REMOVE_QUIT:
809 /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
810 * hier also "nur" noch alle User in betroffenen Channeln infomieren */
811 assert( InformServer == false );
812 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
813 break;
814 case REMOVE_KICK:
815 /* User wurde geKICKed: ggf. andere Server sowie alle betroffenen User
816 * im entsprechenden Channel informieren */
817 if( InformServer ) IRC_WriteStrServersPrefix( Client_NextHop( Origin ), Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
818 IRC_WriteStrChannelPrefix( Client, c, Origin, false, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
819 if(( Client_Conn( Client ) > NONE ) && ( Client_Type( Client ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Client, Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
820 Log( LOG_DEBUG, "User \"%s\" has been kicked of \"%s\" by \"%s\": %s.", Client_Mask( Client ), c->name, Client_ID( Origin ), Reason );
821 break;
822 default:
823 /* PART */
824 if( InformServer ) IRC_WriteStrServersPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
825 IRC_WriteStrChannelPrefix( Origin, c, Client, false, "PART %s :%s", c->name, Reason );
826 if(( Client_Conn( Origin ) > NONE ) && ( Client_Type( Origin ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
827 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
830 /* Wenn Channel nun leer und nicht pre-defined: loeschen */
831 if( ! strchr( Channel_Modes( Chan ), 'P' ))
833 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
836 return true;
837 } /* Remove_Client */
840 LOCAL CL2CHAN *
841 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
843 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
844 } /* Get_First_Cl2Chan */
847 LOCAL CL2CHAN *
848 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
850 CL2CHAN *cl2chan;
852 assert( Client != NULL || Channel != NULL );
854 cl2chan = Start;
855 while( cl2chan )
857 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
858 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
859 cl2chan = cl2chan->next;
861 return NULL;
862 } /* Get_Next_Cl2Chan */
865 LOCAL bool
866 Delete_Channel( CHANNEL *Chan )
868 /* Channel-Struktur loeschen */
870 CHANNEL *chan, *last_chan;
872 last_chan = NULL;
873 chan = My_Channels;
874 while( chan )
876 if( chan == Chan ) break;
877 last_chan = chan;
878 chan = chan->next;
880 if( ! chan ) return false;
882 Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
884 /* Invite- und Ban-Lists aufraeumen */
885 Lists_DeleteChannel( chan );
887 /* Neu verketten und freigeben */
888 if( last_chan ) last_chan->next = chan->next;
889 else My_Channels = chan->next;
890 free( chan );
892 return true;
893 } /* Delete_Channel */
896 /* -eof- */