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