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