]> jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
ce27a5014329915685db4f3b3584a2ca8013d340
[irc/gameservirc.git] / gameserv / gameserv.cpp
1 #include "aClient.h"
2 #include "config.h"
3 #include "extern.h"
4 #include "player.h"
5 #include "pouch.h"
6 #include "flags.h"
7 #include "level.h"
8 #include "sockhelp.h"
9 #include "item.h"
10 #include "script.h"
11 #include "toplist.h"
12
13 #include <algorithm>
14 #include <cctype>
15 #include <fstream>
16 #include <stdlib.h>
17 #include <list>
18 #include <iterator>
19
20 using namespace std;
21
22 #if defined(HAVE_CRYPT_H)
23
24 #include <crypt.h>
25
26 #elif defined(HAVE_UNISTD_H)
27
28 #include <unistd.h>
29
30 #endif
31
32 Monster dragon; // The current dragon
33 Level levels[LEVELS]; // The newest way to store monsters
34 list<item*> Items; // The master list of items
35 list<tavernItem> tavern; // The list of items available at the tavern
36 list<item*> store; // List of items available at the store
37
38 toplist myToplist; // List of the top 10 players
39
40
41
42 bool shuttingdown;
43
44
45 void do_heal(char *u);
46 void do_help(char *u);
47 void do_identify(char *u);
48 void do_inventory(char *u);
49 void do_refresh(char *u);
50 void do_register(char *u);
51 void do_list(char *u);
52 void do_logout(char *u);
53 void do_master(char *u);
54 void do_dragon(char *u);
55 void do_play(char *u);
56 void do_quitg(char *u);
57 void do_reset(char *u);
58 void do_run(char *u);
59 void do_set(char *u);
60 void do_stats(char *u);
61 void do_store(char *u);
62 void do_tavern(char *u);
63 void do_use(char *u);
64
65 #define WNA 16
66
67 int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
68 int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
69 int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
70
71 void gameserv(char *source, char *buf)
72 {
73 char *cmd, z;
74 cmd = strtok(buf, " ");
75
76 #ifndef P10
77 source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
78 #endif
79
80 z = cmd[0];
81 if (z == ':')
82 cmd++; // Get rid of that : at the beginning of the :text (command)
83
84 #ifdef DEBUGMODE
85 log("Source: %s Command: %s", source, cmd);
86 #endif
87
88 if (strnicmp(cmd, "\1PING", 6) == 0)
89 {
90 char *ts;
91 ts = strtok(NULL, "\1");
92 notice(s_GameServ, source, "\1PING %s\1", ts);
93 }
94 else if (stricmp(cmd, "\1VERSION\1") == 0)
95 {
96 notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION);
97 }
98 else if (stricmp(cmd, "SEARCH") == 0)
99 {
100 cmd = strtok(NULL, " ");
101
102 if (!cmd)
103 notice(s_GameServ, source, "SYNTAX: /msg <S SEARCH FOREST");
104 else
105 do_forest(source);
106
107 }
108 else if (stricmp(cmd, "ADMIN") == 0)
109 {
110 do_admin(source);
111 }
112 else if (stricmp(cmd, "ATTACK") == 0)
113 {
114 do_attack(source);
115 }
116 else if (stricmp(cmd, "BANK") == 0)
117 {
118 do_bank(source);
119 }
120 else if (stricmp(cmd, "CHECK") == 0)
121 {
122 do_check(source);
123 }
124 else if (stricmp(cmd, "DRAGON") == 0)
125 {
126 do_dragon(source);
127 }
128 else if (stricmp(cmd, "EQUIP") == 0)
129 {
130 do_equip(source);
131 }
132 else if (stricmp(cmd, "FIGHT") == 0)
133 {
134 do_fight(source);
135 }
136 else if (stricmp(cmd, "HEAL") == 0)
137 {
138 do_heal(source);
139 }
140 else if (stricmp(cmd, "HELP") == 0)
141 {
142 do_help(source);
143 }
144 else if (stricmp(cmd, "IDENTIFY") == 0)
145 {
146 do_identify(source);
147 }
148 else if (stricmp(cmd, "INVENTORY") == 0)
149 {
150 do_inventory(source);
151 }
152 else if (stricmp(cmd, "LIST") == 0)
153 {
154 do_list(source);
155 }
156 else if (stricmp(cmd, "LOGOUT") == 0)
157 {
158 do_logout(source);
159 }
160 else if (stricmp(cmd, "MASTER") == 0)
161 {
162 do_master(source);
163 }
164 else if (stricmp(cmd, "NEWS") == 0)
165 {
166 do_news(source);
167 }
168 else if (stricmp(cmd, "REGISTER") == 0)
169 {
170 do_register(source);
171 }
172 else if (stricmp(cmd, "REFRESH") == 0)
173 {
174 do_refresh(source);
175 }
176 else if (stricmp(cmd, "RESET") == 0)
177 {
178 do_reset(source);
179 }
180 else if (stricmp(cmd, "RUN") == 0)
181 {
182 do_run(source);
183 }
184 else if (stricmp(cmd, "SET") == 0)
185 {
186 do_set(source);
187 }
188 else if (stricmp(cmd, "STATS") == 0)
189 {
190 do_stats(source);
191 }
192 else if (stricmp(cmd, "STORE") == 0)
193 {
194 do_store(source);
195 }
196 else if (stricmp(cmd, "TAVERN") == 0)
197 {
198 do_tavern(source);
199 }
200 else if (stricmp(cmd, "USE") == 0)
201 {
202 do_use(source);
203 }
204 else if (stricmp(cmd, "SHUTDOWN") == 0)
205 {
206 aClient *user;
207
208 if (!(user = find(source)))
209 {
210 notice(s_GameServ, source, "Error: aClient not found. Contact a <S admin");
211 log("Error: aClient not found: %s", source);
212 }
213 else if (!isAdmin(user))
214 {
215 notice(s_GameServ, source, "You must be a <S admin to use this command!");
216 }
217 else
218 {
219 save_gs_dbase();
220 #ifdef P10
221 raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername, user->getRealNick());
222 #else
223 raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source);
224 #endif
225 shuttingdown = true;
226 }
227 }
228 else if (stricmp(cmd, "SAVE") == 0)
229 {
230 aClient *user;
231
232 if (!(user = find(source)))
233 {
234 notice(s_GameServ, source, "Error: aClient not found. Contact a <S admin");
235 log("Error: aClient not found: %s", source);
236 }
237 else if (!isAdmin(user))
238 {
239 notice(s_GameServ, source, "You must be a <S admin to use this command!");
240 }
241 else
242 {
243 save_gs_dbase();
244 }
245 }
246 else if (stricmp(cmd, "LOAD") == 0)
247 {
248 aClient *user;
249
250 if (!(user = find(source)))
251 {
252 notice(s_GameServ, source, "Error: aClient not found. Contact a <S admin");
253 log("Error: aClient not found: %s", source);
254 }
255 else if (!isAdmin(user))
256 {
257 notice(s_GameServ, source, "You must be a <S admin to use this command!");
258 }
259 else
260 {
261 char *cmd2 = strtok(NULL, " ");
262 if (!cmd2)
263 {
264 notice(s_GameServ, source, "Loading player data from %s", playerdata);
265 load_gs_dbase();
266 }
267 else if (stricmp(cmd2, "MONSTERS") == 0)
268 {
269 notice(s_GameServ, source, "Loading monster data");
270 load_monsters();
271 }
272 else if (stricmp(cmd2, "SCRIPTS") == 0)
273 {
274 // Testing scripts for now
275 script scr;
276 notice(s_GameServ, source, "Loading scripts");
277
278 if (scr.loadScript("test.txt"))
279 scr.executeScript(user->stats);
280 }
281 else
282 {
283 display_help(source, cmd);
284 }
285 }
286 }
287 #ifdef DEBUGMODE
288 else if (stricmp(cmd, "RAW") == 0)
289 {
290 aClient *user;
291
292 if (!(user = find(source)))
293 {
294 notice(s_GameServ, source, "Error: aClient not found. Contact a <S admin");
295 log("Error: aClient not found: %s", source);
296 }
297 else if (!isAdmin(user))
298 {
299 notice(s_GameServ, source, "You must be a <S admin to use this command!");
300 }
301 else
302 {
303 char *rest = strtok(NULL, "");
304 raw("%s", rest);
305 }
306 }
307 else if (stricmp(cmd, "RANDOM") == 0)
308 {
309 char *rstr = strtok(NULL, "");
310 range trange;
311 trange.setRange(rstr);
312 notice(s_GameServ, source, "Random number in that range: %d", trange.random());
313 }
314 #endif
315 else
316 {
317 aClient *user;
318 if ((user = find(source)))
319 {
320 if (isIgnore(user))
321 {
322 #ifdef DEBUGMODE
323 log("Ignoring %s.", user->getNick());
324 #endif
325 }
326 else
327 {
328 notice(s_GameServ, source, "Unknown command \002%s\002. Type /msg <S \002HELP\002 to get a list of commands.", cmd);
329 }
330 }
331 }
332
333 #ifndef P10
334 source--; // Bring the ':' back so we don't leak memory
335 #endif
336 if (z == ':')
337 cmd--; // Same thing :)
338 }
339
340
341
342 void do_list(char *u)
343 {
344 aClient *user;
345 Player *p;
346 char *cmd = strtok(NULL, " ");
347
348 if (!(user = find(u)))
349 {
350 log("Fatal Error: Couldn't find %s in the client list", u);
351 return;
352 }
353 else if (isIgnore(user))
354 {
355 #ifdef DEBUGMODE
356 log("Ignoring %s. Command LIST", user->getNick());
357 #endif
358 return;
359 }
360
361 if (cmd == NULL || stricmp(cmd, "TOP") == 0)
362 {
363 list<PlayerWrapper>::iterator iter;
364 bool header = false;
365
366 if (myToplist.empty())
367 {
368 notice(s_GameServ, u, "There are no players");
369 return;
370 }
371 myToplist.sort();
372 myToplist.reverse();
373
374 iter = myToplist.begin();
375
376 while (iter != myToplist.end())
377 {
378 if (!header)
379 {
380 notice(s_GameServ, u, "Top Players");
381 header = true;
382
383 }
384 notice(s_GameServ, u, "Level: %2d Exp: %10d Name: %s",
385 (*iter).getLevel(), (*iter).getExp(), (*iter).getName().c_str());
386 iter++;
387 }
388 }
389 else
390 {
391
392 list<Player*>::iterator iter;
393 bool header = false;
394
395 for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
396 {
397 iter = players[x].begin();
398 if (!players[x].empty())
399 {
400 while(iter != players[x].end())
401 {
402 p = (*iter);
403 if (cmd || is_playing(p->getClient()))
404 {
405 if (!header)
406 {
407 notice(s_GameServ, u, "Players:");
408 header = true;
409 }
410 #ifdef P10
411 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getRealNick() : "Not Playing"),
412 p->getName().c_str());
413 #else
414 notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getNick() : "Not Playing"),
415 p->getName().c_str());
416 #endif
417 }
418 iter++;
419 }
420 }
421 }
422 if (!header)
423 notice(s_GameServ, u, "No one is playing");
424 else
425 notice(s_GameServ, u, "End of List");
426 }
427 }
428
429 void do_set(char *u)
430 {
431 aClient *user;
432 Player *p;
433 char *name = strtok(NULL, " ");
434 char *cmd = strtok(NULL, " ");
435 char *cmd2;
436
437 if (!(user = find(u)))
438 {
439 notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
440 "Buf: %s LOGOUT", u);
441 return;
442 }
443 else if (isIgnore(user))
444 {
445 #ifdef DEBUGMODE
446 log("Ignoring %s.", user->getNick());
447 #endif
448 return;
449 }
450 else if (!name || !cmd)
451 {
452 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}");
453 return;
454 }
455 else if (!(p = findplayer(name)))
456 {
457 // Back the pointers up... they didn't send a name probably
458 cmd2 = cmd;
459 cmd = name;
460 p = user->stats;
461
462 if (!is_playing(user))
463 {
464 notice(s_GameServ, u, "You must be playing to set things for yourself!");
465 return;
466 }
467 }
468 else
469 {
470 cmd2 = strtok(NULL, " ");
471 }
472 if (!cmd2)
473 {
474 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}");
475 return;
476 }
477
478 // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
479 if (stricmp(cmd, "PASSWORD") == 0)
480 {
481 // Person is looking to change their password
482 // If they're an admin, or it's theirself, allow it
483 // cmd2 is pointing to the password now
484 if (isAdmin(user) || user == p->getClient())
485 {
486 p->setPassword(cmd2);
487 notice(s_GameServ, u, "Password successfully changed");
488 }
489 else if (user != p->getClient() && !isAdmin(user))
490 {
491 notice(s_GameServ, u, "You must be a <S admin to set other peoples' passwords.");
492 return;
493 }
494 }
495 else if (stricmp(cmd, "BANK") == 0 || stricmp(cmd, "BALANCE") == 0)
496 {
497 if (!isAdmin(user))
498 {
499 notice(s_GameServ, u, "Admins Only!");
500 return;
501 }
502 else if (stricmp(cmd, "BANK") == 0)
503 {
504 cmd2 = strtok(NULL, " "); // Need an extra parameter for set bank balance
505 }
506 if (!cmd2)
507 {
508 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] [BANK] BALANCE <NUMBER>");
509 return;
510 }
511
512 p->setBank(stringtoint(cmd2));
513
514 notice(s_GameServ, u, "Bank balance changed to %ld!", p->getBank());
515 }
516 else if (stricmp(cmd, "PLAYER") == 0)
517 {
518 if (!isAdmin(user))
519 {
520 notice(s_GameServ, u, "Admins Only!");
521 return;
522 }
523 else if (stricmp(cmd2, "FIGHTS") != 0)
524 {
525 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
526 return;
527 }
528 else
529 {
530 cmd2 = strtok(NULL, " ");
531 if (!cmd2)
532 {
533 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] PLAYER FIGHTS <NUMBER>");
534 return;
535 }
536 p->setPlayerFights(stringtoint(cmd2));
537
538 notice(s_GameServ, u, "Player fights changed to %d!", p->getPlayerFights());
539 }
540 }
541 else if (stricmp(cmd, "FOREST") == 0)
542 {
543 if (!isAdmin(user))
544 {
545 notice(s_GameServ, u, "Admins Only!");
546 return;
547 }
548 else if (stricmp(cmd2, "FIGHTS") != 0)
549 {
550 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <number>");
551 return;
552 }
553 else
554 {
555 cmd2 = strtok(NULL, " ");
556 if (!cmd2)
557 {
558 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] FOREST FIGHTS <NUMBER>");
559 return;
560 }
561
562 p->setForestFights(stringtoint(cmd2));
563
564 notice(s_GameServ, u, "Forest fights changed to %d!", p->getForestFights());
565 }
566 }
567 else if (stricmp(cmd, "GOLD") == 0)
568 {
569 if (!isAdmin(user))
570 {
571 notice(s_GameServ, u, "Admins Only!");
572 return;
573 }
574 else
575 {
576 if (!cmd2)
577 {
578 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] GOLD <NUMBER>");
579 return;
580 }
581 p->setGold(stringtoint(cmd2));
582
583 notice(s_GameServ, u, "Gold set to %ld", p->getGold());
584 return;
585 }
586 }
587 else if (stricmp(cmd, "STRENGTH") == 0 && stricmp(cmd2, "POTIONS") != 0)
588 {
589 if (!isAdmin(user))
590 {
591 notice(s_GameServ, u, "Admins Only!");
592 return;
593 }
594 else
595 {
596 if (!cmd2)
597 {
598 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] STRENGTH <NUMBER>");
599 return;
600 }
601
602 p->setStrength(stringtoint(cmd2));
603
604 notice(s_GameServ, u, "Strength set to %d", p->getStrength());
605 return;
606 }
607 }
608 else if (stricmp(cmd, "DEFENSE") == 0 && stricmp(cmd2, "POTIONS") != 0)
609 {
610 if (!isAdmin(user))
611 {
612 notice(s_GameServ, u, "Admins Only!");
613 return;
614 }
615 else
616 {
617 if (!cmd2)
618 {
619 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] DEFENSE <NUMBER>");
620 return;
621 }
622
623 p->setDefense(stringtoint(cmd2));
624
625 notice(s_GameServ, u, "Defense set to %d", p->getDefense());
626 return;
627 }
628 }
629 else if (stricmp(cmd, "HP") == 0 && stricmp(cmd2, "POTIONS") != 0)
630 {
631 if (!isAdmin(user))
632 {
633 notice(s_GameServ, u, "Admins Only!");
634 return;
635 }
636 else
637 {
638 if (!cmd2)
639 {
640 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] HP <NUMBER>");
641 return;
642 }
643
644 // Make sure it's easy for an admin to set the hp
645 if (p->getMaxHP() < stringtoint(cmd2))
646 p->setMaxHP(stringtoint(cmd2));
647
648 p->setHP(stringtoint(cmd2));
649
650 notice(s_GameServ, u, "HP set to %d", p->getHP());
651 return;
652 }
653 }
654 else if (stricmp(cmd, "MAXHP") == 0)
655 {
656 if (!isAdmin(user))
657 {
658 notice(s_GameServ, u, "Admins Only!");
659 return;
660 }
661 else
662 {
663 if (!cmd2)
664 {
665 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] MAXHP <NUMBER>");
666 return;
667 }
668 p->setMaxHP(stringtoint(cmd2));
669
670 notice(s_GameServ, u, "MaxHP set to %d", p->getMaxHP());
671 return;
672 }
673 }
674 else if (stricmp(cmd, "EXPERIENCE") == 0 || stricmp(cmd, "EXP") == 0)
675 {
676 if (!isAdmin(user))
677 {
678 notice(s_GameServ, u, "Admins Only!");
679 return;
680 }
681 else
682 {
683 if (!cmd2)
684 {
685 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
686 return;
687 }
688
689 p->setExp(stringtoint(cmd2));
690
691 notice(s_GameServ, u, "Exp set to %ld", p->getExp());
692 return;
693 }
694 }
695 else if (stricmp(cmd, "LEVEL") == 0)
696 {
697 if (!isAdmin(user))
698 {
699 notice(s_GameServ, u, "Admins Only!");
700 return;
701 }
702 else
703 {
704 if (!cmd2)
705 {
706 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] LEVEL <NUMBER>");
707 return;
708 }
709 p->setLevel(stringtoint(cmd2));
710
711 notice(s_GameServ, u, "Level set to %d", p->getLevel());
712 return;
713 }
714 }
715 else if (stricmp(cmd, "ALIVE") == 0)
716 {
717 if (!isAdmin(user))
718 {
719 notice(s_GameServ, u, "Admins Only!");
720 return;
721 }
722 else
723 {
724 if (!cmd2)
725 {
726 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] ALIVE TRUE|FALSE");
727 return;
728 }
729 else if (stricmp(cmd2, "TRUE") == 0)
730 {
731 notice(s_GameServ, u, "%s has been Resurrected!", p->getName().c_str());
732 setAlive(p);
733 }
734 else
735 {
736 notice(s_GameServ, u, "%s is now dead!", p->getName().c_str());
737 clearAlive(p);
738 }
739 }
740 }
741 else if (stricmp(cmd, "SEEN") == 0)
742 {
743 if (!isAdmin(user))
744 {
745 notice(s_GameServ, u, "Admins Only!");
746 return;
747 }
748 else if (stricmp(cmd2, "MASTER") != 0)
749 {
750 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NAME] SEEN MASTER {TRUE|FALSE}");
751 return;
752 }
753 else
754 {
755 cmd2 = strtok(NULL, " ");
756 if (!cmd2)
757 {
758 notice(s_GameServ, u, "SYNTAX: /msg <S SET [NICK] SEEN MASTER {TRUE|FALSE}");
759 return;
760 }
761 else if (stricmp(cmd2, "TRUE") == 0)
762 {
763 notice(s_GameServ, u, "%s has seen their master now.", p->getName().c_str());
764 p->addFlag(FLAG_MASTER);
765 }
766 else
767 {
768 notice(s_GameServ, u, "%s has not seen their master now.", p->getName().c_str());
769 p->remFlag(FLAG_MASTER);
770 }
771 }
772 }
773 else
774 {
775 notice(s_GameServ, u, "Unknown command: SET %s", cmd);
776 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}");
777 return;
778 }
779 }
780
781 void do_logout(char *u)
782 {
783 aClient *user;
784 Player *p;
785 char *name = strtok(NULL, " ");
786
787 if (!(user = find(u)))
788 {
789 notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
790 "Buf: %s LOGOUT", u);
791 log("Could not find aClient Buf: %s LOGOUT",
792 u);
793 return;
794 }
795 else if (isIgnore(user))
796 {
797 #ifdef DEBUGMODE
798 log("Ignoring %s.", user->getNick());
799 #endif
800 return;
801 }
802
803 if (name)
804 {
805 if (!isAdmin(user))
806 {
807 notice(s_GameServ, u, "You must be a <S admin to use this command!");
808 }
809 else if (!(p = findplayer(name)))
810 {
811 notice(s_GameServ, u, "Couldn't find a player named %s", name);
812 }
813 else
814 {
815 notice(s_GameServ, u, "Logging out %s", p->getName().c_str());
816 logout(p->getClient());
817 }
818 }
819 else if (!name)
820 {
821 if (!is_playing(user))
822 {
823 notice(s_GameServ, u, "You're not logged in!");
824 }
825 else if (is_fighting(user))
826 {
827 notice(s_GameServ, u, "You can't logout while fighting!");
828 }
829 else
830 {
831 notice(s_GameServ, u, "You have left the fields. You have lived to kill another day!");
832 logout(user);
833 }
834 }
835 }
836
837 void do_register(char *u)
838 {
839 char *password, *name;
840 aClient *user;
841 Player *p;
842 name = strtok(NULL, " ");
843 password = strtok(NULL, " ");
844
845 if (!name)
846 {
847 notice(s_GameServ, u, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
848 }
849 else if (stricmp(name, s_GameServ) == 0)
850 {
851 notice(s_GameServ, u, "You can't use <S as a name!");
852 }
853 else if (!password)
854 {
855 notice(s_GameServ, u, "SYNTAX: /msg <S REGISTER NAME PASSWORD");
856 }
857 else if (strlen(name) > maxnicklen)
858 {
859 notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen);
860 }
861 else if (!alphaNumeric(name))
862 {
863 notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
864 }
865 else if ((p = findplayer(name)))
866 {
867 notice(s_GameServ, u, "%s is already registered!", name);
868 notice(s_GameServ, u, "Choose another name!");
869 }
870 else if (!(user = find(u)))
871 {
872 log("Fatal Error: Couldn't find %s in the clients list", u);
873 }
874 else if (isIgnore(user))
875 {
876 #ifdef DEBUGMODE
877 log("Ignoring %s.", user->getNick());
878 #endif
879 }
880 else
881 {
882 if (!is_playing(user))
883 {
884 item *tempItem;
885 unsigned long hv = iHASH((unsigned char *) name);
886
887 // First create the Player
888 user->stats = new Player();
889
890 // Set the backwards pointer
891 user->stats->setClient(user);
892
893 // Set the player's password
894 user->stats->setPassword(password);
895
896 // Set the player's name
897 user->stats->setName(name);
898
899 // Make sure they have a proper time stamp
900 updateTS(user->stats);
901
902 // Update the last login time
903 user->stats->lastlogin = time(NULL);
904
905 // Send notification of success
906 notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->getName().c_str(), password);
907 notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
908
909 // Log the new player
910 log("Nickname %s registered player %s.", u, user->stats->getName().c_str());
911
912 // Log the player in
913 setPlaying(user);
914
915 // Start the player at the beginning
916 reset(user->stats);
917
918 // Add the stick and clothes
919 tempItem = findItemByID(3001);
920 user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
921 user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes
922
923 // Add the player to the list
924 players[hv].push_back(user->stats);
925
926 // Attempt to add the player to the top list
927 // The class takes care of pruning the user out if they don't deserve to be in the list
928 myToplist.insertPlayer(user->stats);
929 }
930 else
931 {
932 notice(s_GameServ, u, "Already registered. Contact a <S admin for help.");
933 }
934 }
935 }
936
937 void do_identify(char *u)
938 {
939 char *password, *name;
940 aClient *user;
941 Player *p;
942 name = strtok(NULL, " ");
943 password = strtok(NULL, " ");
944 if (!password || !name)
945 {
946 notice(s_GameServ, u, "SYNTAX: /msg <S IDENTIFY NAME PASSWORD");
947 }
948 else if (!(user = find(u)))
949 {
950 notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
951 log("Error: aClient not found: %s", u);
952 }
953 else if (isIgnore(user))
954 {
955 #ifdef DEBUGMODE
956 log("Ignoring %s.", user->getNick());
957 #endif
958 return;
959 }
960 else if (!(p = findplayer(name)))
961 {
962 notice(s_GameServ, u, "Player %s not found", name);
963 }
964 else if (is_playing(user))
965 {
966 notice(s_GameServ, u, "You are already playing!");
967 }
968 else if (is_playing(p->getClient()) && !isAdmin(user))
969 {
970 notice(s_GameServ, u, "That player has already identified.");
971 }
972 else if (!check_password(name, password) && !isAdmin(user))
973 {
974 notice(s_GameServ, u, "Password incorrect");
975 }
976 else
977 {
978 list<Player*>::iterator iter;
979 unsigned long hv = iHASH((unsigned char *) p->getName().c_str());
980
981 iter = find(players[hv].begin(), players[hv].end(), p);
982
983 if (iter == players[hv].end())
984 {
985 notice(s_GameServ, u, "Fatal error. Contact <S Admin. Buf: %s",
986 strtok(NULL, ""));
987 return;
988 }
989 // Make sure the other user is logged out
990 logout(p->getClient());
991
992 user->stats = p;
993 p->setClient(user);
994 updateTS(p);
995
996
997 #ifdef DEBUGMODE
998 log("Player %s IRC: %s Identified", user->stats->getName().c_str(),
999 user->getNick());
1000 #endif
1001 //Set the playing flag
1002 setPlaying(user);
1003
1004 // Update the last login time
1005 user->stats->lastlogin = time(NULL);
1006
1007 notice(s_GameServ, u, "Password Accepted. Identified.");
1008 showNews(u, todaysnews);
1009 }
1010 }
1011
1012 void do_stats(char *u)
1013 {
1014 char *nick;
1015 aClient *user;
1016
1017 nick = strtok(NULL, " ");
1018
1019 if (!(user = find(u)))
1020 {
1021 log("Fatal Error: %s not found in client list", u);
1022 return;
1023 }
1024 else if (isIgnore(user))
1025 {
1026 #ifdef DEBUGMODE
1027 log("Ignoring %s.", user->getNick());
1028 #endif
1029 return;
1030 }
1031 else if (!nick)
1032 {
1033 if (!is_playing(user))
1034 {
1035 notice(s_GameServ, u, "You're not playing, so you have no stats!");
1036 return;
1037 }
1038 else
1039 {
1040 if (!is_fighting(user))
1041 updateTS(user->stats);
1042 showstats(u, user->stats->getName().c_str());
1043 }
1044 }
1045 else
1046 showstats(u, nick);
1047 }
1048
1049 void do_use(char *u)
1050 {
1051 aClient *user;
1052 pouch *p;
1053
1054 char *item = strtok(NULL, " ");
1055 char *numuse = strtok(NULL, " ");
1056 int id, num;
1057 itemContainer *used;
1058
1059 if (!item || int(item[0]) < 48 || int(item[0]) > 57 || (numuse && (int(numuse[0]) < 48 || int(numuse[0]) > 57)))
1060 {
1061 notice(s_GameServ, u, "SYNTAX: USE ####");
1062 notice(s_GameServ, u, "Type /msg <S HELP USE for more information.");
1063 return;
1064 }
1065 else if (!(user = find(u)))
1066 {
1067 notice(s_GameServ, u, "Fatal Error in do_use. Contact a(n) <S Admin");
1068 return;
1069 }
1070 else if (isIgnore(user))
1071 {
1072 #ifdef DEBUGMODE
1073 log("Ignoring %s.", user->getNick());
1074 #endif
1075 return;
1076 }
1077 else if (!is_playing(user))
1078 {
1079 notice(s_GameServ, u, "You must be playing to use items!");
1080 return;
1081 }
1082 id = stringtoint(item);
1083
1084 if (!numuse)
1085 {
1086 num = 1;
1087 }
1088 else
1089 {
1090 num = stringtoint(numuse);
1091 }
1092
1093 updateTS(user->stats);
1094 p = user->stats->inventory;
1095
1096
1097 if (!(used = p->Find(id)))
1098 {
1099 if (!p->isEmpty())
1100 {
1101 notice(s_GameServ, u, "You aren't carrying that item!");
1102 }
1103 showinventory(user->stats, user);
1104 }
1105 else if (used->getItem()->getType() != POTION)
1106 {
1107 notice(s_GameServ, u, "You can't use %s like that. Try /msg <S equip", used->getItem()->getName().c_str());
1108 }
1109 else
1110 {
1111 // Use the item(s)
1112 if (num <= 1 || is_fighting(user))
1113 {
1114 notice(s_GameServ, u, "You used %s.", used->getItem()->getName().c_str());
1115 used->use(user->stats);
1116 if (used->getUses() <= 0)
1117 {
1118 p->deleteItem(used->getItem());
1119 }
1120 end_turn(user);
1121 }
1122 else if (num > 1)
1123 {
1124 int count;
1125 const char *name = used->getItem()->getName().c_str();
1126 for (count = 0; count < num; count++)
1127 {
1128 if (!(used = p->Find(id)))
1129 {
1130 break;
1131 }
1132 else
1133 {
1134 used->use(user->stats);
1135 if (used->getUses() == 0)
1136 {
1137 p->deleteItem(used->getItem());
1138 }
1139 }
1140 }
1141 notice(s_GameServ, u, "You used %d %s's", count, name);
1142 }
1143 }
1144 }
1145 void do_run(char *u)
1146 {
1147 aClient *user;
1148 Player *p, *p2 = NULL;
1149
1150 if (!(user = find(u)))
1151 {
1152 notice(s_GameServ, u, "Couldn't find you. Error. Contact a <S admin");
1153 return;
1154 }
1155 else if (isIgnore(user))
1156 {
1157 #ifdef DEBUGMODE
1158 log("Ignoring %s.", user->getNick());
1159 #endif
1160 return;
1161 }
1162 else if (!is_playing(user))
1163 {
1164 notice(s_GameServ, u, "You must be playing to run!");
1165 return;
1166 }
1167
1168 updateTS(user->stats);
1169 p = user->stats;
1170
1171 if (p->getBattle())
1172 p2 = p->getBattle()->stats;
1173
1174 if (!is_fighting(user))
1175 notice(s_GameServ, u, "You run in place... try fighting next time.");
1176 else if (!player_fight(user) && !master_fight(user) && !dragon_fight(user))
1177 {
1178 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->getMonster()->name.c_str());
1179 p->delMonster();
1180 }
1181 else if (player_fight(user) && isYourTurn(p))
1182 {
1183 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->getName().c_str());
1184 notice(s_GameServ, p->getBattle()->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->getName().c_str());
1185 addNews(todaysnews, "%s ran away from %s like a little baby!!", p->getName().c_str(), p2->getName().c_str()); /* DrLnet - edited by Kain */
1186 p2->delBattle();
1187 p->delBattle();
1188 }
1189 else if (player_fight(user) && !isYourTurn(p))
1190 {
1191 notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->getName().c_str());
1192 }
1193 else if (master_fight(user))
1194 {
1195 notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->getMaster()->name.c_str());
1196 }
1197 else if (dragon_fight(user))
1198 {
1199 notice(s_GameServ, u, "You cannot run from %s! FIGHT!", dragon.name.c_str());
1200 }
1201 }
1202
1203
1204 void do_heal(char *u)
1205 {
1206 aClient *ni;
1207 char *amount = strtok(NULL, " ");
1208 int price, num;
1209
1210 if (!amount)
1211 {
1212 notice(s_GameServ, u, "SYNTAX: /msg <S HEAL {ALL | #}");
1213 return;
1214 }
1215 else if (!(ni = find(u)))
1216 {
1217 notice(s_GameServ, u, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL, ""));
1218 return;
1219 }
1220 else if (isIgnore(ni))
1221 {
1222 #ifdef DEBUGMODE
1223 log("Ignoring %s.", ni->getNick());
1224 #endif
1225 return;
1226 }
1227 else if (!is_playing(ni))
1228 {
1229 notice(s_GameServ, u, "You aren't playing!");
1230 return;
1231 }
1232 else if (!isAlive(ni->stats))
1233 {
1234 notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing.");
1235 return;
1236 }
1237 else if (is_fighting(ni))
1238 {
1239 notice(s_GameServ, u, "You can't heal in battle!");
1240 return;
1241 }
1242 else if (ni->stats->getHP() >= ni->stats->getMaxHP())
1243 {
1244 notice(s_GameServ, u, "You don't need healing!");
1245 return;
1246 }
1247
1248 updateTS(ni->stats);
1249 if (stricmp(amount, "ALL") == 0)
1250 {
1251 price = ni->stats->getLevel() * 3;
1252 if (ni->stats->getGold() < (ni->stats->getMaxHP() - ni->stats->getHP()) * price)
1253 {
1254 notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
1255 (long int)ni->stats->getGold()/price, price);
1256 ni->stats->addHP(ni->stats->getGold() / price);
1257 ni->stats->setGold(ni->stats->getGold() % price);
1258 }
1259 else
1260 {
1261 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1262 "per point.", price);
1263 notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!",
1264 (ni->stats->getMaxHP() - ni->stats->getHP()),
1265 (price * (ni->stats->getMaxHP() - ni->stats->getHP())) );
1266 ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP()));
1267 ni->stats->healall();
1268 }
1269 }
1270 else if (isstringnum(amount))
1271 {
1272 num = stringtoint(amount);
1273 price = ni->stats->getLevel() * 3;
1274 if (ni->stats->getGold() < price * num)
1275 {
1276 notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!",
1277 (long int)ni->stats->getGold()/price);
1278 }
1279 else if (num <= ni->stats->getMaxHP() - ni->stats->getHP())
1280 {
1281 notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
1282 num, price);
1283 ni->stats->addHP(num);
1284 ni->stats->subtractGold(num * price);
1285 }
1286 else if (num > ni->stats->getMaxHP() - ni->stats->getHP())
1287 {
1288 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1289 "per point.", price);
1290 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
1291 (ni->stats->getMaxHP() - ni->stats->getHP()));
1292 ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP()));
1293 ni->stats->healall();
1294 }
1295 }
1296 else if (amount[0] == '-')
1297 notice(s_GameServ, u, "You trying to cheat?");
1298 else
1299 notice(s_GameServ, u, "SYNTAX: /msg <S HEAL {ALL | #}");
1300 }
1301
1302
1303
1304
1305 void do_store(char *u)
1306 {
1307 list<item*>::iterator item_iterator;
1308 item *tempItem;
1309 char *cmd = strtok(NULL, " ");
1310 char *num = strtok(NULL, " ");
1311 char *space;
1312 int id;
1313 aClient *user;
1314 Player *p;
1315
1316
1317 if (!cmd || !num)
1318 {
1319 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1320 notice(s_GameServ, u, " \ 2STORE SELL NUMBER\ 2");
1321 notice(s_GameServ, u, " \ 2STORE BUY \1fNUMBER\1f\ 2");
1322 return;
1323 }
1324 else if (!(user = find(u)))
1325 {
1326 log("Fatal Error: could not find %s in client list", u);
1327 return;
1328 }
1329 else if (isIgnore(user))
1330 {
1331 #ifdef DEBUGMODE
1332 log("Ignoring %s.", user->getNick());
1333 #endif
1334 return;
1335 }
1336 else if (!is_playing(user))
1337 {
1338 notice(s_GameServ, u, "You must be playing to use the store!");
1339 return;
1340 }
1341 else if (is_fighting(user))
1342 {
1343 notice(s_GameServ, u, "You can't go to the store while fighting!");
1344 return;
1345 }
1346 else if (!isAlive(user->stats))
1347 {
1348 notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!");
1349 return;
1350 }
1351 updateTS(user->stats);
1352
1353 if (stricmp(cmd, "LIST") == 0)
1354 {
1355 if (stricmp(num, "WEAPONS") == 0)
1356 {
1357 notice(s_GameServ, u, "Welcome to Kain's Armory");
1358 notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:");
1359 for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator)
1360 {
1361 if ((*item_iterator)->getType() == WEAPON)
1362 {
1363 space = spaces(strlen((*item_iterator)->getName().c_str()), ".");
1364 notice(s_GameServ, u, "%s%ld. %20s..........%ld",
1365 ((*item_iterator)->getID() < 10 ? " " : ""),
1366 (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), (*item_iterator)->price());
1367 }
1368 }
1369 notice(s_GameServ, u, "To purchase a weapon, type /msg <S STORE BUY \ 2#\ 2.");
1370 notice(s_GameServ, u, "Where # is the weapon number from the menu above.");
1371
1372 }
1373 else if (stricmp(num, "ARMOR") == 0)
1374 {
1375 notice(s_GameServ, u, "Welcome to Kain's Armory");
1376 notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:");
1377 for (item_iterator = store.begin(); item_iterator != store.end(); ++item_iterator)
1378 {
1379 if ((*item_iterator)->getType() == ARMOR)
1380 {
1381 notice(s_GameServ, u, "%s%ld. %20s..........%d",
1382 ((*item_iterator)->getID() < 10 ? " " : ""),
1383 (*item_iterator)->getID(), (*item_iterator)->getName().c_str(),
1384 (*item_iterator)->price());
1385 }
1386 }
1387
1388 notice(s_GameServ, u, "To purchase armor, type /msg <S store buy #");
1389 notice(s_GameServ, u, "Where # is the armor number from the menu above.");
1390 }
1391
1392 }
1393 else if (stricmp(cmd, "BUY") == 0)
1394 {
1395 p = user->stats;
1396 if (!num)
1397 {
1398 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
1399 return;
1400 }
1401 else
1402 {
1403 id = stringtoint(num);
1404 }
1405
1406 if (!isstringnum(num))
1407 {
1408 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY \1f#\1f\ 2");
1409 return;
1410 }
1411 else if (!(tempItem = findStoreItemByID(id)))
1412 {
1413 notice(s_GameServ, u, "Sorry, we don't carry that item!");
1414 return;
1415 }
1416 else if (p->getGold() < tempItem->price())
1417 {
1418 notice(s_GameServ, u, "You can't afford to buy %s", tempItem->getName().c_str());
1419 return;
1420 }
1421 else if (p->inventory->addItem(tempItem))
1422 {
1423 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", tempItem->getName().c_str());
1424 p->subtractGold(tempItem->price());
1425 notice(s_GameServ, u, "Don't forget to type /msg <S equip %ld", tempItem->getID());
1426 }
1427 else
1428 {
1429 notice(s_GameServ, u, "You can't carry any more!");
1430 }
1431 }
1432 else if (stricmp(cmd, "SELL" ) == 0)
1433 {
1434 itemContainer *tempContainer;
1435 p = user->stats;
1436 id = stringtoint(num);
1437 if (!isstringnum(num))
1438 {
1439 notice(s_GameServ, u, "SYNTAX: /msg <S store sell #");
1440 return;
1441 }
1442 else if (!(tempContainer = p->inventory->Find(id)))
1443 {
1444 notice(s_GameServ, u, "You're not carrying that!");
1445 return;
1446 }
1447 else if (p->getGold() >= 2000000000)
1448 {
1449 notice(s_GameServ, u, "You have enough gold. Just hang on to it for now.");
1450 }
1451 else
1452 {
1453 tempItem = tempContainer->getItem();
1454
1455 notice(s_GameServ, u, "Thank you for your business! We gave you %ld gold for %s!", (tempItem->price() / 2), tempItem->getName().c_str());
1456 p->addGold((tempItem->price() / 2));
1457 p->inventory->deleteItem(tempItem);
1458 if (tempItem == p->getWeapon())
1459 {
1460 notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str());
1461 tempItem->undo(p);
1462 p->clearWeapon();
1463 }
1464 else if (tempItem == p->getArmor())
1465 {
1466 tempItem->undo(p);
1467 notice(s_GameServ, u, "Since you equipped %s, you're going to have to reequip something", tempItem->getName().c_str());
1468 p->clearArmor();
1469 }
1470 }
1471 }
1472 else
1473 {
1474 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1475 notice(s_GameServ, u, " \ 2STORE SELL #\ 2");
1476 notice(s_GameServ, u, " \ 2STORE BUY \1f#\1f\ 2");
1477 return;
1478 }
1479 }
1480 void do_inventory(char *u)
1481 {
1482 aClient *user;
1483
1484 if (!(user = find(u)))
1485 {
1486 notice(s_GameServ, u, "Fatal Error. Contact a <S admin!");
1487 return;
1488 }
1489 else if (isIgnore(user))
1490 {
1491 #ifdef DEBUGMODE
1492 log("Ignoring %s.", user->getNick());
1493 #endif
1494 return;
1495 }
1496 else if (!is_playing(user))
1497 {
1498 notice(s_GameServ, u, "You must be playing to check your inventory!");
1499 return;
1500 }
1501 if (!is_fighting(user))
1502 updateTS(user->stats);
1503 showinventory(user->stats, user);
1504 }
1505
1506
1507 void do_tavern(char *u)
1508 {
1509 char *cmd = strtok(NULL, " ");
1510
1511 aClient *user;
1512 Player *p;
1513
1514 if (!(user = find(u)))
1515 {
1516 notice(s_GameServ, u, "Fatal Error. See a <S admin for help");
1517 return;
1518 }
1519 else if (isIgnore(user))
1520 {
1521 #ifdef DEBUGMODE
1522 log("Ignoring %s.", user->getNick());
1523 #endif
1524 return;
1525 }
1526 else if (!is_playing(user))
1527 {
1528 notice(s_GameServ, u, "You must be playing to go to the Tavern");
1529 return;
1530 }
1531 else if (is_fighting(user))
1532 {
1533 notice(s_GameServ, u, "You cannot go to the Tavern during a fight!");
1534 return;
1535 }
1536
1537 updateTS(user->stats);
1538 p = user->stats;
1539
1540 if (!cmd)
1541 {
1542 notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary and General Store");
1543 notice(s_GameServ, u, "Your commands:");
1544 notice(s_GameServ, u, "/msg <S TAVERN {LIST | BUY} [NUMBER]");
1545 notice(s_GameServ, u, "What'll it be?");
1546 }
1547 else if (stricmp(cmd, "LIST") == 0)
1548 {
1549 notice(s_GameServ, u, "Here is a list of what we have to offer:");
1550 showTavern(user);
1551 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
1552 }
1553 else if (stricmp(cmd, "BUY") == 0)
1554 {
1555 int amt = 1;
1556 char *chid = strtok(NULL, " ");
1557 char *amount = strtok(NULL, " ");
1558
1559 if (amount)
1560 amt = stringtoint(amount);
1561
1562 if (!chid)
1563 {
1564 notice(s_GameServ, u, "SYNTAX: TAVERN BUY # [#]");
1565 notice(s_GameServ, u, "Example: /msg <S TAVERN BUY 6001");
1566 notice(s_GameServ, u, "Example: /msg <S TAVERN BUY 6001 10");
1567 return;
1568 }
1569 long id = stringtoint(chid);
1570 tavernItem *tempItem;
1571
1572 if (!(tempItem = findTavernItemByID(id)) || user->stats->getLevel() < tempItem->getLevel())
1573 {
1574 notice(s_GameServ, u, "Invalid Choice!");
1575 notice(s_GameServ, u, "Here is a list of what we have to offer:");
1576 showTavern(user);
1577 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
1578 return;
1579 }
1580 else if (!amount && user->stats->getGold() < tempItem->getItem()->price())
1581 {
1582 notice(s_GameServ, u, "You don't have enough gold!");
1583 notice(s_GameServ, u, "Here is a list of what we have to offer:");
1584 showTavern(user);
1585 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY #");
1586 }
1587 else if (user->stats->getGold() < amt * tempItem->getItem()->price())
1588 {
1589 notice(s_GameServ, u, "You don't have enough gold!");
1590 notice(s_GameServ, u, "Here is a list of what we have to offer:");
1591 showTavern(user);
1592 notice(s_GameServ, u, "To buy an item, type /msg <S TAVERN BUY # [#]");
1593 }
1594 else
1595 {
1596 if (amount)
1597 {
1598 int amt = stringtoint(amount);
1599 if (amt < 0 || amount[0] == '-')
1600 {
1601 notice(s_GameServ, u, "You trying to steal from me?");
1602 }
1603 else if (user->stats->inventory->addItem(tempItem->getItem(), amt) == NULL)
1604 {
1605 notice(s_GameServ, u, "You can't carry that many!");
1606 }
1607 else
1608 {
1609 notice(s_GameServ, u, "%d %s's coming right up!", amt, tempItem->getItem()->getName().c_str());
1610 user->stats->subtractGold(tempItem->getItem()->price() * amt);
1611 }
1612 }
1613 else
1614 {
1615 if (user->stats->inventory->addItem(tempItem->getItem()) == NULL)
1616 {
1617 notice(s_GameServ, u, "You can't carry any more!");
1618 }
1619 else
1620 {
1621 notice(s_GameServ, u, "One %s coming right up!", tempItem->getItem()->getName().c_str());
1622 user->stats->subtractGold(tempItem->getItem()->price());
1623 }
1624 }
1625 }
1626 }
1627 else
1628 {
1629 notice(s_GameServ, u, "Improper Syntax.");
1630 notice(s_GameServ, u, "Type /msg <S HELP TAVERN for help");
1631 }
1632 return;
1633 }
1634
1635
1636
1637 void do_dragon(char *u)
1638 {
1639 aClient *user;
1640
1641 if (!(user = find(u)))
1642 {
1643 notice(s_GameServ, u, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL, ""));
1644 return;
1645 }
1646 else if (isIgnore(user))
1647 {
1648 #ifdef DEBUGMODE
1649 log("Ignoring %s.", user->getNick());
1650 #endif
1651 return;
1652 }
1653 else if (!is_playing(user))
1654 {
1655 notice(s_GameServ, u, "You must be playing to fight the dragon!");
1656 return;
1657 }
1658 else if (is_fighting(user))
1659 {
1660 notice(s_GameServ, u, "You are already in a fight. How will you fight the almighty dragon!?");
1661 return;
1662 }
1663 else if (!isAlive(user->stats))
1664 {
1665 notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
1666 return;
1667 }
1668 else if (user->stats->getLevel() < LEVELS)
1669 {
1670 notice(s_GameServ, u, "You fool! Only those strong enough "\
1671 "to vanquish any foe should DARE fight the dragon!");
1672 notice(s_GameServ, u, "To put it in terms you can understand: "\
1673 "You are too weak. You must be Level %d!", REALLEVELS);
1674 return;
1675 }
1676
1677 updateTS(user->stats);
1678
1679 Player *p = user->stats;
1680 setMaster(p);
1681 notice(s_GameServ, u, "You approach the dragon's lair cautiously.");
1682 notice(s_GameServ, u, "The stench of sulfer fills the air as a "\
1683 "deep, red fog rolls in. The air is filled with the "\
1684 "heated mist of deadly fire from beyond the cave "\
1685 "entrance.");
1686 notice(s_GameServ, u, "You adjust your %s, tighten your grip on "\
1687 "your %s, and venture into the hot, dark cave. "\
1688 "You are surprised at the angle of descent as you climb "\
1689 "lower and lower, deeper into the dragon's den.",
1690 (p->getArmor() ? p->getArmor()->getName().c_str() : "Fists"), (p->getWeapon() ? p->getWeapon()->getName().c_str() : "Birthday Suit"));
1691 notice(s_GameServ, u, "You come to the end of the cave to find "\
1692 "a tooth. It is a large tooth... bigger than your torso."\
1693 " Suddenly the darkness lifts from the gleam of an eye "\
1694 " staring into your soul! The eye is large... HUGE!");
1695 notice(s_GameServ, u, "Just then you notice the eye begin to "\
1696 "glare orange! The tooth is moving... but it is still too "\
1697 "dark for you to make out.... THE DRAGON! You see it!");
1698 p->setMonster(&dragon);
1699 setDragonFight(p);
1700 display_monster(u);
1701 }
1702
1703 void do_master(char *u)
1704 {
1705 aClient *user;
1706
1707
1708 if (!(user = find(u)))
1709 {
1710 notice(s_GameServ, u, "Fatal error. Contact a(n) <S admin. buf: %s", strtok(NULL, ""));
1711 return;
1712 }
1713 else if (isIgnore(user))
1714 {
1715 #ifdef DEBUGMODE
1716 log("Ignoring %s.", user->getNick());
1717 #endif
1718 return;
1719 }
1720 else if (!is_playing(user))
1721 {
1722 notice(s_GameServ, u, "You must be playing to see your master!");
1723 return;
1724 }
1725 else if (is_fighting(user))
1726 {
1727 notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!");
1728 return;
1729 }
1730 else if (!isAlive(user->stats))
1731 {
1732 notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
1733 return;
1734 }
1735
1736 updateTS(user->stats);
1737
1738 char *cmd = strtok(NULL, " ");
1739 Player *p = user->stats;
1740 long int need = 0;
1741
1742 if (seenMaster(p))
1743 {
1744 notice(s_GameServ, u, "You have already seen your master today. Wait until tomorrow to try again");
1745 return;
1746 }
1747
1748 if (cmd != NULL)
1749 {
1750 switch(p->getLevel())
1751 {
1752 case 1:
1753 need = 200;
1754 break;
1755 case 2:
1756 need = 800;
1757 break;
1758 case 3:
1759 need = 2000;
1760 break;
1761 case 4:
1762 need = 8000;
1763 break;
1764 case 5:
1765 need = 20000;
1766 break;
1767 case 6:
1768 need = 80000;
1769 break;
1770 case 7:
1771 need = 200000;
1772 break;
1773 case 8:
1774 need = 800000;
1775 break;
1776 case 9:
1777 need = 2000000;
1778 break;
1779 case 10:
1780 need = 8000000;
1781 break;
1782 case 11:
1783 need = 20000000;
1784 break;
1785
1786 case REALLEVELS:
1787 need = p->getExp() + 1;
1788 notice(s_GameServ, u, "You are at level %d. You are the master. What's left? The DRAGON!", REALLEVELS);
1789 return;
1790 break;
1791 default:
1792 need = p->getExp() + 1; // Unknown level... don't let them fight a fake master!
1793 break;
1794 }
1795 }
1796 else
1797 {
1798 notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
1799 return;
1800 }
1801
1802 if (stricmp(cmd, "FIGHT") == 0)
1803 {
1804 if (p->getExp() >= need)
1805 {
1806 setMaster(p);
1807 see_master(u);
1808 }
1809 else
1810 notice(s_GameServ, u, "You are not worthy of fighting %s! You need %ld more experience.",
1811 levels[p->getLevel() - 1].master.name.c_str(), (need - p->getExp()));
1812 return;
1813 }
1814 else if (stricmp(cmd, "QUESTION") == 0)
1815 {
1816 if (p->getExp() >= need)
1817 notice(s_GameServ, u, "%s looks you up and down and decides you are more ready than you will ever be.",
1818 levels[p->getLevel() - 1].master.name.c_str());
1819 else
1820 notice(s_GameServ, u, "You pathetic fool! You are no match for %s, %s!",
1821 levels[p->getLevel() - 1].master.name.c_str(), p->getName().c_str());
1822
1823 return;
1824 }
1825 else
1826 {
1827 notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
1828 }
1829 }
1830
1831
1832
1833 void do_reset(char *u)
1834 {
1835 char *nick = strtok(NULL, " ");
1836 aClient *user;
1837 Player *p;
1838
1839 if (!(user = find(u)))
1840 {
1841 notice(s_GameServ, u, "Error: aClient not found. Contact a <S admin");
1842 log("Error: aClient not found: %s", u);
1843 return;
1844 }
1845 else if (!isAdmin(user))
1846 {
1847 notice(s_GameServ, u, "You must be a <S admin to use this command!");
1848 return;
1849 }
1850
1851 if (!nick)
1852 {
1853 notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}");
1854 }
1855 else if (stricmp(nick, "ALL") == 0)
1856 {
1857 notice(s_GameServ, u, "Resetting everyone's stats!");
1858 resetall();
1859 }
1860 else if (!(p = findplayer(nick)))
1861 {
1862 notice(s_GameServ, u, "Nick %s not found.", nick);
1863 }
1864 else
1865 {
1866 notice(s_GameServ, u, "Resetting %s.", p->getName().c_str());
1867 reset(p);
1868 }
1869 }
1870
1871 void do_help(char *u)
1872 {
1873 char *cmd = strtok(NULL, " ");
1874
1875 display_help(u, cmd);
1876 }
1877
1878
1879
1880