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