source: irc_channel.c @ 4be8239

Last change on this file since 4be8239 was 4be8239, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-03-27T02:39:08Z

Simple IRC channel interface, use it to represent the control channel.

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[4be8239]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* The IRC-based UI - Representing (virtual) channels.                  */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include "bitlbee.h"
27
28irc_channel_t *irc_channel_new( irc_t *irc, const char *name )
29{
30        irc_channel_t *ic;
31       
32        if( strchr( CTYPES, name[0] ) == NULL || !nick_ok( name + 1 ) )
33                return NULL;
34       
35        ic = g_new0( irc_channel_t, 1 );
36        ic->irc = irc;
37        ic->name = g_strdup( name );
38        strcpy( ic->mode, CMODE );
39       
40        irc_channel_add_user( ic, irc->root );
41       
42        irc->channels = g_slist_prepend( irc->channels, ic );
43       
44        return ic;
45}
46
47int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
48{
49        if( g_slist_find( ic->users, iu ) != NULL )
50                return 0;
51       
52        ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
53       
54        if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED )
55        {
56                ic->flags |= IRC_CHANNEL_JOINED;
57                irc_send_join( ic, iu );
58        }
59       
60        return 1;
61}
62
63int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
64{
65        if( g_slist_find( ic->users, iu ) == NULL )
66                return 0;
67       
68        ic->users = g_slist_remove( ic->users, iu );
69       
70        if( ic->flags & IRC_CHANNEL_JOINED )
71                irc_send_part( ic, iu, "" );
72       
73        if( iu == ic->irc->user )
74                ic->flags &= ~IRC_CHANNEL_JOINED;
75       
76        return 1;
77}
78
79int irc_channel_set_topic( irc_channel_t *ic, const char *topic )
80{
81        g_free( ic->topic );
82        ic->topic = g_strdup( topic );
83       
84        if( ic->flags & IRC_CHANNEL_JOINED )
85                irc_send_topic( ic );
86       
87        return 1;
88}
Note: See TracBrowser for help on using the repository browser.