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