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