ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/include/channels.h
Revision: 1.8
Committed: Sat Sep 22 14:27:26 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -2 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

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