]> jfr.im git - irc/gameservirc.git/blob - gameserv/do_set.cpp
Refactored playerGO a bit
[irc/gameservirc.git] / gameserv / do_set.cpp
1 #include "extern.h"
2 #include "aClient.h"
3 #include "flags.h"
4 #include "options.h"
5 #include "player.h"
6
7 void do_set(char *u)
8 {
9 aClient *user;
10 Player *p;
11 char *name = strtok(NULL, " ");
12 char *cmd = strtok(NULL, " ");
13 char *cmd2;
14
15 if (!(user = find(u)))
16 {
17 notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
18 "Buf: %s LOGOUT", u);
19 return;
20 }
21 else if (isIgnore(user))
22 {
23 #ifdef DEBUGMODE
24 log("Ignoring %s.", user->getNick());
25 #endif
26 return;
27 }
28 else if (!name || !cmd)
29 {
30 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
31 return;
32 }
33 else if (!(p = findplayer(name)))
34 {
35 // Back the pointers up... they didn't send a name probably
36 cmd2 = cmd;
37 cmd = name;
38 p = user->stats;
39
40 if (!is_playing(user))
41 {
42 notice(s_GameServ, u, "You must be playing to set things for yourself!");
43 return;
44 }
45 }
46 else
47 {
48 cmd2 = strtok(NULL, " ");
49 }
50 if (!cmd2)
51 {
52 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
53 return;
54 }
55
56 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
57 if (stricmp(cmd, "PASSWORD") == 0)
58 {
59 // Person is looking to change their password
60 // If they're an admin, or it's theirself, allow it
61 // cmd2 is pointing to the password now
62 if (isAdmin(user) || user == p->getClient())
63 {
64 p->setPassword(cmd2);
65 notice(s_GameServ, u, "Password successfully changed");
66 }
67 else if (user != p->getClient() && !isAdmin(user))
68 {
69 notice(s_GameServ, u, "You must be a <S admin to set other peoples' passwords.");
70 return;
71 }
72 }
73 else if (stricmp(cmd, "BANK") == 0 || stricmp(cmd, "BALANCE") == 0)
74 {
75 if (!isAdmin(user))
76 {
77 notice(s_GameServ, u, "Admins Only!");
78 return;
79 }
80 else if (stricmp(cmd, "BANK") == 0)
81 {
82 cmd2 = strtok(NULL, " "); // Need an extra parameter for set bank balance
83 }
84 if (!cmd2)
85 {
86 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] [BANK] BALANCE <NUMBER>");
87 return;
88 }
89
90 p->setBank(stringtoint(cmd2));
91
92 notice(s_GameServ, u, "Bank balance changed to %ld!", p->getBank());
93 }
94 else if (stricmp(cmd, "PLAYER") == 0)
95 {
96 if (!isAdmin(user))
97 {
98 notice(s_GameServ, u, "Admins Only!");
99 return;
100 }
101 else if (stricmp(cmd2, "FIGHTS") != 0)
102 {
103 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
104 return;
105 }
106 else
107 {
108 cmd2 = strtok(NULL, " ");
109 if (!cmd2)
110 {
111 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
112 return;
113 }
114 p->setPlayerFights(stringtoint(cmd2));
115
116 notice(s_GameServ, u, "Player fights changed to %d!", p->getPlayerFights());
117 }
118 }
119 else if (stricmp(cmd, "FOREST") == 0)
120 {
121 if (!isAdmin(user))
122 {
123 notice(s_GameServ, u, "Admins Only!");
124 return;
125 }
126 else if (stricmp(cmd2, "FIGHTS") != 0)
127 {
128 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <number>");
129 return;
130 }
131 else
132 {
133 cmd2 = strtok(NULL, " ");
134 if (!cmd2)
135 {
136 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <NUMBER>");
137 return;
138 }
139
140 p->setForestFights(stringtoint(cmd2));
141
142 notice(s_GameServ, u, "Forest fights changed to %d!", p->getForestFights());
143 }
144 }
145 else if (stricmp(cmd, "GOLD") == 0)
146 {
147 if (!isAdmin(user))
148 {
149 notice(s_GameServ, u, "Admins Only!");
150 return;
151 }
152 else
153 {
154 if (!cmd2)
155 {
156 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] GOLD <NUMBER>");
157 return;
158 }
159 p->setGold(stringtoint(cmd2));
160
161 notice(s_GameServ, u, "Gold set to %ld", p->getGold());
162 return;
163 }
164 }
165 else if (stricmp(cmd, "STRENGTH") == 0 && stricmp(cmd2, "POTIONS") != 0)
166 {
167 if (!isAdmin(user))
168 {
169 notice(s_GameServ, u, "Admins Only!");
170 return;
171 }
172 else
173 {
174 if (!cmd2)
175 {
176 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] STRENGTH <NUMBER>");
177 return;
178 }
179
180 p->setStrength(stringtoint(cmd2));
181
182 notice(s_GameServ, u, "Strength set to %d", p->getStrength());
183 return;
184 }
185 }
186 else if (stricmp(cmd, "DEFENSE") == 0 && stricmp(cmd2, "POTIONS") != 0)
187 {
188 if (!isAdmin(user))
189 {
190 notice(s_GameServ, u, "Admins Only!");
191 return;
192 }
193 else
194 {
195 if (!cmd2)
196 {
197 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] DEFENSE <NUMBER>");
198 return;
199 }
200
201 p->setDefense(stringtoint(cmd2));
202
203 notice(s_GameServ, u, "Defense set to %d", p->getDefense());
204 return;
205 }
206 }
207 else if (stricmp(cmd, "HP") == 0 && stricmp(cmd2, "POTIONS") != 0)
208 {
209 if (!isAdmin(user))
210 {
211 notice(s_GameServ, u, "Admins Only!");
212 return;
213 }
214 else
215 {
216 if (!cmd2)
217 {
218 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] HP <NUMBER>");
219 return;
220 }
221
222 // Make sure it's easy for an admin to set the hp
223 if (p->getMaxHP() < stringtoint(cmd2))
224 p->setMaxHP(stringtoint(cmd2));
225
226 p->setHP(stringtoint(cmd2));
227
228 notice(s_GameServ, u, "HP set to %d", p->getHP());
229 return;
230 }
231 }
232 else if (stricmp(cmd, "MAXHP") == 0)
233 {
234 if (!isAdmin(user))
235 {
236 notice(s_GameServ, u, "Admins Only!");
237 return;
238 }
239 else
240 {
241 if (!cmd2)
242 {
243 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] MAXHP <NUMBER>");
244 return;
245 }
246 p->setMaxHP(stringtoint(cmd2));
247
248 notice(s_GameServ, u, "MaxHP set to %d", p->getMaxHP());
249 return;
250 }
251 }
252 else if (stricmp(cmd, "EXPERIENCE") == 0 || stricmp(cmd, "EXP") == 0)
253 {
254 if (!isAdmin(user))
255 {
256 notice(s_GameServ, u, "Admins Only!");
257 return;
258 }
259 else
260 {
261 if (!cmd2)
262 {
263 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
264 return;
265 }
266
267 p->setExp(stringtoint(cmd2));
268
269 notice(s_GameServ, u, "Exp set to %ld", p->getExp());
270 return;
271 }
272 }
273 else if (stricmp(cmd, "LEVEL") == 0)
274 {
275 if (!isAdmin(user))
276 {
277 notice(s_GameServ, u, "Admins Only!");
278 return;
279 }
280 else
281 {
282 if (!cmd2)
283 {
284 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] LEVEL <NUMBER>");
285 return;
286 }
287 p->setLevel(stringtoint(cmd2));
288
289 notice(s_GameServ, u, "Level set to %d", p->getLevel());
290 return;
291 }
292 }
293 else if (stricmp(cmd, "ALIVE") == 0)
294 {
295 if (!isAdmin(user))
296 {
297 notice(s_GameServ, u, "Admins Only!");
298 return;
299 }
300 else
301 {
302 if (!cmd2)
303 {
304 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] ALIVE TRUE|FALSE");
305 return;
306 }
307 else if (stricmp(cmd2, "TRUE") == 0)
308 {
309 notice(s_GameServ, u, "%s has been Resurrected!", p->getName().c_str());
310 setAlive(p);
311 }
312 else
313 {
314 notice(s_GameServ, u, "%s is now dead!", p->getName().c_str());
315 clearAlive(p);
316 }
317 }
318 }
319 else if (stricmp(cmd, "SEEN") == 0)
320 {
321 if (!isAdmin(user))
322 {
323 notice(s_GameServ, u, "Admins Only!");
324 return;
325 }
326 else if (stricmp(cmd2, "MASTER") != 0)
327 {
328 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] SEEN MASTER {TRUE|FALSE}");
329 return;
330 }
331 else
332 {
333 cmd2 = strtok(NULL, " ");
334 if (!cmd2)
335 {
336 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NICK] SEEN MASTER {TRUE|FALSE}");
337 return;
338 }
339 else if (stricmp(cmd2, "TRUE") == 0)
340 {
341 notice(s_GameServ, u, "%s has seen their master now.", p->getName().c_str());
342 p->addFlag(FLAG_MASTER);
343 }
344 else
345 {
346 notice(s_GameServ, u, "%s has not seen their master now.", p->getName().c_str());
347 p->remFlag(FLAG_MASTER);
348 }
349 }
350 }
351 else
352 {
353 notice(s_GameServ, u, "Unknown command: SET %s", cmd);
354 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
355 return;
356 }
357 }