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