Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 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.42 2002/12/30 17:15:42 alex Exp $";
22 #include "imp.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "conn-func.h"
28 #include "client.h"
30 #include "exp.h"
31 #include "channel.h"
33 #include "imp.h"
34 #include "irc-write.h"
35 #include "resolve.h"
36 #include "conf.h"
37 #include "hash.h"
38 #include "lists.h"
39 #include "log.h"
40 #include "messages.h"
42 #include "exp.h"
45 #define REMOVE_PART 0
46 #define REMOVE_QUIT 1
47 #define REMOVE_KICK 2
50 LOCAL CHANNEL *My_Channels;
51 LOCAL CL2CHAN *My_Cl2Chan;
54 LOCAL CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
55 LOCAL CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
56 LOCAL BOOLEAN Remove_Client PARAMS(( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer ));
57 LOCAL CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
58 LOCAL CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
59 LOCAL BOOLEAN Delete_Channel PARAMS(( CHANNEL *Chan ));
62 GLOBAL VOID
63 Channel_Init( VOID )
64 {
65 My_Channels = NULL;
66 My_Cl2Chan = NULL;
67 } /* Channel_Init */
70 GLOBAL VOID
71 Channel_InitPredefined( VOID )
72 {
73 /* Vordefinierte persistente Channels erzeugen */
75 CHANNEL *chan;
76 CHAR *c;
77 INT i;
79 for( i = 0; i < Conf_Channel_Count; i++ )
80 {
81 /* Ist ein Name konfiguriert? */
82 if( ! Conf_Channel[i].name[0] ) continue;
84 /* Gueltiger Channel-Name? */
85 if( ! Channel_IsValidName( Conf_Channel[i].name ))
86 {
87 Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", Conf_Channel[i].name );
88 continue;
89 }
91 /* Gibt es den Channel bereits? */
92 chan = Channel_Search( Conf_Channel[i].name );
93 if( chan )
94 {
95 Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name );
96 continue;
97 }
99 /* Channel anlegen */
100 chan = Channel_Create( Conf_Channel[i].name );
101 if( chan )
103 Channel_ModeAdd( chan, 'P' );
104 Channel_SetTopic( chan, Conf_Channel[i].topic );
105 c = Conf_Channel[i].modes;
106 while( *c ) Channel_ModeAdd( chan, *c++ );
107 Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name );
109 else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name );
111 } /* Channel_InitPredefined */
114 GLOBAL VOID
115 Channel_Exit( VOID )
117 CHANNEL *c, *c_next;
118 CL2CHAN *cl2chan, *cl2chan_next;
120 /* Channel-Strukturen freigeben */
121 c = My_Channels;
122 while( c )
124 c_next = c->next;
125 free( c );
126 c = c_next;
129 /* Channel-Zuordnungstabelle freigeben */
130 cl2chan = My_Cl2Chan;
131 while( c )
133 cl2chan_next = cl2chan->next;
134 free( cl2chan );
135 cl2chan = cl2chan_next;
137 } /* Channel_Exit */
140 GLOBAL BOOLEAN
141 Channel_Join( CLIENT *Client, CHAR *Name )
143 CHANNEL *chan;
145 assert( Client != NULL );
146 assert( Name != NULL );
148 /* Valider Channel-Name? */
149 if( ! Channel_IsValidName( Name ))
151 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
152 return FALSE;
155 /* Channel suchen */
156 chan = Channel_Search( Name );
157 if( chan )
159 /* Ist der Client bereits Mitglied? */
160 if( Get_Cl2Chan( chan, Client )) return FALSE;
162 else
164 /* Gibt es noch nicht? Dann neu anlegen: */
165 chan = Channel_Create( Name );
166 if( ! chan ) return FALSE;
169 /* User dem Channel hinzufuegen */
170 if( ! Add_Client( chan, Client )) return FALSE;
171 else return TRUE;
172 } /* Channel_Join */
175 GLOBAL BOOLEAN
176 Channel_Part( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
178 CHANNEL *chan;
180 assert( Client != NULL );
181 assert( Name != NULL );
182 assert( Reason != NULL );
184 /* Channel suchen */
185 chan = Channel_Search( Name );
186 if(( ! chan ) || ( ! Get_Cl2Chan( chan, Client )))
188 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
189 return FALSE;
192 /* User aus Channel entfernen */
193 if( ! Remove_Client( REMOVE_PART, chan, Client, Origin, Reason, TRUE )) return FALSE;
194 else return TRUE;
195 } /* Channel_Part */
198 GLOBAL VOID
199 Channel_Kick( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
201 CHANNEL *chan;
203 assert( Client != NULL );
204 assert( Origin != NULL );
205 assert( Name != NULL );
206 assert( Reason != NULL );
208 /* Channel suchen */
209 chan = Channel_Search( Name );
210 if( ! chan )
212 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
213 return;
216 /* Ist der User Mitglied in dem Channel? */
217 if( ! Channel_IsMemberOf( chan, Origin ))
219 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Name );
220 return;
223 /* Ist der User Channel-Operator? */
224 if( ! strchr( Channel_UserModes( chan, Origin ), 'o' ))
226 IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Name);
227 return;
230 /* Ist der Ziel-User Mitglied im Channel? */
231 if( ! Channel_IsMemberOf( chan, Client ))
233 IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( Client ), Name );
234 return;
237 Remove_Client( REMOVE_KICK, chan, Client, Origin, Reason, TRUE );
238 } /* Channel_Kick */
241 GLOBAL VOID
242 Channel_Quit( CLIENT *Client, CHAR *Reason )
244 CHANNEL *c, *next_c;
246 assert( Client != NULL );
247 assert( Reason != NULL );
249 c = My_Channels;
250 while( c )
252 next_c = c->next;
253 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, FALSE );
254 c = next_c;
256 } /* Channel_Quit */
259 GLOBAL LONG
260 Channel_Count( VOID )
262 CHANNEL *c;
263 LONG count;
265 count = 0;
266 c = My_Channels;
267 while( c )
269 count++;
270 c = c->next;
272 return count;
273 } /* Channel_Count */
276 GLOBAL LONG
277 Channel_MemberCount( CHANNEL *Chan )
279 CL2CHAN *cl2chan;
280 LONG count;
282 assert( Chan != NULL );
284 count = 0;
285 cl2chan = My_Cl2Chan;
286 while( cl2chan )
288 if( cl2chan->channel == Chan ) count++;
289 cl2chan = cl2chan->next;
291 return count;
292 } /* Channel_MemberCount */
295 GLOBAL INT
296 Channel_CountForUser( CLIENT *Client )
298 /* Count number of channels a user is member of. */
300 CL2CHAN *cl2chan;
301 INT count;
303 assert( Client != NULL );
305 count = 0;
306 cl2chan = My_Cl2Chan;
307 while( cl2chan )
309 if( cl2chan->client == Client ) count++;
310 cl2chan = cl2chan->next;
313 return count;
314 } /* Channel_CountForUser */
317 GLOBAL INT
318 Channel_PCount( VOID )
320 /* Count the number of persistent (mode 'P') channels */
322 CHANNEL *chan;
323 INT count;
325 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 BOOLEAN
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 BOOLEAN
483 Channel_ModeAdd( CHANNEL *Chan, CHAR Mode )
485 /* Mode soll gesetzt werden. TRUE wird geliefert, wenn der
486 * Mode neu gesetzt wurde, FALSE, wenn der Channel den Mode
487 * bereits hatte. */
489 CHAR x[2];
491 assert( Chan != NULL );
493 x[0] = Mode; x[1] = '\0';
494 if( ! strchr( Chan->modes, x[0] ))
496 /* Client hat den Mode noch nicht -> setzen */
497 strlcat( Chan->modes, x, sizeof( Chan->modes ));
498 return TRUE;
500 else return FALSE;
501 } /* Channel_ModeAdd */
504 GLOBAL BOOLEAN
505 Channel_ModeDel( CHANNEL *Chan, CHAR Mode )
507 /* Mode soll geloescht werden. TRUE wird geliefert, wenn der
508 * Mode entfernt wurde, FALSE, wenn der Channel den Mode
509 * ueberhaupt nicht hatte. */
511 CHAR x[2], *p;
513 assert( Chan != NULL );
515 x[0] = Mode; x[1] = '\0';
517 p = strchr( Chan->modes, x[0] );
518 if( ! p ) return FALSE;
520 /* Client hat den Mode -> loeschen */
521 while( *p )
523 *p = *(p + 1);
524 p++;
526 return TRUE;
527 } /* Channel_ModeDel */
530 GLOBAL BOOLEAN
531 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
533 /* Channel-User-Mode soll gesetzt werden. TRUE wird geliefert,
534 * wenn der Mode neu gesetzt wurde, FALSE, wenn der User den
535 * Channel-Mode bereits hatte. */
537 CL2CHAN *cl2chan;
538 CHAR x[2];
540 assert( Chan != NULL );
541 assert( Client != NULL );
543 cl2chan = Get_Cl2Chan( Chan, Client );
544 assert( cl2chan != NULL );
546 x[0] = Mode; x[1] = '\0';
547 if( ! strchr( cl2chan->modes, x[0] ))
549 /* Client hat den Mode noch nicht -> setzen */
550 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
551 return TRUE;
553 else return FALSE;
554 } /* Channel_UserModeAdd */
557 GLOBAL BOOLEAN
558 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
560 /* Channel-User-Mode soll geloescht werden. TRUE wird geliefert,
561 * wenn der Mode entfernt wurde, FALSE, wenn der User den Channel-Mode
562 * ueberhaupt nicht hatte. */
564 CL2CHAN *cl2chan;
565 CHAR x[2], *p;
567 assert( Chan != NULL );
568 assert( Client != NULL );
570 cl2chan = Get_Cl2Chan( Chan, Client );
571 assert( cl2chan != NULL );
573 x[0] = Mode; x[1] = '\0';
575 p = strchr( cl2chan->modes, x[0] );
576 if( ! p ) return FALSE;
578 /* Client hat den Mode -> loeschen */
579 while( *p )
581 *p = *(p + 1);
582 p++;
584 return TRUE;
585 } /* Channel_UserModeDel */
588 GLOBAL CHAR *
589 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
591 /* Channel-Modes eines Users liefern */
593 CL2CHAN *cl2chan;
595 assert( Chan != NULL );
596 assert( Client != NULL );
598 cl2chan = Get_Cl2Chan( Chan, Client );
599 assert( cl2chan != NULL );
601 return cl2chan->modes;
602 } /* Channel_UserModes */
605 GLOBAL BOOLEAN
606 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
608 /* Pruefen, ob Client Mitglied in Channel ist */
610 assert( Chan != NULL );
611 assert( Client != NULL );
613 if( Get_Cl2Chan( Chan, Client )) return TRUE;
614 else return FALSE;
615 } /* Channel_IsMemberOf */
618 GLOBAL CHAR *
619 Channel_Topic( CHANNEL *Chan )
621 assert( Chan != NULL );
622 return Chan->topic;
623 } /* Channel_Topic */
626 GLOBAL VOID
627 Channel_SetTopic( CHANNEL *Chan, CHAR *Topic )
629 assert( Chan != NULL );
630 assert( Topic != NULL );
632 strlcpy( Chan->topic, Topic, sizeof( Chan->topic ));
633 } /* Channel_SetTopic */
636 GLOBAL VOID
637 Channel_SetModes( CHANNEL *Chan, CHAR *Modes )
639 assert( Chan != NULL );
640 assert( Modes != NULL );
642 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
643 } /* Channel_SetModes */
646 GLOBAL VOID
647 Channel_SetKey( CHANNEL *Chan, CHAR *Key )
649 assert( Chan != NULL );
650 assert( Key != NULL );
652 strlcpy( Chan->key, Key, sizeof( Chan->key ));
653 Log( LOG_DEBUG, "Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
654 } /* Channel_SetKey */
657 GLOBAL VOID
658 Channel_SetMaxUsers( CHANNEL *Chan, LONG Count )
660 assert( Chan != NULL );
662 Chan->maxusers = Count;
663 Log( LOG_DEBUG, "Channel %s: Member limit is now %ld.", Chan->name, Chan->maxusers );
664 } /* Channel_SetMaxUsers */
667 GLOBAL BOOLEAN
668 Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, CHAR *Text )
670 BOOLEAN is_member, has_voice, is_op, ok;
672 /* Okay, Ziel ist ein Channel */
673 is_member = has_voice = is_op = FALSE;
674 if( Channel_IsMemberOf( Chan, From ))
676 is_member = TRUE;
677 if( strchr( Channel_UserModes( Chan, From ), 'v' )) has_voice = TRUE;
678 if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = TRUE;
681 /* pruefen, ob Client in Channel schreiben darf */
682 ok = TRUE;
683 if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = FALSE;
684 if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = FALSE;
686 if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan ));
688 /* Text senden */
689 if( Client_Conn( From ) > NONE ) Conn_UpdateIdle( Client_Conn( From ));
690 return IRC_WriteStrChannelPrefix( Client, Chan, From, TRUE, "PRIVMSG %s :%s", Channel_Name( Chan ), Text );
691 } /* Channel_Write */
694 GLOBAL CHANNEL *
695 Channel_Create( CHAR *Name )
697 /* Neue Channel-Struktur anlegen */
699 CHANNEL *c;
701 assert( Name != NULL );
703 c = malloc( sizeof( CHANNEL ));
704 if( ! c )
706 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
707 return NULL;
709 c->next = NULL;
710 strlcpy( c->name, Name, sizeof( c->name ));
711 c->name[CHANNEL_NAME_LEN - 1] = '\0';
712 strcpy( c->modes, "" );
713 strcpy( c->topic, "" );
714 c->hash = Hash( c->name );
715 strcpy( c->key, "" );
716 c->maxusers = 0;
718 /* Verketten */
719 c->next = My_Channels;
720 My_Channels = c;
722 Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
724 return c;
725 } /* Channel_Create */
728 LOCAL CL2CHAN *
729 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
731 CL2CHAN *cl2chan;
733 assert( Chan != NULL );
734 assert( Client != NULL );
736 cl2chan = My_Cl2Chan;
737 while( cl2chan )
739 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
740 cl2chan = cl2chan->next;
742 return NULL;
743 } /* Get_Cl2Chan */
746 LOCAL CL2CHAN *
747 Add_Client( CHANNEL *Chan, CLIENT *Client )
749 CL2CHAN *cl2chan;
751 assert( Chan != NULL );
752 assert( Client != NULL );
754 /* neue CL2CHAN-Struktur anlegen */
755 cl2chan = malloc( sizeof( CL2CHAN ));
756 if( ! cl2chan )
758 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
759 return NULL;
761 cl2chan->channel = Chan;
762 cl2chan->client = Client;
763 strcpy( cl2chan->modes, "" );
765 /* Verketten */
766 cl2chan->next = My_Cl2Chan;
767 My_Cl2Chan = cl2chan;
769 Log( LOG_DEBUG, "User \"%s\" joined channel \"%s\".", Client_Mask( Client ), Chan->name );
771 return cl2chan;
772 } /* Add_Client */
775 LOCAL BOOLEAN
776 Remove_Client( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer )
778 CL2CHAN *cl2chan, *last_cl2chan;
779 CHANNEL *c;
781 assert( Chan != NULL );
782 assert( Client != NULL );
783 assert( Origin != NULL );
784 assert( Reason != NULL );
786 last_cl2chan = NULL;
787 cl2chan = My_Cl2Chan;
788 while( cl2chan )
790 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
791 last_cl2chan = cl2chan;
792 cl2chan = cl2chan->next;
794 if( ! cl2chan ) return FALSE;
796 c = cl2chan->channel;
797 assert( c != NULL );
799 /* Aus Verkettung loesen und freigeben */
800 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
801 else My_Cl2Chan = cl2chan->next;
802 free( cl2chan );
804 switch( Type )
806 case REMOVE_QUIT:
807 /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
808 * hier also "nur" noch alle User in betroffenen Channeln infomieren */
809 assert( InformServer == FALSE );
810 IRC_WriteStrChannelPrefix( Origin, c, Origin, FALSE, "QUIT :%s", Reason );
811 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
812 break;
813 case REMOVE_KICK:
814 /* User wurde geKICKed: ggf. andere Server sowie alle betroffenen User
815 * im entsprechenden Channel informieren */
816 if( InformServer ) IRC_WriteStrServersPrefix( Client_NextHop( Origin ), Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
817 IRC_WriteStrChannelPrefix( Client, c, Origin, FALSE, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
818 if(( Client_Conn( Client ) > NONE ) && ( Client_Type( Client ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Client, Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
819 Log( LOG_DEBUG, "User \"%s\" has been kicked of \"%s\" by \"%s\": %s.", Client_Mask( Client ), c->name, Client_ID( Origin ), Reason );
820 break;
821 default:
822 /* PART */
823 if( InformServer ) IRC_WriteStrServersPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
824 IRC_WriteStrChannelPrefix( Origin, c, Client, FALSE, "PART %s :%s", c->name, Reason );
825 if(( Client_Conn( Origin ) > NONE ) && ( Client_Type( Origin ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
826 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
829 /* Wenn Channel nun leer und nicht pre-defined: loeschen */
830 if( ! strchr( Channel_Modes( Chan ), 'P' ))
832 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
835 return TRUE;
836 } /* Remove_Client */
839 LOCAL CL2CHAN *
840 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
842 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
843 } /* Get_First_Cl2Chan */
846 LOCAL CL2CHAN *
847 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
849 CL2CHAN *cl2chan;
851 assert( Client != NULL || Channel != NULL );
853 cl2chan = Start;
854 while( cl2chan )
856 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
857 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
858 cl2chan = cl2chan->next;
860 return NULL;
861 } /* Get_Next_Cl2Chan */
864 LOCAL BOOLEAN
865 Delete_Channel( CHANNEL *Chan )
867 /* Channel-Struktur loeschen */
869 CHANNEL *chan, *last_chan;
871 last_chan = NULL;
872 chan = My_Channels;
873 while( chan )
875 if( chan == Chan ) break;
876 last_chan = chan;
877 chan = chan->next;
879 if( ! chan ) return FALSE;
881 Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
883 /* Invite- und Ban-Lists aufraeumen */
884 Lists_DeleteChannel( chan );
886 /* Neu verketten und freigeben */
887 if( last_chan ) last_chan->next = chan->next;
888 else My_Channels = chan->next;
889 free( chan );
891 return TRUE;
892 } /* Delete_Channel */
895 /* -eof- */