]>
Commit | Line | Data |
---|---|---|
1 | /* GNU Thales - IRC to Relational Database Gateway | |
2 | * Copyright (C) 2002 Lucas Nussbaum <lucas@lucas-nussbaum.net> | |
3 | * | |
4 | * This program 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 | * This program 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 this program; if not, write to the Free Software | |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 | */ | |
18 | ||
19 | #include "thales.h" | |
20 | #include "actions.h" | |
21 | #include "db.h" | |
22 | #include "send.h" | |
23 | #include "misc.h" | |
24 | #include "compat.h" | |
25 | #include "memory.h" | |
26 | #include "log.h" | |
27 | #include "sockutil.h" | |
28 | ||
29 | extern char *ServerName; | |
30 | extern char *RemoteServer; | |
31 | extern time_t start_time; | |
32 | extern char inbuf[]; | |
33 | extern int ServerCacheTime; | |
34 | extern int UserCacheTime; | |
35 | extern int HidePasswords; | |
36 | ||
37 | /*************************************************************************/ | |
38 | /* | |
39 | * Max values calculation | |
40 | */ | |
41 | ||
42 | unsigned int nbusers = 0; | |
43 | unsigned int nbusers_max = 0; | |
44 | unsigned int nbchans = 0; | |
45 | unsigned int nbchans_max = 0; | |
46 | /* keep track of logged umodes et cmodes, init to 0 by default */ | |
47 | int log_umode[256]; | |
48 | int log_cmode[256]; | |
49 | ||
50 | /* check if nbchans > nbchans_max */ | |
51 | void do_checknbchansmax() | |
52 | { | |
53 | if (nbchans > nbchans_max) | |
54 | { | |
55 | nbchans_max = nbchans; | |
56 | db_query | |
57 | ("UPDATE " TBL_MAXV | |
58 | " SET val=\'%d\', time=NOW() WHERE type='channels'", | |
59 | nbchans_max); | |
60 | } | |
61 | } | |
62 | ||
63 | /* check if nbusers > nbusers_max */ | |
64 | void do_checknbusersmax() | |
65 | { | |
66 | if (nbusers > nbusers_max) | |
67 | { | |
68 | nbusers_max = nbusers; | |
69 | db_query | |
70 | ("UPDATE " TBL_MAXV | |
71 | " SET val=\'%d\', time=NOW() WHERE type='users'", nbusers_max); | |
72 | } | |
73 | } | |
74 | ||
75 | /*************************************************************************/ | |
76 | /* | |
77 | * general purpose functions | |
78 | */ | |
79 | ||
80 | #if !(defined(IRCD_UNREAL)||defined(IRCD_HYBRID)||defined(IRCD_ULTI28)) | |
81 | /* converts an IP numeric to a char * */ | |
82 | static char *do_ipdecode(char *ipaddr) | |
83 | { | |
84 | static char buf[16]; /* enough for an IPv4 address. TODO IPv6 ? */ | |
85 | unsigned int ip = (unsigned int) strtoul(ipaddr, (char **) NULL, 10); | |
86 | snprintf(buf, 16, "%u.%u.%u.%u", (unsigned int) ip >> 24, | |
87 | (unsigned int) (ip & 0xff0000) >> 16, | |
88 | (unsigned int) (ip & 0xff00) >> 8, (unsigned int) ip & 0xff); | |
89 | return buf; | |
90 | } | |
91 | #endif | |
92 | ||
93 | /* adds modes to a given chanid */ | |
94 | static void do_chanmodes(int chanid, char **av, int ac) | |
95 | { | |
96 | /* the ircd parses the mode before forwarding it to thales, so there's no buffer overrun | |
97 | * possibility here. - lucas | |
98 | */ | |
99 | int atleastone = 0; | |
100 | char db[1000]; /* should be enough for long queries */ | |
101 | char tmp[14] = "mode_XX=\"X\", "; | |
102 | char *modes = av[0]; | |
103 | int argptr = 1; | |
104 | if (*modes == '0') | |
105 | return; | |
106 | strcpy(db, "UPDATE " TBL_CHAN " SET "); | |
107 | while (*modes) | |
108 | { | |
109 | switch (*modes) | |
110 | { | |
111 | case '+': | |
112 | tmp[9] = 'Y'; | |
113 | break; | |
114 | case '-': | |
115 | tmp[9] = 'N'; | |
116 | break; | |
117 | default: | |
118 | if (!strchr(CHANMODES, *modes)) | |
119 | { | |
120 | if (!log_cmode[(int) *modes]) | |
121 | { | |
122 | mylog("unknown mode : chanmode %c (in %s)", *modes, inbuf); | |
123 | log_cmode[(int) *modes] = TRUE; | |
124 | } | |
125 | } | |
126 | #ifdef IRCD_ULTI28 | |
127 | else if (*modes == 'b' || *modes == 'e' || *modes == 'f') /* ignore them */ | |
128 | argptr++; | |
129 | #else | |
130 | else if (*modes == 'b' || *modes == 'e' || *modes == 'I') /* ignore them */ | |
131 | argptr++; | |
132 | #endif | |
133 | #ifdef IRCD_IRCDRU | |
134 | else if (*modes == 'B' || *modes == 'X' || *modes == 'E') /* ignore them too */ | |
135 | argptr++; | |
136 | #endif | |
137 | ||
138 | #if defined(IRCD_SEQUANA)||defined(IRCD_BAHAMUT)||defined(IRCD_IRCDRU) | |
139 | else if (*modes == 'o' || *modes == 'v') | |
140 | #elif defined(IRCD_HYBRID)||defined(IRCD_ULTI28) | |
141 | else if (*modes == 'o' || *modes == 'v' || *modes == 'h') | |
142 | #elif defined(IRCD_ULTIMATE) | |
143 | else if (*modes == 'o' || *modes == 'v' | |
144 | || *modes == 'a' || *modes == 'h') | |
145 | #elif defined(IRCD_UNREAL) | |
146 | else if (*modes == 'o' || *modes == 'v' | |
147 | || *modes == 'a' || *modes == 'h' || *modes == 'q') | |
148 | #endif | |
149 | { | |
150 | char *user; | |
151 | user = db_escape(av[argptr++]); | |
152 | db_query | |
153 | ("UPDATE " TBL_ISON | |
154 | " SET mode_l%c=\"%c\" WHERE chanid=\"%d\" AND nickid=\"%d\"", | |
155 | *modes, tmp[9], chanid, db_getnick(user)); | |
156 | free(user); | |
157 | } | |
158 | else | |
159 | { | |
160 | atleastone = 1; | |
161 | tmp[5] = ((*modes >= 'a') ? 'l' : 'u'); | |
162 | tmp[6] = tolower(*modes); | |
163 | strcat(db, tmp); | |
164 | if (*modes == 'k') | |
165 | { | |
166 | if (tmp[9] == 'Y') | |
167 | { | |
168 | char *key = db_escape(av[argptr++]); | |
169 | if (HidePasswords) | |
170 | { | |
171 | strcat(db, "mode_lk_data=\"HIDDEN\", "); | |
172 | } | |
173 | else | |
174 | { | |
175 | strcat(db, "mode_lk_data=\""); | |
176 | strcat(db, key); | |
177 | strcat(db, "\", "); | |
178 | } | |
179 | free(key); | |
180 | } | |
181 | else | |
182 | { | |
183 | strcat(db, "mode_lk_data=\"\", "); | |
184 | argptr++; /* mode -k needs a parameter */ | |
185 | } | |
186 | } | |
187 | else if (*modes == 'l') | |
188 | { | |
189 | if (tmp[9] == 'Y') | |
190 | { | |
191 | strcat(db, "mode_ll_data=\""); | |
192 | strcat(db, av[argptr++]); | |
193 | strcat(db, "\", "); | |
194 | } | |
195 | else | |
196 | { | |
197 | strcat(db, "mode_ll_data=\"\", "); | |
198 | } | |
199 | } | |
200 | #if defined(IRCD_UNREAL)||defined(IRCD_ULTI28) | |
201 | else if (*modes == 'L') | |
202 | { | |
203 | if (tmp[9] == 'Y') | |
204 | { | |
205 | char *ch = db_escape(av[argptr++]); | |
206 | strcat(db, "mode_ul_data=\""); | |
207 | strcat(db, ch); | |
208 | strcat(db, "\", "); | |
209 | free(ch); | |
210 | } | |
211 | else | |
212 | { | |
213 | strcat(db, "mode_ul_data=\"\", "); | |
214 | } | |
215 | } | |
216 | #endif | |
217 | #ifdef IRCD_UNREAL | |
218 | else if (*modes == 'f') | |
219 | { | |
220 | if (tmp[9] == 'Y') | |
221 | { | |
222 | strcat(db, "mode_lf_data=\""); | |
223 | strcat(db, av[argptr++]); | |
224 | strcat(db, "\", "); | |
225 | } | |
226 | else | |
227 | { | |
228 | strcat(db, "mode_lf_data=\"\", "); | |
229 | } | |
230 | } | |
231 | #endif | |
232 | } | |
233 | break; | |
234 | } | |
235 | modes++; | |
236 | } | |
237 | #ifndef NOMODES | |
238 | if (atleastone) | |
239 | { | |
240 | sprintf(&db[strlen(db) - 2], " WHERE chanid=\'%d\'", chanid); | |
241 | db_query(db); | |
242 | } | |
243 | #endif /* !NOMODES */ | |
244 | } | |
245 | ||
246 | /* add one or more users to a chanid */ | |
247 | static void do_addusers(int chanid, char *users) | |
248 | { | |
249 | int op, voice, halfop, owner, protect; | |
250 | char *nextusers; | |
251 | int nickid; | |
252 | while (users && (*users)) | |
253 | { | |
254 | #if defined(IRCD_UNREAL) | |
255 | /* Unreal uses SJOIN to send bans and exempts. Just ignore them. */ | |
256 | if ((*users == '&') || (*users == '\"')) | |
257 | { | |
258 | nextusers = strchr(users, ' '); | |
259 | if (nextusers) | |
260 | *nextusers = '\0'; | |
261 | users = nextusers; | |
262 | if (users) | |
263 | users++; | |
264 | continue; | |
265 | } | |
266 | #endif | |
267 | op = 0; | |
268 | halfop = 0; | |
269 | voice = 0; | |
270 | owner = 0; | |
271 | protect = 0; | |
272 | #if defined(IRCD_ULTIMATE)||defined(IRCD_ULTI28) | |
273 | #if defined(IRCD_ULTIMATE) | |
274 |