]>
Commit | Line | Data |
---|---|---|
20d2ed0e | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: title | |
5 | * CMDLEVEL: QCMD_TITLES | QCMD_AUTHED | |
6 | * CMDARGS: 1 | |
7 | * CMDDESC: Lists available titles, or sets your title. | |
8 | * CMDFUNC: csh_dotitle | |
9 | * CMDPROTO: int csh_dotitle(void *source, int cargc, char **cargv); | |
10 | * CMDHELP: Usage: @UCOMMAND@ [<id>] | |
11 | * CMDHELP: Lists available titles, or selects a title. | |
12 | * CMDHELP: id - Title ID to select. If omitted, gives a list of | |
13 | * CMDHELP: available titles and IDs. | |
14 | */ | |
15 | ||
16 | #include "../chanserv.h" | |
17 | #include "../../nick/nick.h" | |
18 | #include "../../lib/flags.h" | |
19 | #include "../../lib/irc_string.h" | |
20 | #include "../../channel/channel.h" | |
21 | #include "../../parser/parser.h" | |
22 | #include "../../irc/irc.h" | |
23 | #include "../../localuser/localuserchannel.h" | |
24 | #include "../achievements/achievements.h" | |
25 | #include <string.h> | |
26 | #include <stdio.h> | |
27 | ||
28 | int csh_dotitle(void *source, int cargc, char **cargv) { | |
29 | nick *sender=source; | |
30 | unsigned int i; | |
31 | struct achievement_record *arp; | |
32 | ||
33 | if ((time(NULL) < ACHIEVEMENTS_START) || (time(NULL) > ACHIEVEMENTS_END)) { | |
34 | return CMD_ERROR; | |
35 | } | |
36 | ||
37 | arp=getachievementrec(sender->auth); | |
38 | ||
39 | if (cargc==0) { | |
40 | /* List titles */ | |
41 | if (arp->count32[7] <= 1) { | |
42 | chanservstdmessage(sender, QM_NOTITLES); | |
43 | return CMD_OK; | |
44 | } | |
45 | ||
46 | chanservstdmessage(sender, QM_TITLEHEADER); | |
47 | ||
48 | for(i=0;i<32;i++) { | |
49 | if (arp->count32[7] & (1<<i)) { | |
50 | chanservsendmessage(sender, "%c %2d %s", arp->count16[2]==i?'*':' ', i, titlenames[i]); | |
51 | } | |
52 | } | |
53 | ||
54 | chanservstdmessage(sender, QM_ENDOFLIST); | |
55 | ||
56 | return CMD_OK; | |
57 | } | |
58 | ||
59 | i=strtoul(cargv[0],NULL,10); | |
60 | ||
61 | if (i>31) { | |
62 | chanservstdmessage(sender, QM_INVALIDTITLE); | |
63 | return CMD_ERROR; | |
64 | } | |
65 | ||
66 | if (!(arp->count32[7] & (1<<i))) { | |
67 | chanservstdmessage(sender, QM_INVALIDTITLE); | |
68 | return CMD_ERROR; | |
69 | } | |
70 | ||
71 | if (arp->count16[2] == i) { | |
72 | chanservstdmessage(sender, QM_DONE); | |
73 | return CMD_OK; | |
74 | } | |
75 | ||
76 | if ((arp->count32[11] + 300) > time(NULL)) { | |
77 | chanservstdmessage(sender, QM_TITLETOOFAST); | |
78 | return CMD_ERROR; | |
79 | } | |
80 | ||
81 | arp->count32[11]=time(NULL); | |
82 | ||
83 | arp->count16[2]=i; | |
84 | setusertitle(sender->auth, i); | |
85 | ||
86 | chanservstdmessage(sender, QM_DONE); | |
87 | ||
88 | return CMD_OK; | |
89 | } |