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