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.45 2004/03/11 22:16:31 alex Exp $";
22 #include "imp.h"
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <strings.h>
28 #include "conn-func.h"
29 #include "client.h"
31 #include "exp.h"
32 #include "channel.h"
34 #include "imp.h"
35 #include "irc-write.h"
36 #include "resolve.h"
37 #include "conf.h"
38 #include "hash.h"
39 #include "lists.h"
40 #include "log.h"
41 #include "messages.h"
43 #include "exp.h"
46 #define REMOVE_PART 0
47 #define REMOVE_QUIT 1
48 #define REMOVE_KICK 2
51 LOCAL CHANNEL *My_Channels;
52 LOCAL CL2CHAN *My_Cl2Chan;
55 LOCAL CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
56 LOCAL CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
57 LOCAL BOOLEAN Remove_Client PARAMS(( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer ));
58 LOCAL CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
59 LOCAL CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
60 LOCAL BOOLEAN Delete_Channel PARAMS(( CHANNEL *Chan ));
63 GLOBAL VOID
64 Channel_Init( VOID )
65 {
66 My_Channels = NULL;
67 My_Cl2Chan = NULL;
68 } /* Channel_Init */
71 GLOBAL VOID
72 Channel_InitPredefined( VOID )
73 {
74 /* Vordefinierte persistente Channels erzeugen */
76 CHANNEL *chan;
77 CHAR *c;
78 INT i;
80 for( i = 0; i < Conf_Channel_Count; i++ )
81 {
82 /* Ist ein Name konfiguriert? */
83 if( ! Conf_Channel[i].name[0] ) continue;
85 /* Gueltiger Channel-Name? */
86 if( ! Channel_IsValidName( Conf_Channel[i].name ))
87 {
88 Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", Conf_Channel[i].name );
89 continue;
90 }
92 /* Gibt es den Channel bereits? */
93 chan = Channel_Search( Conf_Channel[i].name );
94 if( chan )
95 {
96 Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name );
97 continue;
98 }
100 /* Channel anlegen */
101 chan = Channel_Create( Conf_Channel[i].name );
102 if( chan )
104 Channel_ModeAdd( chan, 'P' );
105 Channel_SetTopic( chan, Conf_Channel[i].topic );
106 c = Conf_Channel[i].modes;
107 while( *c ) Channel_ModeAdd( chan, *c++ );
108 Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name );
110 else Log( LOG_ERR, "Can't create pre-defined channel \"%s\"!", Conf_Channel[i].name );
112 } /* Channel_InitPredefined */
115 GLOBAL VOID
116 Channel_Exit( VOID )
118 CHANNEL *c, *c_next;
119 CL2CHAN *cl2chan, *cl2chan_next;
121 /* Channel-Strukturen freigeben */
122 c = My_Channels;
123 while( c )
125 c_next = c->next;
126 free( c );
127 c = c_next;
130 /* Channel-Zuordnungstabelle freigeben */
131 cl2chan = My_Cl2Chan;
132 while( c )
134 cl2chan_next = cl2chan->next;
135 free( cl2chan );
136 cl2chan = cl2chan_next;
138 } /* Channel_Exit */
141 GLOBAL BOOLEAN
142 Channel_Join( CLIENT *Client, CHAR *Name )
144 CHANNEL *chan;
146 assert( Client != NULL );
147 assert( Name != NULL );
149 /* Valider Channel-Name? */
150 if( ! Channel_IsValidName( Name ))
152 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
153 return FALSE;
156 /* Channel suchen */
157 chan = Channel_Search( Name );
158 if( chan )
160 /* Ist der Client bereits Mitglied? */
161 if( Get_Cl2Chan( chan, Client )) return FALSE;
163 else
165 /* Gibt es noch nicht? Dann neu anlegen: */
166 chan = Channel_Create( Name );
167 if( ! chan ) return FALSE;
170 /* User dem Channel hinzufuegen */
171 if( ! Add_Client( chan, Client )) return FALSE;
172 else return TRUE;
173 } /* Channel_Join */
176 GLOBAL BOOLEAN
177 Channel_Part( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
179 CHANNEL *chan;
181 assert( Client != NULL );
182 assert( Name != NULL );
183 assert( Reason != NULL );
185 /* Channel suchen */
186 chan = Channel_Search( Name );
187 if(( ! chan ) || ( ! Get_Cl2Chan( chan, Client )))
189 IRC_WriteStrClient( Client, ERR_NOSUCHCHANNEL_MSG, Client_ID( Client ), Name );
190 return FALSE;
193 /* User aus Channel entfernen */
194 if( ! Remove_Client( REMOVE_PART, chan, Client, Origin, Reason, TRUE )) return FALSE;
195 else return TRUE;
196 } /* Channel_Part */
199 GLOBAL VOID
200 Channel_Kick( CLIENT *Client, CLIENT *Origin, CHAR *Name, CHAR *Reason )
202 CHANNEL *chan;
204 assert( Client != NULL );
205 assert( Origin != NULL );
206 assert( Name != NULL );
207 assert( Reason != NULL );
209 /* Channel suchen */
210 chan = Channel_Search( Name );
211 if( ! chan )
213 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
214 return;
217 /* Ist der User Mitglied in dem Channel? */
218 if( ! Channel_IsMemberOf( chan, Origin ))
220 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Name );
221 return;
224 /* Ist der User Channel-Operator? */
225 if( ! strchr( Channel_UserModes( chan, Origin ), 'o' ))
227 IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Name);
228 return;
231 /* Ist der Ziel-User Mitglied im Channel? */
232 if( ! Channel_IsMemberOf( chan, Client ))
234 IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( Client ), Name );
235 return;
238 Remove_Client( REMOVE_KICK, chan, Client, Origin, Reason, TRUE );
239 } /* Channel_Kick */
242 GLOBAL VOID
243 Channel_Quit( CLIENT *Client, CHAR *Reason )
245 CHANNEL *c, *next_c;
247 assert( Client != NULL );
248 assert( Reason != NULL );
250 c = My_Channels;
251 while( c )
253 next_c = c->next;
254 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, FALSE );
255 c = next_c;
257 } /* Channel_Quit */
260 GLOBAL LONG
261 Channel_Count( VOID )
263 CHANNEL *c;
264 LONG count;
266 count = 0;
267 c = My_Channels;
268 while( c )
270 count++;
271 c = c->next;
273 return count;
274 } /* Channel_Count */
277 GLOBAL LONG
278 Channel_MemberCount( CHANNEL *Chan )
280 CL2CHAN *cl2chan;
281 LONG count;
283 assert( Chan != NULL );
285 count = 0;
286 cl2chan = My_Cl2Chan;
287 while( cl2chan )
289 if( cl2chan->channel == Chan ) count++;
290 cl2chan = cl2chan->next;
292 return count;
293 } /* Channel_MemberCount */
296 GLOBAL INT
297 Channel_CountForUser( CLIENT *Client )
299 /* Count number of channels a user is member of. */
301 CL2CHAN *cl2chan;
302 INT count;
304 assert( Client != NULL );
306 count = 0;
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;
326 count = 0;
327 chan = My_Channels;
328 while( chan )
330 if( strchr( chan->modes, 'P' )) count++;
331 chan = chan->next;
334 return count;
335 } /* Channel_PCount */
338 GLOBAL CHAR *
339 Channel_Name( CHANNEL *Chan )
341 assert( Chan != NULL );
342 return Chan->name;
343 } /* Channel_Name */
346 GLOBAL CHAR *
347 Channel_Modes( CHANNEL *Chan )
349 assert( Chan != NULL );
350 return Chan->modes;
351 } /* Channel_Modes */
354 GLOBAL CHAR *
355 Channel_Key( CHANNEL *Chan )
357 assert( Chan != NULL );
358 return Chan->key;
359 } /* Channel_Key */
362 GLOBAL LONG
363 Channel_MaxUsers( CHANNEL *Chan )
365 assert( Chan != NULL );
366 return Chan->maxusers;
367 } /* Channel_MaxUsers */
370 GLOBAL CHANNEL *
371 Channel_First( VOID )
373 return My_Channels;
374 } /* Channel_First */
377 GLOBAL CHANNEL *
378 Channel_Next( CHANNEL *Chan )
380 assert( Chan != NULL );
381 return Chan->next;
382 } /* Channel_Next */
385 GLOBAL CHANNEL *
386 Channel_Search( CHAR *Name )
388 /* Channel-Struktur suchen */
390 CHANNEL *c;
391 UINT32 search_hash;
393 assert( Name != NULL );
395 search_hash = Hash( Name );
396 c = My_Channels;
397 while( c )
399 if( search_hash == c->hash )
401 /* lt. Hash-Wert: Treffer! */
402 if( strcasecmp( Name, c->name ) == 0 ) return c;
404 c = c->next;
406 return NULL;
407 } /* Channel_Search */
410 GLOBAL CL2CHAN *
411 Channel_FirstMember( CHANNEL *Chan )
413 assert( Chan != NULL );
414 return Get_First_Cl2Chan( NULL, Chan );
415 } /* Channel_FirstMember */
418 GLOBAL CL2CHAN *
419 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
421 assert( Chan != NULL );
422 assert( Cl2Chan != NULL );
423 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
424 } /* Channel_NextMember */
427 GLOBAL CL2CHAN *
428 Channel_FirstChannelOf( CLIENT *Client )
430 assert( Client != NULL );
431 return Get_First_Cl2Chan( Client, NULL );
432 } /* Channel_FirstChannelOf */
435 GLOBAL CL2CHAN *
436 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
438 assert( Client != NULL );
439 assert( Cl2Chan != NULL );
440 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
441 } /* Channel_NextChannelOf */
444 GLOBAL CLIENT *
445 Channel_GetClient( CL2CHAN *Cl2Chan )
447 assert( Cl2Chan != NULL );
448 return Cl2Chan->client;
449 } /* Channel_GetClient */
452 GLOBAL CHANNEL *
453 Channel_GetChannel( CL2CHAN *Cl2Chan )
455 assert( Cl2Chan != NULL );
456 return Cl2Chan->channel;
457 } /* Channel_GetChannel */
460 GLOBAL BOOLEAN
461 Channel_IsValidName( CHAR *Name )
463 /* Pruefen, ob Name als Channelname gueltig */
465 CHAR *ptr, badchars[10];
467 assert( Name != NULL );
469 if(( Name[0] != '#' ) || ( strlen( Name ) >= CHANNEL_NAME_LEN )) return FALSE;
471 ptr = Name;
472 strcpy( badchars, " ,:\007" );
473 while( *ptr )
475 if( strchr( badchars, *ptr )) return FALSE;
476 ptr++;
479 return TRUE;
480 } /* Channel_IsValidName */
483 GLOBAL BOOLEAN
484 Channel_ModeAdd( CHANNEL *Chan, CHAR Mode )
486 /* Mode soll gesetzt werden. TRUE wird geliefert, wenn der
487 * Mode neu gesetzt wurde, FALSE, wenn der Channel den Mode
488 * bereits hatte. */
490 CHAR x[2];
492 assert( Chan != NULL );
494 x[0] = Mode; x[1] = '\0';
495 if( ! strchr( Chan->modes, x[0] ))
497 /* Client hat den Mode noch nicht -> setzen */
498 strlcat( Chan->modes, x, sizeof( Chan->modes ));
499 return TRUE;
501 else return FALSE;
502 } /* Channel_ModeAdd */
505 GLOBAL BOOLEAN
506 Channel_ModeDel( CHANNEL *Chan, CHAR Mode )
508 /* Mode soll geloescht werden. TRUE wird geliefert, wenn der
509 * Mode entfernt wurde, FALSE, wenn der Channel den Mode
510 * ueberhaupt nicht hatte. */
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 /* Client hat den Mode -> loeschen */
522 while( *p )
524 *p = *(p + 1);
525 p++;
527 return TRUE;
528 } /* Channel_ModeDel */
531 GLOBAL BOOLEAN
532 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
534 /* Channel-User-Mode soll gesetzt werden. TRUE wird geliefert,
535 * wenn der Mode neu gesetzt wurde, FALSE, wenn der User den
536 * Channel-Mode bereits hatte. */
538 CL2CHAN *cl2chan;
539 CHAR x[2];
541 assert( Chan != NULL );
542 assert( Client != NULL );
544 cl2chan = Get_Cl2Chan( Chan, Client );
545 assert( cl2chan != NULL );
547 x[0] = Mode; x[1] = '\0';
548 if( ! strchr( cl2chan->modes, x[0] ))
550 /* Client hat den Mode noch nicht -> setzen */
551 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
552 return TRUE;
554 else return FALSE;
555 } /* Channel_UserModeAdd */
558 GLOBAL BOOLEAN
559 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, CHAR Mode )
561 /* Channel-User-Mode soll geloescht werden. TRUE wird geliefert,
562 * wenn der Mode entfernt wurde, FALSE, wenn der User den Channel-Mode
563 * ueberhaupt nicht hatte. */
565 CL2CHAN *cl2chan;
566 CHAR x[2], *p;
568 assert( Chan != NULL );
569 assert( Client != NULL );
571 cl2chan = Get_Cl2Chan( Chan, Client );
572 assert( cl2chan != NULL );
574 x[0] = Mode; x[1] = '\0';
576 p = strchr( cl2chan->modes, x[0] );
577 if( ! p ) return FALSE;
579 /* Client hat den Mode -> loeschen */
580 while( *p )
582 *p = *(p + 1);
583 p++;
585 return TRUE;
586 } /* Channel_UserModeDel */
589 GLOBAL CHAR *
590 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
592 /* Channel-Modes eines Users liefern */
594 CL2CHAN *cl2chan;
596 assert( Chan != NULL );
597 assert( Client != NULL );
599 cl2chan = Get_Cl2Chan( Chan, Client );
600 assert( cl2chan != NULL );
602 return cl2chan->modes;
603 } /* Channel_UserModes */
606 GLOBAL BOOLEAN
607 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
609 /* Pruefen, ob Client Mitglied in Channel ist */
611 assert( Chan != NULL );
612 assert( Client != NULL );
614 if( Get_Cl2Chan( Chan, Client )) return TRUE;
615 else return FALSE;
616 } /* Channel_IsMemberOf */
619 GLOBAL CHAR *
620 Channel_Topic( CHANNEL *Chan )
622 assert( Chan != NULL );
623 return Chan->topic;
624 } /* Channel_Topic */
627 GLOBAL VOID
628 Channel_SetTopic( CHANNEL *Chan, CHAR *Topic )
630 assert( Chan != NULL );
631 assert( Topic != NULL );
633 strlcpy( Chan->topic, Topic, sizeof( Chan->topic ));
634 } /* Channel_SetTopic */
637 GLOBAL VOID
638 Channel_SetModes( CHANNEL *Chan, CHAR *Modes )
640 assert( Chan != NULL );
641 assert( Modes != NULL );
643 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
644 } /* Channel_SetModes */
647 GLOBAL VOID
648 Channel_SetKey( CHANNEL *Chan, CHAR *Key )
650 assert( Chan != NULL );
651 assert( Key != NULL );
653 strlcpy( Chan->key, Key, sizeof( Chan->key ));
654 Log( LOG_DEBUG, "Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
655 } /* Channel_SetKey */
658 GLOBAL VOID
659 Channel_SetMaxUsers( CHANNEL *Chan, LONG Count )
661 assert( Chan != NULL );
663 Chan->maxusers = Count;
664 Log( LOG_DEBUG, "Channel %s: Member limit is now %ld.", Chan->name, Chan->maxusers );
665 } /* Channel_SetMaxUsers */
668 GLOBAL BOOLEAN
669 Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, CHAR *Text )
671 BOOLEAN is_member, has_voice, is_op, ok;
673 /* Okay, target is a channel */
674 is_member = has_voice = is_op = FALSE;
675 if( Channel_IsMemberOf( Chan, From ))
677 is_member = TRUE;
678 if( strchr( Channel_UserModes( Chan, From ), 'v' )) has_voice = TRUE;
679 if( strchr( Channel_UserModes( Chan, From ), 'o' )) is_op = TRUE;
682 /* Check weather client is allowed to write to channel */
683 ok = TRUE;
684 if( strchr( Channel_Modes( Chan ), 'n' ) && ( ! is_member )) ok = FALSE;
685 if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = FALSE;
687 /* Is the client banned? */
688 if( Lists_CheckBanned( From, Chan ))
690 /* Client is banned, bus is he channel operator or has voice? */
691 if(( ! has_voice ) && ( ! is_op )) ok = FALSE;
694 if( ! ok ) return IRC_WriteStrClient( From, ERR_CANNOTSENDTOCHAN_MSG, Client_ID( From ), Channel_Name( Chan ));
696 /* Send text */
697 if( Client_Conn( From ) > NONE ) Conn_UpdateIdle( Client_Conn( From ));
698 return IRC_WriteStrChannelPrefix( Client, Chan, From, TRUE, "PRIVMSG %s :%s", Channel_Name( Chan ), Text );
699 } /* Channel_Write */
702 GLOBAL CHANNEL *
703 Channel_Create( CHAR *Name )
705 /* Neue Channel-Struktur anlegen */
707 CHANNEL *c;
709 assert( Name != NULL );
711 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
712 if( ! c )
714 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
715 return NULL;
717 c->next = NULL;
718 strlcpy( c->name, Name, sizeof( c->name ));
719 c->name[CHANNEL_NAME_LEN - 1] = '\0';
720 strcpy( c->modes, "" );
721 strcpy( c->topic, "" );
722 c->hash = Hash( c->name );
723 strcpy( c->key, "" );
724 c->maxusers = 0;
726 /* Verketten */
727 c->next = My_Channels;
728 My_Channels = c;
730 Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
732 return c;
733 } /* Channel_Create */
736 LOCAL CL2CHAN *
737 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
739 CL2CHAN *cl2chan;
741 assert( Chan != NULL );
742 assert( Client != NULL );
744 cl2chan = My_Cl2Chan;
745 while( cl2chan )
747 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
748 cl2chan = cl2chan->next;
750 return NULL;
751 } /* Get_Cl2Chan */
754 LOCAL CL2CHAN *
755 Add_Client( CHANNEL *Chan, CLIENT *Client )
757 CL2CHAN *cl2chan;
759 assert( Chan != NULL );
760 assert( Client != NULL );
762 /* neue CL2CHAN-Struktur anlegen */
763 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
764 if( ! cl2chan )
766 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
767 return NULL;
769 cl2chan->channel = Chan;
770 cl2chan->client = Client;
771 strcpy( cl2chan->modes, "" );
773 /* Verketten */
774 cl2chan->next = My_Cl2Chan;
775 My_Cl2Chan = cl2chan;
777 Log( LOG_DEBUG, "User \"%s\" joined channel \"%s\".", Client_Mask( Client ), Chan->name );
779 return cl2chan;
780 } /* Add_Client */
783 LOCAL BOOLEAN
784 Remove_Client( INT Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, CHAR *Reason, BOOLEAN InformServer )
786 CL2CHAN *cl2chan, *last_cl2chan;
787 CHANNEL *c;
789 assert( Chan != NULL );
790 assert( Client != NULL );
791 assert( Origin != NULL );
792 assert( Reason != NULL );
794 last_cl2chan = NULL;
795 cl2chan = My_Cl2Chan;
796 while( cl2chan )
798 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
799 last_cl2chan = cl2chan;
800 cl2chan = cl2chan->next;
802 if( ! cl2chan ) return FALSE;
804 c = cl2chan->channel;
805 assert( c != NULL );
807 /* Aus Verkettung loesen und freigeben */
808 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
809 else My_Cl2Chan = cl2chan->next;
810 free( cl2chan );
812 switch( Type )
814 case REMOVE_QUIT:
815 /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
816 * hier also "nur" noch alle User in betroffenen Channeln infomieren */
817 assert( InformServer == FALSE );
818 IRC_WriteStrChannelPrefix( Origin, c, Origin, FALSE, "QUIT :%s", Reason );
819 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
820 break;
821 case REMOVE_KICK:
822 /* User wurde geKICKed: ggf. andere Server sowie alle betroffenen User
823 * im entsprechenden Channel informieren */
824 if( InformServer ) IRC_WriteStrServersPrefix( Client_NextHop( Origin ), Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
825 IRC_WriteStrChannelPrefix( Client, c, Origin, FALSE, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
826 if(( Client_Conn( Client ) > NONE ) && ( Client_Type( Client ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Client, Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason );
827 Log( LOG_DEBUG, "User \"%s\" has been kicked of \"%s\" by \"%s\": %s.", Client_Mask( Client ), c->name, Client_ID( Origin ), Reason );
828 break;
829 default:
830 /* PART */
831 if( InformServer ) IRC_WriteStrServersPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
832 IRC_WriteStrChannelPrefix( Origin, c, Client, FALSE, "PART %s :%s", c->name, Reason );
833 if(( Client_Conn( Origin ) > NONE ) && ( Client_Type( Origin ) == CLIENT_USER )) IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason );
834 Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
837 /* Wenn Channel nun leer und nicht pre-defined: loeschen */
838 if( ! strchr( Channel_Modes( Chan ), 'P' ))
840 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
843 return TRUE;
844 } /* Remove_Client */
847 LOCAL CL2CHAN *
848 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
850 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
851 } /* Get_First_Cl2Chan */
854 LOCAL CL2CHAN *
855 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
857 CL2CHAN *cl2chan;
859 assert( Client != NULL || Channel != NULL );
861 cl2chan = Start;
862 while( cl2chan )
864 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
865 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
866 cl2chan = cl2chan->next;
868 return NULL;
869 } /* Get_Next_Cl2Chan */
872 LOCAL BOOLEAN
873 Delete_Channel( CHANNEL *Chan )
875 /* Channel-Struktur loeschen */
877 CHANNEL *chan, *last_chan;
879 last_chan = NULL;
880 chan = My_Channels;
881 while( chan )
883 if( chan == Chan ) break;
884 last_chan = chan;
885 chan = chan->next;
887 if( ! chan ) return FALSE;
889 Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
891 /* Invite- und Ban-Lists aufraeumen */
892 Lists_DeleteChannel( chan );
894 /* Neu verketten und freigeben */
895 if( last_chan ) last_chan->next = chan->next;
896 else My_Channels = chan->next;
897 free( chan );
899 return TRUE;
900 } /* Delete_Channel */
903 /* -eof- */