ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/channels.h
Revision: 1.7
Committed: Sun Sep 16 18:54:42 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +9 -4 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.7 /**
2     * channels.h: Data structures for channel information.
3     *
4     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5     * Rights to this code are as documented in COPYING.
6     *
7     *
8     * Portions of this file were derived from sources bearing the following license:
9 pippijn 1.3 * Copyright © 2005 William Pitcock, et al.
10 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
11 pippijn 1.1 *
12 pippijn 1.7 * $Id: channels.h,v 1.6 2007-09-09 20:05:51 pippijn Exp $
13 pippijn 1.1 */
14    
15     #ifndef CHANNELS_H
16     #define CHANNELS_H
17    
18 pippijn 1.4 #include <map>
19    
20 pippijn 1.6 #include <common/util.h>
21 pippijn 1.3 #include <ermyth/callback.h>
22    
23 pippijn 1.1 #define MAXEXTMODES 5
24    
25 pippijn 1.5 // Channel modes
26     enum
27     {
28     CMODE_INVITE = 1 << 0,
29     CMODE_KEY = 1 << 1,
30     CMODE_LIMIT = 1 << 2,
31     CMODE_MOD = 1 << 3,
32     CMODE_NOEXT = 1 << 4,
33     CMODE_OP = 1 << 5, /* SPECIAL */
34     CMODE_PRIV = 1 << 6, /* AKA PARA */
35     CMODE_SEC = 1 << 7,
36     CMODE_TOPIC = 1 << 8,
37     CMODE_VOICE = 1 << 9 /* SPECIAL */
38     };
39    
40 pippijn 1.3 class channel_t : public zero_initialised
41 pippijn 1.1 {
42 pippijn 1.3 struct callbacks
43     {
44     functor::callback1<channel_t *> add;
45     functor::callback1<channel_t *> akick_add;
46     functor::callback1<channel_t *> remove;
47     functor::callback6<channel_t *, user_t *, server_t *,
48     char const * const /* setter */,
49     time_t /* ts */,
50     char const * const /* topic */,
51     bool /* return value */> can_change_topic;
52     functor::callback3<channel_t *, user_t *, char const * const> message;
53     functor::callback1<channel_t *> topic;
54     functor::callback1<channel_t *> tschange;
55     };
56    
57     public:
58 pippijn 1.5 unsigned modes;
59    
60 pippijn 1.1 char *name;
61    
62     char *key;
63     unsigned int limit;
64     char *extmodes[MAXEXTMODES]; /* non-standard simple modes with param eg +j */
65    
66     unsigned int nummembers;
67    
68     time_t ts;
69    
70     char *topic;
71     char *topic_setter;
72     time_t topicts;
73    
74     list_t members;
75     list_t bans;
76 pippijn 1.3
77     static callbacks callback;
78 pippijn 1.1 };
79    
80     /* struct for channel memberships */
81 pippijn 1.3 class chanuser_t : public zero_initialised
82 pippijn 1.1 {
83 pippijn 1.3 struct callbacks
84     {
85     functor::callback1<chanuser_t *, bool> join;
86     functor::callback1<chanuser_t *> part;
87     };
88    
89     public:
90 pippijn 1.5 unsigned modes;
91    
92 pippijn 1.1 channel_t *chan;
93     user_t *user;
94     node_t unode;
95     node_t cnode;
96 pippijn 1.3
97     static callbacks callback;
98 pippijn 1.1 };
99    
100 pippijn 1.3 struct chanban_t : zero_initialised
101 pippijn 1.1 {
102     channel_t *chan;
103     char *mask;
104     int type; /* 'b', 'e', 'I', etc -- jilles */
105     };
106    
107 pippijn 1.5 enum mtype
108     {
109     MTYPE_NUL,
110     MTYPE_ADD,
111     MTYPE_DEL
112     };
113 pippijn 1.1
114     struct cmode_t
115     {
116     char mode;
117     unsigned int value;
118     };
119    
120 pippijn 1.5 struct extmode_t
121 pippijn 1.1 {
122     char mode;
123 pippijn 1.3 bool (*check) (char const * const, channel_t *, mychan_t *, user_t *, myuser_t *);
124 pippijn 1.1 };
125    
126 pippijn 1.3 #if 0
127 pippijn 1.1 /* channel related hooks */
128     typedef struct
129     {
130     chanuser_t *cu; /* Write NULL here if you kicked the user.
131     When kicking the last user, you must join a
132     service first, otherwise the channel may be
133     destroyed and crashes may occur. The service may
134     not part until you return; chanserv provides
135     MC_INHABIT to help with this.
136     This also prevents kick/rejoin floods.
137     If this is NULL, a previous function kicked
138     the user */
139     } hook_channel_joinpart_t;
140    
141     typedef struct
142     {
143     user_t *u;
144     channel_t *c;
145     char *msg;
146     } hook_cmessage_data_t;
147    
148 pippijn 1.3 struct hook_channel_topic_check_t
149 pippijn 1.1 {
150     user_t *u; /* Online user that changed the topic */
151     server_t *s; /* Server that restored a topic */
152     channel_t *c; /* Channel still has old topic */
153 pippijn 1.3 char const * const setter; /* Stored setter string, can be nick, nick!user@host
154 pippijn 1.1 or server */
155     time_t ts; /* Time the topic was changed */
156 pippijn 1.3 char const * const topic; /* New topic */
157 pippijn 1.1 int approved; /* Write non-zero here to cancel the change */
158    
159 pippijn 1.3 hook_channel_topic_check_t (char const * const _setter, char const * const _topic)
160     : setter (_setter), topic (_topic)
161     {
162     }
163     };
164     #endif
165    
166     /* cmode.C */
167 pippijn 1.1 E char *flags_to_string (int flags);
168     E int mode_to_flag (char c);
169 pippijn 1.3 E void channel_mode (user_t *source, channel_t *chan, int parc, char const * const parv[]);
170     E void channel_mode (user_t *source, channel_t *chan, char const * const arg);
171     E void channel_mode_va (user_t *source, channel_t *chan, int parc, char const * const parv0, ...);
172 pippijn 1.1 E void clear_simple_modes (channel_t *c);
173     E char *channel_modes (channel_t *c, bool doparams);
174     E void modestack_flush_channel (channel_t *channel);
175     E void modestack_forget_channel (channel_t *channel);
176     E void modestack_finalize_channel (channel_t *channel);
177 pippijn 1.5 E void modestack_mode_simple (char *source, channel_t *channel, mtype dir, int flags);
178     E void modestack_mode_limit (char *source, channel_t *channel, mtype dir, unsigned int limit);
179     E void modestack_mode_ext (char *source, channel_t *channel, mtype dir, int i, char const * const value);
180     E void modestack_mode_param (char *source, channel_t *channel, mtype dir, char type, char const * const value);
181 pippijn 1.1 E void check_modes (mychan_t *mychan, bool sendnow);
182    
183 pippijn 1.3 /* channels.C */
184 pippijn 1.4 typedef std::pair<char const * const, channel_t *> channel_pair;
185     typedef std::map<char const * const, channel_t *, irccase_lt> channel_map;
186     E channel_map chanlist;
187 pippijn 1.1
188     E void init_channels (void);
189    
190 pippijn 1.3 E channel_t *channel_add (char const * const name, unsigned int ts, server_t *creator);
191 pippijn 1.1 E void channel_delete (channel_t *c);
192 pippijn 1.3 E channel_t *channel_find (char const * const name);
193 pippijn 1.1
194 pippijn 1.3 E chanuser_t *chanuser_add (channel_t *chan, char const * const user);
195 pippijn 1.1 E void chanuser_delete (channel_t *chan, user_t *user);
196     E chanuser_t *chanuser_find (channel_t *chan, user_t *user);
197    
198 pippijn 1.3 E chanban_t *chanban_add (channel_t *chan, char const * const mask, int type);
199 pippijn 1.1 E void chanban_delete (chanban_t *c);
200 pippijn 1.3 E chanban_t *chanban_find (channel_t *chan, char const * const mask, int type);
201 pippijn 1.1 E void chanban_clear (channel_t *chan);
202    
203     #endif