]> jfr.im git - irc/quakenet/lightweight.git/blob - lightweight.h
changes from production code.
[irc/quakenet/lightweight.git] / lightweight.h
1 /*
2 This file is part of lightweight.
3
4 lightweight is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 lightweight is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with lightweight; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 /* $Id: lightweight.h,v 1.64 2004/08/18 16:07:50 froo Exp $ */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25 #include <unistd.h>
26 #include <strcmp.h>
27
28 #ifndef __LIGHTWEIGHT_H
29 #define __LIGHTWEIGHT_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* path and filename of config file */
36 #define CONFIGFILE "lightweight.conf"
37
38 /* define this for debugging output */
39 #undef DEBUG
40
41 /* define this for CM support */
42 #define HAVE_CLEARMODE
43
44 /* define this for DEOPALL hack */
45 #undef HORRIBLE_DEOPALL_HACK
46
47 /* define this for L on channels */
48 #define SIT_ON_CHANNELS
49
50 /* define this for modes in burst */
51 /* Note that this is NOT sensible in conjunction with SIT_ON_CHANNELS */
52 #undef AUTOMODES_IN_BURST
53
54 /* number of days before expiring unused channels */
55 #define DAYS_BEFORE_EXPIRE 40
56
57 /* number of days before removing suspended channels */
58 #define SUSPEND_EXPIRY_TIME 40
59
60 /* Internal defines. */
61
62 /* Size of the buffer that we read into from our serverfd. */
63 #define CHUNKSIZE 65536
64 /* Maxchannels that we allow a user to have flags on. */
65 #define CHANNELSPERUSER 20
66 /* Maxusers that we allow to have flags on a channel. */
67 #define USERSPERCHANNEL 30
68 /* We need a hashfunction that returns a value x, 0 <= x < HASHMAX. */
69 #define HASHMAX 65000
70 /* Define TOPICSAVE to enable lightweight to save topics. */
71 #undef TOPICSAVE
72
73 /* Defines for saving data. */
74 /* Files will be named accounts.0, accounts.1, ... accounts.x, with number 0 being the newest. */
75 #define ACCOUNTFILE "accounts"
76 #define NUMBEROFSAVEFILES 9
77 /* Files will be named log.0, log.1, ... log.x, with number 0 being the newest. */
78 /* Logs will be rotated once a day, at midnight. */
79 #define LOGFILE "log"
80 #define DEBUGFILE "debug"
81 #define NUMBEROFLOGFILES 7
82
83 /* Defines from ircd. */
84 /* Things fuck up if these arent exactly as the ircd-settings. */
85 #define NICKLEN 15
86 #define SERVERNAMELENGTH 100
87 #define TOPICLEN 250
88
89 /* Structs. */
90
91 /* the struct required to hold multiple auths for a single account */
92 struct usersauthed {
93 struct user *autheduser; /* pointer to user authed with this account */
94 struct usersauthed *nextinlist; /* next in linked list */
95 };
96
97 struct account {
98 char authname[NICKLEN + 1]; /* Auth name: matches the broadcast ACCOUNT name */
99 struct usersauthed *currentuser; /* User that is currently authed with
100 this account. */
101 struct reggedchannel *channel[CHANNELSPERUSER]; /* Pointers to channels
102 * where this account is
103 * known.
104 */
105 char channelflags[CHANNELSPERUSER]; /* Flags corresponding to the channels
106 * above. */
107 time_t lastauth; /* last time the user authed */
108 unsigned char authlevel; /* Authlevel, more commands will be available for people
109 * with higher authlevels. */
110 struct account *nextbyauthname; /* Next in linked list of hashed authnames. */
111 };
112
113 /* Struct to hold a registered channel in lightweight. */
114 /* Please note that this has nothing to do with the channels actually on the
115 * network, this is only the registered channels. */
116 struct reggedchannel {
117 char channelname[30];
118 struct account *channeluser[USERSPERCHANNEL]; /* Pointers back to the users
119 * that have flags on this
120 * channel. Needed when doing
121 * a chanlev for the channel.
122 */
123 struct reggedchannel *nextbychannelname; /* Next in linked list of hashed
124 * channelnames.
125 */
126 struct account *founder; /* the user who founded the channel (first
127 +n) */
128 char addedby[NICKLEN + 1]; /* the user who added the channel */
129 time_t lastused; /* Timestamp for determining unused channels. */
130 time_t timestamp; /* Current timestamp for channel */
131 time_t dateadded; /* Timestamp for when the channel was added */
132 struct account *suspendby; /* User who suspended the channel */
133 char *suspendreason; /* Suspend reason */
134 char *welcome; /* welcome message */
135 char flags; /* Channel flags */
136 #ifdef TOPICSAVE
137 char topic[250]; /* For saving topic in a channel. */
138 #endif
139 };
140
141 /* User struct, holds a user currently online on the network. */
142 struct user {
143 char nick[NICKLEN + 1];
144 char numeric[5 + 1];
145 struct account *authedas; /* If the user is authed, this is a pointer
146 * to the corresponding account.
147 */
148 char oper; /* 0 if non oper, non-zero if oper ('o'). */
149 struct user *nextbynick; /* Next in linked list of hashed nicks. */
150 };
151
152 /* Serverstruct, holds information about a server in the servertree. */
153 struct server {
154 char servername[SERVERNAMELENGTH];
155 int parent;
156 /* This is a 'pointer' to the parent of this server, eg. the
157 * server that is one hop closer to us on the path from us
158 * to the server in the servertree.
159 * 'Pointer' in the meaning that this is the entry in the
160 * servertree array which holds the pointer to the parent
161 * struct.
162 */
163 int maxusers; /* Maxusers of this server. */
164 /* This is really a duplicate, there is a global var for this too,
165 * where should it be?
166 */
167 };
168
169 /* Error types */
170
171 #define ERR_DEBUG 0x0100
172 #define ERR_INFO 0x0200
173 #define ERR_WARNING 0x0400
174 #define ERR_ERROR 0x0800
175 #define ERR_FATAL 0x1000
176
177 #define ERR_TYPEMASK 0x00ff
178 #define ERR_PROTOCOL 0x0001
179 #define ERR_INTERNAL 0x0002
180 #define ERR_STATS 0x0003
181 #define ERR_LOADSAVE 0x0004
182
183 /* Forward declarations. */
184 int RestoreDBFromDisk();
185 int ConnectToServer();
186 int SendInitToServer();
187 int ReadChunk();
188 int GetLineFromChunk();
189 int ParseLine();
190 int SaveDBToDisk();
191 char *StripBlanks(char *paddedstring);
192 char *SeperateWord(char *sentence);
193
194 /* a_string.c */
195 char *a_strstrip(char *str);
196 char *a_strcpy(char *dst, const char *src, int dst_len);
197 char *a_strextract(char *dst, const char *src, int dst_len);
198 int a_strmatch(const char *str, const char *reg, int case_sensitive);
199
200 /* allocate.c */
201 struct server *GetServer();
202 void FreeServer(struct server *);
203 struct user *GetUser();
204 void FreeUser(struct user *);
205
206 /* general.c */
207 int IsCharInString(char chr, char *string);
208 long NumericToLong(const char *numeric, int numericlen);
209 char *StripBlanks(char *paddedstring);
210 char *SeperateWord(char *sentence);
211 int CheckAuthLevel(struct user *user_ptr, unsigned char level);
212 void MessageToUser(struct user *user, char *message, ...);
213 void NoticeToUser(struct user *user, char *message, ...);
214
215 /* nick.c */
216 void UserNickCreation(char *numeric, char *nick, char isoper);
217 void UserNickChange(char *numeric, char *newnick);
218 void DeleteUser(char *numeric);
219 void UserHashStats(void);
220
221 /* connecttoserver.c */
222 void SendLine(char *text);
223
224 /* join.c */
225 void DoJoins(char *numeric, char *channellist, time_t timestamp);
226
227 /* mode.c */
228 void DoChanMode(char *sender, char *channel, char *modes);
229
230 /* server.c */
231 void AddServer(int servernum, const char *servername, int maxusers, int parent);
232 void HandleSquit(char *servername);
233 void DoSquitRecursive(int servernum);
234
235 /* privmsg.c */
236 void ProcessMessage(char *numeric, char *text);
237
238 /* error.c */
239 void Error(int ErrorType, char *reason, ...);
240
241 /* hash.c */
242 int hash(char *buffer);
243
244 /* userdb.c */
245 void RemoveAuthFromUser(struct user *); /* removes the auth from account */
246
247 /* log.c */
248 void FlushLogs(void);
249 int RotateLogs(void);
250 void Log(char *logtext, ...);
251 void DebugLog(char *logtext, ...);
252
253 /* readconfig.c */
254 int LoadCfg(char *configfile);
255
256 /* clientcommands/<command>.c */
257
258 void doaddchan(struct user *user, char *tail);
259 void dodelchan(struct user *user, char *tail);
260 void dochangelev(struct user *user, char *tail);
261 void dosave(struct user *user, char *tail);
262 void dohelp(struct user *user, char *tail);
263 void doshowcommands(struct user *, char *tail);
264 void dowhois(struct user *user, char *tail);
265 void dowhois(struct user *user, char *tail);
266 void dowhoami(struct user *user, char *tail);
267 void dounbanall(struct user *user, char *tail);
268 void doclearchan(struct user *user, char *tail);
269 void doop(struct user *user, char *tail);
270 void dovoice(struct user *user, char *tail);
271 void dodeopall(struct user *user, char *tail);
272 void dochanlev(struct user *user, char *tail);
273 void doinvite(struct user *, char *);
274 void doadduser(struct user *, char *);
275 void doremoveuser(struct user *, char *);
276 void dorecover(struct user *, char *);
277 void doversion(struct user *, char *);
278 void dodeluser(struct user *, char *);
279 void dosuspend(struct user *, char *);
280 void dounsuspend(struct user *, char *);
281 void dochanstat(struct user *, char *);
282 void dostatus(struct user *, char *);
283 void dosuspendlist(struct user *, char *);
284 void dochannellist(struct user *, char *);
285 void doaccountlist(struct user *, char *);
286 void dolistlevel(struct user *, char *);
287 void douserlist(struct user *, char *);
288 void doneigh(struct user *, char *);
289 void docow(struct user *, char *);
290 void donoticeme(struct user *, char *);
291 void dofish(struct user *, char *);
292 void doreauth(struct user *, char *);
293 void doraw(struct user *, char *);
294 void docleanupdb(struct user *, char *);
295 void docleanupdb2(struct user *, char *);
296 void dodie(struct user *, char *);
297 void dowelcome(struct user *, char *);
298 void dogrep(struct user *, char *);
299 void dofind(struct user *, char *);
300 void dosetinvite(struct user *, char *);
301 void doclearinvite(struct user *, char *);
302 void doaccountstats(struct user *);
303 void dopart(struct user *, char *);
304 void dosendchanlev(struct user *, char *);
305 void dorequestowner(struct user *, char *);
306 void dosetenable(struct user *, char *);
307 #ifdef __cplusplus
308 }
309 #endif
310 #endif /* __LIGHTWEIGHT_H */