]> jfr.im git - irc/gameservirc.git/blame - gameserv/gameserv.cpp
Took out all #include lines from the extern.h, and changed them to forward declaratio...
[irc/gameservirc.git] / gameserv / gameserv.cpp
CommitLineData
96f71fee 1#include "aClient.h"
c1068b6e 2#include "config.h"
3#include "extern.h"
37ed80a9 4#include "player.h"
5#include "pouch.h"
96f71fee 6#include "flags.h"
586cf465 7#include "level.h"
96f71fee 8#include "sockhelp.h"
37ed80a9 9#include "item.h"
67b4ac9a 10#include "script.h"
8cd4c581 11#include "toplist.h"
96f71fee 12
c10b78ac 13#include <algorithm>
85ce9d3e 14#include <cctype>
fb37ecc7 15#include <fstream>
9fe7af4c 16#include <stdlib.h>
37ed80a9 17#include <list>
18#include <iterator>
fb37ecc7 19
37ed80a9 20using namespace std;
c1068b6e 21
22#if defined(HAVE_CRYPT_H)
23
e3c5fe46 24#include <crypt.h>
85ce9d3e 25
c1068b6e 26#elif defined(HAVE_UNISTD_H)
27
28#include <unistd.h>
29
30#endif
c8ada07e 31
8e800549 32Monster dragon; // The current dragon
42106907 33Level levels[LEVELS]; // The newest way to store monsters
cd973e97 34list<item*> Items; // The master list of items
d1927afc 35list<tavernItem> tavern; // The list of items available at the tavern
3f107f27 36list<item*> store; // The list of items available at the store
8cd4c581 37toplist myToplist; // List of the top 10 players
bf3a2ff9 38
a8fb9757 39// Database functions
85ce9d3e 40int save_gs_dbase();
41int load_gs_dbase();
cd973e97 42int load_items();
d1927afc 43int load_tavern();
3f107f27 44int load_store();
8e800549 45int load_dragon();
46int save_dragon();
85ce9d3e 47
d1927afc 48item *findItemByID(int id);
e401a866 49item *findStoreItemByID(int id);
19894227 50tavernItem *findTavernItemByID(int id);
d1927afc 51
85ce9d3e 52// String functions
653c4f62 53#ifndef HAVE_STRTOK
85ce9d3e 54char *strtok(char *str, const char *delim);
653c4f62 55#endif
56
85ce9d3e 57int stricmp(const char *s1, const char *s2);
58int strnicmp(const char *s1, const char *s2, size_t len);
59// String Functions
60
e3c5fe46 61/********** Password functions **********/
62
5c449fde 63bool passcmp(const char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
e3c5fe46 64
65bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
bbb7e9be 66
e3c5fe46 67/********** Password functions **********/
68
69
70/********** GameServ Booleans **********/
71
05c527e6 72bool shuttingdown;
40251952 73bool timedOut(Player *p);
14e24ba1 74void updateTS(Player *p);
40251952 75void timeOutEvent(Player *p);
76
e3c5fe46 77bool is_playing(char *u); // True if the given nickname in the clients list is playing.
1af35752 78bool is_playing(aClient *user);
79
e3c5fe46 80bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
1af35752 81bool is_fighting(aClient *user);
82
e3c5fe46 83bool player_fight(char *u); // True if the player is fighting another player.
1af35752 84bool player_fight(aClient *user);
85
e3c5fe46 86bool master_fight(char *u); // True if the player is fighting their master.
1af35752 87bool master_fight(aClient *user);
e3c5fe46 88
fd270bdd 89bool dragon_fight(char *u); // True if the player is fighting the dragon.
90bool dragon_fight(aClient *user);
91
bbb7e9be 92bool alphaNumeric(const char *str); // Returns true if all of the characters in str are alphanumeric non-special chars
e3c5fe46 93/********** GameServ Booleans **********/
85ce9d3e 94
c7340cbd 95void display_help(char *u, char *file = NULL);
85ce9d3e 96void display_monster(char *u);
97void display_players(char *u);
83cf716f 98void display_players(aClient *user);
85ce9d3e 99long int chartoint(char ch);
100int isstringnum(char *num);
101long int pow (int x, int y);
102long int stringtoint(char *number);
103
104char *spaces(int len, char *seperator);
44ea29f7 105void refresh(Player *p);
85ce9d3e 106void refreshall();
1fe6fccd 107void rollover(Player *p);
108void rolloverall();
109
40251952 110void updateTS(Player *p);
ee38284f 111void reset(Player *p);
5c449fde 112bool load_masters();
4dde2ed9 113bool load_monsters();
ea93c39a 114bool load_levels();
c8ada07e 115void delete_monsters();
85ce9d3e 116
96f71fee 117void do_admin(char *u);
c7340cbd 118void do_attack(char *u);
119void do_bank(char *u);
70065ca1 120void do_check(char *u);
1781f48a 121void do_equip(char *u);
c7340cbd 122void do_fight(char *u);
123void do_heal(char *u);
124void do_help(char *u);
85ce9d3e 125void do_identify(char *u);
9cda831c 126void do_inventory(char *u);
c7340cbd 127void do_refresh(char *u);
128void do_register(char *u);
129void do_list(char *u);
b0359af9 130void do_logout(char *u);
c7340cbd 131void do_master(char *u);
fcca861d 132void do_dragon(char *u);
85ce9d3e 133void do_play(char *u);
134void do_quitg(char *u);
135void do_reset(char *u);
85ce9d3e 136void do_run(char *u);
1563e73b 137void do_set(char *u);
85ce9d3e 138void do_stats(char *u);
c7340cbd 139void do_store(char *u);
f5c25639 140void do_tavern(char *u);
83cf716f 141void do_use(char *u);
c7340cbd 142void see_master(char *u);
85ce9d3e 143
b0359af9 144void logout(aClient *user);
85ce9d3e 145void showstats(const char *u, const char *nick);
1e7678e9 146void showTavern(aClient *user);
228a25d5 147void showinventory(Player *from, aClient *to);
e282e9d2 148void showBankBalance(const char *u);
83cf716f 149void end_turn(aClient *user);
85ce9d3e 150
151#define WNA 16
85ce9d3e 152
153int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
154int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
155int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
156
85ce9d3e 157void gameserv(char *source, char *buf)
158{
c10b78ac 159 char *cmd, z;
160 cmd = strtok(buf, " ");
161
162#ifndef P10
163 source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
164#endif
165
166 z = cmd[0];
167 if (z == ':')
168 cmd++; // Get rid of that : at the beginning of the :text (command)
169
170#ifdef DEBUGMODE
171 log("Source: %s Command: %s", source, cmd);
172#endif
173
174 if (strnicmp(cmd, "\1PING", 6) == 0)
85ce9d3e 175 {
c10b78ac 176 char *ts;
177 ts = strtok(NULL, "\1");
178 notice(s_GameServ, source, "\1PING %s\1", ts);
179 }
180 else if (stricmp(cmd, "\1VERSION\1") == 0)
181 {
182 notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION);
183 }
184 else if (stricmp(cmd, "SEARCH") == 0)
185 {
186 cmd = strtok(NULL, " ");
187
188 if (!cmd)
85ce9d3e 189 notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST");
c10b78ac 190 else
85ce9d3e 191 do_forest(source);
c10b78ac 192
193 }
194 else if (stricmp(cmd, "ADMIN") == 0)
195 {
196 do_admin(source);
197 }
198 else if (stricmp(cmd, "ATTACK") == 0)
199 {
200 do_attack(source);
201 }
202 else if (stricmp(cmd, "BANK") == 0)
203 {
204 do_bank(source);
205 }
206 else if (stricmp(cmd, "CHECK") == 0)
207 {
208 do_check(source);
209 }
210 else if (stricmp(cmd, "DRAGON") == 0)
211 {
212 do_dragon(source);
213 }
214 else if (stricmp(cmd, "EQUIP") == 0)
215 {
1781f48a 216 do_equip(source);
c10b78ac 217 }
218 else if (stricmp(cmd, "FIGHT") == 0)
96f71fee 219 {
c10b78ac 220 do_fight(source);
221 }
222 else if (stricmp(cmd, "HEAL") == 0)
45a84400 223 {
c10b78ac 224 do_heal(source);
225 }
226 else if (stricmp(cmd, "HELP") == 0)
96f71fee 227 {
c10b78ac 228 do_help(source);
229 }
230 else if (stricmp(cmd, "IDENTIFY") == 0)
96f71fee 231 {
c10b78ac 232 do_identify(source);
233 }
234 else if (stricmp(cmd, "INVENTORY") == 0)
96f71fee 235 {
c10b78ac 236 do_inventory(source);
237 }
238 else if (stricmp(cmd, "LIST") == 0)
96f71fee 239 {
c10b78ac 240 do_list(source);
241 }
242 else if (stricmp(cmd, "LOGOUT") == 0)
243 {
244 do_logout(source);
245 }
246 else if (stricmp(cmd, "MASTER") == 0)
247 {
248 do_master(source);
249 }
250 else if (stricmp(cmd, "NEWS") == 0)
251 {
252 do_news(source);
253 }
254 else if (stricmp(cmd, "REGISTER") == 0)
255 {
256 do_register(source);
257 }
258 else if (stricmp(cmd, "REFRESH") == 0)
259 {
260 do_refresh(source);
261 }
262 else if (stricmp(cmd, "RESET") == 0)
263 {
264 do_reset(source);
265 }
266 else if (stricmp(cmd, "RUN") == 0)
267 {
268 do_run(source);
269 }
270 else if (stricmp(cmd, "SET") == 0)
271 {
272 do_set(source);
273 }
274 else if (stricmp(cmd, "STATS") == 0)
275 {
276 do_stats(source);
277 }
278 else if (stricmp(cmd, "STORE") == 0)
279 {
280 do_store(source);
281 }
282 else if (stricmp(cmd, "TAVERN") == 0)
283 {
284 do_tavern(source);
285 }
286 else if (stricmp(cmd, "USE") == 0)
287 {
288 do_use(source);
289 }
290 else if (stricmp(cmd, "SHUTDOWN") == 0)
291 {
292 aClient *user;
293
294 if (!(user = find(source)))
295 {
296 notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
297 log("Error: aClient not found: %s", source);
298 }
299 else if (!isAdmin(user))
300 {
301 notice(s_GameServ, source, "You must be a %S admin to use this command!");
302 }
303 else
304 {
305 save_gs_dbase();
306#ifdef P10
307 raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername, user->getRealNick());
308#else
309 raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source);
310#endif
311 shuttingdown = true;
312 }
313 }
314 else if (stricmp(cmd, "SAVE") == 0)
315 {
316 aClient *user;
317
318 if (!(user = find(source)))
319 {
320 notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
321 log("Error: aClient not found: %s", source);
322 }
323 else if (!isAdmin(user))
324 {
325 notice(s_GameServ, source, "You must be a %S admin to use this command!");
326 }
327 else
45a84400 328 {
c10b78ac 329 save_gs_dbase();
330 }
331 }
332 else if (stricmp(cmd, "LOAD") == 0)
96f71fee 333 {
c10b78ac 334 aClient *user;
335
336 if (!(user = find(source)))
337 {
338 notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
339 log("Error: aClient not found: %s", source);
340 }
341 else if (!isAdmin(user))
342 {
343 notice(s_GameServ, source, "You must be a %S admin to use this command!");
344 }
345 else
346 {
347 char *cmd2 = strtok(NULL, " ");
348 if (!cmd2)
349 {
350 notice(s_GameServ, source, "Loading player data from %s", playerdata);
351 load_gs_dbase();
352 }
353 else if (stricmp(cmd2, "MONSTERS") == 0)
354 {
355 notice(s_GameServ, source, "Loading monster data");
356 load_monsters();
357 }
67b4ac9a 358 else if (stricmp(cmd2, "SCRIPTS") == 0)
359 {
360 // Testing scripts for now
361 script scr;
362 notice(s_GameServ, source, "Loading scripts");
363
364 if (scr.loadScript("test.txt"))
365 scr.executeScript(user->stats);
366 }
c10b78ac 367 else
368 {
369 display_help(source, cmd);
370 }
371 }
96f71fee 372 }
c10b78ac 373#ifdef DEBUGMODE
374 else if (stricmp(cmd, "RAW") == 0)
96f71fee 375 {
c10b78ac 376 aClient *user;
377
378 if (!(user = find(source)))
379 {
380 notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
381 log("Error: aClient not found: %s", source);
382 }
383 else if (!isAdmin(user))
384 {
385 notice(s_GameServ, source, "You must be a %S admin to use this command!");
386 }
387 else
45a84400 388 {
c10b78ac 389 char *rest = strtok(NULL, "");
390 raw("%s", rest);
391 }
392 }
393 else if (stricmp(cmd, "RANDOM") == 0)
448a1531 394 {
c10b78ac 395 char *rstr = strtok(NULL, "");
396 range trange;
397 trange.setRange(rstr);
398 notice(s_GameServ, source, "Random number in that range: %d", trange.random());
448a1531 399 }
c10b78ac 400#endif
401 else
402 {
403 aClient *user;
404 if ((user = find(source)))
405 {
406 if (isIgnore(user))
407 {
408#ifdef DEBUGMODE
409 log("Ignoring %s.", user->getNick());
410#endif
411 }
412 else
413 {
414 notice(s_GameServ, source, "Unknown command \002%s\002. Type /msg %S \002HELP\002 to get a list of commands.", cmd);
415 }
416 }
417 }
85ce9d3e 418
c10b78ac 419#ifndef P10
420 source--; // Bring the ':' back so we don't leak memory
421#endif
422 if (z == ':')
448a1531 423 cmd--; // Same thing :)
85ce9d3e 424}
425
426int stricmp(const char *s1, const char *s2)
427{
428 register int c;
429
430 while ((c = tolower(*s1)) == tolower(*s2)) {
431 if (c == 0)
432 return 0;
433 s1++;
434 s2++;
435 }
436 if (c < tolower(*s2))
437 return -1;
438 return 1;
439}
440
441void showstats(const char *u, const char *nick)
442{
d61f68e3 443 aClient *sender = find(u);
444 Player *p;
85ce9d3e 445 char *buf;
446 buf = new char[50];
447 char *space;
448
449
d61f68e3 450 if (!(p = findplayer(nick)))
228a25d5 451 {
85ce9d3e 452 notice(s_GameServ, u, "%s not found", nick);
228a25d5 453 }
4230019f 454 else
228a25d5 455 {
d61f68e3 456 notice(s_GameServ, sender->getNick(), "Stats for %s:", p->getName().c_str());
228a25d5 457
d61f68e3 458 sprintf(buf, "Experience: %ld", p->getExp());
85ce9d3e 459 space = spaces(strlen(buf), " ");
460 notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space,
d61f68e3 461 p->getLevel());
1cf88153 462 delete [] space;
228a25d5 463
d61f68e3 464 sprintf(buf, "Gold: %ld", p->getGold());
85ce9d3e 465 space = spaces(strlen(buf), " ");
d61f68e3 466 notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, p->getBank());
1cf88153 467 delete [] space;
228a25d5 468
d61f68e3 469 notice(s_GameServ, sender->getNick(), "Hit Points: %d of %d", p->getHP(),
470 p->getMaxHP());
228a25d5 471
d61f68e3 472 sprintf(buf, "Strength: %d", p->getStrength());
85ce9d3e 473 space = spaces(strlen(buf), " ");
474 notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
d61f68e3 475 buf, space, p->getDefense());
1cf88153 476 delete [] space;
228a25d5 477
d61f68e3 478 sprintf(buf, "Armor: %s", (p->getArmor() ? p->getArmor()->getName().c_str() : "Nothing"));
85ce9d3e 479 space = spaces(strlen(buf), " ");
228a25d5 480
85ce9d3e 481 notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
d61f68e3 482 (p->getWeapon() ? p->getWeapon()->getName().c_str() : "Fists"));
228a25d5 483
1cf88153 484 delete [] space;
228a25d5 485
d61f68e3 486 sprintf(buf, "Forest Fights: %d", p->getForestFights());
85ce9d3e 487 space = spaces(strlen(buf), " ");
d61f68e3 488 notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, p->getPlayerFights());
1cf88153 489 delete [] space;
d61f68e3 490 if (p->getClient() == sender || isAdmin(sender))
228a25d5 491 {
d61f68e3 492 showinventory(p, sender);
228a25d5 493 }
494 }
4230019f 495
1cf88153 496 delete [] buf;
85ce9d3e 497}
498
499char *spaces(int len, char *seperator)
500{
501 char *final;
42ec1800 502 final = new char[30];
85ce9d3e 503 int y;
504 strcpy(final, seperator);
42ec1800 505 for (y = 0; y < 30 - len; y++)
85ce9d3e 506 strcat(final, seperator);
507 return final;
508}
509
510void raw(const char *fmt, ...)
511{
512 va_list args;
513 char *input;
514 const char *t = fmt;
515 input = new char[1024];
516 va_start(args, fmt);
517 memset(input, 0, sizeof(input)); // Initialize to NULL
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
540
85ce9d3e 541 sprintf(input, "%s%s", input, "\r\n");
85ce9d3e 542 sock_puts(sock, input);
1cf88153 543 delete [] input;
85ce9d3e 544 va_end(args);
545}
546/* Send a NOTICE from the given source to the given nick. */
547
548void notice(const char *source, const char *dest, const char *fmt, ...)
549{
c7340cbd 550 if (fmt[0] == '\0')
551 return;
552
9bafc40d 553 char *commanduse;
554 commanduse = new char[16];
555
556 #ifdef P10
6f727d4c 557 if (isUsePrivmsg())
558 strcpy(commanduse, "P");
9bafc40d 559 else
a51121e0 560 strcpy(commanduse, "O");
9bafc40d 561 #else
562
6f727d4c 563 if (isUsePrivmsg())
564 strcpy(commanduse, "PRIVMSG");
9bafc40d 565 else
6f727d4c 566 strcpy(commanduse, "NOTICE");
9bafc40d 567 #endif
568
85ce9d3e 569 va_list args;
570 char *input;
571 const char *t = fmt;
572 input = new char[1024];
573 va_start(args, fmt);
574 if (dest[0] == ':')
575 {
576 dest++;
ba2a880f 577
578 #if !defined(P10)
9bafc40d 579 sprintf(input, ":%s %s %s :", source, commanduse, dest);
ba2a880f 580 #else
9bafc40d 581 sprintf(input, "%s %s %s :", gsnum, commanduse, dest);
ba2a880f 582 #endif
583
85ce9d3e 584 dest--;
585 }
586 else
ba2a880f 587 {
588 #if !defined(P10)
9bafc40d 589 sprintf(input, ":%s %s %s :", source, commanduse, dest);
ba2a880f 590 #else
9bafc40d 591 sprintf(input, "%s %s %s :", gsnum, commanduse, dest);
ba2a880f 592 #endif
593 }
85ce9d3e 594
595 for (; *t; t++)
596 {
597 if (*t == '%')
598 {
599 switch(*++t) {
600 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
601 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
602 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
d1927afc 603 case 'c': sprintf(input, "%s%c", input, va_arg(args, int)); break;
85ce9d3e 604 case 'l':
605 if (*++t == 'd')
606 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
607 }
608 }
609 else
610 {
611 sprintf(input, "%s%c", input, *t);
612 }
613
614 }
9f8c2acc 615 #ifdef DEBUGMODE
616 log("Input: %s", input);
617 #endif
85ce9d3e 618 sprintf(input, "%s%s", input, "\r\n");
85ce9d3e 619 sock_puts(sock, input);
9bafc40d 620 delete [] commanduse;
1cf88153 621 delete [] input;
85ce9d3e 622va_end(args);
623}
624
625
626int strnicmp(const char *s1, const char *s2, size_t len)
627{
628 register int c;
629
630 if (!len)
631 return 0;
632 while ((c = tolower(*s1)) == tolower(*s2) && len > 0) {
633 if (c == 0 || --len == 0)
634 return 0;
635 s1++;
636 s2++;
637 }
638 if (c < tolower(*s2))
639 return -1;
640 return 1;
641}
642
653c4f62 643#ifndef HAVE_STRTOK
85ce9d3e 644char *strtok(char *str, const char *delim)
645{
646 static char *current = NULL;
647 char *ret;
648
649 if (str)
650 current = str;
651 if (!current)
652 return NULL;
653 current += strspn(current, delim);
654 ret = *current ? current : NULL;
655 current += strcspn(current, delim);
656 if (!*current)
657 current = NULL;
658 else
659 *current++ = 0;
660 return ret;
661}
653c4f62 662#endif
85ce9d3e 663
70065ca1 664void do_check(char *u)
665{
666 int days, hours, minutes, seconds;
667 long complete;
668 complete = (lastrefresh + refreshperiod) - time(NULL);
669 days = complete / 86400;
670 hours = (complete % 86400) / 3600;
671 minutes = (complete % 86400) % 3600 / 60;
672 seconds = (complete % 86400) % 3600 % 60;
673
674 notice(s_GameServ, u, "Time left to next refresh: %dd %dh %dm %ds",
675 days, hours, minutes, seconds);
1fe6fccd 676
677 if (isRolloverForestFights())
678 {
679 complete = (lastrollover + rolloverperiod) - time(NULL);
680
681 days = complete / 86400;
682 hours = (complete % 86400) / 3600;
683 minutes = (complete % 86400) % 3600 / 60;
684 seconds = (complete % 86400) % 3600 % 60;
685
686 notice(s_GameServ, u, "Time left to next rollover: %dd %dh %dm %ds",
687 days, hours, minutes, seconds);
688 }
70065ca1 689}
690
85ce9d3e 691void do_list(char *u)
692{
c10b78ac 693 aClient *user;
d61f68e3 694 Player *p;
c10b78ac 695 char *cmd = strtok(NULL, " ");
696
697 if (!(user = find(u)))
448a1531 698 {
c10b78ac 699 log("Fatal Error: Couldn't find %s in the client list", u);
700 return;
448a1531 701 }
c10b78ac 702 else if (isIgnore(user))
448a1531 703 {
c10b78ac 704#ifdef DEBUGMODE
705 log("Ignoring %s. Command LIST", user->getNick());
706#endif
707 return;
448a1531 708 }
c10b78ac 709
d61f68e3 710 list<Player*>::iterator iter;
c10b78ac 711 bool header = false;
448a1531 712
7996e5fd 713 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
85ce9d3e 714 {
c10b78ac 715 iter = players[x].begin();
716 if (!players[x].empty())
717 {
718 while(iter != players[x].end())
719 {
d61f68e3 720 p = (*iter);
721 if (cmd || is_playing(p->getClient()))
c10b78ac 722 {
723 if (!header)
724 {
725 notice(s_GameServ, u, "Players:");
726 header = true;
727 }
728#ifdef P10
d61f68e3 729 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getRealNick() : "Not Playing"),
730 p->getName().c_str());
c10b78ac 731#else
d61f68e3 732 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getNick() : "Not Playing"),
733 p->getName().c_str());
c10b78ac 734#endif
735 }
736 iter++;
737 }
738 }
85ce9d3e 739 }
c10b78ac 740 if (!header)
85ce9d3e 741 notice(s_GameServ, u, "No one is playing");
c10b78ac 742 else
743 notice(s_GameServ, u, "End of List");
85ce9d3e 744}
c10b78ac 745
1563e73b 746void do_set(char *u)
747{
d61f68e3 748 aClient *user;
749 Player *p;
1563e73b 750 char *name = strtok(NULL, " ");
751 char *cmd = strtok(NULL, " ");
752 char *cmd2;
753
754 if (!(user = find(u)))
755 {
756 notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
53d5585b 757 "Buf: %s LOGOUT", u);
1563e73b 758 return;
759 }
760 else if (isIgnore(user))
761 {
762#ifdef DEBUGMODE
763 log("Ignoring %s.", user->getNick());
764#endif
765 return;
766 }
53d5585b 767 else if (!name || !cmd)
1563e73b 768 {
37ed80a9 769 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
1563e73b 770 return;
771 }
d61f68e3 772 else if (!(p = findplayer(name)))
1563e73b 773 {
774 // Back the pointers up... they didn't send a name probably
53d5585b 775 cmd2 = cmd;
1563e73b 776 cmd = name;
d61f68e3 777 p = user->stats;
53d5585b 778
1563e73b 779 if (!is_playing(user))
53d5585b 780 {
781 notice(s_GameServ, u, "You must be playing to set things for yourself!");
782 return;
783 }
1563e73b 784 }
785 else
786 {
787 cmd2 = strtok(NULL, " ");
788 }
53d5585b 789 if (!cmd2)
790 {
791 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
792 return;
793 }
794
1563e73b 795 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
796 if (stricmp(cmd, "PASSWORD") == 0)
797 {
798 // Person is looking to change their password
799 // If they're an admin, or it's theirself, allow it
800 // cmd2 is pointing to the password now
d61f68e3 801 if (isAdmin(user) || user == p->getClient())
53d5585b 802 {
d61f68e3 803 p->setPassword(cmd2);
53d5585b 804 notice(s_GameServ, u, "Password successfully changed");
805 }
d61f68e3 806 else if (user != p->getClient() && !isAdmin(user))
53d5585b 807 {
808 notice(s_GameServ, u, "You must be a %S admin to set other peoples' passwords.");
809 return;
810 }
1563e73b 811 }
812 else if (stricmp(cmd, "BANK") == 0 || stricmp(cmd, "BALANCE") == 0)
813 {
53d5585b 814 if (!isAdmin(user))
815 {
816 notice(s_GameServ, u, "Admins Only!");
817 return;
818 }
819 else if (stricmp(cmd, "BANK") == 0)
820 {
821 cmd2 = strtok(NULL, " "); // Need an extra parameter for set bank balance
822 }
823 if (!cmd2)
824 {
825 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>");
826 return;
827 }
828
d61f68e3 829 p->setBank(stringtoint(cmd2));
53d5585b 830
d61f68e3 831 notice(s_GameServ, u, "Bank balance changed to %ld!", p->getBank());
1563e73b 832 }
833 else if (stricmp(cmd, "PLAYER") == 0)
834 {
835 if (!isAdmin(user))
53d5585b 836 {
837 notice(s_GameServ, u, "Admins Only!");
838 return;
839 }
1563e73b 840 else if (stricmp(cmd2, "FIGHTS") != 0)
53d5585b 841 {
842 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
843 return;
844 }
1563e73b 845 else
53d5585b 846 {
847 cmd2 = strtok(NULL, " ");
848 if (!cmd2)
849 {
850 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
851 return;
852 }
d61f68e3 853 p->setPlayerFights(stringtoint(cmd2));
53d5585b 854
d61f68e3 855 notice(s_GameServ, u, "Player fights changed to %d!", p->getPlayerFights());
53d5585b 856 }
1563e73b 857 }
858 else if (stricmp(cmd, "FOREST") == 0)
859 {
860 if (!isAdmin(user))
53d5585b 861 {
862 notice(s_GameServ, u, "Admins Only!");
863 return;
864 }
1563e73b 865 else if (stricmp(cmd2, "FIGHTS") != 0)
53d5585b 866 {
867 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>");
868 return;
869 }
1563e73b 870 else
53d5585b 871 {
872 cmd2 = strtok(NULL, " ");
873 if (!cmd2)
874 {
875 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>");
876 return;
877 }
878
d61f68e3 879 p->setForestFights(stringtoint(cmd2));
53d5585b 880
d61f68e3 881 notice(s_GameServ, u, "Forest fights changed to %d!", p->getForestFights());
53d5585b 882 }
1563e73b 883 }
cbd4ede4 884 else if (stricmp(cmd, "GOLD") == 0)
6b72281b 885 {
53d5585b 886 if (!isAdmin(user))
887 {
888 notice(s_GameServ, u, "Admins Only!");
889 return;
890 }
891 else
892 {
893 if (!cmd2)
894 {
895 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>");
896 return;
897 }
d61f68e3 898 p->setGold(stringtoint(cmd2));
53d5585b 899
d61f68e3 900 notice(s_GameServ, u, "Gold set to %ld", p->getGold());
53d5585b 901 return;
902 }
6b72281b 903 }
6b72281b 904 else if (stricmp(cmd, "STRENGTH") == 0 && stricmp(cmd2, "POTIONS") != 0)
6b72281b 905 {
53d5585b 906 if (!isAdmin(user))
907 {
908 notice(s_GameServ, u, "Admins Only!");
909 return;
910 }
911 else
912 {
913 if (!cmd2)
914 {
915 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>");
916 return;
917 }
918
d61f68e3 919 p->setStrength(stringtoint(cmd2));
53d5585b 920
d61f68e3 921 notice(s_GameServ, u, "Strength set to %d", p->getStrength());
53d5585b 922 return;
923 }
6b72281b 924 }
6b72281b 925 else if (stricmp(cmd, "DEFENSE") == 0 && stricmp(cmd2, "POTIONS") != 0)
6b72281b 926 {
53d5585b 927 if (!isAdmin(user))
928 {
929 notice(s_GameServ, u, "Admins Only!");
930 return;
931 }
932 else
933 {
934 if (!cmd2)
935 {
936 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>");
937 return;
938 }
939
d61f68e3 940 p->setDefense(stringtoint(cmd2));
53d5585b 941
d61f68e3 942 notice(s_GameServ, u, "Defense set to %d", p->getDefense());
53d5585b 943 return;
944 }
6b72281b 945 }
cbd4ede4 946 else if (stricmp(cmd, "HP") == 0 && stricmp(cmd2, "POTIONS") != 0)
6b72281b 947 {
53d5585b 948 if (!isAdmin(user))
949 {
950 notice(s_GameServ, u, "Admins Only!");
951 return;
952 }
953 else
954 {
955 if (!cmd2)
956 {
957 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>");
958 return;
959 }
eb6e6dab 960
961 // Make sure it's easy for an admin to set the hp
962 if (p->getMaxHP() < stringtoint(cmd2))
963 p->setMaxHP(stringtoint(cmd2));
964
d61f68e3 965 p->setHP(stringtoint(cmd2));
53d5585b 966
d61f68e3 967 notice(s_GameServ, u, "HP set to %d", p->getHP());
53d5585b 968 return;
969 }
6b72281b 970 }
cbd4ede4 971 else if (stricmp(cmd, "MAXHP") == 0)
6b72281b 972 {
53d5585b 973 if (!isAdmin(user))
974 {
975 notice(s_GameServ, u, "Admins Only!");
976 return;
977 }
978 else
979 {
980 if (!cmd2)
981 {
982 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>");
983 return;
984 }
d61f68e3 985 p->setMaxHP(stringtoint(cmd2));
53d5585b 986
d61f68e3 987 notice(s_GameServ, u, "MaxHP set to %d", p->getMaxHP());
53d5585b 988 return;
989 }
6b72281b 990 }
cbd4ede4 991 else if (stricmp(cmd, "EXPERIENCE") == 0 || stricmp(cmd, "EXP") == 0)
6b72281b 992 {
53d5585b 993 if (!isAdmin(user))
994 {
995 notice(s_GameServ, u, "Admins Only!");
996 return;
997 }
998 else
999 {
1000 if (!cmd2)
1001 {
1002 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
1003 return;
1004 }
1005
d61f68e3 1006 p->setExp(stringtoint(cmd2));
53d5585b 1007
d61f68e3 1008 notice(s_GameServ, u, "Exp set to %ld", p->getExp());
53d5585b 1009 return;
1010 }
6b72281b 1011 }
cbd4ede4 1012 else if (stricmp(cmd, "LEVEL") == 0)
6b72281b 1013 {
53d5585b 1014 if (!isAdmin(user))
1015 {
1016 notice(s_GameServ, u, "Admins Only!");
1017 return;
1018 }
1019 else
1020 {
1021 if (!cmd2)
1022 {
1023 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>");
1024 return;
1025 }
d61f68e3 1026 p->setLevel(stringtoint(cmd2));
53d5585b 1027
d61f68e3 1028 notice(s_GameServ, u, "Level set to %d", p->getLevel());
53d5585b 1029 return;
1030 }
6b72281b 1031 }
cbd4ede4 1032 else if (stricmp(cmd, "ALIVE") == 0)
cbd4ede4 1033 {
53d5585b 1034 if (!isAdmin(user))
1035 {
1036 notice(s_GameServ, u, "Admins Only!");
1037 return;
1038 }
6b72281b 1039 else
53d5585b 1040 {
1041 if (!cmd2)
1042 {
1043 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] ALIVE TRUE|FALSE");
1044 return;
1045 }
1046 else if (stricmp(cmd2, "TRUE") == 0)
1047 {
d61f68e3 1048 notice(s_GameServ, u, "%s has been Resurrected!", p->getName().c_str());
1049 setAlive(p);
53d5585b 1050 }
1051 else
1052 {
d61f68e3 1053 notice(s_GameServ, u, "%s is now dead!", p->getName().c_str());
1054 clearAlive(p);
53d5585b 1055 }
1056 }
cbd4ede4 1057 }
6b72281b 1058 else if (stricmp(cmd, "SEEN") == 0)
1059 {
1060 if (!isAdmin(user))
53d5585b 1061 {
1062 notice(s_GameServ, u, "Admins Only!");
1063 return;
1064 }
6b72281b 1065 else if (stricmp(cmd2, "MASTER") != 0)
53d5585b 1066 {
1067 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}");
1068 return;
1069 }
6b72281b 1070 else
53d5585b 1071 {
1072 cmd2 = strtok(NULL, " ");
1073 if (!cmd2)
1074 {
1075 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}");
1076 return;
1077 }
1078 else if (stricmp(cmd2, "TRUE") == 0)
1079 {
d61f68e3 1080 notice(s_GameServ, u, "%s has seen their master now.", p->getName().c_str());
1081 p->addFlag(FLAG_MASTER);
53d5585b 1082 }
1083 else
1084 {
d61f68e3 1085 notice(s_GameServ, u, "%s has not seen their master now.", p->getName().c_str());
1086 p->remFlag(FLAG_MASTER);
53d5585b 1087 }
1088 }
6b72281b 1089 }
1563e73b 1090 else
53d5585b 1091 {
1092 notice(s_GameServ, u, "Unknown command: SET %s", cmd);
1093 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
1094 return;
1095 }
1563e73b 1096}
1af35752 1097
b0359af9 1098void do_logout(char *u)
1099{
c10b78ac 1100 aClient *user;
d61f68e3 1101 Player *p;
c10b78ac 1102 char *name = strtok(NULL, " ");
1103
1104 if (!(user = find(u)))
b0359af9 1105 {
c10b78ac 1106 notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
1107 "Buf: %s LOGOUT", u);
1108 log("Could not find aClient Buf: %s LOGOUT",
1109 u);
1110 return;
b0359af9 1111 }
c10b78ac 1112 else if (isIgnore(user))
448a1531 1113 {
c10b78ac 1114#ifdef DEBUGMODE
1115 log("Ignoring %s.", user->getNick());
1116#endif
1117 return;
448a1531 1118 }
c10b78ac 1119
1120 if (name)
6e8ec003 1121 {
c10b78ac 1122 if (!isAdmin(user))
1123 {
1124 notice(s_GameServ, u, "You must be a %S admin to use this command!");
1125 }
d61f68e3 1126 else if (!(p = findplayer(name)))
c10b78ac 1127 {
1128 notice(s_GameServ, u, "Couldn't find a player named %s", name);
1129 }
1130 else
1131 {
d61f68e3 1132 notice(s_GameServ, u, "Logging out %s", p->getName().c_str());
1133 logout(p->getClient());
c10b78ac 1134 }
6e8ec003 1135 }
c10b78ac 1136 else if (!name)
b0359af9 1137 {
c10b78ac 1138 if (!is_playing(user))
1139 {
1140 notice(s_GameServ, u, "You're not logged in!");
1141 }
1142 else if (is_fighting(user))
1143 {
1144 notice(s_GameServ, u, "You can't logout while fighting!");
1145 }
1146 else
1147 {
1148 notice(s_GameServ, u, "You have left the fields. You have lived to kill another day!");
1149 logout(user);
1150 }
b0359af9 1151 }
1152}
3f243b0b 1153
b0359af9 1154void logout(aClient *user)
1155{
4798acd2 1156 if (user != NULL)
b0359af9 1157 {
4798acd2 1158 if (user->stats != NULL)
1159 {
1160
1161 list<Player*>::iterator iter;
1162 unsigned long hv = iHASH((unsigned char *) user->stats->getName().c_str());
1163 iter = find(players[hv].begin(), players[hv].end(), user->stats);
1164
1165 if (iter == players[hv].end())
1166 {
1167 notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
1168 "%S Admin. Cannot find you in the players list. This should NEVER happen");
1169 log("Error on logout(). Can't find %s in the players list",
ce97fd48 1170#ifdef P10
4798acd2 1171 user->getRealNick()
ce97fd48 1172#else
4798acd2 1173 user->getNick()
ce97fd48 1174#endif
4798acd2 1175 );
1176 user->stats = NULL;
1177
1178 return;
1179 }
1180 user->stats->delMonster();
1181 user->stats->delMaster();
1182 user->stats->delBattle();
1183 clearDragonFight(user->stats);
1184 clearYourTurn(user->stats);
1185 clearPlaying(user);
1186
1187 user->stats->setClient(NULL);
1188
1189
1190 if (player_fight(user))
1191 {
1192 clearYourTurn(user->stats->getBattle()->stats);
1193 user->stats->getBattle()->stats->delBattle();
1194 }
1195
fbb87959 1196#ifdef DEBUGMODE
4798acd2 1197 log("Logged out player %s",
fbb87959 1198#ifdef P10
4798acd2 1199 user->getRealNick()
fbb87959 1200#else
4798acd2 1201 user->getNick()
fbb87959 1202#endif
4798acd2 1203 );
fbb87959 1204#endif
4798acd2 1205 }
1206 }
1207 if (user)
1208 user->stats = NULL;
b0359af9 1209}
3f243b0b 1210
85ce9d3e 1211void do_register(char *u)
1212{
fbb87959 1213 char *password, *name;
1214 aClient *user;
d61f68e3 1215 Player *p;
fbb87959 1216 name = strtok(NULL, " ");
1217 password = strtok(NULL, " ");
1218
1219 if (!name)
e1c41a84 1220 {
fbb87959 1221 notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
e1c41a84 1222 }
fbb87959 1223 else if (stricmp(name, s_GameServ) == 0)
a41870bf 1224 {
fbb87959 1225 notice(s_GameServ, u, "You can't use %S as a name!");
a41870bf 1226 }
fbb87959 1227 else if (!password)
85ce9d3e 1228 {
fbb87959 1229 notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
85ce9d3e 1230 }
d3758d7f 1231 else if (strlen(name) > maxnicklen)
1232 {
1233 notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen);
1234 }
d61f68e3 1235 else if (!alphaNumeric(name))
1236 {
1237 notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
1238 }
1239 else if ((p = findplayer(name)))
03e0a9d8 1240 {
fbb87959 1241 notice(s_GameServ, u, "%s is already registered!", name);
1242 notice(s_GameServ, u, "Choose another name!");
03e0a9d8 1243 }
fbb87959 1244 else if (!(user = find(u)))
448a1531 1245 {
fbb87959 1246 log("Fatal Error: Couldn't find %s in the clients list", u);
448a1531 1247 }
fbb87959 1248 else if (isIgnore(user))
448a1531 1249 {
fbb87959 1250#ifdef DEBUGMODE
1251 log("Ignoring %s.", user->getNick());
1252#endif
448a1531 1253 }
fbb87959 1254 else
85ce9d3e 1255 {
fbb87959 1256 if (!is_playing(user))
85ce9d3e 1257 {
fbb87959 1258 item *tempItem;
d61f68e3 1259 unsigned long hv = iHASH((unsigned char *) name);
1260
1261 // First create the Player
fbb87959 1262 user->stats = new Player();
d61f68e3 1263
1264 // Set the backwards pointer
1265 user->stats->setClient(user);
1266
1267 // Set the player's password
fbb87959 1268 user->stats->setPassword(password);
d61f68e3 1269
1270 // Set the player's name
fbb87959 1271 user->stats->setName(name);
d61f68e3 1272
1273 // Make sure they have a proper time stamp
fbb87959 1274 updateTS(user->stats);
d61f68e3 1275
fbb87959 1276 // Update the last login time
1277 user->stats->lastlogin = time(NULL);
1278
d61f68e3 1279 // Send notification of success
fbb87959 1280 notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->getName().c_str(), password);
1281 notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
d61f68e3 1282
1283 // Log the new player
fbb87959 1284 log("Nickname %s registered player %s.", u, user->stats->getName().c_str());
d61f68e3 1285
1286 // Log the player in
1287 setPlaying(user);
1288
000f8409 1289 // Start the player at the beginning
1290 reset(user->stats);
1291
d61f68e3 1292 // Add the stick and clothes
fbb87959 1293 tempItem = findItemByID(3001);
53d5585b 1294 user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
1295 user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes
c10b78ac 1296
d61f68e3 1297 // Add the player to the list
1298 players[hv].push_back(user->stats);
8cd4c581 1299
1300 // Attempt to add the player to the top list
1301 // The class takes care of pruning the user out if they don't deserve to be in the list
1302 myToplist.insertPlayer(user->stats);
fbb87959 1303 }
1304 else
1305 {
1306 notice(s_GameServ, u, "Already registered. Contact a %S admin for help.");
1307 }
85ce9d3e 1308 }
1309}
1310
1311void do_identify(char *u)
1312{
fbb87959 1313 char *password, *name;
d61f68e3 1314 aClient *user;
1315 Player *p;
fbb87959 1316 name = strtok(NULL, " ");
1317 password = strtok(NULL, " ");
1318 if (!password || !name)
85ce9d3e 1319 {
fbb87959 1320 notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD");
85ce9d3e 1321 }
fbb87959 1322 else if (!(user = find(u)))
5d04eb42 1323 {
fbb87959 1324 notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
1325 log("Error: aClient not found: %s", u);
5d04eb42 1326 }
fbb87959 1327 else if (isIgnore(user))
448a1531 1328 {
fbb87959 1329#ifdef DEBUGMODE
1330 log("Ignoring %s.", user->getNick());
1331#endif
1332 return;
448a1531 1333 }
d61f68e3 1334 else if (!(p = findplayer(name)))
1335 {
1336 notice(s_GameServ, u, "Player %s not found", name);
1337 }
fbb87959 1338 else if (is_playing(user))
b0359af9 1339 {
fbb87959 1340 notice(s_GameServ, u, "You are already playing!");
b0359af9 1341 }
d61f68e3 1342 else if (is_playing(p->getClient()) && !isAdmin(user))
1579dfa2 1343 {
fbb87959 1344 notice(s_GameServ, u, "That player has already identified.");
1579dfa2 1345 }
fbb87959 1346 else if (!check_password(name, password) && !isAdmin(user))
85ce9d3e 1347 {
fbb87959 1348 notice(s_GameServ, u, "Password incorrect");
85ce9d3e 1349 }
fbb87959 1350 else
85ce9d3e 1351 {
d61f68e3 1352 list<Player*>::iterator iter;
1353 unsigned long hv = iHASH((unsigned char *) p->getName().c_str());
c10b78ac 1354
1355 iter = find(players[hv].begin(), players[hv].end(), p);
1356
1357 if (iter == players[hv].end())
fbb87959 1358 {
1359 notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s",
1360 strtok(NULL, ""));
1361 return;
1362 }
d61f68e3 1363 // Make sure the other user is logged out
1364 logout(p->getClient());
1365
1366 user->stats = p;
1367 p->setClient(user);
1368 updateTS(p);
fbb87959 1369
1370
1371#ifdef DEBUGMODE
1372 log("Player %s IRC: %s Identified", user->stats->getName().c_str(),
1373 user->getNick());
1374#endif
d61f68e3 1375 //Set the playing flag
1376 setPlaying(user);
fbb87959 1377
fbb87959 1378 // Update the last login time
1379 user->stats->lastlogin = time(NULL);
c10b78ac 1380
fbb87959 1381 notice(s_GameServ, u, "Password Accepted. Identified.");
1382 showNews(u, todaysnews);
85ce9d3e 1383 }
1384}
1385
1386void do_stats(char *u)
1387{
fbb87959 1388 char *nick;
1389 aClient *user;
1390
1391 nick = strtok(NULL, " ");
1392
1393 if (!(user = find(u)))
73c71976 1394 {
fbb87959 1395 log("Fatal Error: %s not found in client list", u);
1396 return;
448a1531 1397 }
fbb87959 1398 else if (isIgnore(user))
448a1531 1399 {
fbb87959 1400#ifdef DEBUGMODE
1401 log("Ignoring %s.", user->getNick());
1402#endif
1403 return;
448a1531 1404 }
fbb87959 1405 else if (!nick)
448a1531 1406 {
fbb87959 1407 if (!is_playing(user))
1408 {
1409 notice(s_GameServ, u, "You're not playing, so you have no stats!");
1410 return;
1411 }
1412 else
1413 {
000f8409 1414 if (!is_fighting(user))
1415 updateTS(user->stats);
fbb87959 1416 showstats(u, user->stats->getName().c_str());
1417 }
73c71976 1418 }
fbb87959 1419 else
85ce9d3e 1420 showstats(u, nick);
1421}
448a1531 1422
5c449fde 1423bool load_masters()
ad7dfaa0 1424{
fbb87959 1425 ifstream infile(masterdata);
1426 char *buf;
1427 int l = 0;
1428 buf = new char[1024];
1429
1430 if (infile.fail())
5c449fde 1431 {
fbb87959 1432 log("Error opening %s", masterdata);
1433 return false;
5c449fde 1434 }
fbb87959 1435
1436#ifdef DEBUGMODE
1437 log("Loading masters from %s", masterdata);
1438#endif
1439
1440 for (l = 0; l < LEVELS - 1; l++)
5c449fde 1441 {
fbb87959 1442 infile.getline(buf, 1024, '\n');
1443
1444 log("%s", buf);
1445 if (buf[0] == '#' || buf[0] == '\n' || buf[0] == '\r')
1446 {
1447 l--;
1448 continue;
1449 }
1450 else if (buf[0] == '^')
5c449fde 1451 break;
fbb87959 1452
1453 Monster *master = &levels[l].master;
1454
1455 char *name, *weapon, *strength, *gold, *exp, *maxhp, *death;
1456
1457
1458 name = strtok(buf, "~");
1459 weapon = strtok(NULL, "~");
1460 strength = strtok(NULL, "~");
1461 gold = strtok(NULL, "~");
1462 exp = strtok(NULL, "~");
1463 maxhp = strtok(NULL, "~");
1464 death = strtok(NULL, "~");
5c449fde 1465
fbb87959 1466 master->name = name;
1467 master->weapon = weapon;
1468 master->strength = stringtoint(strength);
1469 master->gold = stringtoint(gold);
1470 master->exp = stringtoint(exp);
1471 master->maxhp = stringtoint(maxhp);
1472 master->hp = master->maxhp;
1473 master->death = death;
5c449fde 1474 }
1475
fbb87959 1476 delete []buf;
1477
1478 if (l < LEVELS - 1) // We didn't load a master for every level - check data/masters.dat
5c449fde 1479 return false;
fbb87959 1480 else
5c449fde 1481 return true;
ad7dfaa0 1482}
85ce9d3e 1483
c8ada07e 1484void delete_monsters()
1485{
fbb87959 1486 for (int x = 0; x < LEVELS; x++)
c10b78ac 1487 levels[x].monsters.clear();
c8ada07e 1488}
1489
85ce9d3e 1490void display_monster(char *u)
1491{
fbb87959 1492 if (is_playing(u))
85ce9d3e 1493 {
fbb87959 1494 aClient *user = find(u);
1495 Player *ni = user->stats;
1496
1497 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->getHP());
1498 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->getMonster()->name.c_str(), ni->getMonster()->hp);
1499 notice(s_GameServ, u, "Here are your commands:");
1500 notice(s_GameServ, u, "/msg %S attack");
1501 notice(s_GameServ, u, "/msg %S run");
1502 notice(s_GameServ, u, "What will you do?");
85ce9d3e 1503 }
1504}
1505
1506void display_players(char *u)
1507{
fbb87959 1508 aClient *user;
1509 if (!(user = find(u)))
85ce9d3e 1510 {
fbb87959 1511 log("Fatal error in display_players(): Couldn't find %s", u);
83cf716f 1512 }
fbb87959 1513 else
85bcf836 1514 display_players(user);
83cf716f 1515}
85bcf836 1516
83cf716f 1517void display_players(aClient *user)
1518{
fbb87959 1519 char *u = user->getNick();
1520 if (is_playing(user) && player_fight(user))
83cf716f 1521 {
fbb87959 1522 aClient *battle = user->stats->getBattle();
1523 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", user->stats->getHP());
1524 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->stats->getName().c_str(), battle->stats->getHP());
1525 notice(s_GameServ, u, "Here are your commands:");
1526 notice(s_GameServ, u, "/msg %S attack");
1527 notice(s_GameServ, u, "/msg %S run");
1528 notice(s_GameServ, u, "What will you do?");
85ce9d3e 1529 }
1530}
1531
1532
1533bool is_playing(char *u)
1534{
fbb87959 1535 aClient *user;
1536 if (!(user = find(u)))
85ce9d3e 1537 return false;
fbb87959 1538 else
40251952 1539 return is_playing(user);
85ce9d3e 1540}
1541
1af35752 1542bool is_playing(aClient *user)
1543{
9c443e07 1544 if (!user)
f1ab3b7c 1545 {
fbb87959 1546 return false;
f1ab3b7c 1547 }
9c443e07 1548 else if (!user->stats)
1549 {
1550 return false;
1551 }
1552 else if (!FL_is_playing(user))
f1ab3b7c 1553 {
fbb87959 1554 return false;
f1ab3b7c 1555 }
9c443e07 1556 else if (user->stats->getClient() != user)
3f243b0b 1557 {
fbb87959 1558 return false;
3f243b0b 1559 }
fbb87959 1560 else
03a4bdbb 1561 return true;
1af35752 1562}
1563
85ce9d3e 1564bool is_fighting(char *u)
1565{
fbb87959 1566 aClient *user;
1567
1568 if (!(user = find(u)))
85ce9d3e 1569 return false;
fbb87959 1570 else
40251952 1571 return is_fighting(user);
85ce9d3e 1572}
40251952 1573
1af35752 1574bool is_fighting(aClient *user)
1575{
fbb87959 1576 if (!is_playing(user))
1af35752 1577 return false;
fbb87959 1578 else
1579 return player_fight(user) || master_fight(user) || user->stats->getMonster() != NULL;
1af35752 1580}
85ce9d3e 1581
1582bool player_fight(char *u)
1583{
fbb87959 1584 aClient *user;
1585
1586 if (!(user = find(u)))
85ce9d3e 1587 return false;
fbb87959 1588 else
40251952 1589 return player_fight(user);
85ce9d3e 1590}
448a1531 1591
1af35752 1592bool player_fight(aClient *user)
1593{
fbb87959 1594 if (!is_playing(user))
1af35752 1595 return false;
9c443e07 1596 else if (is_playing(user->stats->getBattle()))
a51f0dcd 1597 {
9c443e07 1598 return true;
a51f0dcd 1599 }
fbb87959 1600 return false;
1af35752 1601}
85ce9d3e 1602
1603bool master_fight(char *u)
1604{
fbb87959 1605 aClient *user;
1606
1607 if (!(user = find(u)))
85ce9d3e 1608 return false;
fbb87959 1609 else
40251952 1610 return master_fight(user);
85ce9d3e 1611}
40251952 1612
1af35752 1613bool master_fight(aClient *user)
85ce9d3e 1614{
fbb87959 1615 if (!is_playing(user))
1af35752 1616 return false;
fbb87959 1617 else
1618 return user->stats->getMaster() != NULL;
85ce9d3e 1619}
1620
fd270bdd 1621bool dragon_fight(char *u)
1622{
fbb87959 1623 aClient *user;
1624 if (!(user = find(u)))
fd270bdd 1625 return false;
fbb87959 1626 else
fd270bdd 1627 return dragon_fight(user);
1628}
1629
1630bool dragon_fight(aClient *user)
1631{
fbb87959 1632 if (!is_playing(user))
fd270bdd 1633 return false;
fbb87959 1634 else
8e800549 1635 return (isDragonFight(user->stats));
fd270bdd 1636}
fbb87959 1637
bbb7e9be 1638bool alphaNumeric(const char *str)
1639{
1640 int len = strlen(str);
1641 for (int x = 0; x < len; x++)
1642 {
ce97fd48 1643 if (!((int(str[x]) >= 65 && int(str[x]) <= 90) || (int(str[x]) >= 97 && int(str[x]) <= 122) || (int(str[x]) >= 48 && int(str[x]) <= 57) || int(str[x]) == 95))
bbb7e9be 1644 return false;
1645 }
1646 return true;
1647}
1648
85ce9d3e 1649void do_fight(char *u)
1650{
d61f68e3 1651 aClient *ni;
1652 Player *battle;
5ea87d98 1653
1654 char *nick = strtok(NULL, " ");
1655
1656 if (!nick)
85ce9d3e 1657 {
5ea87d98 1658 notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER");
1659 return;
85ce9d3e 1660 }
5ea87d98 1661 else if (!(ni = find(u)))
448a1531 1662 {
5ea87d98 1663 notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
1664 return;
448a1531 1665 }
5ea87d98 1666 else if (isIgnore(ni))
85ce9d3e 1667 {
5ea87d98 1668#ifdef DEBUGMODE
1669 log("Ignoring %s.", ni->getNick());
1670#endif
1671 return;
3348c24e 1672 }
5ea87d98 1673 else if (!is_playing(ni))
b0359af9 1674 {
5ea87d98 1675 notice(s_GameServ, u, "You are not playing!");
1676 return;
b0359af9 1677 }
5ea87d98 1678
1679 updateTS(ni->stats);
1680
fbb87959 1681 if (ni->stats->getPlayerFights() <= 0)
448a1531 1682 {
fbb87959 1683 ni->stats->setPlayerFights(0); // just to be safe
5ea87d98 1684 notice(s_GameServ, u, "You are out of player fights for the "\
1685 "day. You have to wait until tomorrow!");
448a1531 1686 }
5ea87d98 1687 else if (!(battle = findplayer(nick)))
85ce9d3e 1688 {
5ea87d98 1689 notice(s_GameServ, u, "Player %s not found!", nick);
85ce9d3e 1690 }
5ea87d98 1691 else if (!isAlive(ni->stats))
b478c0df 1692 {
5ea87d98 1693 notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!");
b478c0df 1694 }
d61f68e3 1695 else if (!is_playing(battle->getClient()))
b0359af9 1696 {
5ea87d98 1697 notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
1af35752 1698 }
5ea87d98 1699
1700 /* offline fighting not available yet
1701 else if (!(fight = finduser(nick)))
1702 {
1703 ni->stats->battle = battle;
1704 battle->battle = ni;
1705 setYourTurn(ni->stats);
1706 clearYourTurn(battle->stats);
1707
1708 notice(s_GameServ, u, "You decide to fight %s while they're "\
1709 "not in the realm!",
1710 battle->stats->name.c_str());
1711 display_players(u);
1712 }
1713 */
d61f68e3 1714 else if (stricmp(ni->stats->getName().c_str(), battle->getName().c_str()) == 0)
da5cf17a 1715 {
5ea87d98 1716 notice(s_GameServ, u, "Are you trying to commit suicide!?");
da5cf17a 1717 }
d61f68e3 1718 else if (!isAlive(battle))
1902338e 1719 {
5ea87d98 1720 notice(s_GameServ, u, "They are dead. Cannot fight dead players!");
1902338e 1721 }
d61f68e3 1722 else if (player_fight(battle->getClient()))
448a1531 1723 {
d61f68e3 1724 notice(s_GameServ, u, "%s is fighting %s already!", battle->getName().c_str(), battle->getBattle()->stats->getName().c_str());
448a1531 1725 }
d61f68e3 1726 else if (master_fight(battle->getClient()))
1902338e 1727 {
d61f68e3 1728 notice(s_GameServ, u, "%s is fighting their master!", battle->getName().c_str());
1902338e 1729 }
d61f68e3 1730 else if (is_fighting(battle->getClient()))
8450c018 1731 {
d61f68e3 1732 notice(s_GameServ, u, "%s is fighting %s already!", battle->getName().c_str(), battle->getMonster()->name.c_str());
8450c018 1733 }
d61f68e3 1734 else if (!isAdmin(ni) && isFairFights() && (ni->stats->getStrength()/2 - battle->getDefense()) > battle->getHP())
2ca6a3de 1735 {
d61f68e3 1736 notice(s_GameServ, u, "Fair fighting is enabled, and you're too strong for %s!", battle->getName().c_str());
2ca6a3de 1737 }
d61f68e3 1738 else if (ni->stats->getLevel() - battle->getLevel() > maxbfightdistance)
8450c018 1739 {
5ea87d98 1740 // You can't fight someone below you by more than X level(s)
1741 // level 12 can fight level (12 - X) but not < (12 - X)
1742 notice(s_GameServ, u, "You may not fight %s. You're too strong!",
d61f68e3 1743 battle->getName().c_str());
8450c018 1744 }
d61f68e3 1745 else if (battle->getLevel() - ni->stats->getLevel() > maxafightdistance)
85ce9d3e 1746 {
5ea87d98 1747 // You can't fight someone above you by more than X level(S)
1748 // level 1 can fight level (1 + X), but not > (1 + X)
1749 notice(s_GameServ, u, "%s, do you really have a death wish? Try the forest you "\
fbb87959 1750 "weakling!", ni->stats->getName().c_str());
85ce9d3e 1751 }
5ea87d98 1752 else
1753 {
1754 // Set your battle pointer to the other player
d61f68e3 1755 ni->stats->setBattle(battle->getClient());
5ea87d98 1756
1757 // Set the other player's battle pointer to you
d61f68e3 1758 battle->setBattle(ni);
fbb87959 1759
5ea87d98 1760 // The initiator gets the first move (perhaps this should be 50/50)
1761 setYourTurn(ni->stats);
d61f68e3 1762 clearYourTurn(battle);
5ea87d98 1763
1764 // Initiate Battle sequence!
fbb87959 1765 ni->stats->subtractPlayerFights(1);
5ea87d98 1766
d61f68e3 1767 notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getName().c_str());
5ea87d98 1768 notice(s_GameServ, c_Forest, "%s walks up and hits %s in the face! Let's see who will bite the dust.",
d61f68e3 1769 ni->stats->getName().c_str(), battle->getName().c_str()); /* DrLnet - Modified by Kain*/
5ea87d98 1770
d61f68e3 1771 notice(s_GameServ, battle->getClient()->getNick(), "%s has challenged you to an online duel!", ni->stats->getName().c_str());
1772 notice(s_GameServ, battle->getClient()->getNick(), "%s gets to go first "\
fbb87959 1773 "because they initiated!", ni->stats->getName().c_str());
d61f68e3 1774 notice(s_GameServ, battle->getClient()->getNick(), "Please wait while %s decides what to do.", ni->stats->getName().c_str());
5ea87d98 1775 display_players(ni);
1776 }
85ce9d3e 1777}
40251952 1778
1781f48a 1779void do_equip(char *u)
1780{
1781 aClient *user;
1782 pouch *p;
1783 itemContainer *equip;
1cbff036 1784 int id;
1781f48a 1785
1786 char *item = strtok(NULL, " ");
1781f48a 1787
1788 if (!item || int(item[0]) < 48 || int(item[0] > 57))
1789 {
1790 notice(s_GameServ, u, "SYNTAX: EQUIP ####");
1791 notice(s_GameServ, u, "Type /msg %S HELP EQUIP for more information.");
1792 return;
1793 }
1794 else if (!(user = find(u)))
1795 {
1796 notice(s_GameServ, u, "Fatal error in do_equip. Contact a(n) %S Admin");
1797 return;
1798 }
1799 else if (isIgnore(user))
1800 {
1801#ifdef DEBUGMODE
1802 log("Ignoring %s.", user->getNick());
1803#endif
1804 return;
1805 }
1806 else if (!is_playing(user))
1807 {
1808 notice(s_GameServ, u, "You must be playing to equip weapons and armor!");
1809 return;
1810 }
1cbff036 1811 id = stringtoint(item);
000f8409 1812 if (!is_fighting(user))
1813 updateTS(user->stats);
1cbff036 1814 p = user->stats->inventory;
1781f48a 1815
1816
228a25d5 1817 if (!(equip = p->Find(id)))
1781f48a 1818 {
228a25d5 1819 if (!p->isEmpty())
1820 {
1821 notice(s_GameServ, u, "You aren't carrying that item!");
1822 }
1823 showinventory(user->stats, user);
1781f48a 1824 }
1825 else if (equip->getItem()->getType() != ARMOR && equip->getItem()->getType() != WEAPON)
1826 {
228a25d5 1827 notice(s_GameServ, u, "You can't use %s like that. Try /msg %S use", equip->getItem()->getName().c_str());
1781f48a 1828 }
1829 else
1830 {
228a25d5 1831 // Use the item
1832 notice(s_GameServ, u, "You equip %s.", equip->getItem()->getName().c_str());
1833 equip->use(user->stats);
1781f48a 1834 }
1835}
000f8409 1836
83cf716f 1837void do_use(char *u)
1838{
228a25d5 1839 aClient *user;
1840 pouch *p;
1841
1842 char *item = strtok(NULL, " ");
f9db99e0 1843 char *numuse = strtok(NULL, " ");
1844 int id, num;
228a25d5 1845 itemContainer *used;
1846
f9db99e0 1847 if (!item || int(item[0]) < 48 || int(item[0]) > 57 || (numuse && (int(numuse[0]) < 48 || int(numuse[0]) > 57)))
83cf716f 1848 {
228a25d5 1849 notice(s_GameServ, u, "SYNTAX: USE ####");
1850 notice(s_GameServ, u, "Type /msg %S HELP USE for more information.");
1851 return;
83cf716f 1852 }
228a25d5 1853 else if (!(user = find(u)))
83cf716f 1854 {
228a25d5 1855 notice(s_GameServ, u, "Fatal Error in do_use. Contact a(n) %S Admin");
1856 return;
83cf716f 1857 }
228a25d5 1858 else if (isIgnore(user))
448a1531 1859 {
228a25d5 1860#ifdef DEBUGMODE
1861 log("Ignoring %s.", user->getNick());
1862#endif
1863 return;
448a1531 1864 }
228a25d5 1865 else if (!is_playing(user))
83cf716f 1866 {
228a25d5 1867 notice(s_GameServ, u, "You must be playing to use items!");
1868 return;
83cf716f 1869 }
228a25d5 1870 id = stringtoint(item);
f9db99e0 1871
1872 if (!numuse)
1873 {
1874 num = 1;
1875 }
1876 else
1877 {
1878 num = stringtoint(numuse);
1879 }
1880
228a25d5 1881 updateTS(user->stats);
1882 p = user->stats->inventory;
1883
f9db99e0 1884
228a25d5 1885 if (!(used = p->Find(id)))
1886 {
1887 if (!p->isEmpty())
1888 {
1889 notice(s_GameServ, u, "You aren't carrying that item!");
1890 }
1891 showinventory(user->stats, user);
1892 }
1893 else if (used->getItem()->getType() != POTION)
1894 {
1895 notice(s_GameServ, u, "You can't use %s like that. Try /msg %S equip", used->getItem()->getName().c_str());
1896 }
1897 else
1898 {
f9db99e0 1899 // Use the item(s)
1900 if (num <= 1 || is_fighting(user))
228a25d5 1901 {
f9db99e0 1902 notice(s_GameServ, u, "You used %s.", used->getItem()->getName().c_str());
1903 used->use(user->stats);
1904 if (used->getUses() <= 0)
1905 {
1906 p->deleteItem(used->getItem());
1907 }
1908 end_turn(user);
228a25d5 1909 }
f9db99e0 1910 else if (num > 1)
1911 {
1912 int count;
1913 const char *name = used->getItem()->getName().c_str();
1914 for (count = 0; count < num; count++)
1915 {
1916 if (!(used = p->Find(id)))
1917 {
1918 break;
1919 }
1920 else
1921 {
1922 used->use(user->stats);
1923 if (used->getUses() == 0)
1924 {
1925 p->deleteItem(used->getItem());
1926 }
1927 }
1928 }
1929 notice(s_GameServ, u, "You used %d %s's", count, name);
1930 }
1931 }
83cf716f 1932}
c8ada07e 1933void do_run(char *u)
1934{
5ea87d98 1935 aClient *user;
1936 Player *p, *p2 = NULL;
1937
1938 if (!(user = find(u)))
c8ada07e 1939 {
5ea87d98 1940 notice(s_GameServ, u, "Couldn't find you. Error. Contact a %S admin");
1941 return;
c8ada07e 1942 }
5ea87d98 1943 else if (isIgnore(user))
448a1531 1944 {
5ea87d98 1945#ifdef DEBUGMODE
1946 log("Ignoring %s.", user->getNick());
1947#endif
1948 return;
448a1531 1949 }
5ea87d98 1950 else if (!is_playing(user))
bb668fcf 1951 {
5ea87d98 1952 notice(s_GameServ, u, "You must be playing to run!");
1953 return;
bb668fcf 1954 }
5ea87d98 1955
1956 updateTS(user->stats);
1957 p = user->stats;
1958
fbb87959 1959 if (p->getBattle())
1960 p2 = p->getBattle()->stats;
5ea87d98 1961
1962 if (!is_fighting(user))
c8ada07e 1963 notice(s_GameServ, u, "You run in place... try fighting next time.");
776fa0ca 1964 else if (!player_fight(user) && !master_fight(user) && !dragon_fight(user))
c8ada07e 1965 {
fbb87959 1966 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->getMonster()->name.c_str());
1967 p->delMonster();
c8ada07e 1968 }
5ea87d98 1969 else if (player_fight(user) && isYourTurn(p))
c8ada07e 1970 {
fbb87959 1971 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->getName().c_str());
1972 notice(s_GameServ, p->getBattle()->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->getName().c_str());
1973 addNews(todaysnews, "%s ran away from %s like a little baby!!", p->getName().c_str(), p2->getName().c_str()); /* DrLnet - edited by Kain */
1974 p2->delBattle();
8fb0b83e 1975 p->delBattle();
fbb87959 1976 }
5ea87d98 1977 else if (player_fight(user) && !isYourTurn(p))
c8ada07e 1978 {
fbb87959 1979 notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->getName().c_str());
c8ada07e 1980 }
5ea87d98 1981 else if (master_fight(user))
c8ada07e 1982 {
fbb87959 1983 notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->getMaster()->name.c_str());
c8ada07e 1984 }
776fa0ca 1985 else if (dragon_fight(user))
1986 {
1987 notice(s_GameServ, u, "You cannot run from %s! FIGHT!", dragon.name.c_str());
1988 }
c8ada07e 1989}
83cf716f 1990
1991void end_turn(aClient *user)
1992{
228a25d5 1993 char *nick, *u = user->getNick();
1994 Monster *fight;
1995 aClient *battle;
1996 int mhit;
1997
1998 nick = new char[strlen(user->getNick()) + 1];
1999
2000 if (!user || !is_playing(user) || !is_fighting(user))
83cf716f 2001 goto endturn;
228a25d5 2002
2003 if (!player_fight(user) && !master_fight(user))
fbb87959 2004 fight = user->stats->getMonster();
228a25d5 2005 else
fbb87959 2006 fight = user->stats->getMaster();
2007 battle = user->stats->getBattle();
228a25d5 2008
2009 if (!player_fight(user))
83cf716f 2010 {
228a25d5 2011 // Opponent's Hit
fbb87959 2012 mhit = (fight->strength / 2) + (rand() % (fight->strength / 2)) - (user->stats->getDefense());
83cf716f 2013 }
228a25d5 2014 else
83cf716f 2015 {
228a25d5 2016 // Opponent's Hit
fbb87959 2017 mhit = (battle->stats->getStrength() / 2) + (rand() % (battle->stats->getStrength() / 2)) - user->stats->getDefense();
83cf716f 2018 }
228a25d5 2019 if (!player_fight(user))
83cf716f 2020 {
228a25d5 2021
2022 if (mhit > 0)
83cf716f 2023 {
228a25d5 2024 notice(s_GameServ, u, "\1f%s\1f attacks with their \1f%s\1f for \ 2%d\ 2 damage!",
2025 fight->name.c_str(), fight->weapon.c_str(), mhit);
83cf716f 2026 }
228a25d5 2027 else if (mhit <= 0)
2028 notice(s_GameServ, u, "%s completely misses you!", fight->name.c_str());
2029
fbb87959 2030 if (mhit >= user->stats->getHP())
83cf716f 2031 {
228a25d5 2032 if (!master_fight(user))
83cf716f 2033 {
228a25d5 2034 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name.c_str());
2035 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
2036 "of your experience!");
fbb87959 2037 user->stats->setGold(0);
2038 user->stats->subtractExp((long int)(user->stats->getExp() * .10));
2039 user->stats->setHP(0);
2040 user->stats->delMonster();
228a25d5 2041 clearAlive(user->stats);
2042 goto endturn;
83cf716f 2043 }
228a25d5 2044 else
83cf716f 2045 {
228a25d5 2046 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
fbb87959 2047 "until tomorrow to try again", user->stats->getMaster()->name.c_str());
2048 user->stats->delMonster();
2049 user->stats->delMaster();
228a25d5 2050 goto endturn;
83cf716f 2051 }
2052 }
228a25d5 2053 else
83cf716f 2054 {
228a25d5 2055 if (mhit > 0)
fbb87959 2056 user->stats->subtractHP(mhit);
228a25d5 2057 display_monster(u);
2058 goto endturn;
83cf716f 2059 }
2060 }
228a25d5 2061 else
83cf716f 2062 {
228a25d5 2063 clearYourTurn(user->stats);
2064 setYourTurn(battle->stats);
2065 display_players(battle);
83cf716f 2066 }
228a25d5 2067 endturn:
2068 delete []nick;
83cf716f 2069}
2070
85ce9d3e 2071void do_heal(char *u)
2072{
228a25d5 2073 aClient *ni;
2074 char *amount = strtok(NULL, " ");
2075 int price, num;
2076
2077 if (!amount)
85ce9d3e 2078 {
228a25d5 2079 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
2080 return;
85ce9d3e 2081 }
228a25d5 2082 else if (!(ni = find(u)))
1af35752 2083 {
2084 notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
2085 return;
2086 }
448a1531 2087 else if (isIgnore(ni))
2088 {
2089 #ifdef DEBUGMODE
2090 log("Ignoring %s.", ni->getNick());
2091 #endif
2092 return;
2093 }
1af35752 2094 else if (!is_playing(ni))
85ce9d3e 2095 {
2096 notice(s_GameServ, u, "You aren't playing!");
1af35752 2097 return;
2098 }
ee38284f 2099 else if (!isAlive(ni->stats))
1af35752 2100 {
2101 notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing.");
2102 return;
85ce9d3e 2103 }
1af35752 2104 else if (is_fighting(ni))
85ce9d3e 2105 {
2106 notice(s_GameServ, u, "You can't heal in battle!");
40251952 2107 return;
85ce9d3e 2108 }
fbb87959 2109 else if (ni->stats->getHP() >= ni->stats->getMaxHP())
85ce9d3e 2110 {
2111 notice(s_GameServ, u, "You don't need healing!");
40251952 2112 return;
85ce9d3e 2113 }
40251952 2114
2115 updateTS(ni->stats);
2116 if (stricmp(amount, "ALL") == 0)
85ce9d3e 2117 {
fbb87959 2118 price = ni->stats->getLevel() * 3;
2119 if (ni->stats->getGold() < (ni->stats->getMaxHP() - ni->stats->getHP()) * price)
85ce9d3e 2120 {
2121 notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
fbb87959 2122 (long int)ni->stats->getGold()/price, price);
2123 ni->stats->addHP(ni->stats->getGold() / price);
2124 ni->stats->setGold(ni->stats->getGold() % price);
85ce9d3e 2125 }
2126 else
2127 {
2128 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
2129 "per point.", price);
ad7dfaa0 2130 notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!",
fbb87959 2131 (ni->stats->getMaxHP() - ni->stats->getHP()),
2132 (price * (ni->stats->getMaxHP() - ni->stats->getHP())) );
2133 ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP()));
2134 ni->stats->healall();
85ce9d3e 2135 }
2136 }
2137 else if (isstringnum(amount))
2138 {
2139 num = stringtoint(amount);
fbb87959 2140 price = ni->stats->getLevel() * 3;
2141 if (ni->stats->getGold() < price * num)
85ce9d3e 2142 {
2143 notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!",
fbb87959 2144 (long int)ni->stats->getGold()/price);
85ce9d3e 2145 }
fbb87959 2146 else if (num <= ni->stats->getMaxHP() - ni->stats->getHP())
85ce9d3e 2147 {
2148 notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
2149 num, price);
fbb87959 2150 ni->stats->addHP(num);
2151 ni->stats->subtractGold(num * price);
85ce9d3e 2152 }
fbb87959 2153 else if (num > ni->stats->getMaxHP() - ni->stats->getHP())
85ce9d3e 2154 {
2155 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
2156 "per point.", price);
2157 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
fbb87959 2158 (ni->stats->getMaxHP() - ni->stats->getHP()));
2159 ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP()));
2160 ni->stats->healall();
85ce9d3e 2161 }
2162 }
2163 else if (amount[0] == '-')
2164 notice(s_GameServ, u, "You trying to cheat?");
2165 else
2166 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
2167}
2168
2169int isstringnum(char *num)
2170{
28f552b8 2171 unsigned int x;
85ce9d3e 2172 for (x = 0; x < strlen(num); x++)
2173 {
2174 if ((int)num[x] < 48 || (int)num[x] > 57)
2175 return 0;
2176 }
2177return 1;
2178}
2179
2180long int stringtoint(char *number)
2181{
9fe7af4c 2182 return atol(number);
85ce9d3e 2183}
2184
2185long int pow(int x, int y)
2186{
d61f68e3 2187 long int value = 0;
2188 int count = 0;
2189 value += x;
2190
2191 if (x != 0 && y != 0)
85ce9d3e 2192 {
d61f68e3 2193 for (count = 1; count <= y - 1; count++)
2194 value *= x;
85ce9d3e 2195 }
d61f68e3 2196 else
2197 {
2198 return 1;
2199 }
2200 return value;
85ce9d3e 2201}
2202
2203long int chartoint(char ch)
2204{
d61f68e3 2205 if (int(ch) >= 48 && int(ch) <= 57)
2206 return int(ch) - 48;
2207 else
2208 return 0;
85ce9d3e 2209}
2210
2211int save_gs_dbase()
2212{
d61f68e3 2213 list<Player*>::iterator iter;
c10b78ac 2214 Player *it;
2215 ofstream outfile;
2216
2217 outfile.open(playerdata);
2218
2219 if (!outfile)
85ce9d3e 2220 {
c10b78ac 2221 log("Error opening %s", playerdata);
2222 return 0;
85ce9d3e 2223 }
c10b78ac 2224
2225 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
2226 {
2227 for(iter = players[x].begin(); iter != players[x].end(); iter++)
2228 {
d61f68e3 2229 it = (*iter);
c10b78ac 2230 clearYourTurn(it);
2231 item *w, *a;
2232 w = it->getWeapon();
2233 a = it->getArmor();
2234
2235 outfile << it->getName().c_str() << ' ' << it->getLevel() << ' ' << it->getExp() << ' ' << it->getGold() << ' ' << it->getBank() << ' '<< it->getHP() << ' ' << it->getMaxHP() << ' ' << it->getStrength() << ' ' << it->getDefense() << ' ' << it->getForestFights() << ' ' << it->getPlayerFights() << ' ' << it->getFlags() << ' ' << it->getPassword().c_str() << ' ' << it->lastlogin << ' ' << (w ? w->getID() : 0) << ' ' << (a ? a->getID() : 0);
2236
2237 // Traverse the list and write out each item ID and how many uses are left
2238 if (!it->inventory->isEmpty())
2239 {
2240 list<itemContainer> *myitems;
2241 list<itemContainer>::iterator item_iter;
2242 myitems = it->inventory->getItems();
2243
2244 for(item_iter = myitems->begin();item_iter != myitems->end();item_iter++)
2245 {
2246 outfile << ' ' << (*item_iter).getItem()->getID() << ' ' << (*item_iter).getUses();
2247 }
2248 }
2249 outfile << endl;
2250 }
2251 }
2252 outfile.close();
2253 return 1;
85ce9d3e 2254}
2255
8e800549 2256int load_dragon()
2257{
2258 ifstream infile;
2259 char *buf;
2260
2261 infile.open(dragondata);
2262
2263 if (infile.fail())
2264 {
2265 infile.clear();
2266 log ("Error opening %s. Trying initialdragon.dat", dragondata);
2267 infile.open("data/initialdragon.dat");
2268 if (infile.fail())
2269 {
2270 log ("Error opening data/initialdragon.dat");
2271 return 0;
2272 }
2273 }
2274
2275 buf = new char[1024];
2276
2277 infile.getline(buf, 1024, '\n');
2278 infile.close(); // Done with the file... we have what we want
2279
2280 dragon.name = strtok(buf, "~");
2281 dragon.weapon = strtok(NULL, "~");
2282 dragon.gold = 0;
2283 dragon.exp = 0;
2284 dragon.strength = stringtoint(strtok(NULL, "~"));
2285 dragon.hp = stringtoint(strtok(NULL, "~"));
2286 dragon.defense = stringtoint(strtok(NULL, "~"));
2287 dragon.death = strtok(NULL, "");
2288
2289 log ("loaded dragon: %s", dragon.name.c_str());
2290
2291 delete []buf;
2292
2293return save_dragon(); // Save the dragon file and return the status code :)
2294}
2295
2296int save_dragon()
2297{
2298 ofstream outfile;
2299
2300 outfile.open(dragondata);
2301
2302 if (outfile.fail())
2303 {
2304 log ("Error opening %s. Exiting.", dragondata);
2305 return 0;
2306 }
2307
2308 outfile << dragon.name.c_str() << '~' << dragon.weapon.c_str() << '~'
2309 << dragon.strength << '~' << dragon.hp << '~'
2310 << dragon.defense << '~' << dragon.death.c_str() << "\n^"
2311 << endl;
2312
2313outfile.close();
2314
2315return 1;
2316}
3f107f27 2317
2318int load_store()
2319{
2320 ifstream infile;
2321 char *buf;
2322 item *tempItem;
2323 buf = new char[1024];
2324 long id;
2325
2326 infile.open(storeitemdata);
2327
2328 if (infile.fail())
2329 {
2330 log("Error opening %s", storeitemdata);
2331 return 0;
2332 }
2333
2334 while (infile.getline(buf, 1024, '\n'))
2335 {
2336 try
2337 {
2338 if (buf[0] != '#' && buf[0] != '\n' && buf[0] != '\0')
2339 {
2340 item *tempItem2;
2341 id = stringtoint(strtok(buf, ""));
2342 tempItem2 = findItemByID(id);
2343 if (tempItem2 == NULL)
2344 {
2345 log("Invalid ID in %s", storeitemdata);
2346 return 0;
2347 }
2348
2349 tempItem = tempItem2;
2350 store.push_back(tempItem);
2351 }
2352 }
2353 catch (char *str)
2354 {
2355 log("Exception loading store: %s", str);
2356 delete []buf;
2357 return 0;
2358 }
2359 }
2360 delete []buf;
2361 return 1;
2362}
d1927afc 2363int load_tavern()
2364{
2365 ifstream infile;
2366 char *buf;
2367 tavernItem tempItem;
2368 buf = new char[1024];
1e7678e9 2369 long id, level;
d1927afc 2370
2371 infile.open(tavernitemdata);
2372 if (infile.fail())
2373 {
2374 log("Error opening %s", tavernitemdata);
2375 return 0;
2376 }
42c1eadd 2377
d1927afc 2378 while (infile.getline(buf, 1024, '\n'))
2379 {
d1927afc 2380 try
2381 {
2382 if (buf[0] != '#' && buf[0] != '\n' && buf[0] != '\0')
2383 {
2384 item *tempItem2;
2385 id = stringtoint(strtok(buf, "~"));
1e7678e9 2386 level = stringtoint(strtok(NULL, ""));
d1927afc 2387 tempItem2 = findItemByID(id);
2388 if (tempItem2 == NULL)
2389 {
2390 log("Invalid ID in %s", tavernitemdata);
2391 return 0;
2392 }
2393 tempItem.setItem(tempItem2);
2394 tempItem.setLevel(level);
d1927afc 2395 tavern.push_back(tempItem);
2396 }
2397 }
2398 catch (char *str)
2399 {
2400 log("Exception loading tavern: %s", str);
2401 delete []buf;
2402 return 0;
2403 }
2404 }
2405 delete []buf;
2406 return 1;
2407}
cd973e97 2408int load_items()
2409{
2410 ifstream infile;
e0056fa6 2411 char *buf;
cd973e97 2412 item *tempItem;
c10b78ac 2413
cd973e97 2414 buf = new char[1024];
c10b78ac 2415
cd973e97 2416 infile.open(itemdata);
c10b78ac 2417
cd973e97 2418 if (infile.fail())
2419 {
2420 log("Error opening %s", itemdata);
2421 return 0;
2422 }
c10b78ac 2423
cd973e97 2424 while (infile.getline(buf, 1024, '\n'))
2425 {
42c1eadd 2426 if (buf[0] == '^')
c10b78ac 2427 break;
42c1eadd 2428 try
42c1eadd 2429 {
c10b78ac 2430 if (buf[0] != '#' && buf[0] != '\n' && buf[0] != '\0')
2431 {
2432 switch(buf[0])
2433 {
2434 case '1':
2435 tempItem = new weapon();
2436 break;
2437 case '2':
2438 tempItem = new armor();
2439 break;
2440 case '3':
2441 tempItem = new potion();
2442 break;
2443 default:
2444 log("Invalid Item Type %c in %s", buf[0], itemdata);
2445 delete []buf;
2446 return 0;
2447 break;
2448 }
2449 if(tempItem->setData(buf))
2450 {
2451 Items.push_back(tempItem);
2452 }
2453 }
42c1eadd 2454 }
c10b78ac 2455 catch (char *str)
42c1eadd 2456 {
c10b78ac 2457 log("Exception loading items: %s", str);
2458 delete []buf;
2459 return 0;
42c1eadd 2460 }
cd973e97 2461 }
d1927afc 2462 delete []buf;
cd973e97 2463 return 1;
2464}
fbb87959 2465
85ce9d3e 2466int load_gs_dbase()
2467{
fbb87959 2468 ifstream infile;
fbb87959 2469 Player *p;
2470 char *tempname, *buf, *password;
2471 int tempnum;
2472 buf = new char[100000];
2473
2474 infile.open(playerdata);
2475
2476 if (infile.fail())
85ce9d3e 2477 {
fbb87959 2478 log("Error opening %s", playerdata);
2479 return 0;
85ce9d3e 2480 }
d61f68e3 2481
2482
fbb87959 2483 for (int x = 0; x < U_TABLE_SIZE; x++)
19795233 2484 {
d61f68e3 2485 list<Player*>::iterator iter;
2486
c10b78ac 2487 for (iter = players[x].begin(); iter != players[x].end(); iter++)
fbb87959 2488 {
d61f68e3 2489 logout((*iter)->getClient());
2490 delete (*iter);
fbb87959 2491 }
c10b78ac 2492 players[x].clear();
19795233 2493 }
fbb87959 2494
2495 while (infile.getline(buf, 100000, '\n'))
2496 {
fbb87959 2497 tempname = strtok(buf, " ");
d61f68e3 2498 p = new Player(tempname);
fbb87959 2499
2500 p->setLevel(stringtoint(strtok(NULL, " ")));
2501 p->setExp(stringtoint(strtok(NULL, " ")));
2502 p->setGold(stringtoint(strtok(NULL, " ")));
2503 p->setBank(stringtoint(strtok(NULL, " ")));
000f8409 2504 tempnum = stringtoint(strtok(NULL, " "));
fbb87959 2505 p->setMaxHP(stringtoint(strtok(NULL, " ")));
000f8409 2506 p->setHP(tempnum);
fbb87959 2507 p->setStrength(stringtoint(strtok(NULL, " ")));
2508 p->setDefense(stringtoint(strtok(NULL, " ")));
2509 p->setForestFights(stringtoint(strtok(NULL, " ")));
2510 p->setPlayerFights(stringtoint(strtok(NULL, " ")));
2511 p->setFlags(stringtoint(strtok(NULL, " ")));
2512
2513
d61f68e3 2514
2515 password = strtok(NULL, " ");
2516 p->setRawPassword(password);
2517 tempname = strtok(NULL, " ");
2518
2519 if (tempname)
2520 p->lastlogin = stringtoint(tempname);
2521 else
2522 p->lastlogin = time(NULL);
2523
2524 tempname = strtok(NULL, " ");
2525 tempnum = stringtoint(tempname);
2526 item *tempitem;
2527 if (tempnum != 0)
2528 {
2529 tempitem = findItemByID(tempnum);
2530 p->setWeapon(*tempitem);
2531 }
2532
fbb87959 2533 tempname = strtok(NULL, " ");
d61f68e3 2534 tempnum = stringtoint(tempname);
2535
2536 if (tempnum != 0)
2537 {
2538 tempitem = findItemByID(tempnum);
2539 p->setArmor(*tempitem);
2540 }
fbb87959 2541
d61f68e3 2542
2543 unsigned long hv = iHASH((unsigned char *) p->getName().c_str());
2544
2545 p->setClient(NULL);
2546
2547 for (tempname = strtok(NULL, " "); tempname != NULL; tempname = strtok(NULL, " "))
fbb87959 2548 {
d61f68e3 2549 long int id, uses;
2550 list<item*>::iterator item_iter;
2551 id = stringtoint(tempname);
2552 tempname = strtok(NULL, " ");
2553 uses = stringtoint(tempname);
2554
2555 item_iter = Items.begin();
2556 while (item_iter != Items.end())
fbb87959 2557 {
d61f68e3 2558 if ((*item_iter)->getID() == id)
2559 {
2560 // Don't sort every time you add an item or it eats CPU
2561 p->inventory->addItemNoChecks((*item_iter))->setUses(uses);
d61f68e3 2562 }
2563 item_iter++;
fbb87959 2564 }
fbb87959 2565 }
d61f68e3 2566 p->inventory->sort();
2567 players[hv].push_back(p);
fbb87959 2568 }
d61f68e3 2569
2570 delete [] buf;
2571 infile.close();
2572 return 1;
85ce9d3e 2573}
2574
5c449fde 2575bool passcmp(const char *encrypted, char *plaintext)
e3c5fe46 2576{
37ed80a9 2577 char salt[3];
2578 char *plaintext2, *plainToencrypt;
2579 bool same = false;
2580
2581 plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
2582 strcpy(plaintext2, plaintext);
2583
2584 salt[0] = encrypted[0];
2585 salt[1] = encrypted[1];
2586 salt[3] = '\0';
2587
2588 plainToencrypt = crypt(plaintext2, salt);
2589
2590 same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
2591
2592 delete []plaintext2;
2593
2594 return same;
e3c5fe46 2595}
2596
2597bool check_password(char *name, char *plaintext)
2598{
d61f68e3 2599 Player *p;
37ed80a9 2600
d61f68e3 2601 if (!(p = findplayer(name)))
37ed80a9 2602 return false;
2603 else
e3c5fe46 2604 {
d61f68e3 2605 return passcmp(p->getPassword().c_str(), plaintext);
e3c5fe46 2606 }
e3c5fe46 2607}
1cf88153 2608
ad7dfaa0 2609void do_store(char *u)
2610{
3f107f27 2611 list<item*>::iterator item_iterator;
e401a866 2612 item *tempItem;
37ed80a9 2613 char *cmd = strtok(NULL, " ");
37ed80a9 2614 char *num = strtok(NULL, " ");
2615 char *space;
e401a866 2616 int id;
37ed80a9 2617 aClient *user;
2618 Player *p;
fbb87959 2619
2620
e401a866 2621 if (!cmd || !num)
ad7dfaa0 2622 {
37ed80a9 2623 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
e401a866 2624 notice(s_GameServ, u, " \ 2STORE SELL NUMBER\ 2");
2625 notice(s_GameServ, u, " \ 2STORE BUY \1fNUMBER\1f\ 2");
37ed80a9 2626 return;
ad7dfaa0 2627 }
37ed80a9 2628 else if (!(user = find(u)))
448a1531 2629 {
37ed80a9 2630 log("Fatal Error: could not find %s in client list", u);
2631 return;
448a1531 2632 }
37ed80a9 2633 else if (isIgnore(user))
448a1531 2634 {
37ed80a9 2635#ifdef DEBUGMODE
2636 log("Ignoring %s.", user->getNick());
2637#endif
2638 return;
448a1531 2639 }
37ed80a9 2640 else if (!is_playing(user))
40251952 2641 {
37ed80a9 2642 notice(s_GameServ, u, "You must be playing to use the store!");
2643 return;
40251952 2644 }
e401a866 2645 else if (is_fighting(user))
2646 {
2647 notice(s_GameServ, u, "You can't go to the store while fighting!");
2648 return;
2649 }
37ed80a9 2650 else if (!isAlive(user->stats))
1af35752 2651 {
37ed80a9 2652 notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!");
2653 return;
1af35752 2654 }
37ed80a9 2655 updateTS(user->stats);
2656
2657 if (stricmp(cmd, "LIST") == 0)
ad7dfaa0 2658 {
e401a866 2659 if (stricmp(num, "WEAPONS") == 0)
3f107f27 2660 {
fbb87959 2661 notice(s_GameServ, u, "Welcome to Kain's Armory");
2662 notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:");
2663 for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator)
2664 {
2665 if ((*item_iterator)->getType() == WEAPON)
2666 {
2667 space = spaces(strlen((*item_iterator)->getName().c_str()), ".");
2668 notice(s_GameServ, u, "%s%ld. %s%s%ld", ((*item_iterator)->getID() < 10 ? " " : ""), (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), space, (*item_iterator)->price());
2669 free(space);
2670 }
2671 }
2672 notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2#\ 2.");
2673 notice(s_GameServ, u, "Where # is the weapon number from the menu above.");
2674
3f107f27 2675 }
e401a866 2676 else if (stricmp(num, "ARMOR") == 0)
3f107f27 2677 {
fbb87959 2678 notice(s_GameServ, u, "Welcome to Kain's Armory");
2679 notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:");
2680 for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator)
2681 {
2682 if ((*item_iterator)->getType() == ARMOR)
2683 {
2684 space = spaces(strlen((*item_iterator)->getName().c_str()), ".");
2685 notice(s_GameServ, u, "%s%ld. %s%s%d",((*item_iterator)->getID() < 10 ? " " : ""), (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), space, (*item_iterator)->price());
2686 free(space);
2687 }
3f107f27 2688 }
fbb87959 2689
2690 notice(s_GameServ, u, "To purchase armor, type /msg %S store buy #");
2691 notice(s_GameServ, u, "Where # is the armor number from the menu above.");
2692 }
3f107f27 2693
2694 }
e401a866 2695 else if (stricmp(cmd, "BUY") == 0)
2696 {
2697 p = user->stats;
2698 if (!num)
fbb87959 2699 {
2700 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
2701 return;
2702 }
37ed80a9 2703 else
fbb87959 2704 {
2705 id = stringtoint(num);
2706 }
2707
e401a866 2708 if (!isstringnum(num))
fbb87959 2709 {
2710 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
2711 return;
2712 }
e401a866 2713 else if (!(tempItem = findStoreItemByID(id)))
fbb87959 2714 {
2715 notice(s_GameServ, u, "Sorry, we don't carry that item!");
2716 return;
2717 }
2718 else if (p->getGold() < tempItem->price())
2719 {
2720 notice(s_GameServ, u, "You can't afford to buy %s", tempItem->getName().c_str());
2721 return;
2722 }
ba9239df 2723 else if (p->inventory->addItem(tempItem))
fbb87959 2724 {
2725 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", tempItem->getName().c_str());
2726 p->subtractGold(tempItem->price());
fbb87959 2727 notice(s_GameServ, u, "Don't forget to type /msg %S equip %ld", tempItem->getID());
2728 }
ba9239df 2729 else
2730 {
2731 notice(s_GameServ, u, "You can't carry any more!");
2732 }
8c126acc 2733 }
37ed80a9 2734 else if (stricmp(cmd, "SELL" ) == 0)
8c126acc 2735 {
e401a866 2736 itemContainer *tempContainer;
37ed80a9 2737 p = user->stats;
e401a866 2738 id = stringtoint(num);
2739 if (!isstringnum(num))
fbb87959 2740 {
2741 notice(s_GameServ, u, "SYNTAX: /msg %S store sell #");
2742 return;
2743 }
e401a866 2744 else if (!(tempContainer = p->inventory->Find(id)))
fbb87959 2745 {
2746 notice(s_GameServ, u, "You're not carrying that!");
2747 return;
2748 }
2749 else if (p->getGold() >= 2000000000)
2750 {
2751 notice(s_GameServ, u, "You have enough gold. Just hang on to it for now.");
2752 }
e401a866 2753 else
fbb87959 2754 {
2755 tempItem = tempContainer->getItem();
2756
2757 notice(s_GameServ, u, "Thank you for your business! We gave you %ld gold for %s!", (tempItem->price() / 2), tempItem->getName().c_str());
2758 p->addGold((tempItem->price() / 2));
2759 p->inventory->deleteItem(tempItem);
2760 if (tempItem == p->getWeapon())
2761 {
2762 notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str());
2763 tempItem->undo(p);
2764 p->clearWeapon();
2765 }
2766 else if (tempItem == p->getArmor())
2767 {
2768 tempItem->undo(p);
2769 notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str());
2770 p->clearArmor();
2771 }
2772 }
8c126acc 2773 }
37ed80a9 2774 else
6d053d90 2775 {
37ed80a9 2776 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
e401a866 2777 notice(s_GameServ, u, " \ 2STORE SELL #\ 2");
2778 notice(s_GameServ, u, " \ 2STORE BUY \1f#\1f\ 2");
37ed80a9 2779 return;
6d053d90 2780 }
8c126acc 2781}
9cda831c 2782void do_inventory(char *u)
2783{
fbb87959 2784 aClient *user;
2785
2786 if (!(user = find(u)))
9cda831c 2787 {
fbb87959 2788 notice(s_GameServ, u, "Fatal Error. Contact a %S admin!");
2789 return;
9cda831c 2790 }
fbb87959 2791 else if (isIgnore(user))
448a1531 2792 {
fbb87959 2793#ifdef DEBUGMODE
2794 log("Ignoring %s.", user->getNick());
2795#endif
2796 return;
448a1531 2797 }
fbb87959 2798 else if (!is_playing(user))
9cda831c 2799 {
fbb87959 2800 notice(s_GameServ, u, "You must be playing to check your inventory!");
2801 return;
9cda831c 2802 }
000f8409 2803 if (!is_fighting(user))
2804 updateTS(user->stats);
fbb87959 2805 showinventory(user->stats, user);
9cda831c 2806}
37ed80a9 2807
228a25d5 2808void showinventory(Player *from, aClient *to)
9cda831c 2809{
b6bf4226 2810 char *nick;
228a25d5 2811 if (!to || !from)
2812 {
2813 return;
2814 }
b6bf4226 2815
2816 nick = to->getNick();
37ed80a9 2817
228a25d5 2818 if (from->inventory->isEmpty())
37ed80a9 2819 {
2820 notice(s_GameServ, nick, "You aren't carrying anything");
2821 return;
2822 }
228a25d5 2823
2824 list <itemContainer> *items;
2825 items = from->inventory->getItems();
2826
2827 list <itemContainer>::iterator item_iter, item_iter2;
2828 item_iter = items->begin();
2829
fbb87959 2830 notice(s_GameServ, nick, "Inventory for %s:", from->getName().c_str());
228a25d5 2831 long count;
2832 while (item_iter != items->end())
37ed80a9 2833 {
1ee4a31b 2834 // Display a list of counted items so as not to show an extra line for duplicate items
2835 count = 0;
2836 item_iter2 = item_iter;
2837 while (item_iter != items->end() && (*item_iter) == (*item_iter2))
2838 {
2839 if ((*item_iter) == (*item_iter2))
228a25d5 2840 {
2841 ++count;
2842 }
1ee4a31b 2843 else
228a25d5 2844 {
2845 break;
2846 }
1ee4a31b 2847 ++item_iter;
2848 }
2849 notice(s_GameServ, nick, "%ld.) %s (%ld)", (*item_iter2).getItem()->getID(), (*item_iter2).getItem()->getName().c_str(), count);
37ed80a9 2850 }
9cda831c 2851}
7b51307d 2852
f5c25639 2853void do_tavern(char *u)
2854{
d1927afc 2855 char *cmd = strtok(NULL, " ");
7b51307d 2856
d1927afc 2857 aClient *user;
2858 Player *p;
2859
2860 if (!(user = find(u)))
f5c25639 2861 {
d1927afc 2862 notice(s_GameServ, u, "Fatal Error. See a %S admin for help");
2863 return;
f5c25639 2864 }
d1927afc 2865 else if (isIgnore(user))
448a1531 2866 {
d1927afc 2867#ifdef DEBUGMODE
2868 log("Ignoring %s.", user->getNick());
2869#endif
2870 return;
448a1531 2871 }
d1927afc 2872 else if (!is_playing(user))
f5c25639 2873 {
d1927afc 2874 notice(s_GameServ, u, "You must be playing to go to the Tavern");
2875 return;
f5c25639 2876 }
d1927afc 2877 else if (is_fighting(user))
9cda831c 2878 {
d1927afc 2879 notice(s_GameServ, u, "You cannot go to the Tavern during a fight!");
2880 return;
9cda831c 2881 }
d1927afc 2882
2883 updateTS(user->stats);
2884 p = user->stats;
2885
2886 if (!cmd)
f5c25639 2887 {
d1927afc 2888 notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary and General Store");
2889 notice(s_GameServ, u, "Your commands:");
2890 notice(s_GameServ, u, "/msg %S TAVERN {LIST | BUY} [NUMBER]");
2891 notice(s_GameServ, u, "What'll it be?");
f5c25639 2892 }
d1927afc 2893 else if (stricmp(cmd, "LIST") == 0)
f5c25639 2894 {
d1927afc 2895 notice(s_GameServ, u, "Here is a list of what we have to offer:");
1e7678e9 2896 showTavern(user);
d1927afc 2897 notice(s_GameServ, u, "To buy an item, type /msg %S TAVERN BUY #");
f5c25639 2898 }
19894227 2899 else if (stricmp(cmd, "BUY") == 0)
f5c25639 2900 {
53d5585b 2901 int amt = 1;
19894227 2902 char *chid = strtok(NULL, " ");
7b51307d 2903 char *amount = strtok(NULL, " ");
2904
53d5585b 2905 if (amount)
2906 amt = stringtoint(amount);
d1927afc 2907
19894227 2908 if (!chid)
fbb87959 2909 {
7b51307d 2910 notice(s_GameServ, u, "SYNTAX: TAVERN BUY # [#]");
fbb87959 2911 notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 6001");
7b51307d 2912 notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 6001 10");
fbb87959 2913 return;
2914 }
19894227 2915 long id = stringtoint(chid);
2916 tavernItem *tempItem;
d1927afc 2917
fbb87959 2918 if (!(tempItem = findTavernItemByID(id)) || user->stats->getLevel() < tempItem->getLevel())
2919 {
2920 notice(s_GameServ, u, "Invalid Choice!");
2921 notice(s_GameServ, u, "Here is a list of what we have to offer:");
2922 showTavern(user);
2923 notice(s_GameServ, u, "To buy an item, type /msg %S TAVERN BUY #");
2924 return;
2925 }
7b51307d 2926 else if (!amount && user->stats->getGold() < tempItem->getItem()->price())
fbb87959 2927 {
2928 notice(s_GameServ, u, "You don't have enough gold!");
2929 notice(s_GameServ, u, "Here is a list of what we have to offer:");
2930 showTavern(user);
2931 notice(s_GameServ, u, "To buy an item, type /msg %S TAVERN BUY #");
2932 }
7b51307d 2933 else if (user->stats->getGold() < amt * tempItem->getItem()->price())
2934 {
2935 notice(s_GameServ, u, "You don't have enough gold!");
2936 notice(s_GameServ, u, "Here is a list of what we have to offer:");
2937 showTavern(user);
2938 notice(s_GameServ, u, "To buy an item, type /msg %S TAVERN BUY # [#]");
2939 }
2940 else
fbb87959 2941 {
7b51307d 2942 if (amount)
fbb87959 2943 {
7b51307d 2944 int amt = stringtoint(amount);
2945 if (amt < 0 || amount[0] == '-')
2946 {
2947 notice(s_GameServ, u, "You trying to steal from me?");
2948 }
2949 else if (user->stats->inventory->addItem(tempItem->getItem(), amt) == NULL)
2950 {
2951 notice(s_GameServ, u, "You can't carry that many!");
7b51307d 2952 }
2497f916 2953 else
2954 {
2955 notice(s_GameServ, u, "%d %s's coming right up!", amt, tempItem->getItem()->getName().c_str());
2956 user->stats->subtractGold(tempItem->getItem()->price() * amt);
2957 }
7b51307d 2958 }
2959 else
2960 {
2961 if (user->stats->inventory->addItem(tempItem->getItem()) == NULL)
2962 {
2963 notice(s_GameServ, u, "You can't carry any more!");
7b51307d 2964 }
2497f916 2965 else
2966 {
2967 notice(s_GameServ, u, "One %s coming right up!", tempItem->getItem()->getName().c_str());
2968 user->stats->subtractGold(tempItem->getItem()->price());
2969 }
fbb87959 2970 }
fbb87959 2971 }
f5c25639 2972 }
d1927afc 2973 else
9cda831c 2974 {
d1927afc 2975 notice(s_GameServ, u, "Improper Syntax.");
2976 notice(s_GameServ, u, "Type /msg %S HELP TAVERN for help");
9cda831c 2977 }
37ed80a9 2978 return;
f5c25639 2979}
2980
8c126acc 2981void do_bank(char *u)
2982{
228a25d5 2983 char *cmd = strtok(NULL, " ");
2984 char *amount = strtok(NULL, " ");
2985 char *nick = strtok(NULL, " ");
2986
2987 aClient *user;
2988 Player *p;
2989
2990 if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick))
8c126acc 2991 {
228a25d5 2992 notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
2993 notice (s_GameServ, u, "BANK BALANCE");
2994 return;
8c126acc 2995 }
228a25d5 2996 else if (!(user = find(u)))
40251952 2997 {
228a25d5 2998 notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) %S "\
2999 " admin for help");
3000 log("Fatal Error. Couldn't find %s while executing do_bank()", u);
3001 return;
40251952 3002 }
228a25d5 3003 else if (isIgnore(user))
448a1531 3004 {
228a25d5 3005#ifdef DEBUGMODE
3006 log("Ignoring %s.", user->getNick());
3007#endif
3008 return;
448a1531 3009 }
228a25d5 3010 else if (!is_playing(user))
8c126acc 3011 {
228a25d5 3012 notice(s_GameServ, u, "You must be playing to use the bank!");
3013 return;
ad7dfaa0 3014 }
228a25d5 3015 else if (is_fighting(user))
2158299e 3016 {
228a25d5 3017 notice(s_GameServ, u, "You can't go to the bank during a fight!");
3018 return;
2158299e 3019 }
228a25d5 3020 updateTS(user->stats);
3021 if (stricmp(cmd, "BALANCE") == 0)
fa376453 3022 {
228a25d5 3023 showBankBalance(u);
3024 return;
fa376453 3025 }
228a25d5 3026 else if (!isAlive(user->stats))
1af35752 3027 {
228a25d5 3028 notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!");
3029 return;
1af35752 3030 }
228a25d5 3031 else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0)
8c126acc 3032 {
228a25d5 3033 notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!");
3034 return;
8c126acc 3035 }
228a25d5 3036 if (stringtoint(amount) < 0)
11f32a66 3037 {
228a25d5 3038 notice(s_GameServ, u, "Sorry. This bank is not licensed "\
3039 "to handle such sums of cash, noble Lord.");
3040 return;
11f32a66 3041 }
228a25d5 3042 p = user->stats;
3043
3044 if (stricmp(cmd, "DEPOSIT") == 0)
8c126acc 3045 {
fbb87959 3046 if (p->getBank() == 2000000000)
8c126acc 3047 {
228a25d5 3048 notice(s_GameServ, u, "Your bank account is full, sire!");
3049 return;
8c126acc 3050 }
228a25d5 3051 else if (stricmp(amount, "ALL") == 0)
8c126acc 3052 {
fbb87959 3053 if (2000000000 - p->getBank() < p->getGold())
8c126acc 3054 {
228a25d5 3055 notice(s_GameServ, u, "You don't have enough room for all of your gold.");
fbb87959 3056 notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->getBank()));
3057 p->subtractGold((2000000000 - p->getBank()));
3058 p->setBank(2000000000);
228a25d5 3059 showBankBalance(u);
8c126acc 3060 }
228a25d5 3061 else
8c126acc 3062 {
fbb87959 3063 notice(s_GameServ, u, "Depositing %ld gold into your account!", p->getGold());
3064 p->addBank(p->getGold());
3065 p->setGold(0);
228a25d5 3066 showBankBalance(u);
8c126acc 3067 }
3068 }
fbb87959 3069 else if (stringtoint(amount) > p->getGold())
8c126acc 3070 {
fbb87959 3071 notice(s_GameServ, u, "Sire, you only have %ld gold!", p->getGold());
228a25d5 3072 showBankBalance(u);
3073 return;
8c126acc 3074 }
228a25d5 3075 else
8c126acc 3076 {
fbb87959 3077 if (2000000000 - p->getBank() < stringtoint(amount))
8c126acc 3078 {
228a25d5 3079 notice(s_GameServ, u, "You don't have room in your account for that much.");
fbb87959 3080 notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->getBank()));
3081 p->subtractGold((2000000000 - p->getBank()));
3082 p->setBank(2000000000);
228a25d5 3083 showBankBalance(u);
8c126acc 3084 }
228a25d5 3085 else
8c126acc 3086 {
228a25d5 3087 notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount));
fbb87959 3088 p->addBank(stringtoint(amount));
3089 p->subtractGold(stringtoint(amount));
228a25d5 3090 showBankBalance(u);
8c126acc 3091 }
3092 }
3093 }
228a25d5 3094 else if (stricmp(cmd, "WITHDRAW") == 0)
8c126acc 3095 {
fbb87959 3096 if (p->getGold() == 2000000000)
8c126acc 3097 {
228a25d5 3098 notice(s_GameServ, u, "You cannot carry any more gold, sire!");
3099 showBankBalance(u);
3100 return;
8c126acc 3101 }
228a25d5 3102 else if (stricmp(amount, "ALL") == 0)
8c126acc 3103 {
fbb87959 3104 if (2000000000 - p->getGold() < p->getBank())
8c126acc 3105 {
228a25d5 3106 notice(s_GameServ, u, "You don't have enough room to carry all that gold.");
fbb87959 3107 notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->getGold()));
3108 p->subtractBank((2000000000 - p->getGold()));
3109 p->setGold(2000000000);
228a25d5 3110 showBankBalance(u);
8c126acc 3111 }
228a25d5 3112 else
8c126acc 3113 {
fbb87959 3114 notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->getBank());
3115 p->addGold(p->getBank());
3116 p->setBank(0);
228a25d5 3117 showBankBalance(u);
8c126acc 3118 }
3119 }
fbb87959 3120 else if (stringtoint(amount) > p->getBank())
8c126acc 3121 {
fbb87959 3122 notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->getBank());
228a25d5 3123 showBankBalance(u);
3124 return;
8c126acc 3125 }
228a25d5 3126 else
8c126acc 3127 {
fbb87959 3128 if (2000000000 - p->getGold() < stringtoint(amount))
8c126acc 3129 {
228a25d5 3130 notice(s_GameServ, u, "You don't enough have room to carry that much gold!");
3131 notice(s_GameServ, u, "You fill your pockets with %ld gold!",
fbb87959 3132 (2000000000 - p->getGold()));
3133 p->subtractBank((2000000000 - p->getGold()));
3134 p->setGold(2000000000);
228a25d5 3135 showBankBalance(u);
8c126acc 3136 }
228a25d5 3137 else
8c126acc 3138 {
228a25d5 3139 notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount));
fbb87959 3140 p->addGold(stringtoint(amount));
3141 p->subtractBank(stringtoint(amount));
228a25d5 3142 showBankBalance(u);
8c126acc 3143 }
3144 }
228a25d5 3145 }
ad7dfaa0 3146}
ab4f4ec0 3147
fcca861d 3148void do_dragon(char *u)
3149{
228a25d5 3150 aClient *user;
3151
3152 if (!(user = find(u)))
fcca861d 3153 {
228a25d5 3154 notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
3155 return;
fcca861d 3156 }
228a25d5 3157 else if (isIgnore(user))
fcca861d 3158 {
228a25d5 3159#ifdef DEBUGMODE
3160 log("Ignoring %s.", user->getNick());
3161#endif
3162 return;
fcca861d 3163 }
228a25d5 3164 else if (!is_playing(user))
fcca861d 3165 {
228a25d5 3166 notice(s_GameServ, u, "You must be playing to fight the dragon!");
3167 return;
fcca861d 3168 }
228a25d5 3169 else if (is_fighting(user))
fcca861d 3170 {
228a25d5 3171 notice(s_GameServ, u, "You are already in a fight. How will you fight the almighty dragon!?");
3172 return;
fcca861d 3173 }
228a25d5 3174 else if (!isAlive(user->stats))
fcca861d 3175 {
228a25d5 3176 notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
3177 return;
fcca861d 3178 }
fbb87959 3179 else if (user->stats->getLevel() < LEVELS)
fcca861d 3180 {
228a25d5 3181 notice(s_GameServ, u, "You fool! Only those strong enough "\
3182 "to vanquish any foe should DARE fight the dragon!");
3183 notice(s_GameServ, u, "To put it in terms you can understand: "\
3184 "You are too weak. You must be Level %d!", REALLEVELS);
3185 return;
fcca861d 3186 }
228a25d5 3187
3188 updateTS(user->stats);
3189
3190 Player *p = user->stats;
3191 setMaster(p);
3192 notice(s_GameServ, u, "You approach the dragon's lair cautiously.");
3193 notice(s_GameServ, u, "The stench of sulfer fills the air as a "\
3194 "deep, red fog rolls in. The air is filled with the "\
3195 "heated mist of deadly fire from beyond the cave "\
3196 "entrance.");
3197 notice(s_GameServ, u, "You adjust your %s, tighten your grip on "\
3198 "your %s, and venture into the hot, dark cave. "\
3199 "You are surprised at the angle of descent as you climb "\
3200 "lower and lower, deeper into the dragon's den.",
3201 (p->getArmor() ? p->getArmor()->getName().c_str() : "Fists"), (p->getWeapon() ? p->getWeapon()->getName().c_str() : "Birthday Suit"));
3202 notice(s_GameServ, u, "You come to the end of the cave to find "\
3203 "a tooth. It is a large tooth... bigger than your torso."\
3204 " Suddenly the darkness lifts from the gleam of an eye "\
3205 " staring into your soul! The eye is large... HUGE!");
3206 notice(s_GameServ, u, "Just then you notice the eye begin to "\
3207 "glare orange! The tooth is moving... but it is still too "\
3208 "dark for you to make out.... THE DRAGON! You see it!");
5de7a0b0 3209 p->setMonster(&dragon);
228a25d5 3210 setDragonFight(p);
3211 display_monster(u);
fcca861d 3212}
3213
ab4f4ec0 3214void do_master(char *u)
3215{
228a25d5 3216 aClient *user;
3217
3218
3219 if (!(user = find(u)))
ab4f4ec0 3220 {
228a25d5 3221 notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
3222 return;
ab4f4ec0 3223 }
228a25d5 3224 else if (isIgnore(user))
448a1531 3225 {
228a25d5 3226#ifdef DEBUGMODE
3227 log("Ignoring %s.", user->getNick());
3228#endif
3229 return;
448a1531 3230 }
228a25d5 3231 else if (!is_playing(user))
c047f947 3232 {
228a25d5 3233 notice(s_GameServ, u, "You must be playing to see your master!");
3234 return;
c047f947 3235 }
228a25d5 3236 else if (is_fighting(user))
ab4f4ec0 3237 {
228a25d5 3238 notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!");
3239 return;
ab4f4ec0 3240 }
228a25d5 3241 else if (!isAlive(user->stats))
1af35752 3242 {
228a25d5 3243 notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
3244 return;
1af35752 3245 }
228a25d5 3246
3247 updateTS(user->stats);
3248
3249 char *cmd = strtok(NULL, " ");
3250 Player *p = user->stats;
3251 long int need = 0;
3252
3253 if (seenMaster(p))
3254 {
3255 notice(s_GameServ, u, "You have already seen your master today. Wait until tomorrow to try again");
3256 return;
1af35752 3257 }
228a25d5 3258
3259 if (cmd != NULL)
ab4f4ec0 3260 {
fbb87959 3261 switch(p->getLevel())
228a25d5 3262 {
ab4f4ec0 3263 case 1:
228a25d5 3264 need = 200;
3265 break;
ab4f4ec0 3266 case 2:
228a25d5 3267 need = 800;
3268 break;
ab4f4ec0 3269 case 3:
228a25d5 3270 need = 2000;
3271 break;
ab4f4ec0 3272 case 4:
228a25d5 3273 need = 8000;
3274 break;
ab4f4ec0 3275 case 5:
228a25d5 3276 need = 20000;
3277 break;
ab4f4ec0 3278 case 6:
228a25d5 3279 need = 80000;
3280 break;
ab4f4ec0 3281 case 7:
228a25d5 3282 need = 200000;
3283 break;
ab4f4ec0 3284 case 8:
228a25d5 3285 need = 800000;
3286 break;
ab4f4ec0 3287 case 9:
228a25d5 3288 need = 2000000;
3289 break;
ab4f4ec0 3290 case 10:
228a25d5 3291 need = 8000000;
3292 break;
ab4f4ec0 3293 case 11:
228a25d5 3294 need = 20000000;
3295 break;
3296
016a160f 3297 case REALLEVELS:
fbb87959 3298 need = p->getExp() + 1;
228a25d5 3299 notice(s_GameServ, u, "You are at level %d. You are the master. What's left? The DRAGON!", REALLEVELS);
3300 return;
3301 break;
ab4f4ec0 3302 default:
fbb87959 3303 need = p->getExp() + 1; // Unknown level... don't let them fight a fake master!
228a25d5 3304 break;
3305 }
c7340cbd 3306 }
228a25d5 3307 else
c7340cbd 3308 {
228a25d5 3309 notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
3310 return;
c7340cbd 3311 }
228a25d5 3312
3313 if (stricmp(cmd, "FIGHT") == 0)
c7340cbd 3314 {
fbb87959 3315 if (p->getExp() >= need)
228a25d5 3316 {
3317 setMaster(p);
3318 see_master(u);
3319 }
3320 else
ddef84f1 3321 notice(s_GameServ, u, "You are not worthy of fighting %s! You need %ld more experience.",
fbb87959 3322 levels[p->getLevel() - 1].master.name.c_str(), (need - p->getExp()));
228a25d5 3323 return;
c7340cbd 3324 }
228a25d5 3325 else if (stricmp(cmd, "QUESTION") == 0)
c7340cbd 3326 {
fbb87959 3327 if (p->getExp() >= need)
ddef84f1 3328 notice(s_GameServ, u, "%s looks you up and down and decides you are more ready than you will ever be.",
fbb87959 3329 levels[p->getLevel() - 1].master.name.c_str());
228a25d5 3330 else
ddef84f1 3331 notice(s_GameServ, u, "You pathetic fool! You are no match for %s, %s!",
fbb87959 3332 levels[p->getLevel() - 1].master.name.c_str(), p->getName().c_str());
228a25d5 3333
3334 return;
c7340cbd 3335 }
228a25d5 3336 else
c7340cbd 3337 {
228a25d5 3338 notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
ab4f4ec0 3339 }
3340}
3341
3342void see_master(char *u)
3343{
228a25d5 3344 aClient *user;
1af35752 3345
228a25d5 3346 if (!(user = find(u)))
ab4f4ec0 3347 {
228a25d5 3348 notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
3349 return;
ab4f4ec0 3350 }
228a25d5 3351
3352 if (!is_fighting(user) && is_playing(user))
ab4f4ec0 3353 {
228a25d5 3354 Player *p = user->stats;
5de7a0b0 3355 p->setMyMaster(&levels[p->getLevel() - 1].master);
3356 p->setMonster(&levels[p->getLevel() - 1].master);
228a25d5 3357 display_monster(u); // Since master is the same structure, use this function
ab4f4ec0 3358 }
3359}
e282e9d2 3360
1e7678e9 3361void showTavern(aClient *user)
d1927afc 3362{
1e7678e9 3363 Player *p;
d1927afc 3364 list<tavernItem>::iterator item_iterator;
3365 item *tempItem;
228a25d5 3366
1e7678e9 3367 p = user->stats;
228a25d5 3368
1e7678e9 3369 if (!p)
3370 return;
228a25d5 3371
d1927afc 3372 item_iterator = tavern.begin();
3373 if (tavern.empty())
1e7678e9 3374 {
3375 notice(s_GameServ, user->getNick(), "Tavern is empty");
3376 return;
3377 }
228a25d5 3378
d1927afc 3379 while (item_iterator != tavern.end())
3380 {
fbb87959 3381 if (p->getLevel() < (*item_iterator).getLevel())
228a25d5 3382 {
3383 item_iterator++;
3384 continue;
3385 }
d1927afc 3386 tempItem = (*item_iterator).getItem();
1e7678e9 3387 notice(s_GameServ, user->getNick(), "%d. %s for %ld gold", tempItem->getID(), tempItem->getName().c_str(), tempItem->price());
d1927afc 3388 item_iterator++;
3389 }
3390}
3391
e282e9d2 3392void showBankBalance(const char *u)
3393{
228a25d5 3394 aClient *user;
3395 Player *p;
3396
3397 if (!(user = find(u)))
e282e9d2 3398 return;
228a25d5 3399
3400 p = user->stats;
3401
3402 if (!p)
3403 return;
3404
fbb87959 3405 notice(s_GameServ, u, "Account Balance: %ld Gold On hand: %ld", p->getBank(), p->getGold());
e282e9d2 3406}
44ea29f7 3407
1fe6fccd 3408void rolloverall()
3409{
d61f68e3 3410 list<Player*>::iterator iter;
1fe6fccd 3411 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
3412 {
c10b78ac 3413 for (iter = players[x].begin(); iter != players[x].end(); iter++)
228a25d5 3414 {
d61f68e3 3415 rollover((*iter));
228a25d5 3416 }
1fe6fccd 3417 }
3418}
44ea29f7 3419void refreshall()
3420{
d61f68e3 3421 list<Player*>::iterator iter;
1fe6fccd 3422 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
44ea29f7 3423 {
c10b78ac 3424 for (iter = players[x].begin(); iter != players[x].end(); iter++)
228a25d5 3425 {
d61f68e3 3426 refresh((*iter));
228a25d5 3427 }
44ea29f7 3428 }
1fe6fccd 3429}
3430
3431void rollover(Player *p)
3432{
3433 if (!p)
3434 return;
228a25d5 3435
fbb87959 3436 p->addForestFights(numrolloverfights);
228a25d5 3437
fbb87959 3438 if (p->getForestFights() > maxforestfights)
3439 p->setForestFights(maxforestfights);
44ea29f7 3440}
3441
3442void refresh(Player *p)
3443{
228a25d5 3444 if (!p)
44ea29f7 3445 return;
fbb87959 3446
3447 if (p->getHP() < p->getMaxHP())
3448 p->healall();
3449 if (p->getForestFights() < forestfights)
228a25d5 3450 {
fbb87959 3451 p->setForestFights(forestfights);
228a25d5 3452 }
3453
fbb87959 3454 p->setPlayerFights(3);
228a25d5 3455 setAlive(p);
3456 clearMaster(p);
44ea29f7 3457}
c7340cbd 3458
3459void do_refresh(char *u)
3460{
d61f68e3 3461 char *name = strtok(NULL, " ");
228a25d5 3462 aClient *user;
d61f68e3 3463 Player *p;
228a25d5 3464
3465 if (!(user = find(u)))
96f71fee 3466 {
228a25d5 3467 notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
3468 log("Error: aClient not found: %s", u);
3469 return;
96f71fee 3470 }
228a25d5 3471 else if (isIgnore(user))
448a1531 3472 {
228a25d5 3473#ifdef DEBUGMODE
3474 log("Ignoring %s.", user->getNick());
3475#endif
3476 return;
448a1531 3477 }
228a25d5 3478 else if (!isAdmin(user))
96f71fee 3479 {
228a25d5 3480 notice(s_GameServ, u, "You must be a %S admin to use this command!");
3481 return;
96f71fee 3482 }
d61f68e3 3483 if (!name)
c7340cbd 3484 {
228a25d5 3485 notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}");
3486 return;
c7340cbd 3487 }
d61f68e3 3488 else if (stricmp(name, "ALL") == 0)
c7340cbd 3489 {
228a25d5 3490 notice(s_GameServ, u, "Refreshing everyone's stats!");
3491 refreshall();
c7340cbd 3492 }
d61f68e3 3493 else if ((p = findplayer(name)))
c7340cbd 3494 {
d61f68e3 3495 notice(s_GameServ, u, "Refreshing %s.", p->getName().c_str());
3496 refresh(p);
3497 }
228a25d5 3498 else
c7340cbd 3499 {
d61f68e3 3500 notice(s_GameServ, u, "Player %s not found.", name);
228a25d5 3501 return;
c7340cbd 3502 }
3503}
3504
ee38284f 3505
3506void resetall()
3507{
d61f68e3 3508 list<Player*>::iterator iter;
228a25d5 3509 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
3510 {
c10b78ac 3511 for (iter = players[x].begin(); iter != players[x].end(); iter++)
228a25d5 3512 {
d61f68e3 3513 reset((*iter));
228a25d5 3514 }
3515 }
ee38284f 3516}
3517
3518void reset(Player *p)
3519{
6fc832d9 3520 item *tempItem;
000f8409 3521
228a25d5 3522 if (!p)
ee38284f 3523 return;
228a25d5 3524
228a25d5 3525 p->reset();
000f8409 3526 // Add the stick and clothes
6fc832d9 3527 tempItem = findItemByID(3001);
ce97fd48 3528 p->inventory->addItem((*Items.begin()))->use(p); // Add the stick
000f8409 3529 p->inventory->addItem(tempItem)->use(p); // Add Clothes
ee38284f 3530}
3531
40251952 3532void updateTS(Player *p)
3533{
228a25d5 3534 if (!p)
40251952 3535 return;
228a25d5 3536
3537#ifdef DEBUGMODE
53d5585b 3538 log("Old timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
228a25d5 3539#endif
3540 p->lastcommand = time(NULL);
3541#ifdef DEBUGMODE
53d5585b 3542 log("New timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
228a25d5 3543#endif
9c443e07 3544 PF_cleartimedout(p);
228a25d5 3545
40251952 3546}
3547
3548bool timedOut(Player *p)
3549{
228a25d5 3550 if (!p)
40251952 3551 return false;
228a25d5 3552 else if (p->lastcommand == 0)
0b6098d5 3553 return false;
228a25d5 3554 else
0b6098d5 3555 {
228a25d5 3556 if ((time(NULL) - p->lastcommand) >= maxidletime)
0b6098d5 3557 return true;
228a25d5 3558
3559 return false;
0b6098d5 3560 }
40251952 3561}
3562
3563void timeOutEvent(Player *p)
3564{
d61f68e3 3565 if (!p || !is_playing(p->getClient())) // then they're not playing
40251952 3566 return;
228a25d5 3567
d61f68e3 3568 char *nick = p->getClient()->getNick();
9c443e07 3569
d61f68e3 3570 if (player_fight(p->getClient()) && isYourTurn(p))
228a25d5 3571 {
3572 // Check to see if they were the idler or if it was the other
3573 // person
9c443e07 3574 if (!PF_timedout(p->getBattle()->stats))
228a25d5 3575 {
3576 // This person's last command was given earlier,
3577 // so this person is the idler
3578 notice(s_GameServ, nick, "You timed out "\
3579 "during a fight. You lose your turn!");
fbb87959 3580 notice(s_GameServ, p->getBattle()->getNick(),
3581 "%s hesitated for too long. Your move.", p->getName().c_str());
228a25d5 3582 clearYourTurn(p);
fbb87959 3583 setYourTurn(p->getBattle()->stats);
228a25d5 3584
3585 // Update the TS for both players to give them another
3586 // Chance to wake up, but if the other player doesn't
3587 // Attack now, they both get logged out.
3588 updateTS(p);
9c443e07 3589 PF_settimedout(p);
fbb87959 3590 display_players(p->getBattle());
228a25d5 3591 return;
3592 }
3593 else
3594 {
fbb87959 3595 notice(s_GameServ, p->getBattle()->getNick(),
228a25d5 3596 "You and %s timed out at the same time."\
3597 " Don't fight if you're just going to "\
fbb87959 3598 "sit there!", p->getName().c_str());
d61f68e3 3599 notice(s_GameServ, p->getClient()->getNick(),
228a25d5 3600 "You and %s timed out at the same time."\
3601 " Don't fight if you're just going to "\
fbb87959 3602 "sit there!", p->getBattle()->stats->getName().c_str());
3603 logout(p->getBattle());
d61f68e3 3604 logout(p->getClient());
e248e6be 3605 clearYourTurn(p);
3606 clearYourTurn(p->getBattle()->stats);
228a25d5 3607 return;
3608 }
0b6098d5 3609 }
d61f68e3 3610 else if (!player_fight(p->getClient()))
eb7608de 3611 {
d61f68e3 3612 if (isAlive(p) && p->getGold() > 0)
228a25d5 3613 {
3614 // Place fun stuff here :)
3615 int randnum = 1 + rand() % 100; // 1-100
3616#define GSN(s) notice(s_GameServ, nick, s)
3617#define GSN2(s, f) notice(s_GameServ, nick, s, f)
3618
3619 if (randnum < 50)
3620 {
3621 // 35-100% of your gold goes pffft - kain
d61f68e3 3622 int stolen = (35 + (rand() % 66)) * (p->getGold() / 100);
228a25d5 3623
3624 GSN("You stop for a moment to rest on the "\
3625 "street corner. All of a sudden, you "\
3626 "are ambushed from all sides by a hoarde "\
3627 "of knife wielding thugs.");
3628 GSN2("The thugs beat you into utter submission "\
3629 "and steal %ld gold from you!", stolen);
d61f68e3 3630 p->subtractGold(stolen);
228a25d5 3631 }
3632 else if (randnum >= 50 && randnum < 75)
3633 {
3634 // 25-65% of your gold goes pffft - kain
d61f68e3 3635 int stolen = (25 + (rand() % 41)) * (p->getGold() / 100);
228a25d5 3636 GSN("While dilly dallying around, you lose "\
3637 "your sense of time. Little did you know, "\
3638 "but thieves lifted your gold while you "\
3639 "weren't watching.");
3640 GSN2("Better luck next time... you lose %d gold", stolen);
d61f68e3 3641 p->subtractGold(stolen);
228a25d5 3642 }
3643 else if (randnum >= 75)
3644 {
3645 // 25-75% of your gold goes pffft - kain
d61f68e3 3646 int stolen = (25 + (rand() % 51)) * (p->getGold() / 100);
228a25d5 3647 GSN("Good grief! A gaggle of gooey green ghostlike "\
3648 "goblins grabbed your gold!");
3649 GSN2("They stole %d gold from you!", stolen);
d61f68e3 3650 p->subtractGold(stolen);
228a25d5 3651 }
3652 }
3653
3654 // Always log out the user
d61f68e3 3655 logout(p->getClient());
eb7608de 3656 }
40251952 3657}
3658
ee38284f 3659void do_reset(char *u)
3660{
228a25d5 3661 char *nick = strtok(NULL, " ");
3662 aClient *user;
d61f68e3 3663 Player *p;
228a25d5 3664
3665 if (!(user = find(u)))
ee38284f 3666 {
228a25d5 3667 notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
3668 log("Error: aClient not found: %s", u);
3669 return;
ee38284f 3670 }
228a25d5 3671 else if (!isAdmin(user))
ee38284f 3672 {
228a25d5 3673 notice(s_GameServ, u, "You must be a %S admin to use this command!");
3674 return;
ee38284f 3675 }
228a25d5 3676
3677 if (!nick)
ee38284f 3678 {
228a25d5 3679 notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}");
ee38284f 3680 }
228a25d5 3681 else if (stricmp(nick, "ALL") == 0)
ee38284f 3682 {
228a25d5 3683 notice(s_GameServ, u, "Resetting everyone's stats!");
3684 resetall();
ee38284f 3685 }
d61f68e3 3686 else if (!(p = findplayer(nick)))
3687 {
3688 notice(s_GameServ, u, "Nick %s not found.", nick);
3689 }
228a25d5 3690 else
ee38284f 3691 {
d61f68e3 3692 notice(s_GameServ, u, "Resetting %s.", p->getName().c_str());
3693 reset(p);
3694 }
ee38284f 3695}
3696
c7340cbd 3697void do_help(char *u)
3698{
228a25d5 3699 char *cmd = strtok(NULL, " ");
3700
3701 display_help(u, cmd);
c7340cbd 3702}
3703
3704void display_help(char *u, char *file)
3705{
228a25d5 3706 ifstream infile;
3707 char *buf;
3708
3709 if (!file)
c7340cbd 3710 {
228a25d5 3711 infile.open("helpfiles/help");
3712 if (infile.fail())
3713 {
3714 log("Error opening helpfiles/help");
3715 notice(s_GameServ, u, "Error opening helpfiles/help");
3716 return;
3717 }
3718 buf = new char[1024];
3719 while(infile.getline(buf, 1024))
3720 {
3721 // Written this way, it will process %S in the helpfiles
3722 // Instead of notice(s_GameServ, u, "%s", buf);
3723 notice(s_GameServ, u, buf);
3724 }
3725
3726 // Minor recursion
3727 aClient *user = find(u);
3728 if (user && isAdmin(user))
96f71fee 3729 display_help(u, "admin_commands");
c7340cbd 3730 }
228a25d5 3731 else
c7340cbd 3732 {
228a25d5 3733 char *filename;
3734 filename = new char[strlen(file) + 11];
3735 strcpy(filename, "helpfiles/");
3736 strcat(filename, file);
3737
3738 for (unsigned int x = 10; x < strlen(filename); x++)
f27a378f 3739 filename[x] = tolower(filename[x]);
228a25d5 3740
3741 infile.open(filename);
3742 delete [] filename;
3743 if (infile.fail())
3744 {
3745 notice(s_GameServ, u, "No help for \ 2%s\ 2", file);
3746 return;
3747 }
3748 buf = new char[1024];
3749 while(infile.getline(buf, 1024))
3750 {
3751 // Written this way, it will process %S in the helpfiles
3752 // Instead of notice(s_GameServ, u, "%s", buf);
3753 notice(s_GameServ, u, buf);
3754 }
c7340cbd 3755 }
228a25d5 3756 infile.close();
3757 delete [] buf;
c7340cbd 3758}
96f71fee 3759
3760void do_admin(char *u)
3761{
228a25d5 3762 aClient *user;
3763 char *pass = strtok(NULL, " ");
3764
3765 if (!(user = find(u)))
96f71fee 3766 {
228a25d5 3767 log("Error: aClient not found: %s", u);
3768 notice(s_GameServ, u, "Error: aClient not found. Contact %S admin.");
3769 return;
96f71fee 3770 }
228a25d5 3771
3772 if (!pass)
96f71fee 3773 {
228a25d5 3774 notice(s_GameServ, u, "SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2");
3775 return;
96f71fee 3776 }
228a25d5 3777
3778 if (isAdmin(user))
1af35752 3779 {
228a25d5 3780 notice(s_GameServ, u, "You already have administrator privledges.");
3781 return;
1af35752 3782 }
228a25d5 3783 else if (strcmp(pass, adminpass) == 0)
96f71fee 3784 {
228a25d5 3785 notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
3786 setAdmin(user);
3787#ifdef P10
3788 log("%s became an administrator.", user->getRealNick());
3789#else
3790 log("%s became an administrator.", user->getNick());
3791#endif
96f71fee 3792 }
228a25d5 3793 else
96f71fee 3794 {
228a25d5 3795 notice(s_GameServ, u, "Invalid password. Remember: case sensitive");
3796 return;
96f71fee 3797 }
3798}
1af35752 3799
ea93c39a 3800bool load_levels()
3801{
228a25d5 3802 char *filename;
3803 filename = new char[256];
3804
3805 for (int x = 1; x <= LEVELS; x++)
ea93c39a 3806 {
228a25d5 3807 sprintf(filename, "data/levels/level%d.dat", x);
3808 if (levels[x - 1].loadLevel(filename) == false)
5de7a0b0 3809 {
3810 delete []filename;
3811 return false;
3812 }
ea93c39a 3813 }
228a25d5 3814
3815 delete []filename;
3816 return true;
ea93c39a 3817}
d61f68e3 3818
4dde2ed9 3819bool load_monsters()
3820{
228a25d5 3821 char *filename;
3822 ifstream infile;
3823 char *buf;
3824 buf = new char[2048];
3825
bf3a2ff9 3826 for (int level = 1; level <= LEVELS; level++)
228a25d5 3827 {
3828 filename = new char[256];
3829 sprintf(filename, "data/monsters/level%d.dat", level);
3830 infile.open(filename);
3831
3832 if (!infile)
3833 {
3834 log("Error opening %s", filename);
5de7a0b0 3835 delete []filename;
3836 delete []buf;
228a25d5 3837 return false;
3838 }
3839
3840#ifdef DEBUGMODE
3841 log("Loading monsters from %s", filename);
3842#endif
3843
3844 while (infile.getline(buf, 2048))
3845 {
3846 if (buf[0] == '^')
3847 break;
3848 if (buf[0] == '\n' || buf[0] == '\0' || buf[0] == '#')
3849 continue;
3850 Monster *temp;
3851 temp = new Monster;
3852
3853 temp->name = strtok(buf, "~");
3854 temp->weapon = strtok(NULL, "~");
3855 temp->death = strtok(NULL, "~");
3856
c10b78ac 3857 levels[level - 1].monsters.push_back(temp);
3858
228a25d5 3859 }
3860 delete [] filename;
3861 infile.close();
3862 }
3863 delete [] buf;
3864 return true;
4dde2ed9 3865}
d1927afc 3866
3867item *findItemByID(int id)
3868{
3869 list<item*>::iterator item_iterator;
228a25d5 3870
d1927afc 3871 item_iterator = Items.begin();
228a25d5 3872
d1927afc 3873 while (item_iterator != Items.end())
3874 {
3875 if ((*item_iterator)->getID() == id)
228a25d5 3876 {
3877 return (*item_iterator);
3878 }
d1927afc 3879 item_iterator++;
3880 }
3881 return NULL;
3882}
19894227 3883
e401a866 3884item *findStoreItemByID(int id)
3885{
3886 list<item*>::iterator item_iterator;
228a25d5 3887
e401a866 3888 item_iterator = store.begin();
228a25d5 3889
e401a866 3890 while (item_iterator != store.end())
3891 {
3892 if ((*item_iterator)->getID() == id)
228a25d5 3893 {
3894 return (*item_iterator);
3895 }
e401a866 3896 item_iterator++;
3897 }
3898 return NULL;
3899}
3900
19894227 3901tavernItem *findTavernItemByID(int id)
3902{
3903 list<tavernItem>::iterator item_iterator;
228a25d5 3904
19894227 3905 item_iterator = tavern.begin();
228a25d5 3906
19894227 3907 while (item_iterator != tavern.end())
3908 {
3909 if ((*item_iterator).getItem()->getID() == id)
228a25d5 3910 {
3911 return &(*item_iterator);
3912 }
19894227 3913 item_iterator++;
3914 }
3915 return NULL;
3916}