]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/channel.c
5cd24128fe1e5449ad8ef258887ff24c80a2112d
[ngircd-alex.git] / src / ngircd / channel.c
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  */
13
14
15 #define __channel_c__
16
17
18 #include "portab.h"
19
20 static char UNUSED id[] = "$Id: channel.c,v 1.36 2002/12/13 17:22:57 alex Exp $";
21
22 #include "imp.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "conn.h"
28 #include "client.h"
29
30 #include "exp.h"
31 #include "channel.h"
32
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"
41
42 #include "exp.h"
43
44
45 #define REMOVE_PART 0
46 #define REMOVE_QUIT 1
47 #define REMOVE_KICK 2
48
49
50 LOCAL CHANNEL *My_Channels;
51 LOCAL CL2CHAN *My_Cl2Chan;
52
53
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 ));
60
61
62 GLOBAL VOID
63 Channel_Init( VOID )
64 {
65         My_Channels = NULL;
66         My_Cl2Chan = NULL;
67 } /* Channel_Init */
68
69
70 GLOBAL VOID
71 Channel_InitPredefined( VOID )
72 {
73         /* Vordefinierte persistente Channels erzeugen */
74
75         CHANNEL *chan;
76         CHAR *c;
77         INT i;
78         
79         for( i = 0; i < Conf_Channel_Count; i++ )
80         {
81                 /* Ist ein Name konfiguriert? */
82                 if( ! Conf_Channel[i].name[0] ) continue;
83
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                 }
90
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                 }
98                 
99                 /* Channel anlegen */
100                 chan = Channel_Create( Conf_Channel[i].name );
101                 if( chan )
102                 {
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 );
108                 }
109                 else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name );
110         }
111 } /* Channel_InitPredefined */
112
113
114 GLOBAL VOID
115 Channel_Exit( VOID )
116 {
117         CHANNEL *c, *c_next;
118         CL2CHAN *cl2chan, *cl2chan_next;
119         
120         /* Channel-Strukturen freigeben */
121         c = My_Channels;
122         while( c )
123         {
124                 c_next = c->next;
125                 free( c );
126                 c = c_next;
127         }
128
129         /* Channel-Zuordnungstabelle freigeben */
130         cl2chan = My_Cl2Chan;
131         while( c )
132         {
133                 cl2chan_next = cl2chan->next;
134                 free( cl2chan );
135                 cl2chan = cl2chan_next;
136         }
137 } /* Channel_Exit */
138
139
140 GLOBAL BOOLEAN
141 Channel_Join( CLIENT *Client, CHAR *Name )
142 {
143         CHANNEL *chan;
144         
145         assert( Client != NULL );
146         assert( Name != NULL );
147
148         /* Valider Channel-Name? */
149         if( ! Channel_IsValidName( Name ))
150         {
151                 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
152                 return FALSE;
153         }
154
155         /* Channel suchen */
156         chan = Channel_Search( Name );
157         if( chan )
158         {
159                 /* Ist der Client bereits Mitglied? */
160                 if( Get_Cl2Chan( chan, Client )) return FALSE;
161         }
162         else
163         {
164                 /* Gibt es noch nicht? Dann neu anlegen: */
165                 chan = Channel_Create( Name );
166                 if( ! chan ) return FALSE;
167         }
168
169         /* User dem Channel hinzufuegen */
170         if( ! Add_Client( chan, Client )) return FALSE;
171         else return TRUE;
172 } /* Channel_Join */
173
174
175 GLOBAL BOOLEAN
176 Channel_Part( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
177 {
178         CHANNEL *chan;
179
180         assert( Client != NULL );
181         assert( Name != NULL );
182         assert( Reason != NULL );
183
184         /* Channel suchen */
185         chan = Channel_Search( Name );
186         if(( ! chan ) || ( ! Get_Cl2Chan( chan, Client )))
187         {
188                 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
189                 return FALSE;
190         }
191
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 */
196
197
198 GLOBAL VOID
199 Channel_Kick( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
200 {
201         CHANNEL *chan;
202
203         assert( Client != NULL );
204         assert( Origin != NULL );
205         assert( Name != NULL );
206         assert( Reason != NULL );
207
208         /* Channel suchen */
209         chan = Channel_Search( Name );
210         if( ! chan )
211         {
212                 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
213                 return;
214         }
215
216         /* Ist der User Mitglied in dem Channel? */
217         if( ! Channel_IsMemberOf( chan, Origin ))
218         {
219                 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Name );
220                 return;
221         }
222
223         /* Ist der User Channel-Operator? */
224         if( ! strchr( Channel_UserModes( chan, Origin ), 'o' ))
225         {
226                 IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Name);
227                 return;
228         }
229
230         /* Ist der Ziel-User Mitglied im Channel? */
231         if( ! Channel_IsMemberOf( chan, Client ))
232         {
233                 IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( Client ), Name );
234                 return;
235         }
236
237         Remove_Client( REMOVE_KICK, chan, Client, Origin, Reason, TRUE );
238 } /* Channel_Kick */
239
240
241 GLOBAL VOID
242 Channel_Quit( CLIENT *Client, CHAR *Reason )
243 {
244         CHANNEL *c, *next_c;
245
246         assert( Client != NULL );
247         assert( Reason != NULL );
248
249         c = My_Channels;
250         while( c )
251         {
252                 next_c = c->next;
253                 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, FALSE );
254                 c = next_c;
255         }
256 } /* Channel_Quit */
257
258
259 GLOBAL LONG
260 Channel_Count( VOID )
261 {
262         CHANNEL *c;
263         LONG count;
264         
265         count = 0;
266         c = My_Channels;
267         while( c )
268         {
269                 count++;
270                 c = c->next;
271         }
272         return count;
273 } /* Channel_Count */
274
275
276 GLOBAL LONG
277 Channel_MemberCount( CHANNEL *Chan )
278 {
279         CL2CHAN *cl2chan;
280         LONG count;
281
282         assert( Chan != NULL );
283
284         count = 0;
285         cl2chan = My_Cl2Chan;
286         while( cl2chan )
287         {
288                 if( cl2chan->channel == Chan ) count++;
289                 cl2chan = cl2chan->next;
290         }
291         return count;
292 } /* Channel_MemberCount */
293
294
295 GLOBAL INT
296 Channel_CountForUser( CHANNEL *Chan, CLIENT *Client )
297 {
298         /* Count number of channels a user is member of. */
299
300         CL2CHAN *cl2chan;
301         INT count;
302         
303         assert( Chan != NULL );
304         assert( Client != NULL );
305         
306         count = 0;
307         cl2chan = My_Cl2Chan;
308         while( cl2chan )
309         {
310                 if( cl2chan->client == Client ) count++;
311                 cl2chan = cl2chan->next;
312         }
313
314         return count;
315 } /* Channel_CountForUser */
316
317
318
319 GLOBAL CHAR *
320 Channel_Name( CHANNEL *Chan )
321 {
322         assert( Chan != NULL );
323         return Chan->name;
324 } /* Channel_Name */
325
326
327 GLOBAL CHAR *
328 Channel_Modes( CHANNEL *Chan )
329 {
330         assert( Chan != NULL );
331         return Chan->modes;
332 } /* Channel_Modes */
333
334
335 GLOBAL CHANNEL *
336 Channel_First( VOID )
337 {
338         return My_Channels;
339 } /* Channel_First */
340
341
342 GLOBAL CHANNEL *
343 Channel_Next( CHANNEL *Chan )
344 {
345         assert( Chan != NULL );
346         return Chan->next;
347 } /* Channel_Next */
348
349
350 GLOBAL CHANNEL *
351 Channel_Search( CHAR *Name )
352 {
353         /* Channel-Struktur suchen */
354         
355         CHANNEL *c;
356         UINT32 search_hash;
357
358         assert( Name != NULL );
359
360         search_hash = Hash( Name );
361         c = My_Channels;
362         while( c )
363         {
364                 if( search_hash == c->hash )
365                 {
366                         /* lt. Hash-Wert: Treffer! */
367                         if( strcasecmp( Name, c->name ) == 0 ) return c;
368                 }
369                 c = c->next;
370         }
371         return NULL;
372 } /* Channel_Search */
373
374
375 GLOBAL CL2CHAN *
376 Channel_FirstMember( CHANNEL *Chan )
377 {
378         assert( Chan != NULL );
379         return Get_First_Cl2Chan( NULL, Chan );
380 } /* Channel_FirstMember */
381
382
383 GLOBAL CL2CHAN *
384 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
385 {
386         assert( Chan != NULL );
387         assert( Cl2Chan != NULL );
388         return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
389 } /* Channel_NextMember */
390
391
392 GLOBAL CL2CHAN *
393 Channel_FirstChannelOf( CLIENT *Client )
394 {
395         assert( Client != NULL );
396         return Get_First_Cl2Chan( Client, NULL );
397 } /* Channel_FirstChannelOf */
398
399
400 GLOBAL CL2CHAN *
401 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
402 {
403         assert( Client != NULL );
404         assert( Cl2Chan != NULL );
405         return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
406 } /* Channel_NextChannelOf */
407
408
409 GLOBAL CLIENT *
410 Channel_GetClient( CL2CHAN *Cl2Chan )
411 {
412         assert( Cl2Chan != NULL );
413         return Cl2Chan->client;
414 } /* Channel_GetClient */
415
416
417 GLOBAL CHANNEL *
418 Channel_GetChannel( CL2CHAN *Cl2Chan )
419 {
420         assert( Cl2Chan != NULL );
421         return Cl2Chan->channel;
422 } /* Channel_GetChannel */
423
424
425 GLOBAL BOOLEAN
426 Channel_IsValidName( CHAR *Name )
427 {
428         /* Pruefen, ob Name als Channelname gueltig */
429
430         CHAR *ptr, badchars[10];
431         
432         assert( Name != NULL );
433
434         if(( Name[0] != '#' ) || ( strlen( Name ) >= CHANNEL_NAME_LEN )) return FALSE;
435
436         ptr = Name;
437         strcpy( badchars, " ,:\x07" );
438         while( *ptr )
439         {
440                 if( strchr( badchars, *ptr )) return FALSE;
441                 ptr++;
442         }
443         
444         return TRUE;
445 } /* Channel_IsValidName */
446
447
448 GLOBAL BOOLEAN
449 Channel_ModeAdd( CHANNEL *Chan, CHAR Mode )
450 {
451         /* Mode soll gesetzt werden. TRUE wird geliefert, wenn der
452          * Mode neu gesetzt wurde, FALSE, wenn der Channel den Mode
453          * bereits hatte. */
454
455         CHAR x[2];
456
457         assert( Chan != NULL );
458
459         x[0] = Mode; x[1] = '\0';
460         if( ! strchr( Chan->modes, x[0] ))
461         {
462                 /* Client hat den Mode noch nicht -> setzen */
463                 strcat( Chan->modes, x );
464                 return TRUE;
465         }
466         else return FALSE;
467 } /* Channel_ModeAdd */
468
469
470 GLOBAL BOOLEAN
471 Channel_ModeDel( CHANNEL *Chan, CHAR Mode )
472 {
473         /* Mode soll geloescht werden. TRUE wird geliefert, wenn der
474          * Mode entfernt wurde, FALSE, wenn der Channel den Mode
475          * ueberhaupt nicht hatte. */
476
477         CHAR x[2], *p;
478
479         assert( Chan != NULL );
480
481         x[0] = Mode; x[1] = '\0';
482
483         p = strchr( Chan->modes, x[0] );
484         if( ! p ) return FALSE;
485
486         /* Client hat den Mode -> loeschen */
487         while( *p )
488         {
489                 *p = *(p + 1);
490                 p++;
491         }
492         return TRUE;
493 } /* Channel_ModeDel */
494
495
496 GLOBAL BOOLEAN
497 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
498 {
499         /* Channel-User-Mode soll gesetzt werden. TRUE wird geliefert,
500          * wenn der Mode neu gesetzt wurde, FALSE, wenn der User den
501          * Channel-Mode bereits hatte. */
502
503         CL2CHAN *cl2chan;
504         CHAR x[2];
505
506         assert( Chan != NULL );
507         assert( Client != NULL );
508
509         cl2chan = Get_Cl2Chan( Chan, Client );
510         assert( cl2chan != NULL );
511         
512         x[0] = Mode; x[1] = '\0';
513         if( ! strchr( cl2chan->modes, x[0] ))
514         {
515                 /* Client hat den Mode noch nicht -> setzen */
516                 strcat( cl2chan->modes, x );
517                 return TRUE;
518         }
519         else return FALSE;
520 } /* Channel_UserModeAdd */
521
522
523 GLOBAL BOOLEAN
524 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
525 {
526         /* Channel-User-Mode soll geloescht werden. TRUE wird geliefert,
527          * wenn der Mode entfernt wurde, FALSE, wenn der User den Channel-Mode
528          * ueberhaupt nicht hatte. */
529
530         CL2CHAN *cl2chan;
531         CHAR x[2], *p;
532
533         assert( Chan != NULL );
534         assert( Client != NULL );
535
536         cl2chan = Get_Cl2Chan( Chan, Client );
537         assert( cl2chan != NULL );
538
539         x[0] = Mode; x[1] = '\0';
540
541         p = strchr( cl2chan->modes, x[0] );
542         if( ! p ) return FALSE;
543
544         /* Client hat den Mode -> loeschen */
545         while( *p )
546         {
547                 *p = *(p + 1);
548                 p++;
549         }
550         return TRUE;
551 } /* Channel_UserModeDel */
552
553
554 GLOBAL CHAR *
555 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
556 {
557         /* Channel-Modes eines Users liefern */
558         
559         CL2CHAN *cl2chan;
560
561         assert( Chan != NULL );
562         assert( Client != NULL );
563
564         cl2chan = Get_Cl2Chan( Chan, Client );
565         assert( cl2chan != NULL );
566
567         return cl2chan->modes;
568 } /* Channel_UserModes */
569
570
571 GLOBAL BOOLEAN
572 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
573 {
574         /* Pruefen, ob Client Mitglied in Channel ist */
575
576         assert( Chan != NULL );
577         assert( Client != NULL );
578
579         if( Get_Cl2Chan( Chan, Client )) return TRUE;
580         else return FALSE;
581 } /* Channel_IsMemberOf */
582
583
584 GLOBAL CHAR *
585 Channel_Topic( CHANNEL *Chan )
586 {
587         assert( Chan != NULL );
588         return Chan->topic;
589 } /* Channel_Topic */
590
591
592 GLOBAL VOID
593 Channel_SetTopic( CHANNEL *Chan, CHAR *Topic )
594 {
595         assert( Chan != NULL );
596         assert( Topic != NULL );
597         
598         strncpy( Chan->topic, Topic, CHANNEL_TOPIC_LEN - 1 );
599         Chan->topic[CHANNEL_TOPIC_LEN - 1] = '\0';
600 } /* Channel_SetTopic */
601
602
603 GLOBAL VOID
604 Channel_SetModes( CHANNEL *Chan, CHAR *Modes )
605 {
606         assert( Chan != NULL );
607         assert( Modes != NULL );
608
609         strncpy( Chan->modes, Modes, CHANNEL_MODE_LEN - 1 );
610         Chan->topic[CHANNEL_MODE_LEN - 1] = '\0';
611 } /* Channel_SetModes */
612
613
614
615 GLOBAL BOOLEAN
616 Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, CHAR *Text )
617 {
618         BOOLEAN is_member, has_voice, is_op, ok;
619
620         /* Okay, Ziel ist ein Channel */
621         is_member = has_voice = is_op = FALSE;
622         if( Channel_IsMemberOf( Chan, From ))
623         {
624                 is_member = TRUE;
625                 if( strchr( Channel_UserModes( Chan, From ), 'v' )) has_voice = TRUE;
626                 if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = TRUE;
627         }
628
629         /* pruefen, ob Client in Channel schreiben darf */
630         ok = TRUE;
631         if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = FALSE;
632         if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = FALSE;
633
634         if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan ));
635
636         /* Text senden */
637         if( Client_Conn( From ) > NONE ) Conn_UpdateIdle( Client_Conn( From ));
638         return IRC_WriteStrChannelPrefix( Client, Chan, From, TRUE, "PRIVMSG %s :%s", Channel_Name( Chan ), Text );
639 } /* Channel_Write */
640
641
642 GLOBAL CHANNEL *
643 Channel_Create( CHAR *Name )
644 {
645         /* Neue Channel-Struktur anlegen */
646
647         CHANNEL *c;
648
649         assert( Name != NULL );
650         
651         c = malloc( sizeof( CHANNEL ));
652         if( ! c )
653         {
654                 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
655                 return NULL;
656         }
657         c->next = NULL;
658         strncpy( c->name, Name, CHANNEL_NAME_LEN - 1 );
659         c->name[CHANNEL_NAME_LEN - 1] = '\0';
660         strcpy( c->modes, "" );
661         strcpy( c->topic, "" );
662         c->hash = Hash( c->name );
663
664         /* Verketten */
665         c->next = My_Channels;
666         My_Channels = c;
667         
668         Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
669         
670         return c;
671 } /* Channel_Create */
672
673
674 LOCAL CL2CHAN *
675 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
676 {
677         CL2CHAN *cl2chan;
678
679         assert( Chan != NULL );
680         assert( Client != NULL );
681
682         cl2chan = My_Cl2Chan;
683         while( cl2chan )
684         {
685                 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
686                 cl2chan = cl2chan->next;
687         }
688         return NULL;
689 } /* Get_Cl2Chan */
690
691
692 LOCAL CL2CHAN *
693 Add_Client( CHANNEL *Chan, CLIENT *Client )
694 {
695         CL2CHAN *cl2chan;
696
697         assert( Chan != NULL );
698         assert( Client != NULL );
699
700         /* neue CL2CHAN-Struktur anlegen */
701         cl2chan = malloc( sizeof( CL2CHAN ));
702         if( ! cl2chan )
703         {
704                 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
705                 return NULL;
706         }
707         cl2chan->channel = Chan;
708         cl2chan->client = Client;
709         strcpy( cl2chan->modes, "" );
710
711         /* Verketten */
712         cl2chan->next = My_Cl2Chan;
713         My_Cl2Chan = cl2chan;
714
715         Log( LOG_DEBUG, "User \"%s\" joined channel \"%s\".", Client_Mask( Client ), Chan->name );
716
717         return cl2chan;
718 } /* Add_Client */
719
720
721 LOCAL BOOLEAN
722 Remove_Client( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer )
723 {
724         CL2CHAN *cl2chan, *last_cl2chan;
725         CHANNEL *c;
726         
727         assert( Chan != NULL );
728         assert( Client != NULL );
729         assert( Origin != NULL );
730         assert( Reason != NULL );
731
732         last_cl2chan = NULL;
733         cl2chan = My_Cl2Chan;
734         while( cl2chan )
735         {
736                 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
737                 last_cl2chan = cl2chan;
738                 cl2chan = cl2chan->next;
739         }
740         if( ! cl2chan ) return FALSE;
741
742         c = cl2chan->channel;
743         assert( c != NULL );
744
745         /* Aus Verkettung loesen und freigeben */
746         if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
747         else My_Cl2Chan = cl2chan->next;
748         free( cl2chan );
749
750         switch( Type )
751         {
752                 case REMOVE_QUIT:
753                         /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
754                          * hier also "nur" noch alle User in betroffenen Channeln infomieren */
755                         assert( InformServer == FALSE );
756                         IRC_WriteStrChannelPrefix( Origin, c, Origin, FALSE, "QUIT :%s", Reason );
757                         Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
758                         break;
759                 case REMOVE_KICK:
760                         /* User wurde geKICKed: ggf. andere Server sowie alle betroffenen User
761                          * im entsprechenden Channel informieren */
762                         if( InformServer ) IRC_WriteStrServersPrefix( Client_NextHop( Origin ), Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
763                         IRC_WriteStrChannelPrefix( Client, c, Origin, FALSE, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
764                         if(( Client_Conn( Client ) > NONE ) && ( Client_Type( Client ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Client, Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
765                         Log( LOG_DEBUG, "User \"%s\" has been kicked of \"%s\" by \"%s\": %s.", Client_Mask( Client ), c->name, Client_ID( Origin ), Reason );
766                         break;
767                 default:
768                         /* PART */
769                         if( InformServer ) IRC_WriteStrServersPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
770                         IRC_WriteStrChannelPrefix( Origin, c, Client, FALSE, "PART %s :%s", c->name, Reason );
771                         if(( Client_Conn( Origin ) > NONE ) && ( Client_Type( Origin ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
772                         Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
773         }
774
775         /* Wenn Channel nun leer und nicht pre-defined: loeschen */
776         if( ! strchr( Channel_Modes( Chan ), 'P' ))
777         {
778                 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
779         }
780                 
781         return TRUE;
782 } /* Remove_Client */
783
784
785 LOCAL CL2CHAN *
786 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
787 {
788         return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
789 } /* Get_First_Cl2Chan */
790
791
792 LOCAL CL2CHAN *
793 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
794 {
795         CL2CHAN *cl2chan;
796
797         assert( Client != NULL || Channel != NULL );
798         
799         cl2chan = Start;
800         while( cl2chan )
801         {
802                 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
803                 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
804                 cl2chan = cl2chan->next;
805         }
806         return NULL;
807 } /* Get_Next_Cl2Chan */
808
809
810 LOCAL BOOLEAN
811 Delete_Channel( CHANNEL *Chan )
812 {
813         /* Channel-Struktur loeschen */
814         
815         CHANNEL *chan, *last_chan;
816
817         last_chan = NULL;
818         chan = My_Channels;
819         while( chan )
820         {
821                 if( chan == Chan ) break;
822                 last_chan = chan;
823                 chan = chan->next;
824         }
825         if( ! chan ) return FALSE;
826
827         Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
828
829         /* Invite- und Ban-Lists aufraeumen */
830         Lists_DeleteChannel( chan );
831
832         /* Neu verketten und freigeben */
833         if( last_chan ) last_chan->next = chan->next;
834         else My_Channels = chan->next;
835         free( chan );
836                 
837         return TRUE;
838 } /* Delete_Channel */
839
840
841 /* -eof- */