]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include <ctype.h> | |
3 | #include <string.h> | |
4 | #include <time.h> | |
5 | #include <unistd.h> | |
6 | ||
7 | #include "hconf.h" | |
8 | #include "helpmod.h" | |
9 | #include "hterm.h" | |
10 | ||
11 | static int hconf_version; | |
12 | ||
13 | static void helpmod_line_fix(char **ptr) | |
14 | { | |
15 | while (isspace(**ptr)) | |
16 | (*ptr)++; | |
17 | ||
18 | if (strchr(*ptr, '\n') != NULL) | |
19 | *strchr(*ptr, '\n') = '\0'; | |
20 | ||
21 | if (strchr(*ptr, '\r') != NULL) | |
22 | *strchr(*ptr, '\r') = '\0'; | |
23 | } | |
24 | ||
25 | ||
26 | int helpmod_config_read(const char *fname) | |
27 | { | |
28 | FILE *in; | |
29 | char buf[512], *ptr; | |
30 | ||
31 | /* Assume G 2.0 configuration */ | |
32 | hconf_version = HELPMOD_VERSION_2_0; | |
33 | ||
34 | if ((in = fopen(fname,"rt")) == NULL) | |
35 | return -1; | |
36 | ||
37 | while (!feof(in)) | |
38 | { | |
39 | ptr = (char*)buf; | |
40 | ||
41 | fgets(buf, 512, in); | |
42 | if (feof(in)) | |
43 | break; | |
44 | ||
45 | helpmod_line_fix(&ptr); | |
46 | ||
47 | /* support comments */ | |
48 | if (*ptr == '%') | |
49 | continue; | |
50 | if (!*ptr) | |
51 | continue; | |
52 | ||
53 | /* check what kind of a line it was */ | |
54 | if (!strcmp(ptr, "version")) | |
55 | { /* If no version is present, then the assumed G 2.0 version is used */ | |
56 | if (helpmod_config_read_version(in)) | |
57 | Error("helpmod", ERR_WARNING, "Reading of database entry 'version' failed"); | |
58 | ||
59 | if (hconf_version > HELPMOD_VERSION_INTERNAL) | |
60 | Error("helpmod", ERR_WARNING, "Database version is higher than the current version"); | |
61 | } | |
62 | else if (!strcmp(ptr, "channel")) | |
63 | { | |
64 | if (helpmod_config_read_channel(in)) | |
65 | Error("helpmod", ERR_WARNING, "Reading of database entry 'channel' failed"); | |
66 | } | |
67 | else if (!strcmp(ptr, "account")) | |
68 | { | |
69 | if (helpmod_config_read_account(in)) | |
70 | Error("helpmod", ERR_WARNING, "Reading of database entry 'account' failed"); | |
71 | } | |
72 | else if (!strcmp(ptr, "ban")) | |
73 | { | |
74 | if (helpmod_config_read_ban(in)) | |
75 | Error("helpmod", ERR_WARNING, "Reading of database entry 'ban' failed"); | |
76 | } | |
77 | else if (!strcmp(ptr, "lamercontrol profile")) | |
78 | { | |
79 | if (helpmod_config_read_hlc_profile(in)) | |
80 | Error("helpmod", ERR_WARNING, "Reading of database entry 'lamercontrol_profile' failed"); | |
81 | } | |
82 | else if (!strcmp(ptr, "term")) | |
83 | { | |
84 | if (helpmod_config_read_term(in, NULL)) | |
85 | Error("helpmod", ERR_WARNING, "Reading of database entry 'term' failed"); | |
86 | } | |
87 | else if (!strcmp(ptr, "globals")) | |
88 | { | |
89 | if (helpmod_config_read_globals(in)) | |
90 | Error("helpmod", ERR_WARNING, "Reading of database entry 'globals' failed"); | |
91 | } | |
92 | else if (!strcmp(ptr, "report")) | |
93 | { | |
94 | if (helpmod_config_read_report(in)) | |
95 | Error("helpmod", ERR_WARNING, "Reading of database entry 'report' failed"); | |
96 | } | |
97 | else if (!strcmp(ptr, "ticket")) | |
98 | { | |
99 | if (helpmod_config_read_ticket(in)) | |
100 | Error("helpmod", ERR_WARNING, "Reading of database entry 'ticket' failed"); | |
101 | } | |
102 | else | |
103 | Error("helpmod", ERR_WARNING, "Unknown database entry '%s'", ptr); | |
104 | } | |
105 | ||
106 | hchannels_match_accounts(); | |
107 | ||
108 | fclose(in); | |
109 | return 0; | |
110 | } | |
111 | ||
112 | int helpmod_config_write(const char *fname) | |
113 | { | |
114 | FILE *out; | |
115 | time_t timer = time(NULL); | |
116 | ||
117 | if ((out = fopen(fname,"wt")) == NULL) | |
118 | return -1; | |
119 | ||
120 | fprintf(out, "%% G2 version %s database\n", HELPMOD_VERSION); | |
121 | fprintf(out, "%% %s\n\n", asctime(localtime(&timer))); | |
122 | ||
123 | ||
124 | { /* version */ | |
125 | fprintf(out, "%% G internal version\n"); | |
126 | fprintf(out, "version\n"); | |
127 | helpmod_config_write_version(out); | |
128 | } | |
129 | ||
130 | { /* globals */ | |
131 | ||
132 | fprintf(out,"\n%% global variables\n"); | |
133 | fprintf(out,"%% hstat_cycle\n"); | |
134 | fprintf(out,"globals\n"); | |
135 | helpmod_config_write_globals(out); | |
136 | } | |
137 | ||
138 | { /* lamercontrol profiles */ | |
139 | hlc_profile *ptr = hlc_profiles; | |
140 | ||
141 | fprintf(out,"%% lamercontrol profile structure:\n"); | |
142 | fprintf(out,"%% X (string):\n"); | |
143 | fprintf(out,"%% Y (string):\n"); | |
144 | fprintf(out,"%% Z (int):\n"); | |
145 | ||
146 | for(;ptr;ptr=ptr->next) | |
147 | { | |
148 | fprintf(out, "lamercontrol profile\n"); | |
149 | helpmod_config_write_hlc_profile(out, ptr); | |
150 | } | |
151 | } | |
152 | ||
153 | { /* channels */ | |
154 | hchannel *ptr = hchannels; | |
155 | ||
156 | fprintf(out,"\n%% channel structure:\n"); | |
157 | fprintf(out,"%% name (string):\n"); | |
158 | fprintf(out,"%% flags (integer):\n"); | |
159 | fprintf(out,"%% welcome message (string):\n"); | |
160 | fprintf(out,"%% lamercontrol profile (string):\n"); | |
161 | ||
162 | for(;ptr;ptr=ptr->next) | |
163 | { | |
164 | fprintf(out, "channel\n"); | |
165 | helpmod_config_write_channel(out, ptr); | |
166 | } | |
167 | } | |
168 | ||
169 | fprintf(out,"\n"); | |
170 | ||
171 | { /* accounts */ | |
172 | haccount *ptr = haccounts; | |
173 | ||
174 | fprintf(out,"\n%% account structure:\n"); | |
175 | fprintf(out,"%% name (string):\n"); | |
176 | fprintf(out,"%% level (integer) flags (integer) last_activity (integer):\n"); | |
177 | ||
178 | for(;ptr;ptr=ptr->next) | |
179 | { | |
180 | fprintf(out, "account\n"); | |
181 | helpmod_config_write_account(out, ptr); | |
182 | } | |
183 | } | |
184 | ||
185 | fprintf(out,"\n"); | |
186 | ||
187 | { /* bans */ | |
188 | hban *ptr = hbans; | |
189 | ||
190 | fprintf(out,"\n%% ban structure:\n"); | |
191 | fprintf(out,"%% banmask (string):\n"); | |
192 | fprintf(out,"%% reason (string):\n"); | |
193 | fprintf(out,"%% expiration (int):\n"); | |
194 | ||
195 | for(;ptr;ptr=ptr->next) | |
196 | { | |
197 | fprintf(out, "ban\n"); | |
198 | helpmod_config_write_ban(out, ptr); | |
199 | } | |
200 | } | |
201 | ||
202 | { /* global terms */ | |
203 | hterm *ptr = hterms; | |
204 | ||
205 | fprintf(out,"\n%% term structure:\n"); | |
206 | fprintf(out,"%% name (string):\n"); | |
207 | fprintf(out,"%% description (string):\n"); | |
208 | ||
209 | for(;ptr;ptr=ptr->next) | |
210 | { | |
211 | fprintf(out, "term\n"); | |
212 | helpmod_config_write_term(out, ptr); | |
213 | } | |
214 | } | |
215 | ||
216 | { /* tickets */ | |
217 | hchannel *hchan; | |
218 | hticket *htick; | |
219 | ||
220 | fprintf(out, "\n%% ticket structure:\n"); | |
221 | fprintf(out, "%% channel (string)\n"); | |
222 | fprintf(out, "%% authname (string)\n"); | |
223 | fprintf(out, "%% expiration time (int)\n"); | |
224 | ||
225 | for (hchan = hchannels;hchan;hchan = hchan->next) | |
226 | for (htick = hchan->htickets;htick;htick = htick->next) | |
227 | { | |
228 | fprintf(out, "ticket\n"); | |
229 | helpmod_config_write_ticket(out, htick, hchan); | |
230 | } | |
231 | } | |
232 | ||
233 | { /* reports */ | |
234 | hchannel *hchan; | |
235 | ||
236 | fprintf(out, "\n%% report structure:\n"); | |
237 | fprintf(out, "%% channel reported\n"); | |
238 | fprintf(out, "%% channel reported to\n"); | |
239 | ||
240 | for (hchan = hchannels;hchan;hchan = hchan->next) | |
241 | { | |
242 | if ((hchan->flags & H_REPORT) && hchannel_is_valid(hchan->report_to)) | |
243 | { | |
244 | fprintf(out, "report\n"); | |
245 | helpmod_config_write_report(out, hchan); | |
246 | } | |
247 | } | |
248 | } | |
249 | ||
250 | fclose(out); | |
251 | ||
252 | return 0; | |
253 | } | |
254 | ||
255 | int helpmod_config_read_channel(FILE *in) | |
256 | { | |
257 | hchannel *hchan; | |
258 | ||
259 | char buf[256],*ptr=(char*)buf; | |
260 | int flags, entries, idlekick, i; | |
261 | /* name */ | |
262 | fgets(buf, 256, in); | |
263 | if (feof(in)) | |
264 | return -1; | |
265 | helpmod_line_fix(&ptr); | |
266 | ||
267 | hchan = hchannel_add(ptr); | |
268 | /* flags */ | |
269 | fgets((ptr = buf), 256, in); | |
270 | if (feof(in)) | |
271 | return -1; | |
272 | helpmod_line_fix(&ptr); | |
273 | ||
274 | if (sscanf(ptr, "%x", (unsigned int*)&flags) != 1) | |
275 | return -1; | |
276 | ||
277 | hchan->flags = flags; | |
278 | /* welcome message */ | |
279 | fgets((ptr = buf), 256, in); | |
280 | if (feof(in)) | |
281 | return -1; | |
282 | helpmod_line_fix(&ptr); | |
283 | ||
284 | strcpy(hchan->welcome, ptr); | |
285 | ||
286 | /* lamercontrol profile */ | |
287 | fgets((ptr = buf), 256, in); | |
288 | if (feof(in)) | |
289 | return -1; | |
290 | helpmod_line_fix(&ptr); | |
291 | ||
292 | hchan->lc_profile = hlc_get(ptr); | |
293 | ||
294 | if (hconf_version >= HELPMOD_VERSION_2_11) | |
295 | { | |
296 | fgets((ptr = buf), 256, in); | |
297 | if (feof(in)) | |
298 | return -1; | |
299 | helpmod_line_fix(&ptr); | |
300 | ||
301 | if (sscanf(ptr, "%d", &idlekick) != 1) | |
302 | return -1; | |
303 | ||
304 | hchan->max_idle = idlekick; | |
305 | ||
306 | fgets((ptr = buf), 256, in); | |
307 | if (feof(in)) | |
308 | return -1; | |
309 | helpmod_line_fix(&ptr); | |
310 | ||
311 | hchan->ticket_message = getsstring(ptr,strlen(ptr)); | |
312 | } | |
313 | ||
314 | /* censor entries for channel, a bit complex */ | |
315 | fgets((ptr = buf), 256, in); | |
316 | if (feof(in)) | |
317 | return -1; | |
318 | ||
319 | helpmod_line_fix(&ptr); | |
320 | ||
321 | if (sscanf(ptr, "%d", &entries) != 1) | |
322 | return -1; | |
323 | for (i = 0;i<entries;i++) | |
324 | { | |
325 | char buf2[512], *ptr2; | |
326 | int type; | |
327 | ||
328 | fgets((ptr = buf), 256, in); | |
329 | if (feof(in)) | |
330 | return -1; | |
331 | helpmod_line_fix(&ptr); | |
332 | ||
333 | if (hconf_version >= HELPMOD_VERSION_2_10) | |
334 | { | |
335 | if (!sscanf(ptr, "%d", &type)) | |
336 | return -1; | |
337 | ||
338 | fgets((ptr = buf), 256, in); | |
339 | if (feof(in)) | |
340 | return -1; | |
341 | helpmod_line_fix(&ptr); | |
342 | } | |
343 | else | |
344 | type = HCENSOR_KICK; | |
345 | ||
346 | fgets((ptr2 = buf2), 256, in); | |
347 | if (feof(in)) | |
348 | return -1; | |
349 | helpmod_line_fix(&ptr2); | |
350 | ||
351 | if (ptr2[0] == '\0') | |
352 | ptr2 = NULL; | |
353 | ||
354 | hcensor_add(&hchan->censor, ptr, ptr2, type); | |
355 | } | |
356 | /* channel specific hterms */ | |
357 | fgets((ptr = buf), 256, in); | |
358 | if (feof(in)) | |
359 | return -1; | |
360 | ||
361 | helpmod_line_fix(&ptr); | |
362 | ||
363 | if (sscanf(ptr, "%d", &entries) != 1) | |
364 | return -1; | |
365 | for (i=0;i<entries;i++) | |
366 | helpmod_config_read_term(in, &hchan->channel_hterms); | |
367 | ||
368 | helpmod_config_read_chanstats(in, hchan->stats); | |
369 | ||
370 | /* needs to be done here */ | |
371 | hchannel_mode_check(hchan); | |
372 | ||
373 | return 0; | |
374 | } | |
375 | ||
376 | int helpmod_config_write_channel(FILE *out, hchannel *target) | |
377 | { | |
378 | fprintf(out, "\t%s\n", hchannel_get_name(target)); | |
379 | fprintf(out, "\t%x\n", target->flags & 0x0FFFFFF); | |
380 | fprintf(out, "\t%s\n", target->welcome); | |
381 | if (target->lc_profile == NULL) | |
382 | fprintf(out, "\t(null)\n"); | |
383 | else | |
384 | fprintf(out, "\t%s\n", target->lc_profile->name->content); | |
385 | ||
386 | fprintf(out, "\t%d\n", target->max_idle); | |
387 | ||
388 | if (target->ticket_message == NULL) | |
389 | fprintf(out, "\t(null)\n"); | |
390 | else | |
391 | fprintf(out, "\t%s\n", target->ticket_message->content); | |
392 | ||
393 | fprintf(out, "\t%d %% censor\n", hcensor_count(target->censor)); | |
394 | { | |
395 | hcensor *hcens = target->censor; | |
396 | for (;hcens;hcens = hcens->next) | |
397 | { | |
398 | fprintf(out, "\t\t%d\n", hcens->type); | |
399 | fprintf(out, "\t\t%s\n", hcens->pattern->content); | |
400 | fprintf(out, "\t\t%s\n", hcens->reason?hcens->reason->content:""); | |
401 | } | |
402 | } | |
403 | ||
404 | fprintf(out, "\t%d %% terms\n", hterm_count(target->channel_hterms)); | |
405 | { | |
406 | hterm *tmp = target->channel_hterms; | |
407 | for (;tmp;tmp = tmp->next) | |
408 | { | |
409 | helpmod_config_write_term(out, tmp); | |
410 | } | |
411 | } | |
412 | ||
413 | helpmod_config_write_chanstats(out, target->stats); | |
414 | ||
415 | return 0; | |
416 | } | |
417 | ||
418 | ||
419 | int helpmod_config_read_account(FILE *in) | |
420 | { | |
421 | haccount *hack; | |
422 | int nstats; | |
423 | ||
424 | char buf[256],*ptr=(char*)buf; | |
425 | int flags, level, last_activity = time(NULL); | |
426 | ||
427 | fgets(ptr = buf, 256, in); | |
428 | if (feof(in)) | |
429 | return -1; | |
430 | helpmod_line_fix(&ptr); | |
431 | ||
432 | hack = haccount_add(ptr, H_PEON); | |
433 | ||
434 | fgets(ptr = buf, 256, in); | |
435 | if (feof(in)) | |
436 | return -1; | |
437 | helpmod_line_fix(&ptr); | |
438 | if (hconf_version < HELPMOD_VERSION_2_11) | |
439 | { | |
440 | if (sscanf(ptr, "%x %x", (unsigned int*)&level, (unsigned int*)&flags) != 2) | |
441 | return -1; | |
442 | } | |
443 | else | |
444 | if (sscanf(ptr, "%x %x %x", (unsigned int*)&level, (unsigned int*)&flags, (unsigned int *)&last_activity) != 3) | |
445 | return -1; | |
446 | ||
447 | if (hconf_version < HELPMOD_VERSION_2_16) | |
448 | { /* For the new friend userlevel */ | |
449 | if (level >= H_FRIEND) | |
450 | level++; | |
451 | } | |
452 | ||
453 | hack->level = level; | |
454 | hack->flags = flags; | |
455 | hack->last_activity = last_activity; | |
456 | ||
457 | fgets(ptr = buf, 256, in); | |
458 | if (feof(in)) | |
459 | return -1; | |
460 | helpmod_line_fix(&ptr); | |
461 | ||
462 | if (sscanf(ptr, "%d", &nstats) != 1) | |
463 | return -1; | |
464 | ||
465 | while (nstats) | |
466 | { | |
467 | hstat_account *tmp = hack->stats; | |
468 | hack->stats = (hstat_account*)malloc(sizeof(hstat_account)); | |
469 | hack->stats->next = tmp; | |
470 | if (helpmod_config_read_stats(in, hack->stats) == -1) | |
471 | return -1; | |
472 | nstats--; | |
473 | } | |
474 | ||
475 | return 0; | |
476 | } | |
477 | ||
478 | int helpmod_config_write_account(FILE *out, haccount *target) | |
479 | { | |
480 | hstat_account *tmp; | |
481 | fprintf(out, "\t%s\n", target->name->content); | |
482 | fprintf(out, "\t%x\t%x\t%x\n", target->level, target->flags, (unsigned int)target->last_activity); | |
483 | ||
484 | fprintf(out, "\t%d %% statistics for this channel\n", hstat_account_count(target->stats)); | |
485 | for (tmp = target->stats;tmp;tmp = tmp->next) | |
486 | helpmod_config_write_stats(out, tmp); | |
487 | ||
488 | return 0; | |
489 | } | |
490 | ||
491 | int helpmod_config_read_ban(FILE *in) | |
492 | { | |
493 | char buf1[512], buf2[512], buf3[512], *ptr1, *ptr2, *ptr3; | |
494 | int tmp; | |
495 | ||
496 | fgets(ptr1 = buf1, 256, in); | |
497 | if (feof(in)) | |
498 | return -1; | |
499 | helpmod_line_fix(&ptr1); | |
500 | ||
501 | fgets(ptr2 = buf2, 256, in); | |
502 | if (feof(in)) | |
503 | return -1; | |
504 | helpmod_line_fix(&ptr2); | |
505 | ||
506 | fgets(ptr3 = buf3, 256, in); | |
507 | if (feof(in)) | |
508 | return -1; | |
509 | helpmod_line_fix(&ptr3); | |
510 | ||
511 | if (sscanf(ptr3, "%d", &tmp) != 1) | |
512 | return -1; | |
513 | ||
514 | hban_add(ptr1, ptr2, tmp, 0); | |
515 | ||
516 | return 0; | |
517 | } | |
518 | ||
519 | int helpmod_config_write_ban(FILE *out, hban *hb) | |
520 | { | |
521 | fprintf(out, "\t%s\n", bantostring(hb->real_ban)); | |
522 | fprintf(out, "\t%s\n", hb->reason?hb->reason->content:NULL); | |
523 | fprintf(out, "\t%u\n", (unsigned int)hb->expiration); | |
524 | return 0; | |
525 | } | |
526 | ||
527 | int helpmod_config_read_hlc_profile(FILE *in) | |
528 | { | |
529 | hlc_profile *hlc_prof; | |
530 | int tmp[3]; | |
531 | float tmp_float; | |
532 | char buf[256],*ptr=(char*)buf; | |
533 | ||
534 | /* name */ | |
535 | fgets(ptr = buf, 256, in); | |
536 | if (feof(in)) | |
537 | return -1; | |
538 | helpmod_line_fix(&ptr); | |
539 | ||
540 | if ((hlc_prof = hlc_add(ptr)) == NULL) | |
541 | return -1; | |
542 | ||
543 | /* caps */ | |
544 | fgets(ptr = buf, 256, in); | |
545 | if (feof(in)) | |
546 | return -1; | |
547 | helpmod_line_fix(&ptr); | |
548 | ||
549 | if (sscanf(ptr, "%d %d", &tmp[0], &tmp[1]) != 2) | |
550 | return -1; | |
551 | ||
552 | hlc_prof->caps_max_percentage = tmp[0]; | |
553 | hlc_prof->caps_min_count = tmp[1]; | |
554 | ||
555 | /* repeating */ | |
556 | fgets(ptr = buf, 256, in); | |
557 | if (feof(in)) | |
558 | return -1; | |
559 | helpmod_line_fix(&ptr); | |
560 | ||
561 | if (sscanf(ptr, "%d %d", &tmp[0], &tmp[1]) != 2) | |
562 | return -1; | |
563 | ||
564 | hlc_prof->repeats_max_count = tmp[0]; | |
565 | hlc_prof->repeats_min_length = tmp[1]; | |
566 | ||
567 | /* character / symbol repeat */ | |
568 | fgets(ptr = buf, 256, in); | |
569 | if (feof(in)) | |
570 | return -1; | |
571 | helpmod_line_fix(&ptr); | |
572 | ||
573 | if (sscanf(ptr, "%d %d %d", &tmp[0], &tmp[1], &tmp[2]) != 3) | |
574 | return -1; | |
575 | ||
576 | hlc_prof->symbol_repeat_max_count = tmp[0]; | |
577 | hlc_prof->character_repeat_max_count = tmp[1]; | |
578 | hlc_prof->symbol_max_count = tmp[1]; | |
579 | ||
580 | /* flood, spam const, spam */ | |
581 | fgets(ptr = buf, 256, in); | |
582 | if (feof(in)) | |
583 | return -1; | |
584 | helpmod_line_fix(&ptr); | |
585 | ||
586 | if (sscanf(ptr, "%d %f %d", &tmp[0], &tmp_float, &tmp[1]) != 3) | |
587 | return -1; | |
588 | ||
589 | hlc_prof->tolerance_flood = tmp[0]; | |
590 | hlc_prof->constant_spam = tmp_float; | |
591 | hlc_prof->tolerance_spam = tmp[1]; | |
592 | ||
593 | /* tolerances */ | |
594 | fgets(ptr = buf, 256, in); | |
595 | if (feof(in)) | |
596 | return -1; | |
597 | helpmod_line_fix(&ptr); | |
598 | ||
599 | if (sscanf(ptr, "%d %d %d", &tmp[0], &tmp[1], &tmp[2]) != 3) | |
600 | return -1; | |
601 | ||
602 | hlc_prof->tolerance_warn = tmp[0]; | |
603 | hlc_prof->tolerance_kick = tmp[1]; | |
604 | hlc_prof->tolerance_remove = tmp[2]; | |
605 | ||
606 | return 0; | |
607 | } | |
608 | ||
609 | /* we use extended buffers here */ | |
610 | int helpmod_config_read_term(FILE *in, hterm** target) | |
611 | { | |
612 | char buf1[2048], buf2[2048], *ptr1 = buf1, *ptr2 = buf2; | |
613 | ||
614 | /* name */ | |
615 | fgets(buf1, 2048, in); | |
616 | if (feof(in)) | |
617 | return -1; | |
618 | helpmod_line_fix(&ptr1); | |
619 | ||
620 | /* description */ | |
621 | fgets(buf2, 2048, in); | |
622 | if (feof(in)) | |
623 | return -1; | |
624 | helpmod_line_fix(&ptr2); | |
625 | ||
626 | /* add to public domain */ | |
627 | hterm_add(target, ptr1, ptr2); | |
628 | ||
629 | return 0; | |
630 | } | |
631 | ||
632 | int helpmod_config_write_term(FILE *out, hterm *htrm) | |
633 | { | |
634 | fprintf(out, "\t%s\n", htrm->name->content); | |
635 | fprintf(out, "\t%s\n", htrm->description->content); | |
636 | return 0; | |
637 | } | |
638 | ||
639 | int helpmod_config_write_hlc_profile(FILE *out, hlc_profile *hlc_prof) | |
640 | { | |
641 | fprintf(out, "\t%s\n", hlc_prof->name->content); | |
642 | fprintf(out, "\t%d %d\n", hlc_prof->caps_max_percentage, hlc_prof->caps_min_count); | |
643 | fprintf(out, "\t%d %d\n", hlc_prof->repeats_max_count, hlc_prof->repeats_min_length); | |
644 | fprintf(out, "\t%d %d %d\n", hlc_prof->symbol_repeat_max_count, hlc_prof->character_repeat_max_count, hlc_prof->symbol_max_count); | |
645 | fprintf(out, "\t%d %.3f %d\n", hlc_prof->tolerance_flood, hlc_prof->constant_spam, hlc_prof->tolerance_spam); | |
646 | fprintf(out, "\t%d %d %d\n", hlc_prof->tolerance_warn, hlc_prof->tolerance_kick, hlc_prof->tolerance_remove); | |
647 | return 0; | |
648 | } | |
649 | ||
650 | int helpmod_config_read_chanstats(FILE *in, hstat_channel *hs_chan) | |
651 | { | |
652 | char buf[256],*ptr=(char*)buf; | |
653 | int i; | |
654 | hstat_channel_entry *entry; | |
655 | ||
656 | for (i=0;i<17;i++) | |
657 | { | |
658 | fgets(ptr = buf, 256, in); | |
659 | if (feof(in)) | |
660 | return -1; | |
661 | helpmod_line_fix(&ptr); | |
662 | ||
663 | if (i < 7) /* days */ | |
664 | entry = &hs_chan->week[(hstat_day() + i) % 7]; | |
665 | else /* weeks */ | |
666 | entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10]; | |
667 | ||
668 | if (hconf_version < HELPMOD_VERSION_2_10) | |
669 | { | |
670 | if (sscanf(buf, "%d %d %d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 6) | |
671 | return -1; | |
672 | } | |
673 | else | |
674 | { | |
675 | if (sscanf(buf, "%d %d %d %d %d %d %d %d", &entry->active_time, &entry->staff_active_time, &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 8) | |
676 | return -1; | |
677 | } | |
678 | } | |
679 | return 0; | |
680 | } | |
681 | ||
682 | int helpmod_config_write_chanstats(FILE *out, hstat_channel *hs_chan) | |
683 | { | |
684 | int i; | |
685 | hstat_channel_entry *entry; | |
686 | ||
687 | for (i=0;i<17;i++) | |
688 | { | |
689 | if (i < 7) /* days */ | |
690 | entry = &hs_chan->week[(hstat_day() + i) % 7]; | |
691 | else /* weeks */ | |
692 | entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10]; | |
693 | ||
694 | fprintf(out, "\t%d %d %d %d %d %d %d %d\n", entry->active_time, entry->staff_active_time, entry->time_spent, entry->prime_time_spent, entry->joins, entry->queue_use, entry->lines, entry->words); | |
695 | } | |
696 | return 0; | |
697 | } | |
698 | ||
699 | int helpmod_config_read_stats(FILE *in, hstat_account *hs_acc) | |
700 | { | |
701 | char buf[256],*ptr=(char*)buf; | |
702 | int i; | |
703 | hstat_account_entry *entry; | |
704 | ||
705 | fgets(ptr = buf, 256, in); | |
706 | if (feof(in)) | |
707 | return -1; | |
708 | helpmod_line_fix(&ptr); | |
709 | ||
710 | hs_acc->hchan = hchannel_get_by_name(ptr); | |
711 | ||
712 | if (hs_acc->hchan == NULL) | |
713 | return -1; | |
714 | ||
715 | for (i=0;i<17;i++) | |
716 | { | |
717 | fgets(ptr = buf, 256, in); | |
718 | if (feof(in)) | |
719 | return -1; | |
720 | helpmod_line_fix(&ptr); | |
721 | ||
722 | if (i < 7) /* days */ | |
723 | entry = &hs_acc->week[(hstat_day() + i) % 7]; | |
724 | else /* weeks */ | |
725 | entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10]; | |
726 | ||
727 | if (sscanf(buf, "%d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->lines, &entry->words) != 4) | |
728 | return -1; | |
729 | } | |
730 | return 0; | |
731 | } | |
732 | ||
733 | int helpmod_config_write_stats(FILE *out, hstat_account *hs_acc) | |
734 | { | |
735 | int i; | |
736 | hstat_account_entry *entry; | |
737 | ||
738 | fprintf(out, "\t%s\n", hchannel_get_name(hs_acc->hchan)); | |
739 | ||
740 | for (i=0;i<17;i++) | |
741 | { | |
742 | if (i < 7) /* days */ | |
743 | entry = &hs_acc->week[(hstat_day() + i) % 7]; | |
744 | else /* weeks */ | |
745 | entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10]; | |
746 | ||
747 | fprintf(out, "\t%d %d %d %d\n", entry->time_spent, entry->prime_time_spent, entry->lines, entry->words); | |
748 | } | |
749 | return 0; | |
750 | } | |
751 | ||
752 | int helpmod_config_read_globals(FILE *in) | |
753 | { | |
754 | char buf[256],*ptr=(char*)buf; | |
755 | ||
756 | fgets(ptr = buf, 256, in); | |
757 | if (feof(in)) | |
758 | return -1; | |
759 | helpmod_line_fix(&ptr); | |
760 | ||
761 | if (sscanf(ptr, "%d", &hstat_cycle) != 1) | |
762 | return -1; | |
763 | ||
764 | return 0; | |
765 | } | |
766 | ||
767 | int helpmod_config_write_globals(FILE *out) | |
768 | { | |
769 | fprintf(out, "\t%d\n", hstat_cycle); | |
770 | return 0; | |
771 | } | |
772 | ||
773 | int helpmod_config_read_report(FILE *in) | |
774 | { | |
775 | char buf[256], *ptr=(char*)buf; | |
776 | hchannel *tmp1, *tmp2; | |
777 | ||
778 | fgets(ptr = buf, 256, in); | |
779 | if (feof(in)) | |
780 | return -1; | |
781 | helpmod_line_fix(&ptr); | |
782 | ||
783 | tmp1 = hchannel_get_by_name(ptr); | |
784 | ||
785 | fgets(ptr = buf, 256, in); | |
786 | if (feof(in)) | |
787 | return -1; | |
788 | helpmod_line_fix(&ptr); | |
789 | ||
790 | tmp2 = hchannel_get_by_name(ptr); | |
791 | ||
792 | if (hchannel_is_valid(tmp1) && hchannel_is_valid(tmp2)) | |
793 | tmp1->report_to = tmp2; | |
794 | ||
795 | return 0; | |
796 | } | |
797 | ||
798 | int helpmod_config_write_report(FILE *out, hchannel *hchan) | |
799 | { | |
800 | fprintf(out, "\t%s\n", hchannel_get_name(hchan)); | |
801 | fprintf(out, "\t%s\n", hchannel_get_name(hchan->report_to)); | |
802 | return 0; | |
803 | } | |
804 | ||
805 | int helpmod_config_read_ticket(FILE *in) | |
806 | { | |
807 | char buf[256], buf2[256], buf3[64], *ptr=(char*)buf; | |
808 | unsigned int tmp; | |
809 | ||
810 | fgets(ptr = buf, 256, in); | |
811 | if (feof(in)) | |
812 | return -1; | |
813 | helpmod_line_fix(&ptr); | |
814 | ||
815 | strcpy(buf2, ptr); | |
816 | ||
817 | fgets(ptr = buf, 64, in); | |
818 | if (feof(in)) | |
819 | return -1; | |
820 | helpmod_line_fix(&ptr); | |
821 | ||
822 | strcpy(buf3, ptr); | |
823 | ||
824 | fgets(ptr = buf, 256, in); | |
825 | if (feof(in)) | |
826 | return -1; | |
827 | helpmod_line_fix(&ptr); | |
828 | ||
829 | if (!sscanf(ptr, "%u", &tmp)) | |
830 | return -1; | |
831 | ||
832 | if (tmp > time(NULL)) | |
833 | { | |
834 | if (hconf_version < HELPMOD_VERSION_2_17) | |
835 | hticket_add(buf3, tmp, hchannel_get_by_name(buf2), NULL); | |
836 | else | |
837 | { | |
838 | fgets(ptr = buf, 256, in); | |
839 | if (feof(in)) | |
840 | return -1; | |
841 | helpmod_line_fix(&ptr); | |
842 | ||
843 | if (*ptr == '\0') | |
844 | hticket_add(buf3, tmp, hchannel_get_by_name(buf2), NULL); | |
845 | else | |
846 | hticket_add(buf3, tmp, hchannel_get_by_name(buf2), ptr); | |
847 | } | |
848 | } | |
849 | ||
850 | return 0; | |
851 | } | |
852 | ||
853 | int helpmod_config_write_ticket(FILE *out, hticket *htick, hchannel *hchan) | |
854 | { | |
855 | fprintf(out, "\t%s\n", hchannel_get_name(hchan)); | |
856 | fprintf(out, "\t%s\n", htick->authname); | |
857 | fprintf(out, "\t%u\n", (unsigned int)htick->time_expiration); | |
858 | if (htick->message) | |
859 | fprintf(out, "\t%s\n", htick->message->content); | |
860 | else | |
861 | fprintf(out, "\n"); | |
862 | ||
863 | return 0; | |
864 | } | |
865 | ||
866 | int helpmod_config_read_version(FILE *in) | |
867 | { | |
868 | char buf[256], *ptr=(char*)buf; | |
869 | ||
870 | fgets(ptr = buf, 256, in); | |
871 | if (feof(in)) | |
872 | return -1; | |
873 | helpmod_line_fix(&ptr); | |
874 | ||
875 | if (sscanf(ptr, "%d", &hconf_version) != 1) | |
876 | return -1; | |
877 | ||
878 | return 0; | |
879 | } | |
880 | ||
881 | int helpmod_config_write_version(FILE *out) | |
882 | { | |
883 | fprintf(out, "\t%d\n", HELPMOD_VERSION_INTERNAL); | |
884 | ||
885 | return 0; | |
886 | } | |
887 | ||
888 | void helpmod_config_scheduled_events(void) | |
889 | { | |
890 | rename(HELPMOD_DEFAULT_DB, HELPMOD_DEFAULT_DB".old"); | |
891 | helpmod_config_write(HELPMOD_DEFAULT_DB); | |
892 | } |