source: irc_channel.c @ b9e020a

Last change on this file since b9e020a was b9e020a, checked in by Wilmer van der Gaast <wilmer@…>, at 2010-03-27T03:04:35Z

Added JOIN, NAMES and PART commands.

  • Property mode set to 100644
File size: 2.7 KB
Line 
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
47irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name )
48{
49        GSList *l;
50       
51        for( l = irc->channels; l; l = l->next )
52        {
53                irc_channel_t *ic = l->data;
54               
55                if( name[0] == ic->name[0] && nick_cmp( name + 1, ic->name + 1 ) == 0 )
56                        return ic;
57        }
58       
59        return NULL;
60}
61
62int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
63{
64        if( g_slist_find( ic->users, iu ) != NULL )
65                return 0;
66       
67        ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
68       
69        if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED )
70        {
71                ic->flags |= IRC_CHANNEL_JOINED;
72                irc_send_join( ic, iu );
73        }
74       
75        return 1;
76}
77
78int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
79{
80        if( g_slist_find( ic->users, iu ) == NULL )
81                return 0;
82       
83        ic->users = g_slist_remove( ic->users, iu );
84       
85        if( ic->flags & IRC_CHANNEL_JOINED )
86                irc_send_part( ic, iu, "" );
87       
88        if( iu == ic->irc->user )
89                ic->flags &= ~IRC_CHANNEL_JOINED;
90       
91        return 1;
92}
93
94int irc_channel_set_topic( irc_channel_t *ic, const char *topic )
95{
96        g_free( ic->topic );
97        ic->topic = g_strdup( topic );
98       
99        if( ic->flags & IRC_CHANNEL_JOINED )
100                irc_send_topic( ic );
101       
102        return 1;
103}
Note: See TracBrowser for help on using the repository browser.