]>
Commit | Line | Data |
---|---|---|
96f71fee | 1 | #include "aClient.h" |
c1068b6e | 2 | #include "config.h" |
3 | #include "extern.h" | |
96f71fee | 4 | #include "flags.h" |
85ce9d3e | 5 | #include "list.h" |
96f71fee | 6 | #include "sockhelp.h" |
7 | ||
85ce9d3e | 8 | #include <cctype> |
fb37ecc7 | 9 | #include <fstream> |
10 | ||
11 | using std::ifstream; | |
12 | using std::ofstream; | |
85bcf836 | 13 | using std::ios; |
c1068b6e | 14 | |
15 | #if defined(HAVE_CRYPT_H) | |
16 | ||
e3c5fe46 | 17 | #include <crypt.h> |
85ce9d3e | 18 | |
c1068b6e | 19 | #elif defined(HAVE_UNISTD_H) |
20 | ||
21 | #include <unistd.h> | |
22 | ||
23 | #endif | |
c8ada07e | 24 | |
fc9d2643 | 25 | |
c8ada07e | 26 | Monster *monsters[LEVELS][MONSTERS]; // Monsters per level. Total = MONSTERS * LEVELS |
7031d99e | 27 | Monster boss; // The boss monster |
c8ada07e | 28 | |
29 | Monster *masters[LEVELS]; // A master for each level | |
85ce9d3e | 30 | |
a8fb9757 | 31 | // Database functions |
85ce9d3e | 32 | int save_gs_dbase(); |
33 | int load_gs_dbase(); | |
34 | ||
35 | // String functions | |
653c4f62 | 36 | #ifndef HAVE_STRTOK |
85ce9d3e | 37 | char *strtok(char *str, const char *delim); |
653c4f62 | 38 | #endif |
39 | ||
85ce9d3e | 40 | int stricmp(const char *s1, const char *s2); |
41 | int strnicmp(const char *s1, const char *s2, size_t len); | |
42 | // String Functions | |
43 | ||
e3c5fe46 | 44 | /********** Password functions **********/ |
45 | ||
46 | bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one | |
47 | ||
48 | bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given. | |
49 | ||
50 | /********** Password functions **********/ | |
51 | ||
52 | ||
53 | /********** GameServ Booleans **********/ | |
54 | ||
05c527e6 | 55 | bool shuttingdown; |
40251952 | 56 | bool timedOut(Player *p); |
57 | void updateTS(Player *p); | |
58 | void timeOutEvent(Player *p); | |
59 | ||
e3c5fe46 | 60 | bool is_playing(char *u); // True if the given nickname in the clients list is playing. |
1af35752 | 61 | bool is_playing(aClient *user); |
62 | ||
e3c5fe46 | 63 | bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything. |
1af35752 | 64 | bool is_fighting(aClient *user); |
65 | ||
e3c5fe46 | 66 | bool player_fight(char *u); // True if the player is fighting another player. |
1af35752 | 67 | bool player_fight(aClient *user); |
68 | ||
e3c5fe46 | 69 | bool master_fight(char *u); // True if the player is fighting their master. |
1af35752 | 70 | bool master_fight(aClient *user); |
e3c5fe46 | 71 | |
72 | /********** GameServ Booleans **********/ | |
85ce9d3e | 73 | |
c7340cbd | 74 | void display_help(char *u, char *file = NULL); |
85ce9d3e | 75 | void display_monster(char *u); |
76 | void display_players(char *u); | |
83cf716f | 77 | void display_players(aClient *user); |
85ce9d3e | 78 | long int chartoint(char ch); |
79 | int isstringnum(char *num); | |
80 | long int pow (int x, int y); | |
81 | long int stringtoint(char *number); | |
82 | ||
83 | char *spaces(int len, char *seperator); | |
44ea29f7 | 84 | void refresh(Player *p); |
85ce9d3e | 85 | void refreshall(); |
40251952 | 86 | void updateTS(Player *p); |
ee38284f | 87 | void reset(Player *p); |
c8ada07e | 88 | void init_masters(); |
85ce9d3e | 89 | void init_monsters(); |
4dde2ed9 | 90 | bool load_monsters(); |
c8ada07e | 91 | void delete_monsters(); |
92 | void delete_masters(); | |
85ce9d3e | 93 | |
96f71fee | 94 | void do_admin(char *u); |
c7340cbd | 95 | void do_attack(char *u); |
96 | void do_bank(char *u); | |
97 | void do_fight(char *u); | |
98 | void do_heal(char *u); | |
99 | void do_help(char *u); | |
85ce9d3e | 100 | void do_identify(char *u); |
9cda831c | 101 | void do_inventory(char *u); |
c7340cbd | 102 | void do_refresh(char *u); |
103 | void do_register(char *u); | |
104 | void do_list(char *u); | |
b0359af9 | 105 | void do_logout(char *u); |
c7340cbd | 106 | void do_master(char *u); |
fcca861d | 107 | void do_dragon(char *u); |
85ce9d3e | 108 | void do_play(char *u); |
109 | void do_quitg(char *u); | |
110 | void do_reset(char *u); | |
85ce9d3e | 111 | void do_run(char *u); |
85ce9d3e | 112 | void do_stats(char *u); |
c7340cbd | 113 | void do_store(char *u); |
f5c25639 | 114 | void do_tavern(char *u); |
83cf716f | 115 | void do_use(char *u); |
c7340cbd | 116 | void see_master(char *u); |
85ce9d3e | 117 | |
b0359af9 | 118 | void logout(aClient *user); |
85ce9d3e | 119 | void showstats(const char *u, const char *nick); |
c62d75be | 120 | void showinventory(aClient *from, aClient *to); |
e282e9d2 | 121 | void showBankBalance(const char *u); |
83cf716f | 122 | void end_turn(aClient *user); |
85ce9d3e | 123 | |
124 | #define WNA 16 | |
125 | char *weapons[WNA] = { "Fists", "Stick", "Dagger", "Quarterstaff", "Short Sword", | |
126 | "Long Sword", "Silver Spear", "Battle Axe", "The Ragnarok", | |
127 | "Chain Saw", "Poison Sword", "Flame Sword", "Earth Hammer", | |
128 | "Light Saber", "Masamune", "Mystical Sword"}; | |
129 | ||
b410b364 | 130 | char *armors[WNA] = { "Birthday Suit", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor", |
85ce9d3e | 131 | "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit", |
132 | "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor", | |
e7a0d0ab | 133 | "Hades' Cloak", "Dragon Scales", "Adamantium"}; |
85ce9d3e | 134 | |
135 | int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000, | |
136 | 1000000, 4000000, 10000000, 40000000, 100000000, 400000000}; | |
b410b364 | 137 | int webonus[WNA] = {2, 10, 15, 25, 35, 45, 65, 85, 125, 185, 255, 355, 505, 805, 1205, 1805}; |
138 | int arbonus[WNA] = {2, 3, 5, 10, 15, 25, 35, 50, 75, 100, 150, 225, 300, 400, 600, 1000}; | |
85ce9d3e | 139 | |
140 | int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550}; | |
141 | int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200}; | |
142 | int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150}; | |
143 | ||
85ce9d3e | 144 | void gameserv(char *source, char *buf) |
145 | { | |
448a1531 | 146 | char *cmd, z; |
85ce9d3e | 147 | cmd = strtok(buf, " "); |
148 | ||
fc9d2643 | 149 | #ifndef P10 |
150 | source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text | |
151 | #endif | |
152 | ||
448a1531 | 153 | z = cmd[0]; |
154 | if (z == ':') | |
fc9d2643 | 155 | cmd++; // Get rid of that : at the beginning of the :text (command) |
85ce9d3e | 156 | |
9f8c2acc | 157 | #ifdef DEBUGMODE |
158 | log("Source: %s Command: %s", source, cmd); | |
159 | #endif | |
160 | ||
0eeaca4c | 161 | if (strnicmp(cmd, "\1PING", 6) == 0) |
85ce9d3e | 162 | { |
44ea29f7 | 163 | char *ts; |
164 | ts = strtok(NULL, "\1"); | |
165 | notice(s_GameServ, source, "\1PING %s\1", ts); | |
0eeaca4c | 166 | } else if (stricmp(cmd, "\1VERSION\1") == 0) { |
a3017ab1 | 167 | notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION); |
85ce9d3e | 168 | } else if (stricmp(cmd, "SEARCH") == 0) { |
169 | cmd = strtok(NULL, " "); | |
170 | ||
171 | if (!cmd) | |
172 | notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST"); | |
173 | else | |
174 | do_forest(source); | |
1af35752 | 175 | |
85ce9d3e | 176 | } else if (stricmp(cmd, "FIGHT") == 0) { |
177 | do_fight(source); | |
178 | } else if (stricmp(cmd, "ATTACK") == 0) { | |
179 | do_attack(source); | |
c8ada07e | 180 | } else if (stricmp(cmd, "RUN") == 0) { |
181 | do_run(source); | |
83cf716f | 182 | } else if (stricmp(cmd, "USE") == 0) { |
183 | do_use(source); | |
85ce9d3e | 184 | } else if (stricmp(cmd, "HEAL") == 0) { |
185 | do_heal(source); | |
9cda831c | 186 | } else if (stricmp(cmd, "INVENTORY") == 0) { |
187 | do_inventory(source); | |
ab4f4ec0 | 188 | } else if (stricmp(cmd, "MASTER") == 0) { |
189 | do_master(source); | |
fcca861d | 190 | } else if (stricmp(cmd, "DRAGON") == 0) { |
191 | do_dragon(source); | |
ad7dfaa0 | 192 | } else if (stricmp(cmd, "STORE") == 0) { |
193 | do_store(source); | |
8c126acc | 194 | } else if (stricmp(cmd, "BANK") == 0) { |
195 | do_bank(source); | |
96f71fee | 196 | } else if (stricmp(cmd, "ADMIN") == 0) { |
197 | do_admin(source); | |
c7340cbd | 198 | } else if (stricmp(cmd, "REFRESH") == 0) { |
96f71fee | 199 | do_refresh(source); |
ee38284f | 200 | } else if (stricmp(cmd, "RESET") == 0) { |
201 | do_reset(source); | |
f5c25639 | 202 | } else if (stricmp(cmd, "TAVERN") == 0) { |
203 | do_tavern(source); | |
85ce9d3e | 204 | } else if (stricmp(cmd, "LIST") == 0) { |
205 | do_list(source); | |
b0359af9 | 206 | } else if (stricmp(cmd, "LOGOUT") == 0) { |
207 | do_logout(source); | |
174e7f8f | 208 | } else if (stricmp(cmd, "NEWS") == 0) { |
5aa1d28d | 209 | do_news(source); |
85ce9d3e | 210 | } else if (stricmp(cmd, "REGISTER") == 0) { |
211 | do_register(source); | |
212 | } else if (stricmp(cmd, "IDENTIFY") == 0) { | |
213 | do_identify(source); | |
214 | } else if (stricmp(cmd, "HELP") == 0) { | |
c7340cbd | 215 | do_help(source); |
85ce9d3e | 216 | } else if (stricmp(cmd, "STATS") == 0) { |
217 | do_stats(source); | |
218 | } else if (stricmp(cmd, "SHUTDOWN") == 0) { | |
96f71fee | 219 | aClient *user; |
220 | ||
221 | if (!(user = find(source))) | |
45a84400 | 222 | { |
96f71fee | 223 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); |
9f8c2acc | 224 | log("Error: aClient not found: %s", source); |
96f71fee | 225 | } |
226 | else if (!isAdmin(user)) | |
227 | { | |
228 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
45a84400 | 229 | } |
230 | else | |
231 | { | |
96f71fee | 232 | save_gs_dbase(); |
23ec3ff4 | 233 | #ifdef P10 |
ce61cdfa | 234 | raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername, user->getRealNick()); |
23ec3ff4 | 235 | #else |
4e5760fd | 236 | raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source); |
23ec3ff4 | 237 | #endif |
05c527e6 | 238 | shuttingdown = true; |
45a84400 | 239 | } |
85ce9d3e | 240 | } else if (stricmp(cmd, "SAVE") == 0) { |
96f71fee | 241 | aClient *user; |
242 | ||
243 | if (!(user = find(source))) | |
244 | { | |
245 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
9f8c2acc | 246 | log("Error: aClient not found: %s", source); |
96f71fee | 247 | } |
248 | else if (!isAdmin(user)) | |
249 | { | |
250 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
251 | } | |
252 | else | |
45a84400 | 253 | { |
254 | save_gs_dbase(); | |
255 | } | |
85ce9d3e | 256 | } else if (stricmp(cmd, "LOAD") == 0) { |
96f71fee | 257 | aClient *user; |
258 | ||
259 | if (!(user = find(source))) | |
260 | { | |
261 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 262 | log("Error: aClient not found: %s", source); |
96f71fee | 263 | } |
264 | else if (!isAdmin(user)) | |
265 | { | |
266 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
267 | } | |
268 | else | |
45a84400 | 269 | { |
4dde2ed9 | 270 | char *cmd2 = strtok(NULL, " "); |
271 | if (!cmd2) | |
272 | { | |
273 | notice(s_GameServ, source, "Loading player data from %s", playerdata); | |
274 | load_gs_dbase(); | |
275 | } | |
276 | else if (stricmp(cmd2, "MONSTERS") == 0) | |
277 | { | |
278 | notice(s_GameServ, source, "Loading monster data from %s", monsterdata); | |
279 | load_monsters(); | |
280 | } | |
281 | else | |
282 | display_help(source, cmd); | |
45a84400 | 283 | } |
8450c018 | 284 | #ifdef DEBUGMODE |
85ce9d3e | 285 | } else if (stricmp(cmd, "RAW") == 0) { |
96f71fee | 286 | aClient *user; |
287 | ||
288 | if (!(user = find(source))) | |
289 | { | |
290 | notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin"); | |
9f8c2acc | 291 | log("Error: aClient not found: %s", source); |
96f71fee | 292 | } |
293 | else if (!isAdmin(user)) | |
294 | { | |
295 | notice(s_GameServ, source, "You must be a %S admin to use this command!"); | |
296 | } | |
297 | else | |
45a84400 | 298 | { |
299 | char *rest = strtok(NULL, ""); | |
300 | raw("%s", rest); | |
301 | } | |
8450c018 | 302 | #endif |
42ec1800 | 303 | } else { |
448a1531 | 304 | aClient *user; |
305 | if ((user = find(source))) | |
306 | { | |
307 | if (isIgnore(user)) | |
308 | { | |
309 | #ifdef DEBUGMODE | |
310 | log("Ignoring %s.", user->getNick()); | |
311 | #endif | |
312 | } | |
313 | else | |
314 | { | |
315 | notice(s_GameServ, source, "Unknown command \002%s\002. Type /msg %S \002HELP\002 to get a list of commands.", cmd); | |
316 | } | |
317 | } | |
c7340cbd | 318 | } |
85ce9d3e | 319 | |
448a1531 | 320 | #ifndef P10 |
321 | source--; // Bring the ':' back so we don't leak memory | |
322 | #endif | |
323 | if (z == ':') | |
324 | cmd--; // Same thing :) | |
85ce9d3e | 325 | } |
326 | ||
327 | int stricmp(const char *s1, const char *s2) | |
328 | { | |
329 | register int c; | |
330 | ||
331 | while ((c = tolower(*s1)) == tolower(*s2)) { | |
332 | if (c == 0) | |
333 | return 0; | |
334 | s1++; | |
335 | s2++; | |
336 | } | |
337 | if (c < tolower(*s2)) | |
338 | return -1; | |
339 | return 1; | |
340 | } | |
341 | ||
342 | void showstats(const char *u, const char *nick) | |
343 | { | |
344 | aClient *ni, *sender = find(u); | |
345 | char *buf; | |
346 | buf = new char[50]; | |
347 | char *space; | |
348 | ||
349 | ||
73c71976 | 350 | if (!(ni = findplayer(nick))) |
85ce9d3e | 351 | { |
352 | notice(s_GameServ, u, "%s not found", nick); | |
353 | } | |
354 | else if (ni->stats) | |
355 | { | |
85ce9d3e | 356 | notice(s_GameServ, sender->getNick(), "Stats for %s:", ni->stats->name); |
357 | ||
358 | sprintf(buf, "Experience: %ld", ni->stats->exp); | |
359 | space = spaces(strlen(buf), " "); | |
360 | notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space, | |
361 | ni->stats->level); | |
1cf88153 | 362 | delete [] space; |
85ce9d3e | 363 | |
364 | sprintf(buf, "Gold: %ld", ni->stats->gold); | |
365 | space = spaces(strlen(buf), " "); | |
366 | notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, ni->stats->bank); | |
1cf88153 | 367 | delete [] space; |
85ce9d3e | 368 | |
c7340cbd | 369 | notice(s_GameServ, sender->getNick(), "Hit Points: %d of %d", ni->stats->hp, |
85ce9d3e | 370 | ni->stats->maxhp); |
371 | ||
372 | sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]); | |
373 | space = spaces(strlen(buf), " "); | |
374 | notice(s_GameServ, sender->getNick(), "%s%sDefense: %d", | |
375 | buf, space, ni->stats->defense + arbonus[ni->stats->armor]); | |
1cf88153 | 376 | delete [] space; |
85ce9d3e | 377 | |
378 | sprintf(buf, "Armor: %s", armors[ni->stats->armor]); | |
379 | space = spaces(strlen(buf), " "); | |
380 | notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space, | |
381 | weapons[ni->stats->weapon]); | |
1cf88153 | 382 | delete [] space; |
85ce9d3e | 383 | |
384 | sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights); | |
385 | space = spaces(strlen(buf), " "); | |
386 | notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, ni->stats->player_fights); | |
1cf88153 | 387 | delete [] space; |
35cba3f5 | 388 | Pouch *inv = &ni->stats->inventory; |
389 | ||
390 | notice(s_GameServ, u, "Potions"); | |
391 | sprintf(buf, "Healing: %d", inv->Healing()); | |
392 | space = spaces(strlen(buf), " "); | |
393 | notice(s_GameServ, sender->getNick(), "%s%sHP: %d", buf, | |
394 | space, inv->HP()); | |
395 | delete [] space; | |
396 | ||
397 | sprintf(buf, "Strength: %d", inv->Strength()); | |
398 | space = spaces(strlen(buf), " "); | |
399 | notice(s_GameServ, sender->getNick(), "%s%sDefense: %d", buf, | |
400 | space, inv->Defense()); | |
401 | delete [] space; | |
85ce9d3e | 402 | } |
73c71976 | 403 | else |
404 | { | |
405 | notice(s_GameServ, u, "%s is not playing!", ni->stats->name); | |
406 | } | |
1cf88153 | 407 | delete [] buf; |
85ce9d3e | 408 | } |
409 | ||
410 | char *spaces(int len, char *seperator) | |
411 | { | |
412 | char *final; | |
42ec1800 | 413 | final = new char[30]; |
85ce9d3e | 414 | int y; |
415 | strcpy(final, seperator); | |
42ec1800 | 416 | for (y = 0; y < 30 - len; y++) |
85ce9d3e | 417 | strcat(final, seperator); |
418 | return final; | |
419 | } | |
420 | ||
421 | void raw(const char *fmt, ...) | |
422 | { | |
423 | va_list args; | |
424 | char *input; | |
425 | const char *t = fmt; | |
426 | input = new char[1024]; | |
427 | va_start(args, fmt); | |
428 | memset(input, 0, sizeof(input)); // Initialize to NULL | |
429 | for (; *t; t++) | |
430 | { | |
431 | if (*t == '%') | |
432 | { | |
433 | switch(*++t) { | |
434 | case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break; | |
435 | case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break; | |
436 | case 'S': sprintf(input, "%s%s", input, s_GameServ); break; | |
437 | case 'l': | |
438 | if (*++t == 'd') | |
439 | sprintf(input, "%s%ld", input, va_arg(args, long int)); break; | |
440 | } | |
441 | } | |
442 | else | |
443 | { | |
444 | sprintf(input, "%s%c", input, *t); | |
445 | } | |
446 | ||
447 | } | |
9f8c2acc | 448 | #ifdef DEBUGMODE |
449 | log("Input: %s", input); | |
450 | #endif | |
451 | ||
85ce9d3e | 452 | sprintf(input, "%s%s", input, "\r\n"); |
85ce9d3e | 453 | sock_puts(sock, input); |
1cf88153 | 454 | delete [] input; |
85ce9d3e | 455 | va_end(args); |
456 | } | |
457 | /* Send a NOTICE from the given source to the given nick. */ | |
458 | ||
459 | void notice(const char *source, const char *dest, const char *fmt, ...) | |
460 | { | |
c7340cbd | 461 | if (fmt[0] == '\0') |
462 | return; | |
463 | ||
9bafc40d | 464 | char *commanduse; |
465 | commanduse = new char[16]; | |
466 | ||
467 | #ifdef P10 | |
6f727d4c | 468 | if (isUsePrivmsg()) |
469 | strcpy(commanduse, "P"); | |
9bafc40d | 470 | else |
a51121e0 | 471 | strcpy(commanduse, "O"); |
9bafc40d | 472 | #else |
473 | ||
6f727d4c | 474 | if (isUsePrivmsg()) |
475 | strcpy(commanduse, "PRIVMSG"); | |
9bafc40d | 476 | else |
6f727d4c | 477 | strcpy(commanduse, "NOTICE"); |
9bafc40d | 478 | #endif |
479 | ||
85ce9d3e | 480 | va_list args; |
481 | char *input; | |
482 | const char *t = fmt; | |
483 | input = new char[1024]; | |
484 | va_start(args, fmt); | |
485 | if (dest[0] == ':') | |
486 | { | |
487 | dest++; | |
ba2a880f | 488 | |
489 | #if !defined(P10) | |
9bafc40d | 490 | sprintf(input, ":%s %s %s :", source, commanduse, dest); |
ba2a880f | 491 | #else |
9bafc40d | 492 | sprintf(input, "%s %s %s :", gsnum, commanduse, dest); |
ba2a880f | 493 | #endif |
494 | ||
85ce9d3e | 495 | dest--; |
496 | } | |
497 | else | |
ba2a880f | 498 | { |
499 | #if !defined(P10) | |
9bafc40d | 500 | sprintf(input, ":%s %s %s :", source, commanduse, dest); |
ba2a880f | 501 | #else |
9bafc40d | 502 | sprintf(input, "%s %s %s :", gsnum, commanduse, dest); |
ba2a880f | 503 | #endif |
504 | } | |
85ce9d3e | 505 | |
506 | for (; *t; t++) | |
507 | { | |
508 | if (*t == '%') | |
509 | { | |
510 | switch(*++t) { | |
511 | case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break; | |
512 | case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break; | |
513 | case 'S': sprintf(input, "%s%s", input, s_GameServ); break; | |
514 | case 'l': | |
515 | if (*++t == 'd') | |
516 | sprintf(input, "%s%ld", input, va_arg(args, long int)); break; | |
517 | } | |
518 | } | |
519 | else | |
520 | { | |
521 | sprintf(input, "%s%c", input, *t); | |
522 | } | |
523 | ||
524 | } | |
9f8c2acc | 525 | #ifdef DEBUGMODE |
526 | log("Input: %s", input); | |
527 | #endif | |
85ce9d3e | 528 | sprintf(input, "%s%s", input, "\r\n"); |
85ce9d3e | 529 | sock_puts(sock, input); |
9bafc40d | 530 | delete [] commanduse; |
1cf88153 | 531 | delete [] input; |
85ce9d3e | 532 | va_end(args); |
533 | } | |
534 | ||
535 | ||
536 | int strnicmp(const char *s1, const char *s2, size_t len) | |
537 | { | |
538 | register int c; | |
539 | ||
540 | if (!len) | |
541 | return 0; | |
542 | while ((c = tolower(*s1)) == tolower(*s2) && len > 0) { | |
543 | if (c == 0 || --len == 0) | |
544 | return 0; | |
545 | s1++; | |
546 | s2++; | |
547 | } | |
548 | if (c < tolower(*s2)) | |
549 | return -1; | |
550 | return 1; | |
551 | } | |
552 | ||
653c4f62 | 553 | #ifndef HAVE_STRTOK |
85ce9d3e | 554 | char *strtok(char *str, const char *delim) |
555 | { | |
556 | static char *current = NULL; | |
557 | char *ret; | |
558 | ||
559 | if (str) | |
560 | current = str; | |
561 | if (!current) | |
562 | return NULL; | |
563 | current += strspn(current, delim); | |
564 | ret = *current ? current : NULL; | |
565 | current += strcspn(current, delim); | |
566 | if (!*current) | |
567 | current = NULL; | |
568 | else | |
569 | *current++ = 0; | |
570 | return ret; | |
571 | } | |
653c4f62 | 572 | #endif |
85ce9d3e | 573 | |
574 | void do_list(char *u) | |
575 | { | |
448a1531 | 576 | aClient *user; |
9cb6f227 | 577 | char *cmd = strtok(NULL, " "); |
578 | ||
448a1531 | 579 | if (!(user = find(u))) |
580 | { | |
581 | log("Fatal Error: Couldn't find %s in the client list", u); | |
582 | return; | |
583 | } | |
584 | else if (isIgnore(user)) | |
585 | { | |
586 | #ifdef DEBUGMODE | |
587 | log("Ignoring %s. Command LIST", user->getNick()); | |
588 | #endif | |
589 | return; | |
590 | } | |
591 | ||
85ce9d3e | 592 | ListNode<aClient> *temp; |
7996e5fd | 593 | bool header = false; |
9cb6f227 | 594 | |
7996e5fd | 595 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
596 | { | |
597 | temp = players[x].First(); | |
598 | if (!players[x].isEmpty()) | |
85ce9d3e | 599 | { |
85ce9d3e | 600 | while(temp) |
601 | { | |
9cb6f227 | 602 | if (!cmd || is_playing(temp->getData())) |
603 | { | |
604 | if (!header) | |
605 | { | |
606 | notice(s_GameServ, u, "Players:"); | |
607 | header = true; | |
608 | } | |
609 | #ifdef P10 | |
610 | notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getRealNick(), | |
611 | temp->getData()->stats->name); | |
612 | #else | |
613 | notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getNick(), | |
614 | temp->getData()->stats->name); | |
615 | #endif | |
616 | } | |
ce61cdfa | 617 | |
85ce9d3e | 618 | temp = temp->Next(); |
619 | } | |
85ce9d3e | 620 | } |
7996e5fd | 621 | } |
622 | if (!header) | |
85ce9d3e | 623 | notice(s_GameServ, u, "No one is playing"); |
7996e5fd | 624 | else |
625 | notice(s_GameServ, u, "End of List"); | |
626 | ||
85ce9d3e | 627 | } |
1af35752 | 628 | |
b0359af9 | 629 | void do_logout(char *u) |
630 | { | |
631 | aClient *user; | |
18b84d11 | 632 | char *name = strtok(NULL, " "); |
633 | ||
b0359af9 | 634 | if (!(user = find(u))) |
635 | { | |
636 | notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\ | |
637 | "Buf: %s LOGOUT", u); | |
638 | log("Could not find aClient Buf: %s LOGOUT", | |
639 | u); | |
18b84d11 | 640 | return; |
b0359af9 | 641 | } |
448a1531 | 642 | else if (isIgnore(user)) |
643 | { | |
644 | #ifdef DEBUGMODE | |
645 | log("Ignoring %s.", user->getNick()); | |
646 | #endif | |
647 | return; | |
648 | } | |
18b84d11 | 649 | |
650 | if (name) | |
6e8ec003 | 651 | { |
18b84d11 | 652 | if (!isAdmin(user)) |
653 | { | |
654 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
655 | } | |
656 | else if (!(user = findplayer(name))) | |
657 | { | |
658 | notice(s_GameServ, u, "Couldn't find a player named %s", name); | |
659 | } | |
660 | else | |
661 | { | |
662 | notice(s_GameServ, u, "Logging out %s", user->stats->name); | |
663 | logout(user); | |
664 | } | |
6e8ec003 | 665 | } |
18b84d11 | 666 | else if (!name) |
b0359af9 | 667 | { |
18b84d11 | 668 | if (!is_playing(user)) |
669 | { | |
670 | notice(s_GameServ, u, "You're not logged in!"); | |
671 | } | |
672 | else if (is_fighting(user)) | |
673 | { | |
674 | notice(s_GameServ, u, "You can't logout while fighting!"); | |
675 | } | |
676 | else | |
677 | { | |
678 | notice(s_GameServ, u, "You have left the fields. You have lived to kill another day!"); | |
679 | logout(user); | |
680 | } | |
b0359af9 | 681 | } |
682 | } | |
3f243b0b | 683 | |
b0359af9 | 684 | void logout(aClient *user) |
685 | { | |
686 | if (is_playing(user)) | |
687 | { | |
688 | ListNode<aClient> *it; | |
689 | aClient *temp; | |
448a1531 | 690 | unsigned long hv = iHASH((unsigned char *) user->stats->name); |
7996e5fd | 691 | it = players[hv].Find(user); |
448a1531 | 692 | |
b0359af9 | 693 | if (!it) |
694 | { | |
695 | notice(s_GameServ, user->getNick(), "Fatal error. Contact "\ | |
696 | "%S Admin. Cannot find you in the players list."); | |
697 | log("Error on logout(). Can't find %s in the players list", | |
698 | #ifdef P10 | |
699 | user->getRealNick() | |
700 | #else | |
701 | user->getNick() | |
702 | #endif | |
703 | ); | |
704 | return; | |
705 | } | |
706 | ||
707 | temp = new aClient; | |
708 | temp->stats = new Player; | |
709 | temp->stats->setData(user->stats); | |
85bcf836 | 710 | user->stats->client = NULL; |
6e8ec003 | 711 | |
712 | if (player_fight(user)) | |
713 | user->stats->battle->stats->battle = NULL; | |
714 | ||
b0359af9 | 715 | delete user->stats; |
716 | user->stats = NULL; | |
85bcf836 | 717 | temp->stats->client = NULL; |
b0359af9 | 718 | #ifdef P10 |
448a1531 | 719 | temp->setRealNick("Not Playing"); |
b0359af9 | 720 | #endif |
448a1531 | 721 | temp->setNick("Not Playing"); |
b0359af9 | 722 | |
723 | it->setNewPtr(temp); | |
724 | #ifdef DEBUGMODE | |
725 | log("Logged out player %s", | |
726 | #ifdef P10 | |
727 | user->getRealNick() | |
728 | #else | |
729 | user->getNick() | |
730 | #endif | |
731 | ); | |
732 | #endif | |
733 | } | |
3f243b0b | 734 | clearPlaying(user); |
b0359af9 | 735 | } |
3f243b0b | 736 | |
85ce9d3e | 737 | void do_register(char *u) |
738 | { | |
e1c41a84 | 739 | char *password, *name; |
40251952 | 740 | aClient *user; |
e1c41a84 | 741 | name = strtok(NULL, " "); |
85ce9d3e | 742 | password = strtok(NULL, " "); |
743 | ||
e3c5fe46 | 744 | static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
745 | static char salt[3]; | |
746 | ||
747 | salt[0] = saltChars[rand() % strlen(saltChars)]; | |
748 | salt[1] = saltChars[rand() % strlen(saltChars)]; | |
f27a378f | 749 | salt[2] = '\0'; |
e3c5fe46 | 750 | |
e1c41a84 | 751 | if (!name) |
752 | { | |
753 | notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD"); | |
754 | } | |
755 | else if (!password) | |
85ce9d3e | 756 | { |
e1c41a84 | 757 | notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD"); |
85ce9d3e | 758 | } |
03e0a9d8 | 759 | else if ((user = findplayer(name))) |
760 | { | |
761 | notice(s_GameServ, u, "%s is already registered!", name); | |
762 | notice(s_GameServ, u, "Choose another name!"); | |
763 | } | |
448a1531 | 764 | else if (!(user = find(u))) |
765 | { | |
766 | log("Fatal Error: Couldn't find %s in the clients list", u); | |
767 | } | |
768 | else if (isIgnore(user)) | |
769 | { | |
770 | #ifdef DEBUGMODE | |
771 | log("Ignoring %s.", user->getNick()); | |
772 | #endif | |
773 | return; | |
774 | } | |
775 | else | |
85ce9d3e | 776 | { |
3f243b0b | 777 | if (!is_playing(user)) |
85ce9d3e | 778 | { |
ae2685f6 | 779 | ListNode<aClient> *temp; |
85ce9d3e | 780 | user->stats = new Player(user); |
85bcf836 | 781 | user->stats->client = user; // Set the backwards pointer |
ae2685f6 | 782 | user->stats->reset(); // set the user up |
783 | strncpy(user->stats->password, crypt(password, salt), 255); | |
784 | strncpy(user->stats->name, name, 255); | |
448a1531 | 785 | unsigned long hv = iHASH((unsigned char *) name); |
40251952 | 786 | updateTS(user->stats); |
ae2685f6 | 787 | temp = players[hv].insertAtBack_RLN(user); |
788 | temp->setPtr(user); // This is an extra step, but necessary for now | |
789 | ||
c7340cbd | 790 | notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password); |
791 | notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!"); | |
5d04eb42 | 792 | log("Nickname %s registered player %s.", u, user->stats->name); |
3f243b0b | 793 | setPlaying(user); // set the playing flag |
85ce9d3e | 794 | } |
795 | else | |
796 | { | |
797 | notice(s_GameServ, u, "Already registered. Contact a %S admin for help."); | |
798 | } | |
799 | } | |
800 | } | |
801 | ||
802 | void do_identify(char *u) | |
803 | { | |
0a1518fa | 804 | char *password, *name; |
805 | aClient *user, *p; | |
806 | name = strtok(NULL, " "); | |
85ce9d3e | 807 | password = strtok(NULL, " "); |
0a1518fa | 808 | if (!password || !name) |
85ce9d3e | 809 | { |
0a1518fa | 810 | notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD"); |
85ce9d3e | 811 | } |
448a1531 | 812 | else if (!(user = find(u))) |
5d04eb42 | 813 | { |
814 | notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, "")); | |
815 | log("Error: aClient not found: %s", u); | |
816 | } | |
448a1531 | 817 | else if (isIgnore(user)) |
818 | { | |
819 | #ifdef DEBUGMODE | |
820 | log("Ignoring %s.", user->getNick()); | |
821 | #endif | |
822 | return; | |
823 | } | |
0a1518fa | 824 | else if (!(p = findplayer(name)) || !p->stats) |
825 | notice(s_GameServ, u, "Player %s not found", name); | |
b0359af9 | 826 | else if (is_playing(user)) |
827 | { | |
828 | notice(s_GameServ, u, "You are already playing!"); | |
829 | } | |
85bcf836 | 830 | else if (p->stats->client != NULL && !isAdmin(user)) |
1579dfa2 | 831 | { |
832 | notice(s_GameServ, u, "That player has already identified."); | |
1579dfa2 | 833 | } |
20d5d721 | 834 | else if (!check_password(name, password) && !isAdmin(user)) |
85ce9d3e | 835 | { |
0a1518fa | 836 | notice(s_GameServ, u, "Password incorrect"); |
85ce9d3e | 837 | } |
1579dfa2 | 838 | else { |
b0359af9 | 839 | ListNode<aClient> *temp; |
448a1531 | 840 | unsigned long hv = iHASH((unsigned char *) p->stats->name); |
7996e5fd | 841 | temp = players[hv].Find(p); |
b0359af9 | 842 | if (!temp) |
85ce9d3e | 843 | { |
b0359af9 | 844 | notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s", |
845 | strtok(NULL, "")); | |
846 | return; | |
85ce9d3e | 847 | } |
b0359af9 | 848 | user->stats = new Player(p->stats->name); |
849 | #ifdef DEBUGMODE | |
850 | log("Setting data for identified"); | |
851 | #endif | |
0b6098d5 | 852 | user->stats->setData(p->stats); |
448a1531 | 853 | user->stats->client = user; |
40251952 | 854 | updateTS(user->stats); |
855 | ||
b0359af9 | 856 | |
857 | #ifdef DEBUGMODE | |
448a1531 | 858 | log("Player %s IRC: %s Identified", user->stats->name, |
859 | user->getNick()); | |
b0359af9 | 860 | #endif |
861 | ||
3f243b0b | 862 | setPlaying(user); // set the playing flag |
863 | ||
b0359af9 | 864 | temp->setPtr(user); |
c260a8d7 | 865 | notice(s_GameServ, u, "Password Accepted. Identified."); |
866 | showNews(u, todaysnews); | |
85ce9d3e | 867 | } |
868 | } | |
869 | ||
870 | void do_stats(char *u) | |
871 | { | |
872 | char *nick; | |
73c71976 | 873 | aClient *user; |
85ce9d3e | 874 | |
875 | nick = strtok(NULL, " "); | |
85ce9d3e | 876 | |
448a1531 | 877 | if (!(user = find(u))) |
73c71976 | 878 | { |
448a1531 | 879 | log("Fatal Error: %s not found in client list", u); |
880 | return; | |
881 | } | |
882 | else if (isIgnore(user)) | |
883 | { | |
884 | #ifdef DEBUGMODE | |
885 | log("Ignoring %s.", user->getNick()); | |
886 | #endif | |
887 | return; | |
888 | } | |
889 | else if (!nick) | |
890 | { | |
891 | if (!is_playing(user)) | |
73c71976 | 892 | { |
893 | notice(s_GameServ, u, "You're not playing, so you have no stats!"); | |
894 | return; | |
895 | } | |
896 | else | |
40251952 | 897 | { |
898 | updateTS(user->stats); | |
73c71976 | 899 | showstats(u, user->stats->name); |
40251952 | 900 | } |
73c71976 | 901 | } |
85ce9d3e | 902 | else |
903 | showstats(u, nick); | |
904 | } | |
448a1531 | 905 | |
ad7dfaa0 | 906 | void init_masters() |
907 | { | |
5d04eb42 | 908 | #ifdef DEBUGMODE |
909 | log("Calling delete_masters()"); | |
910 | #endif | |
911 | ||
ab4f4ec0 | 912 | delete_masters(); |
c8ada07e | 913 | |
5d04eb42 | 914 | #ifdef DEBUGMODE |
915 | log("Initializing masters"); | |
916 | #endif | |
917 | ||
c8ada07e | 918 | for (int x = 0; x < LEVELS; x++) |
919 | masters[x] = new Monster; | |
920 | ||
921 | strcpy(masters[0]->name, "Old Bones"); | |
922 | strcpy(masters[0]->weapon, "Dull Sword Cane"); | |
f0314ad5 | 923 | masters[0]->strength = 32; |
c8ada07e | 924 | masters[0]->gold = 0; |
925 | masters[0]->exp = 0; | |
6d053d90 | 926 | masters[0]->maxhp = 35; |
927 | masters[0]->hp = 35; | |
c8ada07e | 928 | strcpy(masters[0]->death, "You have done well my student, but the road is long. Use your new strength with humility and honor as you progress in levels!"); |
e282e9d2 | 929 | |
c8ada07e | 930 | strcpy(masters[1]->name, "Master Chang"); |
931 | strcpy(masters[1]->weapon, "Nanchaku"); | |
f0314ad5 | 932 | masters[1]->strength = 48; |
c8ada07e | 933 | masters[1]->gold = 0; |
934 | masters[1]->exp = 0; | |
6d053d90 | 935 | masters[1]->maxhp = 51; |
936 | masters[1]->hp = 51; | |
c8ada07e | 937 | strcpy(masters[1]->death, "You try to make out what Master Chang is saying, but the only thing you catch is something about a grasshopper."); |
938 | ||
939 | strcpy(masters[2]->name, "Chuck Norris"); | |
940 | strcpy(masters[2]->weapon, "Ranger Kick"); | |
f0314ad5 | 941 | masters[2]->strength = 88; |
c8ada07e | 942 | masters[2]->gold = 0; |
943 | masters[2]->exp = 0; | |
6d053d90 | 944 | masters[2]->maxhp = 100; |
945 | masters[2]->hp = 100; | |
c8ada07e | 946 | strcpy(masters[2]->death, "Be strong, and keep your goals in site. Drink milk, and don't do drugs. One day you may be fighting next to me as a Texas Ranger YEEHAW!"); |
947 | ||
948 | ||
949 | strcpy(masters[3]->name, "Mr. Miagi"); | |
950 | strcpy(masters[3]->weapon, "Petrified Bonsai"); | |
f0314ad5 | 951 | masters[3]->strength = 169; |
c8ada07e | 952 | masters[3]->gold = 0; |
953 | masters[3]->exp = 0; | |
6d053d90 | 954 | masters[3]->maxhp = 165; |
955 | masters[3]->hp = 165; | |
c8ada07e | 956 | strcpy(masters[3]->death, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!"); |
957 | ||
958 | strcpy(masters[4]->name, "Jackie Chan"); | |
e282e9d2 | 959 | strcpy(masters[4]->weapon, "Kung Fu Kick"); |
f0314ad5 | 960 | masters[4]->strength = 275; |
c8ada07e | 961 | masters[4]->gold = 0; |
962 | masters[4]->exp = 0; | |
6d053d90 | 963 | masters[4]->maxhp = 232; |
964 | masters[4]->hp = 232; | |
c8ada07e | 965 | strcpy(masters[4]->death, "I like to let people talk who like to talk... it's easier to find out how full of it they really are!"); |
966 | ||
967 | strcpy(masters[5]->name, "Jet Li"); | |
968 | strcpy(masters[5]->weapon, "Motorcycle"); | |
f0314ad5 | 969 | masters[5]->strength = 347; |
c8ada07e | 970 | masters[5]->gold = 0; |
971 | masters[5]->exp = 0; | |
6d053d90 | 972 | masters[5]->maxhp = 504; |
973 | masters[5]->hp = 504; | |
c8ada07e | 974 | strcpy(masters[5]->death, "Failure is a fuel for excuses. It's the doing the do, that makes the making."); |
975 | ||
976 | ||
977 | strcpy(masters[6]->name, "Muhammad Ali"); | |
978 | strcpy(masters[6]->weapon, "Quick Jab"); | |
f0314ad5 | 979 | masters[6]->strength = 515; |
c8ada07e | 980 | masters[6]->gold = 0; |
981 | masters[6]->exp = 0; | |
6d053d90 | 982 | masters[6]->maxhp = 1078; |
983 | masters[6]->hp = 1078; | |
c8ada07e | 984 | strcpy(masters[6]->death, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up."); |
985 | ||
986 | strcpy(masters[7]->name, "Li Mu Bai"); | |
987 | strcpy(masters[7]->weapon, "Green Destiny"); | |
f0314ad5 | 988 | masters[7]->strength = 655; |
c8ada07e | 989 | masters[7]->gold = 0; |
990 | masters[7]->exp = 0; | |
6d053d90 | 991 | masters[7]->maxhp = 2207; |
992 | masters[7]->hp = 2207; | |
c8ada07e | 993 | strcpy(masters[7]->death, "No growth without resistance. No action without reaction. No desire without restraint."); |
994 | ||
995 | ||
996 | strcpy(masters[8]->name, "Jimmy Wang Yu"); | |
997 | strcpy(masters[8]->weapon, "Flying Guillotine"); | |
f0314ad5 | 998 | masters[8]->strength = 819; |
c8ada07e | 999 | masters[8]->gold = 0; |
1000 | masters[8]->exp = 0; | |
6d053d90 | 1001 | masters[8]->maxhp = 2780; |
1002 | masters[8]->hp = 2780; | |
c8ada07e | 1003 | strcpy(masters[8]->death, "You have beaten the one armed boxer. Proceed with caution!"); |
1004 | ||
1005 | strcpy(masters[9]->name, "Wong Fei Hung"); | |
1006 | strcpy(masters[9]->weapon, "Drunken Boxing"); | |
f0314ad5 | 1007 | masters[9]->strength = 1014; |
c8ada07e | 1008 | masters[9]->gold = 0; |
1009 | masters[9]->exp = 0; | |
6d053d90 | 1010 | masters[9]->maxhp = 3046; |
1011 | masters[9]->hp = 3046; | |
e282e9d2 | 1012 | strcpy(masters[9]->death, "Hiccup! Monkey drinks master's wine!"); |
c8ada07e | 1013 | |
1014 | strcpy(masters[10]->name, "Bruce Lee"); | |
1015 | strcpy(masters[10]->weapon, "Fists of fury"); | |
f0314ad5 | 1016 | masters[10]->strength = 1286; |
c8ada07e | 1017 | masters[10]->gold = 0; |
1018 | masters[10]->exp = 0; | |
6d053d90 | 1019 | masters[10]->maxhp = 3988; |
1020 | masters[10]->hp = 3988; | |
c8ada07e | 1021 | strcpy(masters[10]->death, "You must learn to concentrate. It is like a finger pointing away to the moon... DONT concentrate on the finger, or you will miss all the heavenly glory."); |
ad7dfaa0 | 1022 | } |
85ce9d3e | 1023 | |
1024 | void init_monsters() | |
1025 | { | |
5d04eb42 | 1026 | #ifdef DEBUGMODE |
1027 | log("Calling delete_monsters"); | |
1028 | #endif | |
1029 | ||
c8ada07e | 1030 | delete_monsters(); |
5d04eb42 | 1031 | |
c8ada07e | 1032 | for (int x = 0; x < LEVELS; x++) |
1033 | for (int y = 0; y < MONSTERS; y++) | |
1034 | monsters[x][y] = new Monster(); | |
c8ada07e | 1035 | } |
1036 | ||
1037 | void delete_monsters() | |
1038 | { | |
1039 | for (int x = 0; x < LEVELS; x++) | |
1040 | for (int y = 0; y < MONSTERS; y++) | |
1041 | if (monsters[x][y]) | |
1042 | delete monsters[x][y]; | |
1043 | } | |
1044 | ||
1045 | void delete_masters() | |
1046 | { | |
1047 | for (int x = 0; x < LEVELS; x++) | |
1048 | if (masters[x]) | |
1049 | delete masters[x]; | |
85ce9d3e | 1050 | } |
1051 | ||
1052 | void display_monster(char *u) | |
1053 | { | |
1054 | if (is_playing(u)) | |
1055 | { | |
1056 | aClient *user = find(u); | |
1057 | Player *ni = user->stats; | |
1058 | ||
1059 | notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->hp); | |
1060 | notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->fight->name, ni->fight->hp); | |
1061 | notice(s_GameServ, u, "Here are your commands:"); | |
1062 | notice(s_GameServ, u, "/msg %S attack"); | |
1063 | notice(s_GameServ, u, "/msg %S run"); | |
1064 | notice(s_GameServ, u, "What will you do?"); | |
1065 | } | |
1066 | } | |
1067 | ||
1068 | void display_players(char *u) | |
1069 | { | |
85bcf836 | 1070 | aClient *user; |
1071 | if (!(user = find(u))) | |
85ce9d3e | 1072 | { |
85bcf836 | 1073 | log("Fatal error in display_players(): Couldn't find %s", u); |
83cf716f | 1074 | } |
85bcf836 | 1075 | else |
1076 | display_players(user); | |
83cf716f | 1077 | } |
85bcf836 | 1078 | |
83cf716f | 1079 | void display_players(aClient *user) |
1080 | { | |
1081 | char *u = user->getNick(); | |
1082 | if (is_playing(user) && player_fight(user)) | |
1083 | { | |
1084 | aClient *battle = user->stats->battle; | |
1085 | notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", user->stats->hp); | |
ce61cdfa | 1086 | notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->stats->name, battle->stats->hp); |
83cf716f | 1087 | notice(s_GameServ, u, "Here are your commands:"); |
1088 | notice(s_GameServ, u, "/msg %S attack"); | |
1089 | notice(s_GameServ, u, "/msg %S run"); | |
85ce9d3e | 1090 | notice(s_GameServ, u, "What will you do?"); |
1091 | } | |
1092 | } | |
1093 | ||
1094 | ||
1095 | bool is_playing(char *u) | |
1096 | { | |
1097 | aClient *user; | |
1098 | if (!(user = find(u))) | |
85ce9d3e | 1099 | return false; |
85ce9d3e | 1100 | else |
40251952 | 1101 | return is_playing(user); |
85ce9d3e | 1102 | } |
1103 | ||
1af35752 | 1104 | bool is_playing(aClient *user) |
1105 | { | |
03a4bdbb | 1106 | if (user->stats == NULL) |
f1ab3b7c | 1107 | { |
03a4bdbb | 1108 | return false; |
f1ab3b7c | 1109 | } |
03a4bdbb | 1110 | else if (user->stats->client == NULL) |
f1ab3b7c | 1111 | { |
03a4bdbb | 1112 | return false; |
f1ab3b7c | 1113 | } |
3f243b0b | 1114 | else if (!FL_is_playing(user)) |
1115 | { | |
1116 | return false; | |
1117 | } | |
03a4bdbb | 1118 | else |
1119 | return true; | |
1af35752 | 1120 | } |
1121 | ||
85ce9d3e | 1122 | bool is_fighting(char *u) |
1123 | { | |
1124 | aClient *user; | |
1125 | ||
1126 | if (!(user = find(u))) | |
85ce9d3e | 1127 | return false; |
85ce9d3e | 1128 | else |
40251952 | 1129 | return is_fighting(user); |
85ce9d3e | 1130 | } |
40251952 | 1131 | |
1af35752 | 1132 | bool is_fighting(aClient *user) |
1133 | { | |
1134 | if (!is_playing(user)) | |
1135 | return false; | |
1136 | else | |
448a1531 | 1137 | return player_fight(user) || master_fight(user) || user->stats->fight != NULL; |
1af35752 | 1138 | } |
85ce9d3e | 1139 | |
1140 | bool player_fight(char *u) | |
1141 | { | |
1142 | aClient *user; | |
1143 | ||
1144 | if (!(user = find(u))) | |
1145 | return false; | |
40251952 | 1146 | else |
1147 | return player_fight(user); | |
85ce9d3e | 1148 | } |
448a1531 | 1149 | |
1af35752 | 1150 | bool player_fight(aClient *user) |
1151 | { | |
448a1531 | 1152 | if (!is_playing(user)) |
1af35752 | 1153 | return false; |
a51f0dcd | 1154 | else if (user->stats->battle != NULL) |
1155 | { | |
1156 | return user->stats->battle->stats != NULL; | |
1157 | } | |
1158 | return false; | |
1af35752 | 1159 | } |
85ce9d3e | 1160 | |
1161 | bool master_fight(char *u) | |
1162 | { | |
1163 | aClient *user; | |
1164 | ||
1165 | if (!(user = find(u))) | |
1166 | return false; | |
85ce9d3e | 1167 | else |
40251952 | 1168 | return master_fight(user); |
85ce9d3e | 1169 | } |
40251952 | 1170 | |
1af35752 | 1171 | bool master_fight(aClient *user) |
85ce9d3e | 1172 | { |
1af35752 | 1173 | if (!is_playing(user)) |
1174 | return false; | |
1175 | else | |
1176 | return user->stats->master != NULL; | |
85ce9d3e | 1177 | } |
1178 | ||
1179 | void do_fight(char *u) | |
1180 | { | |
1181 | aClient *ni, *battle; | |
1182 | ||
1183 | char *nick = strtok(NULL, " "); | |
1184 | ||
1185 | if (!nick) | |
1186 | { | |
1187 | notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER"); | |
40251952 | 1188 | return; |
85ce9d3e | 1189 | } |
1190 | else if (!(ni = find(u))) | |
1191 | { | |
1af35752 | 1192 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); |
40251952 | 1193 | return; |
85ce9d3e | 1194 | } |
448a1531 | 1195 | else if (isIgnore(ni)) |
1196 | { | |
1197 | #ifdef DEBUGMODE | |
1198 | log("Ignoring %s.", ni->getNick()); | |
1199 | #endif | |
1200 | return; | |
1201 | } | |
71098075 | 1202 | else if (!is_playing(ni)) |
85ce9d3e | 1203 | { |
71098075 | 1204 | notice(s_GameServ, u, "You are not playing!"); |
40251952 | 1205 | return; |
85ce9d3e | 1206 | } |
40251952 | 1207 | |
1208 | updateTS(ni->stats); | |
1209 | ||
1210 | if (ni->stats->player_fights <= 0) | |
3348c24e | 1211 | { |
1212 | ni->stats->player_fights = 0; // just to be safe | |
1213 | notice(s_GameServ, u, "You are out of player fights for the "\ | |
1214 | "day. You have to wait until tomorrow!"); | |
1215 | } | |
71098075 | 1216 | else if (!(battle = findplayer(nick))) |
b0359af9 | 1217 | { |
1218 | notice(s_GameServ, u, "Player %s not found!", nick); | |
1219 | } | |
448a1531 | 1220 | else if (!isAlive(ni->stats)) |
1221 | { | |
1222 | notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!"); | |
1223 | } | |
b0359af9 | 1224 | else if (!is_playing(battle)) |
85ce9d3e | 1225 | { |
71098075 | 1226 | notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick); |
85ce9d3e | 1227 | } |
b478c0df | 1228 | |
1229 | /* offline fighting not available yet | |
1230 | else if (!(fight = finduser(nick))) | |
1231 | { | |
1232 | ni->stats->battle = battle; | |
1233 | battle->battle = ni; | |
1234 | setYourTurn(ni->stats); | |
1235 | clearYourTurn(battle->stats); | |
1236 | ||
1237 | notice(s_GameServ, u, "You decide to fight %s while they're "\ | |
1238 | "not in the realm!", | |
1239 | battle->stats->name); | |
1240 | display_players(u); | |
1241 | } | |
1242 | */ | |
b0359af9 | 1243 | else if (stricmp(ni->stats->name, battle->stats->name) == 0) |
1244 | { | |
1245 | notice(s_GameServ, u, "Are you trying to commit suicide!?"); | |
1af35752 | 1246 | } |
da5cf17a | 1247 | else if (!isAlive(battle->stats)) |
1248 | { | |
1249 | notice(s_GameServ, u, "They are dead. Cannot fight dead players!"); | |
da5cf17a | 1250 | } |
1902338e | 1251 | else if (player_fight(battle)) |
1252 | { | |
1253 | notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->battle->stats->name); | |
1902338e | 1254 | } |
448a1531 | 1255 | else if (master_fight(battle)) |
1256 | { | |
1257 | notice(s_GameServ, u, "%s is fighting their master!", battle->stats->name); | |
1258 | } | |
1902338e | 1259 | else if (is_fighting(battle)) |
1260 | { | |
1261 | notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->fight->name); | |
1902338e | 1262 | } |
8450c018 | 1263 | else if (ni->stats->level - battle->stats->level > maxbfightdistance) |
1264 | { | |
1265 | // You can't fight someone below you by more than X level(s) | |
1266 | // level 12 can fight level (12 - X) but not < (12 - X) | |
1267 | notice(s_GameServ, u, "You may not fight %s. You're too strong!", | |
ae2685f6 | 1268 | battle->stats->name); |
8450c018 | 1269 | } |
1270 | else if (battle->stats->level - ni->stats->level > maxafightdistance) | |
1271 | { | |
1272 | // You can't fight someone above you by more than X level(S) | |
1273 | // level 1 can fight level (1 + X), but not > (1 + X) | |
1274 | notice(s_GameServ, u, "%s, do you really have a death wish? Try the forest you "\ | |
1275 | "weakling!", ni->stats->name); | |
8450c018 | 1276 | } |
b0359af9 | 1277 | else |
85ce9d3e | 1278 | { |
1279 | // Set your battle pointer to the other player | |
1280 | ni->stats->battle = battle; | |
1281 | ||
1282 | // Set the other player's battle pointer to you | |
448a1531 | 1283 | ni->stats->battle->stats->battle = ni; |
85ce9d3e | 1284 | |
1285 | // The initiator gets the first move (perhaps this should be 50/50) | |
ee38284f | 1286 | setYourTurn(ni->stats); |
1287 | clearYourTurn(battle->stats); | |
85ce9d3e | 1288 | |
1289 | // Initiate Battle sequence! | |
b0359af9 | 1290 | ni->stats->player_fights -= 1; |
f2072f1a | 1291 | |
ce61cdfa | 1292 | notice(s_GameServ, u, "You challenge %s to an online duel!", battle->stats->name); |
1293 | notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", ni->stats->name); | |
71098075 | 1294 | notice(s_GameServ, battle->getNick(), "%s gets to go first "\ |
1295 | "because they initiated!", ni->stats->name); | |
ce61cdfa | 1296 | notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", ni->stats->name); |
85bcf836 | 1297 | display_players(ni); |
85ce9d3e | 1298 | } |
1299 | } | |
40251952 | 1300 | |
83cf716f | 1301 | void do_use(char *u) |
1302 | { | |
1303 | aClient *user; | |
1304 | Pouch *p; | |
1305 | ||
1306 | char *item = strtok(NULL, " "); | |
1307 | ||
1308 | if (!item) | |
1309 | { | |
1310 | notice(s_GameServ, u, "SYNTAX: USE ITEM"); | |
1311 | notice(s_GameServ, u, "Type /msg %S HELP USE for more information."); | |
1312 | return; | |
1313 | } | |
1314 | else if (!(user = find(u))) | |
1315 | { | |
1316 | notice(s_GameServ, u, "Fatal Error in do_use. Contact a(n) %S Admin"); | |
1317 | return; | |
1318 | } | |
448a1531 | 1319 | else if (isIgnore(user)) |
1320 | { | |
1321 | #ifdef DEBUGMODE | |
1322 | log("Ignoring %s.", user->getNick()); | |
1323 | #endif | |
1324 | return; | |
1325 | } | |
83cf716f | 1326 | else if (!is_playing(user)) |
1327 | { | |
1328 | notice(s_GameServ, u, "You must be playing to use items!"); | |
1329 | return; | |
1330 | } | |
1331 | ||
40251952 | 1332 | updateTS(user->stats); |
1333 | ||
83cf716f | 1334 | p = &user->stats->inventory; |
1335 | ||
35cba3f5 | 1336 | if (stricmp(item, "HEALING") == 0) |
83cf716f | 1337 | { |
1338 | if (p->Healing() <= 0) | |
1339 | { | |
35cba3f5 | 1340 | notice(s_GameServ, u, "You are out of Healing Potions!"); |
83cf716f | 1341 | return; |
1342 | } | |
35cba3f5 | 1343 | int oldhealing = user->stats->hp; |
36b31e1c | 1344 | user->stats->hp += (10 * user->stats->level) + (rand() % 10) * user->stats->level; |
1345 | if (user->stats->hp - user->stats->maxhp >= 100) | |
1346 | { | |
1347 | user->stats->hp = user->stats->maxhp + 100; | |
1348 | ||
1349 | if (oldhealing >= (user->stats->maxhp + 100)) | |
1350 | { | |
1351 | notice(s_GameServ, u, "You cannot hold anymore HP!"); | |
1352 | return; | |
1353 | } | |
1354 | } | |
1355 | ||
83cf716f | 1356 | notice(s_GameServ, u, "You hastiliy gulp down the flask of cool life-giving waters."); |
1357 | notice(s_GameServ, u, "Rejuvination spreads throughout your body."); | |
35cba3f5 | 1358 | notice(s_GameServ, u, "You gain %d HP!", user->stats->hp - oldhealing); |
83cf716f | 1359 | p->decHealing(); |
35cba3f5 | 1360 | if (player_fight(user)) |
1361 | { | |
1362 | notice(s_GameServ, user->stats->battle->getNick(), | |
1363 | "%s has used a healing potion!"); | |
1364 | } | |
83cf716f | 1365 | } |
1366 | else if (stricmp(item, "STRENGTH") == 0) | |
1367 | { | |
1368 | if (p->Strength() <= 0) | |
1369 | { | |
1370 | notice(s_GameServ, u, "You are out of Strength Potions!"); | |
1371 | return; | |
1372 | } | |
1373 | int oldstrength = user->stats->strength; | |
1374 | notice(s_GameServ, u, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!"); | |
1375 | notice(s_GameServ, u, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!"); | |
ae2685f6 | 1376 | user->stats->strength += 1 + (rand() % 10 >= 8 ? 1 : 0); // 1-2 |
83cf716f | 1377 | notice(s_GameServ, u, "You gain %d Strength points!", user->stats->strength - oldstrength); |
1378 | p->decStrength(); | |
35cba3f5 | 1379 | if (player_fight(user)) |
1380 | { | |
1381 | notice(s_GameServ, user->stats->battle->getNick(), | |
1382 | "%s has used a strength potion!"); | |
1383 | } | |
83cf716f | 1384 | } |
1385 | else if (stricmp(item, "DEFENSE") == 0) | |
1386 | { | |
1387 | if (p->Defense() <= 0) | |
1388 | { | |
1389 | notice(s_GameServ, u, "You are out of Defense Potions!"); | |
1390 | return; | |
1391 | } | |
8c734eb9 | 1392 | int olddefense = user->stats->defense; |
83cf716f | 1393 | notice(s_GameServ, u, "You drink the foul tasting viscous liquid while pinching your nose in disgust."); |
1394 | notice(s_GameServ, u, "It tasted bad, but you feel like you are unbeatable!"); | |
ae2685f6 | 1395 | user->stats->defense += 1 + (rand() % 10 >= 8 ? 1 : 0); // 1-2 |
83cf716f | 1396 | notice(s_GameServ, u, "You gain %d Defense points!", user->stats->defense - olddefense); |
1397 | p->decDefense(); | |
35cba3f5 | 1398 | if (player_fight(user)) |
1399 | { | |
1400 | notice(s_GameServ, user->stats->battle->getNick(), | |
1401 | "%s has used a defense potion!"); | |
1402 | } | |
83cf716f | 1403 | } |
8c734eb9 | 1404 | else if (stricmp(item, "HP") == 0) |
1405 | { | |
1406 | if (p->HP() <= 0) | |
1407 | { | |
1408 | notice(s_GameServ, u, "You are out of HP Potions!"); | |
1409 | return; | |
1410 | } | |
1411 | int oldHP = user->stats->maxhp; | |
1412 | notice(s_GameServ, u, "You feel your life growing longer as you drink the green glowing liquid."); | |
4e64da60 | 1413 | user->stats->maxhp += 2 + |
1414 | (rand() % 100 > 70 ? (rand() % 7) : (rand() % 2) ); | |
ae2685f6 | 1415 | |
8c734eb9 | 1416 | notice(s_GameServ, u, "You gain %d Maximum hit points!", user->stats->maxhp - oldHP); |
1417 | p->decHP(); | |
35cba3f5 | 1418 | if (player_fight(user)) |
1419 | { | |
1420 | notice(s_GameServ, user->stats->battle->getNick(), | |
1421 | "%s has used a HP potion!"); | |
1422 | } | |
8c734eb9 | 1423 | } |
ee38284f | 1424 | else |
1425 | { | |
35cba3f5 | 1426 | notice(s_GameServ, u, "SYNTAX: /msg %S USE {HEALING | STRENGTH | DEFENSE | HP}"); |
ee38284f | 1427 | return; |
1428 | } | |
83cf716f | 1429 | |
1430 | end_turn(user); // If they're fighting, end their turn | |
1431 | } | |
c8ada07e | 1432 | void do_run(char *u) |
1433 | { | |
1434 | aClient *user; | |
28f552b8 | 1435 | Player *p, *p2 = NULL; |
85ce9d3e | 1436 | |
c8ada07e | 1437 | if (!(user = find(u))) |
1438 | { | |
1439 | notice(s_GameServ, u, "Couldn't find you. Error. Contact a %S admin"); | |
1440 | return; | |
1441 | } | |
448a1531 | 1442 | else if (isIgnore(user)) |
1443 | { | |
1444 | #ifdef DEBUGMODE | |
1445 | log("Ignoring %s.", user->getNick()); | |
1446 | #endif | |
1447 | return; | |
1448 | } | |
bb668fcf | 1449 | else if (!is_playing(user)) |
1450 | { | |
adaf4cdb | 1451 | notice(s_GameServ, u, "You must be playing to run!"); |
bb668fcf | 1452 | return; |
1453 | } | |
1454 | ||
40251952 | 1455 | updateTS(user->stats); |
c8ada07e | 1456 | p = user->stats; |
1457 | ||
1458 | if (p->battle) | |
1459 | p2 = p->battle->stats; | |
1460 | ||
1af35752 | 1461 | if (!is_fighting(user)) |
c8ada07e | 1462 | notice(s_GameServ, u, "You run in place... try fighting next time."); |
1af35752 | 1463 | else if (!player_fight(user) && !master_fight(user)) |
c8ada07e | 1464 | { |
1465 | notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->fight->name); | |
1466 | delete p->fight; | |
1467 | p->fight = NULL; | |
1468 | } | |
ee38284f | 1469 | else if (player_fight(user) && isYourTurn(p)) |
c8ada07e | 1470 | { |
1471 | notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->name); | |
1472 | notice(s_GameServ, p->battle->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->name); | |
1473 | p2->battle = NULL; | |
1474 | } | |
ee38284f | 1475 | else if (player_fight(user) && !isYourTurn(p)) |
c8ada07e | 1476 | { |
1477 | notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->name); | |
1478 | } | |
1af35752 | 1479 | else if (master_fight(user)) |
c8ada07e | 1480 | { |
1481 | notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->master->name); | |
1482 | } | |
1483 | p->battle = NULL; | |
1484 | } | |
83cf716f | 1485 | |
1486 | void end_turn(aClient *user) | |
1487 | { | |
1488 | char *nick, *u = user->getNick(); | |
1489 | Monster *fight; | |
1490 | aClient *battle; | |
1491 | int mhit; | |
1492 | ||
1493 | nick = new char[strlen(user->getNick()) + 1]; | |
1494 | ||
1495 | if (!user || !is_playing(user) || !is_fighting(user)) | |
1496 | goto endturn; | |
1497 | ||
1498 | if (!player_fight(user) && !master_fight(user)) | |
1499 | fight = user->stats->fight; | |
1500 | else | |
1501 | fight = user->stats->master; | |
1502 | battle = user->stats->battle; | |
1503 | ||
1504 | if (!player_fight(user)) | |
1505 | { | |
1506 | // Opponent's Hit | |
1507 | mhit = (fight->strength / 2) + | |
1508 | (rand() % (fight->strength / 2) - (user->stats->defense + | |
1509 | arbonus[user->stats->armor])); | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | // Opponent's Hit | |
1514 | mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) + | |
1515 | (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) - | |
1516 | (user->stats->defense + arbonus[user->stats->armor])); | |
1517 | } | |
1518 | if (!player_fight(user)) | |
1519 | { | |
1520 | ||
1521 | if (mhit > 0) | |
1522 | { | |
1523 | notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!", | |
1524 | fight->name, fight->weapon, mhit); | |
1525 | } | |
1526 | else if (mhit <= 0) | |
1527 | notice(s_GameServ, u, "%s completely misses you!", fight->name); | |
1528 | ||
1529 | if (mhit >= user->stats->hp) | |
1530 | { | |
1531 | if (!master_fight(user)) | |
1532 | { | |
1533 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name); | |
1534 | notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ | |
1535 | "of your experience!"); | |
1536 | user->stats->gold = 0; | |
1537 | user->stats->exp -= (long int)(user->stats->exp * .10); | |
b478c0df | 1538 | user->stats->hp = 0; |
83cf716f | 1539 | user->stats->fight = NULL; |
ee38284f | 1540 | clearAlive(user->stats); |
83cf716f | 1541 | goto endturn; |
1542 | } | |
1543 | else | |
1544 | { | |
1545 | notice(s_GameServ, u, "%s has bested you! You will have to wait "\ | |
1546 | "until tomorrow to try again", user->stats->master->name); | |
1547 | user->stats->fight = NULL; | |
1548 | user->stats->master = NULL; | |
1549 | goto endturn; | |
1550 | } | |
1551 | } | |
1552 | else | |
1553 | { | |
1554 | if (mhit > 0) | |
1555 | user->stats->hp -= mhit; | |
1556 | display_monster(u); | |
1557 | goto endturn; | |
1558 | } | |
1559 | } | |
1560 | else | |
1561 | { | |
ee38284f | 1562 | clearYourTurn(user->stats); |
1563 | setYourTurn(battle->stats); | |
83cf716f | 1564 | display_players(battle); |
1565 | } | |
1566 | endturn: | |
1567 | delete nick; | |
1568 | } | |
1569 | ||
85ce9d3e | 1570 | void do_attack(char *u) |
1571 | { | |
1572 | int hit, mhit; | |
1573 | aClient *ni, *battle; // The player and perhaps the player they're fighting | |
1574 | Monster *fight; // The monster they may be fighting | |
1575 | ||
1576 | if (!(ni = find(u))) | |
83cf716f | 1577 | { |
1578 | notice(s_GameServ, u, "Fatal error in do_attack. Contact a(n) %S admin for help."); | |
1579 | return; | |
1580 | } | |
448a1531 | 1581 | else if (isIgnore(ni)) |
1582 | { | |
1583 | #ifdef DEBUGMODE | |
1584 | log("Ignoring %s.", ni->getNick()); | |
1585 | #endif | |
1586 | return; | |
1587 | } | |
83cf716f | 1588 | else if (!is_playing(ni)) |
85ce9d3e | 1589 | { |
1590 | notice(s_GameServ, u, "You're not playing!"); | |
1591 | return; | |
1592 | } | |
83cf716f | 1593 | else if (!is_fighting(ni)) |
85ce9d3e | 1594 | { |
1595 | notice(s_GameServ, u, "You're not in battle!"); | |
1596 | return; | |
1597 | } | |
1598 | else | |
1599 | { | |
1600 | if (!ni->stats->master) // This is not a master fight | |
1601 | fight = ni->stats->fight; // Monster Could be NULL | |
1602 | else // This IS a master fight | |
1603 | fight = ni->stats->master; // Master Could be NULL | |
1604 | ||
1605 | battle = ni->stats->battle; // Player Could be NULL | |
1606 | ||
1607 | // One has to be !NULL based on the previous else if | |
1608 | // We wouldn't be here if they were all NULL | |
1609 | } | |
40251952 | 1610 | updateTS(ni->stats); |
85ce9d3e | 1611 | |
1af35752 | 1612 | if (!player_fight(ni)) |
85ce9d3e | 1613 | { |
1614 | // Player's Hit | |
1615 | hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) + | |
1616 | (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2)); | |
1617 | ||
1618 | // Opponent's Hit | |
1619 | mhit = (fight->strength / 2) + | |
1620 | (rand() % (fight->strength / 2) - (ni->stats->defense + | |
1621 | arbonus[ni->stats->armor])); | |
1622 | } | |
1623 | else | |
1624 | { | |
1625 | // Opponent's Hit | |
1626 | mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) + | |
1627 | (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) - | |
1628 | (ni->stats->defense + arbonus[ni->stats->armor])); | |
1629 | ||
1630 | // Player's Hit | |
1631 | hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) + | |
1632 | (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) - | |
1633 | (battle->stats->defense + arbonus[battle->stats->armor])); | |
1634 | } | |
1635 | ||
1af35752 | 1636 | if (!player_fight(ni)) |
85ce9d3e | 1637 | { |
1638 | if (hit > 0) | |
1639 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name, hit); | |
1640 | else | |
1641 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name); | |
1642 | ||
1643 | if (hit >= fight->hp) | |
1644 | { | |
1af35752 | 1645 | if (master_fight(ni)) |
c260a8d7 | 1646 | { |
85ce9d3e | 1647 | notice(s_GameServ, u, "You have bested %s!", fight->name); |
c260a8d7 | 1648 | addNews(todaysnews, "%s has bested %s and moved "\ |
1649 | "to level %d", ni->stats->name, fight->name, | |
1650 | (ni->stats->level + 1)); | |
1651 | } | |
85ce9d3e | 1652 | else |
1653 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name); | |
1654 | ||
1655 | notice(s_GameServ, u, "%s", fight->death); | |
1656 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!", | |
1657 | fight->exp, fight->gold); | |
1658 | ||
1659 | // If your new experience (or gold) will be greater than 2 billion, | |
1660 | // then set your exp to 2bil. (2 billion max)... otherwise add them. | |
1661 | // This could be a problem with overflowing out of the sign bit. | |
1662 | // Unsigned long int maybe? Leave it for now. | |
1663 | ni->stats->exp = ( (ni->stats->exp + fight->exp) > 2000000000 ? 2000000000 : | |
1664 | ni->stats->exp + fight->exp); | |
ee38284f | 1665 | |
85ce9d3e | 1666 | ni->stats->gold = (ni->stats->gold + fight->gold > 2000000000 ? 2000000000 : |
1667 | ni->stats->gold + fight->gold); | |
c8ada07e | 1668 | |
85ce9d3e | 1669 | |
1af35752 | 1670 | if (master_fight(ni)) |
85ce9d3e | 1671 | { |
1672 | notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1); | |
1673 | notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!", | |
1674 | strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]); | |
1675 | ||
1676 | // Increase your level | |
85ce9d3e | 1677 | |
1678 | // Increase your maximum hit points | |
1679 | ni->stats->maxhp += hpbonus[ni->stats->level - 1]; | |
1680 | ||
1681 | // Heal the player by setting hp to their max | |
1682 | ni->stats->hp = ni->stats->maxhp; | |
1683 | ||
1684 | // Add to your strength | |
1685 | ni->stats->strength += strbonus[ni->stats->level - 1]; | |
1686 | ||
1687 | // Add to your defensive power | |
1688 | ni->stats->defense += defbonus[ni->stats->level - 1]; | |
1689 | ||
6370e3da | 1690 | ni->stats->level++; |
1691 | ||
85ce9d3e | 1692 | // Clear the pointer for your master |
1693 | ni->stats->master = NULL; | |
1694 | } | |
ab4f4ec0 | 1695 | |
1696 | // They're dead so remove the pointer | |
1697 | delete ni->stats->fight; | |
1698 | ni->stats->fight = NULL; | |
1699 | ni->stats->master = NULL; | |
1700 | ||
85ce9d3e | 1701 | return; |
1702 | } | |
1703 | else | |
1704 | { | |
1705 | if (hit > 0) | |
1706 | fight->hp -= hit; | |
1707 | if (mhit > 0) | |
1708 | { | |
e282e9d2 | 1709 | notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!", |
85ce9d3e | 1710 | fight->name, fight->weapon, mhit); |
1711 | } | |
1712 | else if (mhit <= 0) | |
1713 | notice(s_GameServ, u, "%s completely misses you!", fight->name); | |
1714 | ||
1715 | if (mhit >= ni->stats->hp) | |
1716 | { | |
1af35752 | 1717 | if (!master_fight(ni)) |
85ce9d3e | 1718 | { |
1719 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name); | |
1720 | notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\ | |
1721 | "of your experience!"); | |
c260a8d7 | 1722 | addNews(todaysnews, "%s has been killed by %s!", |
1723 | ni->stats->name, fight->name); | |
85ce9d3e | 1724 | ni->stats->gold = 0; |
1725 | ni->stats->exp -= (long int)(ni->stats->exp * .10); | |
b478c0df | 1726 | ni->stats->hp = 0; |
85ce9d3e | 1727 | ni->stats->fight = NULL; |
ee38284f | 1728 | clearAlive(ni->stats); |
85ce9d3e | 1729 | return; |
1730 | } | |
1731 | else | |
1732 | { | |
1733 | notice(s_GameServ, u, "%s has bested you! You will have to wait "\ | |
1734 | "until tomorrow to try again", ni->stats->master->name); | |
c260a8d7 | 1735 | addNews(todaysnews, "%s tried to best %s and failed!", |
1736 | ni->stats->name, fight->name); | |
85ce9d3e | 1737 | ni->stats->fight = NULL; |
1738 | ni->stats->master = NULL; | |
1739 | return; | |
1740 | } | |
1741 | } | |
1742 | else | |
1743 | { | |
1744 | if (mhit > 0) | |
1745 | ni->stats->hp -= mhit; | |
1746 | display_monster(u); | |
1747 | return; | |
1748 | } | |
1749 | } | |
1750 | } | |
1af35752 | 1751 | else if (player_fight(ni)) |
85ce9d3e | 1752 | { |
1753 | /* Offline fighting not available yet | |
1754 | if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online)) | |
1755 | { | |
1756 | if (hit > 0) | |
1757 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->nick, hit); | |
1758 | else | |
1759 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->nick); | |
1760 | if (hit >= battle->stats->hp) | |
1761 | { | |
1762 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->nick); | |
1763 | * notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!", | |
1764 | (long int)(battle->stats->exp * .10), battle->stats->gold); | |
1765 | if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10)) | |
1766 | { | |
1767 | ni->stats->exp += (long int)(battle->stats->exp * .10); | |
1768 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1769 | } | |
1770 | * else | |
1771 | { | |
1772 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1773 | ni->stats->exp = 2000000000; | |
1774 | } | |
1775 | ||
1776 | if (2000000000 - ni->stats->gold > battle->stats->gold) | |
1777 | { | |
1778 | * ni->stats->gold += battle->stats->gold; | |
1779 | battle->stats->gold = 0; | |
1780 | } | |
1781 | else | |
1782 | { | |
1783 | battle->stats->gold = 2000000000 - ni->stats->gold; | |
1784 | ni->stats->gold = 2000000000; | |
1785 | } | |
1786 | * ni->stats->battle->stats->alive = 0; | |
1787 | ni->stats->battle->battle = NULL; | |
1788 | ni->stats->battle = NULL; | |
1789 | return; | |
1790 | } | |
1791 | else | |
1792 | { | |
1793 | if (hit > 0) | |
1794 | * battle->stats->hp -= hit; | |
1795 | if (mhit > 0) | |
1796 | { | |
1797 | notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!", | |
1798 | battle->nick, weapons[battle->stats->weapon], mhit); | |
1799 | } | |
1800 | else if (mhit <= 0) | |
1801 | notice(s_GameServ, u, "%s completely misses you!", battle->nick); | |
1802 | * | |
1803 | if (mhit >= ni->stats->hp) | |
1804 | { | |
1805 | notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", battle->nick); | |
1806 | if (2000000000 - battle->stats->gold > ni->stats->gold) | |
1807 | { | |
1808 | notice(s_GameServ, u, "%s took all your gold!", battle->nick); | |
1809 | battle->stats->gold += ni->stats->gold; | |
1810 | * ni->stats->gold = 0; | |
1811 | } | |
1812 | else | |
1813 | { | |
1814 | notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.", | |
1815 | battle->nick); | |
1816 | ni->stats->gold -= (2000000000 - battle->stats->gold); | |
1817 | notice(s_GameServ, u, "You were left dead with %d gold.", | |
1818 | * (long int)ni->stats->gold); | |
1819 | battle->stats->gold = 2000000000; | |
1820 | } | |
1821 | ni->stats->battle->battle = NULL; | |
1822 | ni->stats->battle = NULL; | |
1823 | ni->stats->alive = 0; | |
1824 | return; | |
1825 | } | |
1826 | * else | |
1827 | { | |
1828 | if (mhit > 0) | |
1829 | ni->stats->hp -= mhit; | |
1830 | display_players(u); | |
1831 | return; | |
1832 | } | |
1833 | } | |
1834 | } | |
1835 | * end offline fighting */ | |
1836 | ||
ce61cdfa | 1837 | if (is_playing(battle)) |
85ce9d3e | 1838 | { |
ee38284f | 1839 | if (!isYourTurn(ni->stats)) |
85ce9d3e | 1840 | { |
1841 | notice(s_GameServ, u, "Please wait until %s decides what to do!", | |
ce61cdfa | 1842 | battle->stats->name); |
85ce9d3e | 1843 | return; |
1844 | } | |
1845 | if (hit > 0) | |
1846 | { | |
ce61cdfa | 1847 | notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name, hit); |
85ce9d3e | 1848 | |
1849 | notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\ | |
ce61cdfa | 1850 | "\ 2%d\ 2 damage!", ni->stats->name, |
1851 | weapons[ni->stats->weapon], hit); | |
85ce9d3e | 1852 | } |
1853 | else | |
1854 | { | |
ce61cdfa | 1855 | notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->name); |
1856 | notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name); | |
85ce9d3e | 1857 | } |
c260a8d7 | 1858 | |
85ce9d3e | 1859 | if (hit >= battle->stats->hp) |
1860 | { | |
ce61cdfa | 1861 | notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->name); |
85ce9d3e | 1862 | notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!", |
1863 | (long int)(battle->stats->exp * .10), battle->stats->gold); | |
ce61cdfa | 1864 | notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", |
1865 | ni->stats->name); | |
85ce9d3e | 1866 | battle->stats->hp = 0; |
ee38284f | 1867 | clearAlive(battle->stats); |
85ce9d3e | 1868 | |
1869 | if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10)) | |
1870 | { | |
1871 | ni->stats->exp += (long int)(battle->stats->exp * .10); | |
1872 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1873 | } | |
1874 | else | |
1875 | { | |
1876 | battle->stats->exp -= (long int)(battle->stats->exp * .10); | |
1877 | ni->stats->exp = 2000000000; | |
1878 | } | |
1879 | ||
1880 | if (2000000000 - ni->stats->gold > battle->stats->gold) | |
1881 | { | |
1882 | notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\ | |
1883 | "all gold on hand!"); | |
1884 | ni->stats->gold += battle->stats->gold; | |
1885 | battle->stats->gold = 0; | |
1886 | } | |
1887 | else | |
1888 | { | |
1889 | battle->stats->gold = 2000000000 - ni->stats->gold; | |
1890 | notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!"); | |
1891 | ||
1892 | notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\ | |
ce61cdfa | 1893 | "gold.", ni->stats->name); |
85ce9d3e | 1894 | |
1895 | notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\ | |
1896 | "left. All is not lost!", battle->stats->gold); | |
1897 | ||
1898 | ni->stats->gold = 2000000000; | |
1899 | } | |
c260a8d7 | 1900 | clearYourTurn(ni->stats); |
1901 | clearYourTurn(battle->stats); | |
85ce9d3e | 1902 | battle->stats->battle = NULL; |
1903 | ni->stats->battle = NULL; | |
1904 | return; | |
1905 | } | |
1906 | else | |
1907 | { | |
1908 | if (hit > 0) | |
1909 | battle->stats->hp -= hit; | |
ee38284f | 1910 | clearYourTurn(ni->stats); |
1911 | setYourTurn(battle->stats); | |
c260a8d7 | 1912 | display_players(battle); |
85ce9d3e | 1913 | notice(s_GameServ, u, "Please wait while %s decides what to do!", |
ce61cdfa | 1914 | battle->stats->name); |
85ce9d3e | 1915 | return; |
1916 | } | |
1917 | } | |
1918 | } | |
1919 | } | |
ce61cdfa | 1920 | |
85ce9d3e | 1921 | void do_heal(char *u) |
1922 | { | |
1923 | aClient *ni; | |
1924 | char *amount = strtok(NULL, " "); | |
1925 | int price, num; | |
1926 | ||
1927 | if (!amount) | |
1928 | { | |
1929 | notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}"); | |
40251952 | 1930 | return; |
85ce9d3e | 1931 | } |
1af35752 | 1932 | else if (!(ni = find(u))) |
1933 | { | |
1934 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
1935 | return; | |
1936 | } | |
448a1531 | 1937 | else if (isIgnore(ni)) |
1938 | { | |
1939 | #ifdef DEBUGMODE | |
1940 | log("Ignoring %s.", ni->getNick()); | |
1941 | #endif | |
1942 | return; | |
1943 | } | |
1af35752 | 1944 | else if (!is_playing(ni)) |
85ce9d3e | 1945 | { |
1946 | notice(s_GameServ, u, "You aren't playing!"); | |
1af35752 | 1947 | return; |
1948 | } | |
ee38284f | 1949 | else if (!isAlive(ni->stats)) |
1af35752 | 1950 | { |
1951 | notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing."); | |
1952 | return; | |
85ce9d3e | 1953 | } |
1af35752 | 1954 | else if (is_fighting(ni)) |
85ce9d3e | 1955 | { |
1956 | notice(s_GameServ, u, "You can't heal in battle!"); | |
40251952 | 1957 | return; |
85ce9d3e | 1958 | } |
1959 | else if (ni->stats->hp >= ni->stats->maxhp) | |
1960 | { | |
1961 | notice(s_GameServ, u, "You don't need healing!"); | |
40251952 | 1962 | return; |
85ce9d3e | 1963 | } |
40251952 | 1964 | |
1965 | updateTS(ni->stats); | |
1966 | if (stricmp(amount, "ALL") == 0) | |
85ce9d3e | 1967 | { |
1968 | price = ni->stats->level * 3; | |
1969 | if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price) | |
1970 | { | |
1971 | notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.", | |
1972 | (long int)ni->stats->gold/price, price); | |
1973 | ni->stats->hp += ni->stats->gold / price; | |
1974 | ni->stats->gold %= price; | |
1975 | } | |
1976 | else | |
1977 | { | |
1978 | notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\ | |
1979 | "per point.", price); | |
ad7dfaa0 | 1980 | notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!", |
1981 | (ni->stats->maxhp - ni->stats->hp), | |
1982 | (price * (ni->stats->maxhp - ni->stats->hp)) ); | |
85ce9d3e | 1983 | ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp); |
1984 | ni->stats->hp = ni->stats->maxhp; | |
1985 | } | |
1986 | } | |
1987 | else if (isstringnum(amount)) | |
1988 | { | |
1989 | num = stringtoint(amount); | |
1990 | price = ni->stats->level * 3; | |
1991 | if (ni->stats->gold < price * num) | |
1992 | { | |
1993 | notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!", | |
1994 | (long int)ni->stats->gold/price); | |
1995 | } | |
1996 | else if (num <= ni->stats->maxhp - ni->stats->hp) | |
1997 | { | |
1998 | notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.", | |
1999 | num, price); | |
2000 | ni->stats->hp += num; | |
2001 | ni->stats->gold -= num * price; | |
2002 | } | |
2003 | else if (num > ni->stats->maxhp - ni->stats->hp) | |
2004 | { | |
2005 | notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\ | |
2006 | "per point.", price); | |
2007 | notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!", | |
2008 | (ni->stats->maxhp - ni->stats->hp)); | |
2009 | ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp); | |
2010 | ni->stats->hp = ni->stats->maxhp; | |
2011 | } | |
2012 | } | |
2013 | else if (amount[0] == '-') | |
2014 | notice(s_GameServ, u, "You trying to cheat?"); | |
2015 | else | |
2016 | notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}"); | |
2017 | } | |
2018 | ||
2019 | int isstringnum(char *num) | |
2020 | { | |
28f552b8 | 2021 | unsigned int x; |
85ce9d3e | 2022 | for (x = 0; x < strlen(num); x++) |
2023 | { | |
2024 | if ((int)num[x] < 48 || (int)num[x] > 57) | |
2025 | return 0; | |
2026 | } | |
2027 | return 1; | |
2028 | } | |
2029 | ||
2030 | long int stringtoint(char *number) | |
2031 | { | |
2032 | long int x, len = strlen(number), sum = 0; | |
2033 | if (len == 1) | |
2034 | return chartoint(number[0]); | |
2035 | sum += chartoint(number[len - 1]); | |
2036 | for (x = len - 2; x >= 0; x--) | |
85ce9d3e | 2037 | sum += chartoint(number[x]) * pow(10, abs(x - len + 1)); |
85ce9d3e | 2038 | return sum; |
2039 | } | |
2040 | ||
2041 | long int pow(int x, int y) | |
2042 | { | |
2043 | long int value = 0; | |
2044 | int count = 0; | |
2045 | value += x; | |
2046 | ||
2047 | if (x != 0 && y != 0) | |
2048 | { | |
2049 | for (count = 1; count <= y - 1; count++) | |
2050 | value *= x; | |
2051 | } | |
2052 | else | |
2053 | return 1; | |
2054 | return value; | |
2055 | } | |
2056 | ||
2057 | long int chartoint(char ch) | |
2058 | { | |
8c126acc | 2059 | if (int(ch) >= 48 && int(ch) <= 57) |
2060 | return int(ch) - 48; | |
2061 | else | |
2062 | return 0; | |
85ce9d3e | 2063 | } |
2064 | ||
2065 | int save_gs_dbase() | |
2066 | { | |
7996e5fd | 2067 | ListNode<aClient> *ptr; |
85ce9d3e | 2068 | Player *it; |
2069 | ofstream outfile; | |
2070 | ||
2071 | outfile.open(playerdata); | |
2072 | ||
2073 | if (!outfile) | |
2074 | { | |
fb37ecc7 | 2075 | log("Error opening %s", playerdata); |
85ce9d3e | 2076 | return 0; |
2077 | } | |
2078 | ||
7996e5fd | 2079 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
2080 | { | |
2081 | ptr = players[x].First(); | |
85ce9d3e | 2082 | while(ptr) |
2083 | { | |
2084 | it = ptr->getData()->stats; | |
ae2685f6 | 2085 | clearYourTurn(it); |
85ce9d3e | 2086 | outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' ' |
2087 | << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' ' | |
ee38284f | 2088 | << it->armor << ' ' << it->weapon << ' ' |
e3c5fe46 | 2089 | << it->forest_fights << ' ' << it->player_fights << ' ' |
266608f6 | 2090 | << it->getFlags() << ' ' << it->password << ' ' << it->inventory.Healing() |
9d3b1d42 | 2091 | << ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << ' ' << it->inventory.HP() << endl; |
85ce9d3e | 2092 | ptr = ptr->Next(); |
2093 | } | |
7996e5fd | 2094 | } |
85ce9d3e | 2095 | outfile.close(); |
28f552b8 | 2096 | return 1; |
85ce9d3e | 2097 | } |
2098 | ||
2099 | int load_gs_dbase() | |
2100 | { | |
2101 | ifstream infile; | |
2102 | aClient *temp; | |
2103 | Player *p; | |
ee38284f | 2104 | char *tempname, *buf, *password; |
85ce9d3e | 2105 | buf = new char[1023]; |
2106 | ||
2107 | infile.open(playerdata); | |
2108 | ||
2109 | if (infile.fail()) | |
2110 | { | |
fb37ecc7 | 2111 | log("Error opening %s", playerdata); |
85ce9d3e | 2112 | return 0; |
2113 | } | |
2114 | ||
19795233 | 2115 | for (int x = 0; x < U_TABLE_SIZE; x++) |
2116 | { | |
2117 | ListNode<aClient> *tempNode; | |
2118 | tempNode = players[x].First(); | |
2119 | while (tempNode) | |
2120 | { | |
2121 | if (tempNode->getData()->stats->client) | |
2122 | logout(tempNode->getData()->stats->client); | |
2123 | tempNode = tempNode->Next(); | |
2124 | } | |
2125 | players[x].deleteNodes(); | |
2126 | } | |
2127 | ||
85ce9d3e | 2128 | while (infile.getline(buf, 1024, '\n')) |
2129 | { | |
2130 | temp = new aClient; | |
2131 | tempname = strtok(buf, " "); | |
2132 | temp->stats = new Player(tempname); | |
2133 | p = temp->stats; | |
2134 | ||
85ce9d3e | 2135 | p->level = stringtoint(strtok(NULL, " ")); |
2136 | p->exp = stringtoint(strtok(NULL, " ")); | |
2137 | p->gold = stringtoint(strtok(NULL, " ")); | |
2138 | p->bank = stringtoint(strtok(NULL, " ")); | |
2139 | p->hp = stringtoint(strtok(NULL, " ")); | |
2140 | p->maxhp = stringtoint(strtok(NULL, " ")); | |
2141 | p->strength = stringtoint(strtok(NULL, " ")); | |
2142 | p->defense = stringtoint(strtok(NULL, " ")); | |
2143 | p->armor = stringtoint(strtok(NULL, " ")); | |
2144 | p->weapon = stringtoint(strtok(NULL, " ")); | |
85ce9d3e | 2145 | p->forest_fights = stringtoint(strtok(NULL, " ")); |
2146 | p->player_fights = stringtoint(strtok(NULL, " ")); | |
1af35752 | 2147 | p->setFlags(stringtoint(strtok(NULL, " "))); |
ee38284f | 2148 | |
e3c5fe46 | 2149 | password = strtok(NULL, " "); |
2150 | strcpy(p->password, password); | |
448a1531 | 2151 | temp->setNick("Not Playing"); |
ce61cdfa | 2152 | #ifdef P10 |
448a1531 | 2153 | temp->setRealNick("Not Playing"); |
ce61cdfa | 2154 | #endif |
85ce9d3e | 2155 | |
9d3b1d42 | 2156 | p->inventory.reset(); // Set inventory to all 0s |
ee38284f | 2157 | // Old player databases didn't have these three extra values |
2158 | // If they come up null, leave them to 0 as the default. | |
2159 | // On the next gameserv database save, it will save the values. | |
266608f6 | 2160 | tempname = strtok(NULL, " "); |
9d3b1d42 | 2161 | if (tempname) |
2162 | p->inventory.setHealing(stringtoint(tempname)); | |
2163 | ||
2164 | tempname = strtok(NULL, " "); | |
2165 | if (tempname) | |
2166 | p->inventory.setStrength(stringtoint(tempname)); | |
2167 | ||
2168 | tempname = strtok(NULL, " "); | |
2169 | if (tempname) | |
2170 | p->inventory.setDefense(stringtoint(tempname)); | |
2171 | ||
2172 | tempname = strtok(NULL, " "); | |
2173 | if (tempname) | |
2174 | p->inventory.setHP(stringtoint(tempname)); | |
448a1531 | 2175 | unsigned long hv = iHASH((unsigned char *) temp->stats->name); |
85bcf836 | 2176 | |
2177 | temp->stats->client = NULL; | |
7996e5fd | 2178 | players[hv].insertAtBack(temp); |
85ce9d3e | 2179 | delete temp; |
2180 | } | |
1cf88153 | 2181 | delete [] buf; |
28f552b8 | 2182 | infile.close(); |
2183 | return 1; | |
85ce9d3e | 2184 | } |
2185 | ||
e3c5fe46 | 2186 | bool passcmp(char *encrypted, char *plaintext) |
2187 | { | |
2188 | char salt[3]; | |
cdc9a6db | 2189 | char *plaintext2, *plainToencrypt; |
2190 | bool same = false; | |
2191 | ||
2192 | plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra | |
2193 | strcpy(plaintext2, plaintext); | |
2194 | ||
e3c5fe46 | 2195 | salt[0] = encrypted[0]; |
2196 | salt[1] = encrypted[1]; | |
2197 | salt[3] = '\0'; | |
cdc9a6db | 2198 | |
2199 | plainToencrypt = crypt(plaintext2, salt); | |
2200 | ||
2201 | same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false); | |
2202 | ||
2203 | delete []plaintext2; | |
2204 | ||
2205 | return same; | |
e3c5fe46 | 2206 | } |
2207 | ||
2208 | bool check_password(char *name, char *plaintext) | |
2209 | { | |
0a1518fa | 2210 | aClient *client; |
e3c5fe46 | 2211 | |
0a1518fa | 2212 | if (!(client = findplayer(name))) |
2213 | return false; | |
2214 | else | |
e3c5fe46 | 2215 | { |
0a1518fa | 2216 | return passcmp(client->stats->password, plaintext); |
e3c5fe46 | 2217 | } |
e3c5fe46 | 2218 | } |
1cf88153 | 2219 | |
ad7dfaa0 | 2220 | void do_store(char *u) |
2221 | { | |
2222 | char *cmd = strtok(NULL, " "); | |
2223 | char *item = strtok(NULL, " "); | |
2224 | char *num = strtok(NULL, " "); | |
2225 | char *space; | |
8c126acc | 2226 | int wep; |
2227 | aClient *user; | |
2228 | Player *p; | |
ad7dfaa0 | 2229 | |
1af35752 | 2230 | if (!cmd || !item) |
ad7dfaa0 | 2231 | { |
2232 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2233 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2234 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
40251952 | 2235 | return; |
ad7dfaa0 | 2236 | } |
448a1531 | 2237 | else if (!(user = find(u))) |
2238 | { | |
2239 | log("Fatal Error: could not find %s in client list", u); | |
2240 | return; | |
2241 | } | |
2242 | else if (isIgnore(user)) | |
2243 | { | |
2244 | #ifdef DEBUGMODE | |
2245 | log("Ignoring %s.", user->getNick()); | |
2246 | #endif | |
2247 | return; | |
2248 | } | |
2249 | else if (!is_playing(user)) | |
40251952 | 2250 | { |
1af35752 | 2251 | notice(s_GameServ, u, "You must be playing to use the store!"); |
40251952 | 2252 | return; |
2253 | } | |
ee38284f | 2254 | else if (!isAlive(user->stats)) |
1af35752 | 2255 | { |
2256 | notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!"); | |
2257 | return; | |
2258 | } | |
40251952 | 2259 | updateTS(user->stats); |
2260 | ||
2261 | if (stricmp(cmd, "LIST") == 0) | |
ad7dfaa0 | 2262 | { |
2263 | if (stricmp(item, "WEAPONS") == 0) | |
2264 | { | |
2265 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
2266 | notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:"); | |
2267 | for (int x = 1; x < WNA; x++) | |
2268 | { | |
2269 | space = spaces(strlen(weapons[x]), "."); | |
2270 | notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, weapons[x], space, prices[x - 1]); | |
2271 | free(space); | |
2272 | } | |
2273 | notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2NUM\ 2."); | |
2274 | notice(s_GameServ, u, "Where num. is the weapon number from the menu above."); | |
2275 | ||
2276 | } | |
2277 | else if (stricmp(item, "ARMOR") == 0) | |
2278 | { | |
2279 | notice(s_GameServ, u, "Welcome to Kain's Armory"); | |
2280 | notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:"); | |
2281 | for (int x = 1; x < WNA; x++) | |
2282 | { | |
2283 | space = spaces(strlen(armors[x]), "."); | |
2284 | notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, armors[x], space, prices[x - 1]); | |
2285 | free(space); | |
2286 | } | |
2287 | notice(s_GameServ, u, "To purchase armor, type /msg %S store buy armor num."); | |
2288 | notice(s_GameServ, u, "Where num. is the armor number from the menu above."); | |
2289 | ||
2290 | ||
2291 | } | |
2292 | } else if (stricmp(cmd, "BUY") == 0) { | |
8c126acc | 2293 | if (!num) |
2294 | { | |
2295 | notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2296 | return; | |
2297 | } | |
2298 | else if (!isstringnum(num)) | |
2299 | { | |
2300 | notice(s_GameServ, u, "You must specify a number between 1 and %d. Not %s!", WNA - 1, num); | |
2301 | return; | |
2302 | } | |
2303 | if (stricmp(item, "WEAPON") == 0) | |
2304 | { | |
2305 | wep = stringtoint(num); | |
2306 | if (wep >= WNA || wep < 1) | |
2307 | { | |
2308 | notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1); | |
2309 | return; | |
2310 | } | |
2311 | ||
2312 | p = user->stats; | |
2313 | ||
2314 | if (p->weapon != 0) | |
2315 | notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]); | |
2316 | else if (p->gold < prices[wep - 1]) | |
2317 | notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]); | |
2318 | else | |
2319 | { | |
2320 | notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]); | |
2321 | p->weapon = wep; | |
2322 | p->gold -= prices[wep - 1]; | |
2323 | } | |
2324 | } | |
2325 | else if (stricmp(item, "ARMOR") == 0) | |
2326 | { | |
2327 | wep = stringtoint(num); | |
2328 | if (wep >= WNA || wep < 1) | |
2329 | { | |
2330 | notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1); | |
2331 | return; | |
2332 | } | |
2333 | ||
2334 | p = user->stats; | |
2335 | ||
2336 | if (p->armor != 0) | |
2337 | notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]); | |
2338 | else if (p->gold < prices[wep - 1]) | |
2339 | notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]); | |
2340 | else | |
2341 | { | |
2342 | notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]); | |
2343 | p->armor = wep; | |
2344 | p->gold -= prices[wep - 1]; | |
2345 | } | |
2346 | } | |
2347 | } | |
2348 | else if (stricmp(cmd, "SELL" ) == 0) | |
2349 | { | |
2350 | p = user->stats; | |
2351 | ||
2352 | if (stricmp(item, "WEAPON") == 0) | |
2353 | { | |
2354 | if (p->weapon == 0) | |
2355 | { | |
2356 | notice(s_GameServ, u, "You want me to chop off your hands?"); | |
2357 | return; | |
2358 | } | |
2359 | else if (p->gold == 2000000000) | |
2360 | { | |
2361 | notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire."); | |
2362 | p->weapon = 0; | |
2363 | } | |
2364 | else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2)) | |
2365 | { | |
2366 | notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry."); | |
2367 | notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]); | |
2368 | p->gold = 2000000000; | |
2369 | p->weapon = 0; | |
2370 | } | |
2371 | else | |
2372 | { | |
2373 | notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2)); | |
2374 | p->gold += (prices[p->weapon - 1] / 2); | |
2375 | p->weapon = 0; | |
2376 | } | |
2377 | } | |
2378 | else if (stricmp(item, "ARMOR") == 0) | |
2379 | { | |
2380 | p = user->stats; | |
2381 | ||
2382 | if (p->armor == 0) | |
2383 | { | |
2384 | notice(s_GameServ, u, "I don't think you can be any more naked..."); | |
2385 | return; | |
2386 | } | |
2387 | if (p->gold == 2000000000) | |
2388 | { | |
2389 | notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire."); | |
2390 | p->armor = 0; | |
2391 | } | |
2392 | else if (2000000000 - p->gold < (prices[p->armor - 1] / 2)) | |
2393 | { | |
2394 | notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry."); | |
2395 | notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]); | |
2396 | p->gold = 2000000000; | |
2397 | p->armor = 0; | |
2398 | } | |
2399 | else | |
2400 | { | |
2401 | notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!", | |
2402 | (prices[p->armor - 1] / 2)); | |
2403 | ||
2404 | p->gold += (prices[p->armor - 1] / 2); | |
2405 | p->armor = 0; | |
2406 | } | |
2407 | } | |
2408 | else | |
2409 | { | |
2410 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2411 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2412 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2413 | } | |
2414 | } | |
6d053d90 | 2415 | else |
2416 | { | |
2417 | notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}"); | |
2418 | notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2"); | |
2419 | notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2"); | |
2420 | return; | |
2421 | } | |
8c126acc | 2422 | } |
9cda831c | 2423 | void do_inventory(char *u) |
2424 | { | |
2425 | aClient *user; | |
2426 | ||
2427 | if (!(user = find(u))) | |
2428 | { | |
2429 | notice(s_GameServ, u, "Fatal Error. Contact a %S admin!"); | |
2430 | return; | |
2431 | } | |
448a1531 | 2432 | else if (isIgnore(user)) |
2433 | { | |
2434 | #ifdef DEBUGMODE | |
2435 | log("Ignoring %s.", user->getNick()); | |
2436 | #endif | |
2437 | return; | |
2438 | } | |
9cda831c | 2439 | else if (!is_playing(user)) |
2440 | { | |
2441 | notice(s_GameServ, u, "You must be playing to check your inventory!"); | |
2442 | return; | |
2443 | } | |
40251952 | 2444 | updateTS(user->stats); |
9cda831c | 2445 | showinventory(user, user); |
2446 | } | |
2447 | void showinventory(aClient *from, aClient *to) | |
2448 | { | |
2449 | char *nick = to->getNick(); | |
8c126acc | 2450 | |
9cda831c | 2451 | if (!to) |
2452 | to = from; | |
2453 | if (is_playing(from)) | |
2454 | { | |
2455 | Pouch *p = &from->stats->inventory; | |
ce61cdfa | 2456 | notice(s_GameServ, nick, "Inventory for %s:", from->stats->name); |
9cda831c | 2457 | notice(s_GameServ, nick, " Healing Potions: %d", p->Healing()); |
2458 | notice(s_GameServ, nick, "Strength Potions: %d", p->Strength()); | |
2459 | notice(s_GameServ, nick, " Defense Potions: %d", p->Defense()); | |
9d3b1d42 | 2460 | notice(s_GameServ, nick, " HP Potions: %d", p->HP()); |
9cda831c | 2461 | } |
2462 | } | |
f5c25639 | 2463 | void do_tavern(char *u) |
2464 | { | |
2465 | char *cmd = strtok(NULL, " "); | |
2466 | long int price; | |
2467 | ||
2468 | aClient *user; | |
2469 | Player *p; | |
a6352eed | 2470 | |
f5c25639 | 2471 | if (!(user = find(u))) |
2472 | { | |
2473 | notice(s_GameServ, u, "Fatal Error. See a %S admin for help"); | |
2474 | return; | |
2475 | } | |
448a1531 | 2476 | else if (isIgnore(user)) |
2477 | { | |
2478 | #ifdef DEBUGMODE | |
2479 | log("Ignoring %s.", user->getNick()); | |
2480 | #endif | |
2481 | return; | |
2482 | } | |
f5c25639 | 2483 | else if (!is_playing(user)) |
2484 | { | |
2485 | notice(s_GameServ, u, "You must be playing to go to the Tavern"); | |
2486 | return; | |
2487 | } | |
9cda831c | 2488 | else if (is_fighting(user)) |
2489 | { | |
2490 | notice(s_GameServ, u, "You cannot go to the Tavern during a fight!"); | |
2491 | return; | |
2492 | } | |
40251952 | 2493 | |
2494 | updateTS(user->stats); | |
f5c25639 | 2495 | p = user->stats; |
40251952 | 2496 | |
f5c25639 | 2497 | if (!cmd) |
2498 | { | |
2499 | notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary"); | |
2500 | notice(s_GameServ, u, "Your commands:"); | |
2501 | notice(s_GameServ, u, "/msg %S TAVERN {LIST | BUY} [NUMBER]"); | |
2502 | notice(s_GameServ, u, "What'll it be?"); | |
2503 | } | |
2504 | else if (stricmp(cmd, "LIST") == 0) | |
2505 | { | |
a6352eed | 2506 | notice(s_GameServ, u, "Here is a list of what we have to offer:"); |
2507 | notice(s_GameServ, u, "1. Healing Potions for %ld Gold", | |
2508 | 1000 * p->level * 4); | |
2509 | notice(s_GameServ, u, "2. Strength Potions for %ld Gold", | |
2510 | 2500 * p->level * 4); | |
2511 | notice(s_GameServ, u, "3. Defense Potions for %ld Gold", | |
2512 | 3000 * p->level * 4); | |
2513 | notice(s_GameServ, u, "4. HP Potions for %ld Gold", | |
2514 | 2000 * p->level * 4); | |
2515 | notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #"); | |
2516 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!"); | |
f5c25639 | 2517 | } |
2518 | else if (stricmp(cmd, "BUY") == 0) | |
2519 | { | |
2520 | char *chnum = strtok(NULL, " "); | |
f5c25639 | 2521 | |
2522 | if (!chnum) | |
2523 | { | |
2524 | notice(s_GameServ, u, "SYNTAX: TAVERN BUY #"); | |
2525 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1"); | |
2526 | return; | |
2527 | } | |
19795233 | 2528 | int num = stringtoint(chnum); |
2529 | ||
8c734eb9 | 2530 | if (num < 1 || num > 4) |
f5c25639 | 2531 | { |
2532 | notice(s_GameServ, u, "Invalid Choice!"); | |
2533 | notice(s_GameServ, u, "Here is a list of what we have to offer:"); | |
a6352eed | 2534 | notice(s_GameServ, u, "1. Healing Potions for %ld Gold", |
2535 | 1000 * p->level * 4); | |
2536 | notice(s_GameServ, u, "2. Strength Potions for %ld Gold", | |
2537 | 2500 * p->level * 4); | |
2538 | notice(s_GameServ, u, "3. Defense Potions for %ld Gold", | |
2539 | 3000 * p->level * 4); | |
2540 | notice(s_GameServ, u, "4. HP Potions for %ld Gold", | |
2541 | 2000 * p->level * 4); | |
f5c25639 | 2542 | notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #"); |
2543 | notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!"); | |
ee38284f | 2544 | return; |
f5c25639 | 2545 | } |
2546 | switch(num) | |
2547 | { | |
2548 | case 1: | |
a6352eed | 2549 | price = (1000 * p->level * 4); |
f5c25639 | 2550 | if (p->gold >= price) |
2551 | { | |
2552 | notice(s_GameServ, u, "One healing potion coming right up!"); | |
2553 | p->inventory.incHealing(); | |
ee38284f | 2554 | p->gold -= price; |
f5c25639 | 2555 | } |
2556 | else | |
2557 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2558 | break; | |
2559 | case 2: | |
a6352eed | 2560 | price = 2500 * p->level * 4; |
f5c25639 | 2561 | if (p->gold >= price) |
2562 | { | |
2563 | notice(s_GameServ, u, "One strength boost coming right up!"); | |
2564 | p->inventory.incStrength(); | |
ee38284f | 2565 | p->gold -= price; |
f5c25639 | 2566 | } |
2567 | else | |
2568 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2569 | break; | |
2570 | case 3: | |
a6352eed | 2571 | price = 3000 * p->level * 4; |
f5c25639 | 2572 | if (p->gold >= price) |
2573 | { | |
2574 | notice(s_GameServ, u, "One defense boost coming right up!"); | |
2575 | p->inventory.incDefense(); | |
ee38284f | 2576 | p->gold -= price; |
f5c25639 | 2577 | } |
2578 | else | |
2579 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2580 | break; | |
8c734eb9 | 2581 | case 4: |
a6352eed | 2582 | price = 3000 * p->level * 4; |
8c734eb9 | 2583 | if (p->gold >= price) |
2584 | { | |
2585 | notice(s_GameServ, u, "One HP Potion coming right up!"); | |
2586 | p->inventory.incHP(); | |
2587 | p->gold -= price; | |
2588 | } | |
2589 | else | |
2590 | notice(s_GameServ, u, "You don't have enough gold!"); | |
2591 | break; | |
f5c25639 | 2592 | default: |
2593 | notice(s_GameServ, u, "Logical Error. See a %S admin for help!"); | |
2594 | break; | |
2595 | } | |
2596 | } | |
9cda831c | 2597 | else |
2598 | { | |
2599 | notice(s_GameServ, u, "Improper Syntax."); | |
2600 | notice(s_GameServ, u, "Type /msg %S HELP TAVERN for help"); | |
2601 | } | |
f5c25639 | 2602 | } |
2603 | ||
8c126acc | 2604 | void do_bank(char *u) |
2605 | { | |
2606 | char *cmd = strtok(NULL, " "); | |
2607 | char *amount = strtok(NULL, " "); | |
2608 | char *nick = strtok(NULL, " "); | |
2609 | ||
2610 | aClient *user; | |
2611 | Player *p; | |
2612 | ||
8c734eb9 | 2613 | if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick)) |
8c126acc | 2614 | { |
2615 | notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}"); | |
e282e9d2 | 2616 | notice (s_GameServ, u, "BANK BALANCE"); |
8c126acc | 2617 | return; |
2618 | } | |
40251952 | 2619 | else if (!(user = find(u))) |
2620 | { | |
2621 | notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) %S "\ | |
2622 | " admin for help"); | |
2623 | log("Fatal Error. Couldn't find %s while executing do_bank()", u); | |
2624 | return; | |
2625 | } | |
448a1531 | 2626 | else if (isIgnore(user)) |
2627 | { | |
2628 | #ifdef DEBUGMODE | |
2629 | log("Ignoring %s.", user->getNick()); | |
2630 | #endif | |
2631 | return; | |
2632 | } | |
40251952 | 2633 | else if (!is_playing(user)) |
8c126acc | 2634 | { |
2635 | notice(s_GameServ, u, "You must be playing to use the bank!"); | |
2636 | return; | |
ad7dfaa0 | 2637 | } |
2158299e | 2638 | else if (is_fighting(user)) |
2639 | { | |
2640 | notice(s_GameServ, u, "You can't go to the bank during a fight!"); | |
2641 | return; | |
2642 | } | |
40251952 | 2643 | updateTS(user->stats); |
2644 | if (stricmp(cmd, "BALANCE") == 0) | |
fa376453 | 2645 | { |
2646 | showBankBalance(u); | |
2647 | return; | |
2648 | } | |
ee38284f | 2649 | else if (!isAlive(user->stats)) |
1af35752 | 2650 | { |
2651 | notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!"); | |
2652 | return; | |
2653 | } | |
8c126acc | 2654 | else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0) |
2655 | { | |
2656 | notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!"); | |
2657 | return; | |
2658 | } | |
11f32a66 | 2659 | if (stringtoint(amount) < 0) |
2660 | { | |
2661 | notice(s_GameServ, u, "Sorry. This bank is not licensed "\ | |
2662 | "to handle such sums of cash, noble Lord."); | |
2663 | return; | |
2664 | } | |
8c126acc | 2665 | p = user->stats; |
2666 | ||
fa376453 | 2667 | if (stricmp(cmd, "DEPOSIT") == 0) |
8c126acc | 2668 | { |
2669 | if (p->bank == 2000000000) | |
2670 | { | |
2671 | notice(s_GameServ, u, "Your bank account is full, sire!"); | |
2672 | return; | |
2673 | } | |
2674 | else if (stricmp(amount, "ALL") == 0) | |
2675 | { | |
2676 | if (2000000000 - p->bank < p->gold) | |
2677 | { | |
2678 | notice(s_GameServ, u, "You don't have enough room for all of your gold."); | |
2679 | notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->bank)); | |
2680 | p->gold -= (2000000000 - p->bank); | |
2681 | p->bank = 2000000000; | |
e282e9d2 | 2682 | showBankBalance(u); |
8c126acc | 2683 | } |
2684 | else | |
2685 | { | |
2686 | notice(s_GameServ, u, "Depositing %ld gold into your account!", p->gold); | |
2687 | p->bank += p->gold; | |
2688 | p->gold = 0; | |
e282e9d2 | 2689 | showBankBalance(u); |
8c126acc | 2690 | } |
2691 | } | |
2692 | else if (stringtoint(amount) > p->gold) | |
2693 | { | |
2694 | notice(s_GameServ, u, "Sire, you only have %ld gold!", p->gold); | |
e282e9d2 | 2695 | showBankBalance(u); |
8c126acc | 2696 | return; |
2697 | } | |
2698 | else | |
2699 | { | |
2700 | if (2000000000 - p->bank < stringtoint(amount)) | |
2701 | { | |
2702 | notice(s_GameServ, u, "You don't have room in your account for that much."); | |
2703 | notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->bank)); | |
2704 | p->gold -= (2000000000 - p->bank); | |
2705 | p->bank = 2000000000; | |
e282e9d2 | 2706 | showBankBalance(u); |
8c126acc | 2707 | } |
2708 | else | |
2709 | { | |
2710 | notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount)); | |
2711 | p->bank += stringtoint(amount); | |
2712 | p->gold -= stringtoint(amount); | |
e282e9d2 | 2713 | showBankBalance(u); |
8c126acc | 2714 | } |
2715 | } | |
2716 | } | |
2717 | else if (stricmp(cmd, "WITHDRAW") == 0) | |
2718 | { | |
2719 | if (p->gold == 2000000000) | |
2720 | { | |
2721 | notice(s_GameServ, u, "You cannot carry any more gold, sire!"); | |
e282e9d2 | 2722 | showBankBalance(u); |
8c126acc | 2723 | return; |
2724 | } | |
2725 | else if (stricmp(amount, "ALL") == 0) | |
2726 | { | |
2727 | if (2000000000 - p->gold < p->bank) | |
2728 | { | |
2729 | notice(s_GameServ, u, "You don't have enough room to carry all that gold."); | |
2730 | notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->gold)); | |
2731 | p->bank -= (2000000000 - p->gold); | |
2732 | p->gold = 2000000000; | |
e282e9d2 | 2733 | showBankBalance(u); |
8c126acc | 2734 | } |
2735 | else | |
2736 | { | |
2737 | notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->bank); | |
2738 | p->gold += p->bank; | |
2739 | p->bank = 0; | |
e282e9d2 | 2740 | showBankBalance(u); |
8c126acc | 2741 | } |
2742 | } | |
2743 | else if (stringtoint(amount) > p->bank) | |
2744 | { | |
2745 | notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->bank); | |
e282e9d2 | 2746 | showBankBalance(u); |
8c126acc | 2747 | return; |
2748 | } | |
2749 | else | |
2750 | { | |
2751 | if (2000000000 - p->gold < stringtoint(amount)) | |
2752 | { | |
2753 | notice(s_GameServ, u, "You don't enough have room to carry that much gold!"); | |
2754 | notice(s_GameServ, u, "You fill your pockets with %ld gold!", | |
2755 | (2000000000 - p->gold)); | |
2756 | p->bank -= (2000000000 - p->gold); | |
2757 | p->gold = 2000000000; | |
e282e9d2 | 2758 | showBankBalance(u); |
8c126acc | 2759 | } |
2760 | else | |
2761 | { | |
2762 | notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount)); | |
2763 | p->gold += stringtoint(amount); | |
2764 | p->bank -= stringtoint(amount); | |
e282e9d2 | 2765 | showBankBalance(u); |
8c126acc | 2766 | } |
2767 | } | |
2768 | } | |
2769 | ||
ad7dfaa0 | 2770 | } |
ab4f4ec0 | 2771 | |
fcca861d | 2772 | void do_dragon(char *u) |
2773 | { | |
2774 | aClient *user; | |
2775 | ||
2776 | if (!(user = find(u))) | |
2777 | { | |
2778 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2779 | return; | |
2780 | } | |
2781 | else if (isIgnore(user)) | |
2782 | { | |
2783 | #ifdef DEBUGMODE | |
2784 | log("Ignoring %s.", user->getNick()); | |
2785 | #endif | |
2786 | return; | |
2787 | } | |
2788 | else if (!is_playing(user)) | |
2789 | { | |
2790 | notice(s_GameServ, u, "You must be playing to fight the dragon!"); | |
2791 | return; | |
2792 | } | |
2793 | else if (is_fighting(user)) | |
2794 | { | |
2795 | notice(s_GameServ, u, "You are already in a fight. How will you fight the almighty dragon!?"); | |
2796 | return; | |
2797 | } | |
2798 | else if (!isAlive(user->stats)) | |
2799 | { | |
2800 | notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!"); | |
2801 | return; | |
2802 | } | |
016a160f | 2803 | else if (user->stats->level < REALLEVELS) |
fcca861d | 2804 | { |
2805 | notice(s_GameServ, u, "You fool! Only those strong enough "\ | |
2806 | "to vanquish any foe should DARE fight the dragon!"); | |
2807 | notice(s_GameServ, u, "To put it in terms you can understand: "\ | |
016a160f | 2808 | "You are too weak. You must be Level %d!", REALLEVELS); |
68379f96 | 2809 | return; |
fcca861d | 2810 | } |
2811 | ||
2812 | updateTS(user->stats); | |
2813 | ||
fcca861d | 2814 | Player *p = user->stats; |
2815 | p->fight = new Monster(boss); | |
2816 | notice(s_GameServ, u, "You approach the dragon's lair cautiously."); | |
2817 | notice(s_GameServ, u, "The stench of sulfer fills the air as a "\ | |
2818 | "deep, red fog rolls in. The air is filled with the "\ | |
2819 | "heated mist of deadly fire from beyond the cave "\ | |
2820 | "entrance."); | |
9cb6f227 | 2821 | notice(s_GameServ, u, "You adjust your %s, tighten your grip on "\ |
fcca861d | 2822 | "your %s, and venture into the hot, dark cave. "\ |
2823 | "You are surprised at the angle of descent as you climb "\ | |
2824 | "lower and lower, deeper into the dragon's den."); | |
2825 | notice(s_GameServ, u, "You come to the end of the cave to find "\ | |
2826 | "a tooth. It is a large tooth... bigger than your torso."\ | |
2827 | " Suddenly the darkness lifts from the gleam of an eye "\ | |
2828 | " staring into your soul! The eye is large... HUGE!"); | |
2829 | notice(s_GameServ, u, "Just then you notice the eye begin to "\ | |
2830 | "glare orange! The tooth is moving... but it is still too "\ | |
2831 | "dark for you to make out.... THE DRAGON! You see it!"); | |
9cb6f227 | 2832 | display_monster(u); |
fcca861d | 2833 | } |
2834 | ||
ab4f4ec0 | 2835 | void do_master(char *u) |
2836 | { | |
2837 | aClient *user; | |
1af35752 | 2838 | |
448a1531 | 2839 | |
2840 | if (!(user = find(u))) | |
ab4f4ec0 | 2841 | { |
2842 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2843 | return; | |
2844 | } | |
448a1531 | 2845 | else if (isIgnore(user)) |
2846 | { | |
2847 | #ifdef DEBUGMODE | |
2848 | log("Ignoring %s.", user->getNick()); | |
2849 | #endif | |
2850 | return; | |
2851 | } | |
c047f947 | 2852 | else if (!is_playing(user)) |
2853 | { | |
2854 | notice(s_GameServ, u, "You must be playing to see your master!"); | |
2855 | return; | |
2856 | } | |
1af35752 | 2857 | else if (is_fighting(user)) |
ab4f4ec0 | 2858 | { |
2859 | notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!"); | |
2860 | return; | |
2861 | } | |
ee38284f | 2862 | else if (!isAlive(user->stats)) |
1af35752 | 2863 | { |
2864 | notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!"); | |
2865 | return; | |
2866 | } | |
40251952 | 2867 | |
2868 | updateTS(user->stats); | |
c047f947 | 2869 | |
c7340cbd | 2870 | char *cmd = strtok(NULL, " "); |
2871 | Player *p = user->stats; | |
2872 | long int need = 0; | |
2873 | ||
1af35752 | 2874 | if (seenMaster(p)) |
2875 | { | |
2876 | notice(s_GameServ, u, "You have already seen your master today. Wait until tomorrow to try again"); | |
2877 | return; | |
2878 | } | |
2879 | ||
c7340cbd | 2880 | if (cmd != NULL) |
ab4f4ec0 | 2881 | { |
ab4f4ec0 | 2882 | switch(p->level) |
2883 | { | |
2884 | case 1: | |
fcca861d | 2885 | need = 200; |
ab4f4ec0 | 2886 | break; |
2887 | case 2: | |
fcca861d | 2888 | need = 800; |
ab4f4ec0 | 2889 | break; |
2890 | case 3: | |
fcca861d | 2891 | need = 2000; |
ab4f4ec0 | 2892 | break; |
2893 | case 4: | |
fcca861d | 2894 | need = 8000; |
ab4f4ec0 | 2895 | break; |
2896 | case 5: | |
fcca861d | 2897 | need = 20000; |
ab4f4ec0 | 2898 | break; |
2899 | case 6: | |
fcca861d | 2900 | need = 80000; |
ab4f4ec0 | 2901 | break; |
2902 | case 7: | |
fcca861d | 2903 | need = 200000; |
ab4f4ec0 | 2904 | break; |
2905 | case 8: | |
fcca861d | 2906 | need = 800000; |
ab4f4ec0 | 2907 | break; |
2908 | case 9: | |
fcca861d | 2909 | need = 2000000; |
ab4f4ec0 | 2910 | break; |
2911 | case 10: | |
fcca861d | 2912 | need = 8000000; |
ab4f4ec0 | 2913 | break; |
2914 | case 11: | |
fcca861d | 2915 | need = 20000000; |
ab4f4ec0 | 2916 | break; |
016a160f | 2917 | |
2918 | case REALLEVELS: | |
ab4f4ec0 | 2919 | need = p->exp + 1; |
016a160f | 2920 | notice(s_GameServ, u, "You are at level %d. You are the master. What's left? The DRAGON!", REALLEVELS); |
fcca861d | 2921 | return; |
ab4f4ec0 | 2922 | break; |
2923 | default: | |
2924 | need = p->exp + 1; // Unknown level... don't let them fight a fake master! | |
2925 | break; | |
c7340cbd | 2926 | } |
2927 | } | |
2928 | else | |
2929 | { | |
2930 | notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}"); | |
2931 | return; | |
2932 | } | |
2933 | ||
2934 | if (stricmp(cmd, "FIGHT") == 0) | |
2935 | { | |
ab4f4ec0 | 2936 | if (p->exp >= need) |
1af35752 | 2937 | { |
2938 | setMaster(p); | |
ab4f4ec0 | 2939 | see_master(u); |
1af35752 | 2940 | } |
ab4f4ec0 | 2941 | else |
2942 | notice(s_GameServ, u, "You are not worthy of fighting %s! You need %ld more experience.", masters[p->level - 1]->name, (need - p->exp)); | |
c7340cbd | 2943 | return; |
2944 | } | |
2945 | else if (stricmp(cmd, "QUESTION") == 0) | |
2946 | { | |
2947 | if (p->exp >= need) | |
2948 | notice(s_GameServ, u, "%s looks you up and down and decides you are more ready than you will ever be.", masters[p->level - 1]->name); | |
2949 | else | |
2950 | notice(s_GameServ, u, "You pathetic fool! You are no match for %s, %s!", masters[p->level - 1]->name, p->name); | |
2951 | ||
2952 | return; | |
2953 | } | |
2954 | else | |
2955 | { | |
2956 | notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}"); | |
ab4f4ec0 | 2957 | } |
2958 | } | |
2959 | ||
2960 | void see_master(char *u) | |
2961 | { | |
2962 | aClient *user; | |
1af35752 | 2963 | |
ab4f4ec0 | 2964 | if (!(user = find(u))) |
2965 | { | |
2966 | notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, "")); | |
2967 | return; | |
2968 | } | |
2969 | ||
1af35752 | 2970 | if (!is_fighting(user) && is_playing(user)) |
ab4f4ec0 | 2971 | { |
2972 | Player *p = user->stats; | |
2973 | p->master = new Monster(masters[p->level - 1]); | |
2974 | p->fight = p->master; | |
2975 | display_monster(u); // Since master is the same structure, use this function | |
2976 | } | |
2977 | } | |
e282e9d2 | 2978 | |
2979 | void showBankBalance(const char *u) | |
2980 | { | |
2981 | aClient *user; | |
2982 | Player *p; | |
1af35752 | 2983 | |
e282e9d2 | 2984 | if (!(user = find(u))) |
2985 | return; | |
2986 | ||
2987 | p = user->stats; | |
2988 | ||
2989 | if (!p) | |
2990 | return; | |
2991 | ||
2992 | notice(s_GameServ, u, "Account Balance: %ld Gold On hand: %ld", p->bank, p->gold); | |
2993 | ||
2994 | } | |
44ea29f7 | 2995 | |
2996 | void refreshall() | |
2997 | { | |
2998 | ListNode <aClient> *it; | |
2999 | Player *p; | |
7996e5fd | 3000 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
3001 | { | |
3002 | it = players[x].First(); | |
44ea29f7 | 3003 | |
3004 | while (it) | |
3005 | { | |
3006 | p = it->getData()->stats; | |
3007 | refresh(p); | |
3008 | it = it->Next(); | |
3009 | } | |
7996e5fd | 3010 | } |
44ea29f7 | 3011 | } |
3012 | ||
3013 | void refresh(Player *p) | |
3014 | { | |
3015 | if (!p) | |
3016 | return; | |
3017 | ||
ee38284f | 3018 | if (p->hp < p->maxhp) |
3019 | p->hp = p->maxhp; | |
20d5d721 | 3020 | p->forest_fights = forestfights; |
44ea29f7 | 3021 | p->player_fights = 3; |
ee38284f | 3022 | setAlive(p); |
1af35752 | 3023 | clearMaster(p); |
44ea29f7 | 3024 | } |
c7340cbd | 3025 | |
3026 | void do_refresh(char *u) | |
3027 | { | |
3028 | char *nick = strtok(NULL, " "); | |
3029 | aClient *user; | |
3030 | ||
96f71fee | 3031 | if (!(user = find(u))) |
3032 | { | |
3033 | notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 3034 | log("Error: aClient not found: %s", u); |
96f71fee | 3035 | return; |
3036 | } | |
448a1531 | 3037 | else if (isIgnore(user)) |
3038 | { | |
3039 | #ifdef DEBUGMODE | |
3040 | log("Ignoring %s.", user->getNick()); | |
3041 | #endif | |
3042 | return; | |
3043 | } | |
96f71fee | 3044 | else if (!isAdmin(user)) |
3045 | { | |
3046 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
3047 | return; | |
3048 | } | |
c7340cbd | 3049 | if (!nick) |
3050 | { | |
96f71fee | 3051 | notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}"); |
c7340cbd | 3052 | return; |
3053 | } | |
3054 | else if (stricmp(nick, "ALL") == 0) | |
3055 | { | |
3056 | notice(s_GameServ, u, "Refreshing everyone's stats!"); | |
3057 | refreshall(); | |
3058 | } | |
ae2685f6 | 3059 | else if ((user = findplayer(nick))) |
c7340cbd | 3060 | { |
1af35752 | 3061 | if (is_playing(user)) |
c7340cbd | 3062 | { |
ce61cdfa | 3063 | #ifdef P10 |
3064 | notice(s_GameServ, u, "Refreshing %s.", user->getRealNick()); | |
3065 | #else | |
c7340cbd | 3066 | notice(s_GameServ, u, "Refreshing %s.", user->getNick()); |
ce61cdfa | 3067 | #endif |
c7340cbd | 3068 | refresh(user->stats); |
3069 | } | |
3070 | else | |
3071 | { | |
ce61cdfa | 3072 | #ifdef P10 |
3073 | notice(s_GameServ, u, "%s is not playing.", user->getRealNick()); | |
3074 | #else | |
c7340cbd | 3075 | notice(s_GameServ, u, "%s is not playing.", user->getNick()); |
ce61cdfa | 3076 | #endif |
c7340cbd | 3077 | } |
3078 | } | |
3079 | else | |
3080 | { | |
3081 | notice(s_GameServ, u, "Nick %s not found.", nick); | |
3082 | return; | |
3083 | } | |
3084 | } | |
3085 | ||
ee38284f | 3086 | |
3087 | void resetall() | |
3088 | { | |
3089 | ListNode <aClient> *it; | |
3090 | Player *p; | |
3091 | ||
7996e5fd | 3092 | for (unsigned long x = 0; x < U_TABLE_SIZE; x++) |
3093 | { | |
3094 | it = players[x].First(); | |
ee38284f | 3095 | |
3096 | while (it) | |
3097 | { | |
3098 | p = it->getData()->stats; | |
3099 | reset(p); | |
3100 | it = it->Next(); | |
3101 | } | |
7996e5fd | 3102 | } |
ee38284f | 3103 | } |
3104 | ||
3105 | void reset(Player *p) | |
3106 | { | |
3107 | if (!p) | |
3108 | return; | |
3109 | ||
3110 | p->reset(); | |
3111 | } | |
3112 | ||
40251952 | 3113 | void updateTS(Player *p) |
3114 | { | |
3115 | if (!p) | |
3116 | return; | |
0b6098d5 | 3117 | |
3118 | #ifdef DEBUGMODE | |
3119 | log("Old timestamp for %s: %ld", p->name, p->lastcommand); | |
3120 | #endif | |
40251952 | 3121 | p->lastcommand = time(NULL); |
0b6098d5 | 3122 | #ifdef DEBUGMODE |
3123 | log("New timestamp for %s: %ld", p->name, p->lastcommand); | |
3124 | #endif | |
3125 | ||
40251952 | 3126 | } |
3127 | ||
3128 | bool timedOut(Player *p) | |
3129 | { | |
3130 | if (!p) | |
3131 | return false; | |
0b6098d5 | 3132 | else if (p->lastcommand == 0) |
3133 | return false; | |
40251952 | 3134 | else |
0b6098d5 | 3135 | { |
3136 | if ((time(NULL) - p->lastcommand) >= maxidletime) | |
3137 | return true; | |
3138 | ||
3139 | return false; | |
3140 | } | |
40251952 | 3141 | } |
3142 | ||
3143 | void timeOutEvent(Player *p) | |
3144 | { | |
0b6098d5 | 3145 | aClient *user = findplayer(p->name); |
40251952 | 3146 | |
ae2685f6 | 3147 | if (!user || !p->client) // then they're not playing |
40251952 | 3148 | return; |
3149 | ||
3150 | char *nick = user->getNick(); | |
3151 | ||
0b6098d5 | 3152 | if (player_fight(user) && isYourTurn(p)) |
3153 | { | |
3154 | // Check to see if they were the idler or if it was the other | |
3155 | // person | |
3156 | if (p->lastcommand != p->battle->stats->lastcommand) | |
3157 | { | |
3158 | // This person's last command was given earlier, | |
3159 | // so this person is the idler | |
3160 | notice(s_GameServ, nick, "You timed out "\ | |
3161 | "during a fight. You lose your turn!"); | |
3162 | notice(s_GameServ, p->battle->getNick(), | |
3163 | "%s hesitated for too long. Your move.", p->name); | |
3164 | clearYourTurn(p); | |
3165 | setYourTurn(p->battle->stats); | |
3166 | ||
3167 | // Update the TS for both players to give them another | |
3168 | // Chance to wake up, but if the other player doesn't | |
3169 | // Attack now, they both get logged out. | |
3170 | updateTS(p); | |
3171 | p->battle->stats->lastcommand = p->lastcommand; | |
3172 | display_players(p->battle); | |
3173 | return; | |
3174 | } | |
3175 | else | |
3176 | { | |
3177 | notice(s_GameServ, p->battle->getNick(), | |
3178 | "You and %s timed out at the same time."\ | |
3179 | " Don't fight if you're just going to "\ | |
3180 | "sit there!", p->name); | |
3181 | notice(s_GameServ, user->getNick(), | |
3182 | "You and %s timed out at the same time."\ | |
3183 | " Don't fight if you're just going to "\ | |
3184 | "sit there!", p->battle->stats->name); | |
3185 | logout(p->battle); | |
3186 | logout(user); | |
3187 | return; | |
3188 | } | |
3189 | } | |
3190 | else if (!player_fight(user)) | |
eb7608de | 3191 | { |
c047f947 | 3192 | if (isAlive(user->stats) && user->stats->gold > 0) |
903cd861 | 3193 | { |
eb7608de | 3194 | // Place fun stuff here :) |
3195 | int randnum = 1 + rand() % 100; // 1-100 | |
0b259dff | 3196 | #define GSN(s) notice(s_GameServ, nick, s) |
3197 | #define GSN2(s, f) notice(s_GameServ, nick, s, f) | |
eb7608de | 3198 | |
3199 | if (randnum < 50) | |
3200 | { | |
0b259dff | 3201 | // 35-100% of your gold goes pffft - kain |
3202 | int stolen = (35 + (rand() % 66)) * user->stats->gold / 100; | |
3203 | ||
eb7608de | 3204 | GSN("You stop for a moment to rest on the "\ |
3205 | "street corner. All of a sudden, you "\ | |
3206 | "are ambushed from all sides by a hoarde "\ | |
3207 | "of knife wielding thugs."); | |
3208 | GSN2("The thugs beat you into utter submission "\ | |
3209 | "and steal %d gold from you!", stolen); | |
3210 | user->stats->gold -= stolen; | |
3211 | } | |
0b259dff | 3212 | else if (randnum >= 50 && randnum < 75) |
3213 | { | |
3214 | // 25-65% of your gold goes pffft - kain | |
3215 | int stolen = (25 + (rand() % 41)) * user->stats->gold / 100; | |
3216 | GSN("While dilly dallying around, you lose "\ | |
3217 | "your sense of time. Little did you know, "\ | |
3218 | "but thieves lifted your gold while you "\ | |
3219 | "weren't watching."); | |
3220 | GSN2("Better luck next time... you lose %d gold", stolen); | |
3221 | user->stats->gold -= stolen; | |
3222 | } | |
3223 | else if (randnum >= 75) | |
3224 | { | |
3225 | // 25-75% of your gold goes pffft - kain | |
3226 | int stolen = (25 + (rand() % 51)) * user->stats->gold / 100; | |
3227 | GSN("Good grief! A gaggle of gooey green ghostlike "\ | |
3228 | "goblins grabbed your gold!"); | |
3229 | GSN2("They stole %d gold from you!", stolen); | |
3230 | user->stats->gold -= stolen; | |
3231 | } | |
903cd861 | 3232 | } |
eb7608de | 3233 | |
3234 | // Always log out the user | |
0b6098d5 | 3235 | logout(user); |
eb7608de | 3236 | } |
40251952 | 3237 | } |
3238 | ||
ee38284f | 3239 | void do_reset(char *u) |
3240 | { | |
3241 | char *nick = strtok(NULL, " "); | |
3242 | aClient *user; | |
3243 | ||
3244 | if (!(user = find(u))) | |
3245 | { | |
3246 | notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin"); | |
5d04eb42 | 3247 | log("Error: aClient not found: %s", u); |
ee38284f | 3248 | return; |
3249 | } | |
3250 | else if (!isAdmin(user)) | |
3251 | { | |
3252 | notice(s_GameServ, u, "You must be a %S admin to use this command!"); | |
3253 | return; | |
3254 | } | |
448a1531 | 3255 | |
ee38284f | 3256 | if (!nick) |
3257 | { | |
3258 | notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}"); | |
3259 | return; | |
3260 | } | |
3261 | else if (stricmp(nick, "ALL") == 0) | |
3262 | { | |
3263 | notice(s_GameServ, u, "Resetting everyone's stats!"); | |
3264 | resetall(); | |
3265 | } | |
ce61cdfa | 3266 | else if ((user = findbyrealnick(nick))) |
ee38284f | 3267 | { |
3268 | if (is_playing(user)) | |
3269 | { | |
ce61cdfa | 3270 | #ifdef P10 |
3271 | notice(s_GameServ, u, "Resetting %s.", user->getRealNick()); | |
3272 | #else | |
ee38284f | 3273 | notice(s_GameServ, u, "Resetting %s.", user->getNick()); |
ce61cdfa | 3274 | #endif |
ee38284f | 3275 | reset(user->stats); |
3276 | } | |
3277 | else | |
3278 | { | |
ce61cdfa | 3279 | #ifdef P10 |
3280 | notice(s_GameServ, u, "%s is not playing.", user->getRealNick()); | |
3281 | #else | |
ee38284f | 3282 | notice(s_GameServ, u, "%s is not playing.", user->getNick()); |
ce61cdfa | 3283 | #endif |
ee38284f | 3284 | } |
3285 | } | |
3286 | else | |
3287 | { | |
3288 | notice(s_GameServ, u, "Nick %s not found.", nick); | |
3289 | return; | |
3290 | } | |
3291 | } | |
3292 | ||
c7340cbd | 3293 | void do_help(char *u) |
3294 | { | |
3295 | char *cmd = strtok(NULL, " "); | |
3296 | ||
c7340cbd | 3297 | display_help(u, cmd); |
3298 | } | |
3299 | ||
3300 | void display_help(char *u, char *file) | |
3301 | { | |
3302 | ifstream infile; | |
3303 | char *buf; | |
3304 | ||
3305 | if (!file) | |
3306 | { | |
3307 | infile.open("helpfiles/help"); | |
3308 | if (infile.fail()) | |
3309 | { | |
fb37ecc7 | 3310 | log("Error opening helpfiles/help"); |
c7340cbd | 3311 | notice(s_GameServ, u, "Error opening helpfiles/help"); |
3312 | return; | |
3313 | } | |
3314 | buf = new char[1024]; | |
3315 | while(infile.getline(buf, 1024)) | |
3316 | { | |
3317 | // Written this way, it will process %S in the helpfiles | |
3318 | // Instead of notice(s_GameServ, u, "%s", buf); | |
3319 | notice(s_GameServ, u, buf); | |
3320 | } | |
3321 | ||
3322 | // Minor recursion | |
96f71fee | 3323 | aClient *user = find(u); |
3324 | if (user && isAdmin(user)) | |
3325 | display_help(u, "admin_commands"); | |
c7340cbd | 3326 | } |
3327 | else | |
3328 | { | |
3329 | char *filename; | |
f27a378f | 3330 | filename = new char[strlen(file) + 11]; |
3331 | strcpy(filename, "helpfiles/"); | |
3332 | strcat(filename, file); | |
4dde2ed9 | 3333 | |
f27a378f | 3334 | for (unsigned int x = 10; x < strlen(filename); x++) |
3335 | filename[x] = tolower(filename[x]); | |
4dde2ed9 | 3336 | |
c7340cbd | 3337 | infile.open(filename); |
3338 | delete [] filename; | |
3339 | if (infile.fail()) | |
3340 | { | |
3341 | notice(s_GameServ, u, "No help for \ 2%s\ 2", file); | |
3342 | return; | |
3343 | } | |
3344 | buf = new char[1024]; | |
3345 | while(infile.getline(buf, 1024)) | |
3346 | { | |
3347 | // Written this way, it will process %S in the helpfiles | |
3348 | // Instead of notice(s_GameServ, u, "%s", buf); | |
3349 | notice(s_GameServ, u, buf); | |
3350 | } | |
3351 | } | |
3352 | infile.close(); | |
3353 | delete [] buf; | |
3354 | } | |
96f71fee | 3355 | |
3356 | void do_admin(char *u) | |
3357 | { | |
3358 | aClient *user; | |
3359 | char *pass = strtok(NULL, " "); | |
3360 | ||
3361 | if (!(user = find(u))) | |
3362 | { | |
5d04eb42 | 3363 | log("Error: aClient not found: %s", u); |
96f71fee | 3364 | notice(s_GameServ, u, "Error: aClient not found. Contact %S admin."); |
3365 | return; | |
3366 | } | |
448a1531 | 3367 | |
96f71fee | 3368 | if (!pass) |
3369 | { | |
3370 | notice(s_GameServ, u, "SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2"); | |
3371 | return; | |
3372 | } | |
3373 | ||
1af35752 | 3374 | if (isAdmin(user)) |
3375 | { | |
3376 | notice(s_GameServ, u, "You already have administrator privledges."); | |
3377 | return; | |
3378 | } | |
3379 | else if (strcmp(pass, adminpass) == 0) | |
96f71fee | 3380 | { |
3381 | notice(s_GameServ, u, "Password accepted. You now have administrator privledges."); | |
3382 | setAdmin(user); | |
ce61cdfa | 3383 | #ifdef P10 |
3384 | log("%s became an administrator.", user->getRealNick()); | |
3385 | #else | |
5d04eb42 | 3386 | log("%s became an administrator.", user->getNick()); |
ce61cdfa | 3387 | #endif |
96f71fee | 3388 | } |
3389 | else | |
3390 | { | |
3391 | notice(s_GameServ, u, "Invalid password. Remember: case sensitive"); | |
3392 | return; | |
3393 | } | |
3394 | } | |
1af35752 | 3395 | |
4dde2ed9 | 3396 | bool load_monsters() |
3397 | { | |
3398 | ifstream infile; | |
3399 | infile.open("monsters.dat"); | |
3400 | ||
3401 | char *buf; | |
3402 | ||
3403 | if (infile.fail()) | |
3404 | { | |
fb37ecc7 | 3405 | log("Error opening monsters.dat"); |
4dde2ed9 | 3406 | return false; |
3407 | } | |
3408 | init_monsters(); | |
3409 | buf = new char[2048]; | |
3410 | ||
5d04eb42 | 3411 | #ifdef DEBUGMODE |
3412 | log("Loading monsters from monsters.dat"); | |
3413 | #endif | |
3414 | ||
4dde2ed9 | 3415 | for (int l = 0; l < REALLEVELS; l++) |
3416 | { | |
3417 | for (int m = 0; m < MONSTERS;) | |
3418 | { | |
3419 | infile.getline(buf, 2048); | |
3420 | if (buf[0] == '\n' || buf[0] == '\0' || buf[0] == '#') | |
3421 | continue; | |
3422 | else | |
3423 | { | |
3424 | strcpy(monsters[l][m]->name, strtok(buf, "~")); | |
3425 | strcpy(monsters[l][m]->weapon, strtok(NULL, "~")); | |
3426 | monsters[l][m]->strength = stringtoint(strtok(NULL, "~")); | |
3427 | monsters[l][m]->gold = stringtoint(strtok(NULL, "~")); | |
3428 | monsters[l][m]->exp = stringtoint(strtok(NULL, "~")); | |
3429 | monsters[l][m]->maxhp = stringtoint(strtok(NULL, "~")); | |
ee38284f | 3430 | monsters[l][m]->hp = monsters[l][m]->maxhp; |
4dde2ed9 | 3431 | strcpy(monsters[l][m]->death, strtok(NULL, "")); |
3432 | m++; | |
3433 | } | |
3434 | } | |
3435 | } | |
3436 | delete [] buf; | |
3437 | return true; | |
3438 | } |