]> jfr.im git - irc/gameservirc.git/blob - gameserv/gameserv.cpp
Updated the way monsters were stored. Previously, they were held in a static array...
[irc/gameservirc.git] / gameserv / gameserv.cpp
1 #include "sockhelp.h"
2 #include "aClient.h"
3 #include "list.h"
4 #include "extern.h"
5 #include <cctype>
6 #include <fstream.h>
7 #include <crypt.h>
8
9 #define LEVELS 5 // Number of character levels in the game
10 #define MONSTERS 12 // Monsters per level
11
12 List<aClient> players;
13 Monster *monsters[LEVELS][MONSTERS]; // Monsters per level. Total = MONSTERS * LEVELS
14
15 Monster *masters[LEVELS]; // A master for each level
16
17 // Database functions
18 int save_gs_dbase();
19 int load_gs_dbase();
20
21 // String functions
22 #undef strtok
23 char *strtok(char *str, const char *delim);
24 int stricmp(const char *s1, const char *s2);
25 int strnicmp(const char *s1, const char *s2, size_t len);
26 // String Functions
27
28
29 /********** Password functions **********/
30
31 bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
32
33 bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
34
35 /********** Password functions **********/
36
37
38 /********** GameServ Booleans **********/
39
40 bool is_playing(char *u); // True if the given nickname in the clients list is playing.
41 bool has_started(char *u); // True if the given nickname in the clients list has started playing.
42 bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
43 bool isnt_fighting(char *u); // True if the given nick isn't fighting. Same as !is_fighting(u).
44 bool player_fight(char *u); // True if the player is fighting another player.
45 bool master_fight(char *u); // True if the player is fighting their master.
46
47 /********** GameServ Booleans **********/
48
49
50 void display_monster(char *u);
51 void display_players(char *u);
52 long int chartoint(char ch);
53 int isstringnum(char *num);
54 long int pow (int x, int y);
55 long int stringtoint(char *number);
56
57 char *spaces(int len, char *seperator);
58 void refresh(aClient *ni);
59 void refreshall();
60 void reset(aClient *ni);
61 void init_masters();
62 void init_monsters();
63 void delete_monsters();
64 void delete_masters();
65
66 void do_list(char *u);
67 void do_register(char *u);
68 void do_identify(char *u);
69 void do_play(char *u);
70 void do_quitg(char *u);
71 void do_reset(char *u);
72 void do_fight(char *u);
73 void do_store(char *u);
74 void do_heal(char *u);
75 void do_bank(char *u);
76 void do_attack(char *u);
77 void do_run(char *u);
78 void do_visit(char *u);
79 void do_stats(char *u);
80 void see_mystic(char *u);
81
82 void showstats(const char *u, const char *nick);
83
84 #define WNA 16
85 char *weapons[WNA] = { "Fists", "Stick", "Dagger", "Quarterstaff", "Short Sword",
86 "Long Sword", "Silver Spear", "Battle Axe", "The Ragnarok",
87 "Chain Saw", "Poison Sword", "Flame Sword", "Earth Hammer",
88 "Light Saber", "Masamune", "Mystical Sword"};
89
90 char *armors[WNA] = { "Nothing", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor",
91 "Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit",
92 "Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor",
93 "Hades' Cloak", "Dragon Scales", "Mystical Armor"};
94
95 int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000,
96 1000000, 4000000, 10000000, 40000000, 100000000, 400000000};
97 int webonus[WNA] = {0, 10, 15, 25, 35, 45, 65, 85, 125, 185, 255, 355, 505, 805, 1205, 1805};
98 int arbonus[WNA] = {0, 1, 3, 10, 15, 25, 35, 50, 75, 100, 150, 225, 300, 400, 600, 1000};
99
100 int hpbonus[11] = {10, 15, 20, 30, 50, 75, 125, 185, 250, 350, 550};
101 int strbonus[11] = {5, 7, 10, 12, 20, 35, 50, 75, 110, 150, 200};
102 int defbonus[11] = {2, 3, 5, 10, 15, 22, 35, 60, 80, 120, 150};
103
104
105 void gameserv(char *source, char *buf)
106 {
107 char *cmd, input[1024];
108 cmd = strtok(buf, " ");
109
110 source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
111 cmd++; // Get rid of that : at the beginning of the :text (command)
112
113 cout << "Source: " << source << "\ncmd: " << cmd << endl;
114 if (strnicmp(cmd, ":\1PING", 6) == 0)
115 {
116 char *timestamp;
117 timestamp = strtok(NULL, "\1");
118 notice(s_GameServ, source, "\1PING %s\1", timestamp);
119 } else if (stricmp(cmd, ":\1VERSION\1") == 0) {
120 notice(s_GameServ, source, "\1VERSION GameServ v1.0b\1");
121 } else if (stricmp(cmd, "SEARCH") == 0) {
122 cmd = strtok(NULL, " ");
123
124 if (!cmd)
125 notice(s_GameServ, source, "SYNTAX: /msg %S SEARCH FOREST");
126 else
127 do_forest(source);
128 } else if (stricmp(cmd, "FIGHT") == 0) {
129 do_fight(source);
130 } else if (stricmp(cmd, "ATTACK") == 0) {
131 do_attack(source);
132 } else if (stricmp(cmd, "RUN") == 0) {
133 do_run(source);
134 } else if (stricmp(cmd, "HEAL") == 0) {
135 do_heal(source);
136 } else if (stricmp(cmd, "STORE") == 0) {
137 do_store(source);
138 } else if (stricmp(cmd, "BANK") == 0) {
139 do_bank(source);
140 } else if (stricmp(cmd, "PRINT") == 0) {
141 cout << "Printing Clients List: " << endl;
142 clients.print();
143 cout << "\nPrinting Player List: " << endl;
144 players.print();
145 } else if (stricmp(cmd, "LIST") == 0) {
146 do_list(source);
147 } else if (stricmp(cmd, "REGISTER") == 0) {
148 do_register(source);
149 } else if (stricmp(cmd, "IDENTIFY") == 0) {
150 do_identify(source);
151 } else if (stricmp(cmd, "HELP") == 0) {
152 } else if (stricmp(cmd, "STATS") == 0) {
153 do_stats(source);
154 } else if (stricmp(cmd, "SHUTDOWN") == 0) {
155 save_gs_dbase();
156 raw("SQUIT %s :leaving", servername);
157 } else if (stricmp(cmd, "SAVE") == 0) {
158 save_gs_dbase();
159 } else if (stricmp(cmd, "LOAD") == 0) {
160 load_gs_dbase();
161 } else if (stricmp(cmd, "RAW") == 0) {
162 char *rest = strtok(NULL, "");
163 raw(rest);
164 }
165
166 source--; // Bring the : back so we don't leak memory
167 cmd--; // Same thing :)
168 }
169
170 int stricmp(const char *s1, const char *s2)
171 {
172 register int c;
173
174 while ((c = tolower(*s1)) == tolower(*s2)) {
175 if (c == 0)
176 return 0;
177 s1++;
178 s2++;
179 }
180 if (c < tolower(*s2))
181 return -1;
182 return 1;
183 }
184
185 void showstats(const char *u, const char *nick)
186 {
187 aClient *ni, *sender = find(u);
188 char *buf;
189 buf = new char[50];
190 char *space;
191
192
193 cout << "\n\nu: " << u << "\nnick: " << nick << endl;
194 if (!(ni = findbynick(nick)))
195 {
196 notice(s_GameServ, u, "%s not found", nick);
197 }
198 else if (ni->stats)
199 {
200
201 notice(s_GameServ, sender->getNick(), "Stats for %s:", ni->stats->name);
202
203 sprintf(buf, "Experience: %ld", ni->stats->exp);
204 space = spaces(strlen(buf), " ");
205 notice(s_GameServ, sender->getNick(), "%s%sLevel: %d", buf, space,
206 ni->stats->level);
207 delete [] space;
208
209 sprintf(buf, "Gold: %ld", ni->stats->gold);
210 space = spaces(strlen(buf), " ");
211 notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, ni->stats->bank);
212 delete [] space;
213
214 notice(s_GameServ, sender->getNick(), "Health Points: %d of %d", ni->stats->hp,
215 ni->stats->maxhp);
216
217 sprintf(buf, "Strength: %d", ni->stats->strength + webonus[ni->stats->weapon]);
218 space = spaces(strlen(buf), " ");
219 notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
220 buf, space, ni->stats->defense + arbonus[ni->stats->armor]);
221 delete [] space;
222
223 sprintf(buf, "Armor: %s", armors[ni->stats->armor]);
224 space = spaces(strlen(buf), " ");
225 notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
226 weapons[ni->stats->weapon]);
227 delete [] space;
228
229 sprintf(buf, "Forest Fights: %d", ni->stats->forest_fights);
230 space = spaces(strlen(buf), " ");
231 notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, ni->stats->player_fights);
232 delete [] space;
233 }
234 delete [] buf;
235
236 }
237
238 char *spaces(int len, char *seperator)
239 {
240 char *final;
241 final = new char[40];
242 int y;
243 strcpy(final, seperator);
244 for (y = 0; y < 40 - len; y++)
245 strcat(final, seperator);
246 return final;
247 }
248
249 void raw(const char *fmt, ...)
250 {
251 va_list args;
252 char *input;
253 const char *t = fmt;
254 input = new char[1024];
255 va_start(args, fmt);
256 memset(input, 0, sizeof(input)); // Initialize to NULL
257 for (; *t; t++)
258 {
259 if (*t == '%')
260 {
261 switch(*++t) {
262 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
263 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
264 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
265 case 'l':
266 if (*++t == 'd')
267 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
268 }
269 }
270 else
271 {
272 sprintf(input, "%s%c", input, *t);
273 }
274
275 }
276 sprintf(input, "%s%s", input, "\r\n");
277 cout << "input: " << input << flush;
278 sock_puts(sock, input);
279 delete [] input;
280 va_end(args);
281 }
282 /* Send a NOTICE from the given source to the given nick. */
283
284 void notice(const char *source, const char *dest, const char *fmt, ...)
285 {
286 va_list args;
287 char *input;
288 const char *t = fmt;
289 input = new char[1024];
290 va_start(args, fmt);
291 if (dest[0] == ':')
292 {
293 dest++;
294 sprintf(input, ":%s NOTICE %s :", source, dest);
295 dest--;
296 }
297 else
298 sprintf(input, ":%s NOTICE %s :", source, dest);
299
300 for (; *t; t++)
301 {
302 if (*t == '%')
303 {
304 switch(*++t) {
305 case 'd': sprintf(input, "%s%d", input, va_arg(args, int)); break;
306 case 's': sprintf(input, "%s%s", input, va_arg(args, char *)); break;
307 case 'S': sprintf(input, "%s%s", input, s_GameServ); break;
308 case 'l':
309 if (*++t == 'd')
310 sprintf(input, "%s%ld", input, va_arg(args, long int)); break;
311 }
312 }
313 else
314 {
315 sprintf(input, "%s%c", input, *t);
316 }
317
318 }
319 sprintf(input, "%s%s", input, "\r\n");
320 cout << "input: " << input << flush;
321 sock_puts(sock, input);
322 delete [] input;
323 va_end(args);
324 }
325
326
327 int strnicmp(const char *s1, const char *s2, size_t len)
328 {
329 register int c;
330
331 if (!len)
332 return 0;
333 while ((c = tolower(*s1)) == tolower(*s2) && len > 0) {
334 if (c == 0 || --len == 0)
335 return 0;
336 s1++;
337 s2++;
338 }
339 if (c < tolower(*s2))
340 return -1;
341 return 1;
342 }
343
344 char *strtok(char *str, const char *delim)
345 {
346 static char *current = NULL;
347 char *ret;
348
349 if (str)
350 current = str;
351 if (!current)
352 return NULL;
353 current += strspn(current, delim);
354 ret = *current ? current : NULL;
355 current += strcspn(current, delim);
356 if (!*current)
357 current = NULL;
358 else
359 *current++ = 0;
360 return ret;
361 }
362
363 void do_list(char *u)
364 {
365 ListNode<aClient> *temp;
366 temp = players.First();
367 if (!players.isEmpty())
368 {
369 notice(s_GameServ, u, "People Playing:");
370 while(temp)
371 {
372 notice(s_GameServ, u, "IRC: %s Game: %s", temp->getData()->getNick(), temp->getData()->stats->name);
373 temp = temp->Next();
374 }
375 notice(s_GameServ, u, "End of List");
376 }
377 else
378 notice(s_GameServ, u, "No one is playing");
379 }
380 void do_register(char *u)
381 {
382 char *password;
383 aClient *user;
384 password = strtok(NULL, " ");
385
386 static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
387 static char salt[3];
388
389 salt[0] = saltChars[rand() % strlen(saltChars)];
390 salt[1] = saltChars[rand() % strlen(saltChars)];
391 salt[3] = '\0';
392
393 if (!password)
394 {
395 notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
396 }
397 else if (user = find(u))
398 {
399 if (!user->stats)
400 {
401 user->stats = new Player(user);
402 user->stats->started = 1;
403 user->stats->user = user; // Set the backwards pointer
404 strcpy(user->stats->password, crypt(password, salt));
405 players.insertAtBack(user);
406 }
407 else
408 {
409 notice(s_GameServ, u, "Already registered. Contact a %S admin for help.");
410 }
411 }
412 }
413
414 void do_identify(char *u)
415 {
416 char *password, *name;
417 aClient *user, *p;
418 name = strtok(NULL, " ");
419 password = strtok(NULL, " ");
420
421 if (!password || !name)
422 {
423 notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD");
424 }
425 else if (!(p = findplayer(name)) || !p->stats)
426 notice(s_GameServ, u, "Player %s not found", name);
427 else if (!check_password(name, password))
428 {
429 notice(s_GameServ, u, "Password incorrect");
430 }
431 else if (user = find(u))
432 {
433 if (!user->stats)
434 {
435 ListNode<aClient> *temp;
436 temp = players.Find(p);
437 if (!temp)
438 {
439 notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s",
440 strtok(NULL, ""));
441 return;
442 }
443 user->stats = new Player(p->stats->name);
444 cout << "Setting data for identified" << endl;
445 user->stats->setData(p->stats);
446 cout << "Player Identified" << endl << flush;
447
448 temp->setPtr(user);
449
450 notice(s_GameServ, u, "Password Accepted. Identified.");
451
452 }
453 else
454 {
455 notice(s_GameServ, u, "Already identified. Contact a %S admin for help.");
456 }
457 }
458 }
459
460 void do_stats(char *u)
461 {
462 char *nick;
463 aClient *source;
464
465 nick = strtok(NULL, " ");
466 source = find(u);
467
468 if (!nick)
469 showstats(u, source->getNick());
470 else
471 showstats(u, nick);
472 }
473 void init_masters()
474 {
475 //delete_masters();
476
477 for (int x = 0; x < LEVELS; x++)
478 masters[x] = new Monster;
479
480 strcpy(masters[0]->name, "Old Bones");
481 strcpy(masters[0]->weapon, "Dull Sword Cane");
482 masters[0]->strength = 30;
483 masters[0]->gold = 0;
484 masters[0]->exp = 0;
485 masters[0]->maxhp = 30;
486 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!");
487
488 strcpy(masters[1]->name, "Master Chang");
489 strcpy(masters[1]->weapon, "Nanchaku");
490 masters[1]->strength = 57;
491 masters[1]->gold = 0;
492 masters[1]->exp = 0;
493 masters[1]->maxhp = 40;
494 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.");
495
496 strcpy(masters[2]->name, "Chuck Norris");
497 strcpy(masters[2]->weapon, "Ranger Kick");
498 masters[2]->strength = 85;
499 masters[2]->gold = 0;
500 masters[2]->exp = 0;
501 masters[2]->maxhp = 70;
502 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!");
503
504
505 strcpy(masters[3]->name, "Mr. Miagi");
506 strcpy(masters[3]->weapon, "Petrified Bonsai");
507 masters[3]->strength = 100;
508 masters[3]->gold = 0;
509 masters[3]->exp = 0;
510 masters[3]->maxhp = 120;
511 strcpy(masters[3]->death, "Skill comes from repeating the correct but seemingly mundane actions. Wax ON, wax OFF!");
512
513 strcpy(masters[4]->name, "Jackie Chan");
514 strcpy(masters[4]->weapon, "Drunken Boxing");
515 masters[4]->strength = 125;
516 masters[4]->maxhp = 200;
517 masters[4]->gold = 0;
518 masters[4]->exp = 0;
519 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!");
520
521 strcpy(masters[5]->name, "Jet Li");
522 strcpy(masters[5]->weapon, "Motorcycle");
523 masters[5]->strength = 150;
524 masters[5]->maxhp = 400;
525 masters[5]->gold = 0;
526 masters[5]->exp = 0;
527 strcpy(masters[5]->death, "Failure is a fuel for excuses. It's the doing the do, that makes the making.");
528
529
530 strcpy(masters[6]->name, "Muhammad Ali");
531 strcpy(masters[6]->weapon, "Quick Jab");
532 masters[6]->strength = 175;
533 masters[6]->maxhp = 600;
534 masters[6]->gold = 0;
535 masters[6]->exp = 0;
536 strcpy(masters[6]->death, "It's just a job. Grass grows, birds fly, waves pound the sand. I beat people up.");
537
538 strcpy(masters[7]->name, "Li Mu Bai");
539 strcpy(masters[7]->weapon, "Green Destiny");
540 masters[7]->strength = 200;
541 masters[7]->maxhp = 800;
542 masters[7]->gold = 0;
543 masters[7]->exp = 0;
544 strcpy(masters[7]->death, "No growth without resistance. No action without reaction. No desire without restraint.");
545
546
547 strcpy(masters[8]->name, "Jimmy Wang Yu");
548 strcpy(masters[8]->weapon, "Flying Guillotine");
549 masters[8]->strength = 275;
550 masters[8]->maxhp = 1200;
551 masters[8]->gold = 0;
552 masters[8]->exp = 0;
553 strcpy(masters[8]->death, "You have beaten the one armed boxer. Proceed with caution!");
554
555 strcpy(masters[9]->name, "Wong Fei Hung");
556 strcpy(masters[9]->weapon, "Drunken Boxing");
557 masters[9]->strength = 350;
558 masters[9]->maxhp = 1800;
559 masters[9]->gold = 0;
560 masters[9]->exp = 0;
561 strcpy(masters[9]->death, "Hiccup!");
562
563 strcpy(masters[10]->name, "Bruce Lee");
564 strcpy(masters[10]->weapon, "Fists of fury");
565 masters[10]->strength = 575;
566 masters[10]->maxhp = 2500;
567 masters[10]->gold = 0;
568 masters[10]->exp = 0;
569 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.");
570 }
571
572 void init_monsters()
573 {
574 delete_monsters();
575 for (int x = 0; x < LEVELS; x++)
576 for (int y = 0; y < MONSTERS; y++)
577 monsters[x][y] = new Monster();
578
579 // Hard coded for now - Kain
580
581 strcpy(monsters[0][0]->name, "Slime");
582 strcpy(monsters[0][0]->weapon, "Acid Goo");
583 monsters[0][0]->strength = 6;
584 monsters[0][0]->gold = 50;
585 monsters[0][0]->exp = 3;
586 monsters[0][0]->maxhp = 9;
587 strcpy(monsters[0][0]->death, "The slime oozes into nothing... you clean the acid goo off of your weapon");
588
589 strcpy(monsters[0][1]->name, "Ghost");
590 strcpy(monsters[0][1]->weapon, "Cold Breath");
591 monsters[0][1]->strength = 8;
592 monsters[0][1]->gold = 100;
593 monsters[0][1]->exp = 10;
594 monsters[0][1]->maxhp = 10;
595 strcpy(monsters[0][1]->death, "You feel a chill as the spirit leaves the realm.");
596
597 strcpy(monsters[0][2]->name, "Ugly Rodent");
598 strcpy(monsters[0][2]->weapon, "Sharp Teeth");
599 monsters[0][2]->strength = 9;
600 monsters[0][2]->gold = 75;
601 monsters[0][2]->exp = 8;
602 monsters[0][2]->maxhp = 13;
603 strcpy(monsters[0][2]->death, "You stomp on the Ugly Rodent's remains for a finishing blow.");
604
605 strcpy(monsters[0][3]->name, "Whart Hog");
606 strcpy(monsters[0][3]->weapon, "Tusks");
607 monsters[0][3]->strength = 10;
608 monsters[0][3]->gold = 80;
609 monsters[0][3]->exp = 6;
610 monsters[0][3]->maxhp = 10;
611 strcpy(monsters[0][3]->death, "You cook and eat the hog for good measure!");
612
613 strcpy(monsters[0][4]->name, "Pesky Kid");
614 strcpy(monsters[0][4]->weapon, "Slingshot");
615 monsters[0][4]->strength = 8;
616 monsters[0][4]->gold = 30;
617 monsters[0][4]->exp = 4;
618 monsters[0][4]->maxhp = 6;
619 strcpy(monsters[0][4]->death, "You take his slingshot and snap the band, sending the kid crying home to mom!");
620
621 strcpy(monsters[0][5]->name, "Playground Bully");
622 strcpy(monsters[0][5]->weapon, "Painful Noogie");
623 monsters[0][5]->strength = 11;
624 monsters[0][5]->gold = 44;
625 monsters[0][5]->exp = 6;
626 monsters[0][5]->maxhp = 10;
627 strcpy(monsters[0][5]->death, "You give him an indian burn, and punt him across the schoolyard!");
628
629 strcpy(monsters[0][6]->name, "Small Imp");
630 strcpy(monsters[0][6]->weapon, "Dagger");
631 monsters[0][6]->strength = 6;
632 monsters[0][6]->gold = 64;
633 monsters[0][6]->exp = 10;
634 monsters[0][6]->maxhp = 10;
635 strcpy(monsters[0][6]->death, "You can't help but laugh as he stumbles and falls onto his own dagger!");
636
637 strcpy(monsters[0][7]->name, "Little Monkey");
638 strcpy(monsters[0][7]->weapon, "Monkey Wrench");
639 monsters[0][7]->strength = 6;
640 monsters[0][7]->gold = 53;
641 monsters[0][7]->exp = 9;
642 monsters[0][7]->maxhp = 9;
643 strcpy(monsters[0][7]->death, "You want to cook it, but you just can't think of eating something that looks so human!");
644
645 strcpy(monsters[0][8]->name, "Grub Worm");
646 strcpy(monsters[0][8]->weapon, "Minor Nudge");
647 monsters[0][8]->strength = 2;
648 monsters[0][8]->gold = 10;
649 monsters[0][8]->exp = 3;
650 monsters[0][8]->maxhp = 3;
651 strcpy(monsters[0][8]->death, "You decide to save the poor little fella for your next fishing trip.");
652
653 strcpy(monsters[0][9]->name, "Drakee");
654 strcpy(monsters[0][9]->weapon, "Tail Slap");
655 monsters[0][9]->strength = 5;
656 monsters[0][9]->gold = 22;
657 monsters[0][9]->exp = 7;
658 monsters[0][9]->maxhp = 5;
659 strcpy(monsters[0][9]->death, "You pull the little Drakee by its tale and slam it down on a dry stump!");
660
661 strcpy(monsters[0][10]->name, "Fat Slob");
662 strcpy(monsters[0][10]->weapon, "Smelly Breath");
663 monsters[0][10]->strength = 6;
664 monsters[0][10]->gold = 40;
665 monsters[0][10]->exp = 10;
666 monsters[0][10]->maxhp = 7;
667 strcpy(monsters[0][10]->death, "You kick his stomach for fun, and are thrown back by the spring of it all!");
668
669 strcpy(monsters[0][11]->name, "Lost Warrior");
670 strcpy(monsters[0][11]->weapon, "Long Sword");
671 monsters[0][11]->strength = 10;
672 monsters[0][11]->gold = 250;
673 monsters[0][11]->exp = 19;
674 monsters[0][11]->maxhp = 15;
675 strcpy(monsters[0][11]->death, "You give him a proper burial in respect for the dead warrior.");
676
677 strcpy(monsters[1][0]->name, "Lost Warrior's Cousin Larry");
678 strcpy(monsters[1][0]->weapon, "Wood Axe");
679 monsters[1][0]->strength = 19;
680 monsters[1][0]->gold = 134;
681 monsters[1][0]->exp = 24;
682 monsters[1][0]->maxhp = 30;
683 strcpy(monsters[1][0]->death, "He was pretty pissed you killed his cousin, but he seems to have suffered the same fate!");
684
685 strcpy(monsters[1][1]->name, "Sandman");
686 strcpy(monsters[1][1]->weapon, "Sleeping Dust");
687 monsters[1][1]->strength = 25;
688 monsters[1][1]->gold = 80;
689 monsters[1][1]->exp = 6;
690 monsters[1][1]->maxhp = 27;
691 strcpy(monsters[1][1]->death, "You put the sandman to his final sleep.");
692
693 strcpy(monsters[1][2]->name, "Dirty Prostitute");
694 strcpy(monsters[1][2]->weapon, "Stiletto Heel");
695 monsters[1][2]->strength = 21;
696 monsters[1][2]->gold = 160;
697 monsters[1][2]->exp = 12;
698 monsters[1][2]->maxhp = 25;
699 strcpy(monsters[1][2]->death, "Your pimp hand is strong!");
700
701 strcpy(monsters[1][3]->name, "Goblin Gardener");
702 strcpy(monsters[1][3]->weapon, "Garden Spade");
703 monsters[1][3]->strength = 18;
704 monsters[1][3]->gold = 130;
705 monsters[1][3]->exp = 8;
706 monsters[1][3]->maxhp = 20;
707 strcpy(monsters[1][3]->death, "You trample on his garden after slaying him... that felt good!");
708
709 strcpy(monsters[1][4]->name, "Evil Elf");
710 strcpy(monsters[1][4]->weapon, "Dark Bow");
711 monsters[1][4]->strength = 23;
712 monsters[1][4]->gold = 136;
713 monsters[1][4]->exp = 13;
714 monsters[1][4]->maxhp = 24;
715 strcpy(monsters[1][4]->death, "Elves are usually nice you thought... hmm.");
716
717 strcpy(monsters[1][5]->name, "Viking Warrior");
718 strcpy(monsters[1][5]->weapon, "Broad Sword");
719 monsters[1][5]->strength = 21;
720 monsters[1][5]->gold = 330;
721 monsters[1][5]->exp = 20;
722 monsters[1][5]->maxhp = 18;
723 strcpy(monsters[1][5]->death, "You heard vikings were big, but not THAT big you thought.");
724
725 strcpy(monsters[1][6]->name, "Wicked Witch");
726 strcpy(monsters[1][6]->weapon, "Cackling Laugh");
727 monsters[1][6]->strength = 20;
728 monsters[1][6]->gold = 130;
729 monsters[1][6]->exp = 20;
730 monsters[1][6]->maxhp = 26;
731 strcpy(monsters[1][6]->death, "Just for kicks, you splash some water on her and watch her melt.");
732
733 strcpy(monsters[1][7]->name, "Vampire Bat");
734 strcpy(monsters[1][7]->weapon, "Blood Sucking Fangs");
735 monsters[1][7]->strength = 18;
736 monsters[1][7]->gold = 125;
737 monsters[1][7]->exp = 21;
738 monsters[1][7]->maxhp = 29;
739 strcpy(monsters[1][7]->death, "You fry up the bat and eat it... needs garlic.");
740
741 strcpy(monsters[1][8]->name, "Thorn Bush");
742 strcpy(monsters[1][8]->weapon, "101 Thorns");
743 monsters[1][8]->strength = 16;
744 monsters[1][8]->gold = 94;
745 monsters[1][8]->exp = 15;
746 monsters[1][8]->maxhp = 25;
747 strcpy(monsters[1][8]->death, "You set the bush ablaze and roast some marshmallows.");
748
749 strcpy(monsters[1][9]->name, "Barbarian");
750 strcpy(monsters[1][9]->weapon, "Heavy Sword");
751 monsters[1][9]->strength = 29;
752 monsters[1][9]->gold = 250;
753 monsters[1][9]->exp = 25;
754 monsters[1][9]->maxhp = 30;
755 strcpy(monsters[1][9]->death, "You listen to him moan as he falls over dead.");
756
757 strcpy(monsters[1][10]->name, "Crypt Rat");
758 strcpy(monsters[1][10]->weapon, "Stinging Bite");
759 monsters[1][10]->strength = 25;
760 monsters[1][10]->gold = 119;
761 monsters[1][10]->exp = 20;
762 monsters[1][10]->maxhp = 26;
763 strcpy(monsters[1][10]->death, "You squash the little rodent for fear that it might not be dead.");
764
765 strcpy(monsters[1][11]->name, "Small Orc");
766 strcpy(monsters[1][11]->weapon, "blade");
767 monsters[1][11]->strength = 28;
768 monsters[1][11]->gold = 300;
769 monsters[1][11]->exp = 30;
770 monsters[1][11]->maxhp = 36;
771 strcpy(monsters[1][11]->death, "It's an ugly one, and it would've grown up to be a terror...");
772
773 strcpy(monsters[2][0]->name, "Teferi");
774 strcpy(monsters[2][0]->weapon, "Puzzle Box");
775 monsters[2][0]->strength = 29;
776 monsters[2][0]->gold = 380;
777 monsters[2][0]->exp = 18;
778 monsters[2][0]->maxhp = 29;
779 strcpy(monsters[2][0]->death, "It was a puzzling experience.");
780
781 strcpy(monsters[2][1]->name, "Spineless Thug");
782 strcpy(monsters[2][1]->weapon, "Spiked Bat");
783 monsters[2][1]->strength = 37;
784 monsters[2][1]->gold = 384;
785 monsters[2][1]->exp = 27;
786 monsters[2][1]->maxhp = 32;
787 strcpy(monsters[2][1]->death, "See you at the crossroads!");
788
789 strcpy(monsters[2][2]->name, "Pyromaniac");
790 strcpy(monsters[2][2]->weapon, "Flame Thrower");
791 monsters[2][2]->strength = 29;
792 monsters[2][2]->gold = 563;
793 monsters[2][2]->exp = 22;
794 monsters[2][2]->maxhp = 45;
795 strcpy(monsters[2][2]->death, "He chants FIRE FIRE as he falls to the ground... a burning heap of flesh.");
796
797 strcpy(monsters[2][3]->name, "Evil Enchantress");
798 strcpy(monsters[2][3]->weapon, "Deadly Spell");
799 monsters[2][3]->strength = 50;
800 monsters[2][3]->gold = 830;
801 monsters[2][3]->exp = 35;
802 monsters[2][3]->maxhp = 35;
803 strcpy(monsters[2][3]->death, "She looked just about as good as she fought.");
804
805 strcpy(monsters[2][4]->name, "Killer Leprechaun");
806 strcpy(monsters[2][4]->weapon, "Gold Rush");
807 monsters[2][4]->strength = 35;
808 monsters[2][4]->gold = 1300;
809 monsters[2][4]->exp = 30;
810 monsters[2][4]->maxhp = 37;
811 strcpy(monsters[2][4]->death, "You steal his pot of gold... that's a lot of money!");
812
813 strcpy(monsters[2][5]->name, "Avalanche Rider");
814 strcpy(monsters[2][5]->weapon, "Huge Snowball");
815 monsters[2][5]->strength = 32;
816 monsters[2][5]->gold = 700;
817 monsters[2][5]->exp = 32;
818 monsters[2][5]->maxhp = 38;
819 strcpy(monsters[2][5]->death, "You take his snowboard and snap it in two!");
820
821 strcpy(monsters[2][6]->name, "Blundering Idiot");
822 strcpy(monsters[2][6]->weapon, "Stupidity");
823 monsters[2][6]->strength = 14;
824 monsters[2][6]->gold = 700;
825 monsters[2][6]->exp = 20;
826 monsters[2][6]->maxhp = 29;
827 strcpy(monsters[2][6]->death, "Now there's one person you don't feel sorry for killing!");
828
829 strcpy(monsters[2][7]->name, "Militant Anarchist");
830 strcpy(monsters[2][7]->weapon, "Molotov Cocktail");
831 monsters[2][7]->strength = 33;
832 monsters[2][7]->gold = 245;
833 monsters[2][7]->exp = 45;
834 monsters[2][7]->maxhp = 32;
835 strcpy(monsters[2][7]->death, "Order has been restored for now...");
836
837 strcpy(monsters[2][8]->name, "Scathe Zombies");
838 strcpy(monsters[2][8]->weapon, "Death Grip");
839 monsters[2][8]->strength = 38;
840 monsters[2][8]->gold = 763;
841 monsters[2][8]->exp = 15;
842 monsters[2][8]->maxhp = 45;
843 strcpy(monsters[2][8]->death, "That was perhaps the scariest experience of your life.");
844
845 strcpy(monsters[2][9]->name, "Spitting Llama");
846 strcpy(monsters[2][9]->weapon, "Spit Spray");
847 monsters[2][9]->strength = 48;
848 monsters[2][9]->gold = 638;
849 monsters[2][9]->exp = 28;
850 monsters[2][9]->maxhp = 34;
851 strcpy(monsters[2][9]->death, "You wipe the spit off your face and fling it back at the Llama.");
852
853 strcpy(monsters[2][10]->name, "Juggalo");
854 strcpy(monsters[2][10]->weapon, "Clown Axe");
855 monsters[2][10]->strength = 60;
856 monsters[2][10]->gold = 650;
857 monsters[2][10]->exp = 30;
858 monsters[2][10]->maxhp = 29;
859 strcpy(monsters[2][10]->death, "What is a Juggalo? I don't know!");
860
861 strcpy(monsters[2][11]->name, "The Boogie Man");
862 strcpy(monsters[2][11]->weapon, "Striking Fear");
863 monsters[2][11]->strength = 46;
864 monsters[2][11]->gold = 600;
865 monsters[2][11]->exp = 35;
866 monsters[2][11]->maxhp = 27;
867 strcpy(monsters[2][11]->death, "He's scared you for the very last time!");
868
869 strcpy(monsters[3][0]->name, "Living Fire");
870 strcpy(monsters[3][0]->weapon, "Scorching Wind");
871 monsters[3][0]->strength = 55;
872 monsters[3][0]->gold = 1100;
873 monsters[3][0]->exp = 36;
874 monsters[3][0]->maxhp = 55;
875 strcpy(monsters[3][0]->death, "You extinguish the Living Flame once and for all!");
876
877 strcpy(monsters[3][1]->name, "Raging Orc");
878 strcpy(monsters[3][1]->weapon, "Orcish Artillary");
879 monsters[3][1]->strength = 89;
880 monsters[3][1]->gold = 900;
881 monsters[3][1]->exp = 25;
882 monsters[3][1]->maxhp = 50;
883 strcpy(monsters[3][1]->death, "This orc was a bit tougher than you remembered!");
884
885 strcpy(monsters[3][2]->name, "Huge Tarantula");
886 strcpy(monsters[3][2]->weapon, "Tangling Web");
887 monsters[3][2]->strength = 59;
888 monsters[3][2]->gold = 1000;
889 monsters[3][2]->exp = 35;
890 monsters[3][2]->maxhp = 60;
891 strcpy(monsters[3][2]->death, "You're glad you overcame your arachniphobia so soon!");
892
893 strcpy(monsters[3][3]->name, "Rabid Wolf");
894 strcpy(monsters[3][3]->weapon, "Cujo Bite");
895 monsters[3][3]->strength = 40;
896 monsters[3][3]->gold = 1200;
897 monsters[3][3]->exp = 47;
898 monsters[3][3]->maxhp = 76;
899 strcpy(monsters[3][3]->death, "The mutt falls over dead as white foam drips from its deadly canines...");
900
901 strcpy(monsters[3][4]->name, "Goblin Fighter");
902 strcpy(monsters[3][4]->weapon, "Morning Star");
903 monsters[3][4]->strength = 38;
904 monsters[3][4]->gold = 700;
905 monsters[3][4]->exp = 30;
906 monsters[3][4]->maxhp = 75;
907 strcpy(monsters[3][4]->death, "He almost caught you with his chain mace, but you sliced off his head.");
908
909 strcpy(monsters[3][5]->name, "Grizzly Bear");
910 strcpy(monsters[3][5]->weapon, "Razor Claws");
911 monsters[3][5]->strength = 68;
912 monsters[3][5]->gold = 1747;
913 monsters[3][5]->exp = 81;
914 monsters[3][5]->maxhp = 51;
915 strcpy(monsters[3][5]->death, "It almost got you this time... better be careful");
916
917 strcpy(monsters[3][6]->name, "Skeleton Man");
918 strcpy(monsters[3][6]->weapon, "Leg Bone");
919 monsters[3][6]->strength = 70;
920 monsters[3][6]->gold = 597;
921 monsters[3][6]->exp = 57;
922 monsters[3][6]->maxhp = 60;
923 strcpy(monsters[3][6]->death, "As a finisher, you wind up with the broad side of your weapon and hit his skull off for a home run!");
924
925 strcpy(monsters[3][7]->name, "Young Werewolf");
926 strcpy(monsters[3][7]->weapon, "Howling Bites");
927 monsters[3][7]->strength = 75;
928 monsters[3][7]->gold = 1742;
929 monsters[3][7]->exp = 65;
930 monsters[3][7]->maxhp = 42;
931 strcpy(monsters[3][7]->death, "You scatter the wolf's body parts in hopes he will stay dead!");
932
933 strcpy(monsters[3][8]->name, "Dark Infantry");
934 strcpy(monsters[3][8]->weapon, "Flesh Reaper");
935 monsters[3][8]->strength = 69;
936 monsters[3][8]->gold = 870;
937 monsters[3][8]->exp = 43;
938 monsters[3][8]->maxhp = 65;
939 strcpy(monsters[3][8]->death, "Light has prevailed this time... but it's only so long before you meet again.");
940
941 strcpy(monsters[3][9]->name, "Erie Spirit");
942 strcpy(monsters[3][9]->weapon, "Deadly Grin");
943 monsters[3][9]->strength = 63;
944 monsters[3][9]->gold = 1300;
945 monsters[3][9]->exp = 32;
946 monsters[3][9]->maxhp = 50;
947 strcpy(monsters[3][9]->death, "His cousin the ghost was a little bit easier.");
948
949 strcpy(monsters[3][10]->name, "Gollum");
950 strcpy(monsters[3][10]->weapon, "Precious Treasure");
951 monsters[3][10]->strength = 66;
952 monsters[3][10]->gold = 1492;
953 monsters[3][10]->exp = 73;
954 monsters[3][10]->maxhp = 54;
955 strcpy(monsters[3][10]->death, "Gollum screams out \"MY PRECIOUS\" as his small body falls limp from your blow.");
956
957 strcpy(monsters[3][11]->name, "Rock Fighter");
958 strcpy(monsters[3][11]->weapon, "Small Boulders");
959 monsters[3][11]->strength = 87;
960 monsters[3][11]->gold = 1742;
961 monsters[3][11]->exp = 99;
962 monsters[3][11]->maxhp = 65;
963 strcpy(monsters[3][11]->death, "You dodge his last rock, and counter with a low blow, cutting off his legs.");
964
965
966 strcpy(monsters[4][0]->name, "Giant Sphinx");
967 strcpy(monsters[4][0]->weapon, "Ancient Curse");
968 monsters[4][0]->strength = 120;
969 monsters[4][0]->gold = 1000;
970 monsters[4][0]->exp = 100;
971 monsters[4][0]->maxhp = 80;
972 strcpy(monsters[4][0]->death, "You look in awe at the great wonder, collapsed at your feet!");
973
974 strcpy(monsters[4][1]->name, "Giant Ogre");
975 strcpy(monsters[4][1]->weapon, "Big Log");
976 monsters[4][1]->strength = 130;
977 monsters[4][1]->gold = 857;
978 monsters[4][1]->exp = 175;
979 monsters[4][1]->maxhp = 100;
980 strcpy(monsters[4][1]->death, "Your wits outmatched the ogre's brawn... big dumb thing.");
981
982 strcpy(monsters[4][2]->name, "Massive Cockroach");
983 strcpy(monsters[4][2]->weapon, "Piercing Hiss");
984 monsters[4][2]->strength = 125;
985 monsters[4][2]->gold = 700;
986 monsters[4][2]->exp = 150;
987 monsters[4][2]->maxhp = 112;
988 strcpy(monsters[4][2]->death, "Where's the exterminator when you need one?");
989
990 strcpy(monsters[4][3]->name, "Big Venomous Snake");
991 strcpy(monsters[4][3]->weapon, "Poison Fangs");
992 monsters[4][3]->strength = 140;
993 monsters[4][3]->gold = 900;
994 monsters[4][3]->exp = 175;
995 monsters[4][3]->maxhp = 126;
996 strcpy(monsters[4][3]->death, "After killing this beast you check for puncture marks... you find none, luckily.");
997
998 strcpy(monsters[4][4]->name, "Lizard Man");
999 strcpy(monsters[4][4]->weapon, "Deadly Jaws");
1000 monsters[4][4]->strength = 145;
1001 monsters[4][4]->gold = 1250;
1002 monsters[4][4]->exp = 175;
1003 monsters[4][4]->maxhp = 150;
1004 strcpy(monsters[4][4]->death, "His scales made for tough armor, and his jaws for a tougher opponent!");
1005
1006 strcpy(monsters[4][5]->name, "Face Dancer");
1007 strcpy(monsters[4][5]->weapon, "Illusion Scyth");
1008 monsters[4][5]->strength = 138;
1009 monsters[4][5]->gold = 1603;
1010 monsters[4][5]->exp = 198;
1011 monsters[4][5]->maxhp = 173;
1012 strcpy(monsters[4][5]->death, "His carcus takes the shape of many things before it dies. His true form is so repulsive, you know why he changed faces so much!");
1013
1014 strcpy(monsters[4][6]->name, "Darklord Longbow Archer");
1015 strcpy(monsters[4][6]->weapon, "Deadly Bow and Arrows");
1016 monsters[4][6]->strength = 145;
1017 monsters[4][6]->gold = 1569;
1018 monsters[4][6]->exp = 243;
1019 monsters[4][6]->maxhp = 170;
1020 strcpy(monsters[4][6]->death, "Your face turns white with horror after you realize you just met the devil's protector!");
1021
1022 strcpy(monsters[4][7]->name, "Hell's Paladin");
1023 strcpy(monsters[4][7]->weapon, "Sword of Hellfire");
1024 monsters[4][7]->strength = 200;
1025 monsters[4][7]->gold = 2191;
1026 monsters[4][7]->exp = 254;
1027 monsters[4][7]->maxhp = 175;
1028 strcpy(monsters[4][7]->death, "This is starting to get tough you think. Do you really want to go to level 6?");
1029
1030 strcpy(monsters[4][8]->name, "The Unknown Soldier");
1031 strcpy(monsters[4][8]->weapon, "Soul Torture");
1032 monsters[4][8]->strength = 175;
1033 monsters[4][8]->gold = 1890;
1034 monsters[4][8]->exp = 200;
1035 monsters[4][8]->maxhp = 180;
1036 strcpy(monsters[4][8]->death, "Who was that? Where was he from? And what was that weapon??");
1037
1038 strcpy(monsters[4][9]->name, "Undead Cult Leader");
1039 strcpy(monsters[4][9]->weapon, "Lance of Deceit");
1040 monsters[4][9]->strength = 180;
1041 monsters[4][9]->gold = 1792;
1042 monsters[4][9]->exp = 195;
1043 monsters[4][9]->maxhp = 190;
1044 strcpy(monsters[4][9]->death, "His words fall on deaf ears... this is one cult you will NOT be part of!");
1045
1046 strcpy(monsters[4][10]->name, "Water Serpent");
1047 strcpy(monsters[4][10]->weapon, "Forked Tongue");
1048 monsters[4][10]->strength = 150;
1049 monsters[4][10]->gold = 1500;
1050 monsters[4][10]->exp = 176;
1051 monsters[4][10]->maxhp = 220;
1052 strcpy(monsters[4][10]->death, "The serpent squeals as you cut off its head!");
1053
1054 strcpy(monsters[4][11]->name, "Silverback Gorilla");
1055 strcpy(monsters[4][11]->weapon, "Deadly Banana Peel");
1056 monsters[4][11]->strength = 160;
1057 monsters[4][11]->gold = 1300;
1058 monsters[4][11]->exp = 150;
1059 monsters[4][11]->maxhp = 178;
1060 strcpy(monsters[4][11]->death, "Was that gorilla or guerilla?");
1061 }
1062
1063 void delete_monsters()
1064 {
1065 for (int x = 0; x < LEVELS; x++)
1066 for (int y = 0; y < MONSTERS; y++)
1067 if (monsters[x][y])
1068 delete monsters[x][y];
1069 }
1070
1071 void delete_masters()
1072 {
1073 for (int x = 0; x < LEVELS; x++)
1074 if (masters[x])
1075 delete masters[x];
1076 }
1077
1078 void display_monster(char *u)
1079 {
1080 if (is_playing(u))
1081 {
1082 aClient *user = find(u);
1083 Player *ni = user->stats;
1084
1085 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->hp);
1086 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", ni->fight->name, ni->fight->hp);
1087 notice(s_GameServ, u, "Here are your commands:");
1088 notice(s_GameServ, u, "/msg %S attack");
1089 notice(s_GameServ, u, "/msg %S run");
1090 notice(s_GameServ, u, "What will you do?");
1091 }
1092 }
1093
1094 void display_players(char *u)
1095 {
1096 if (is_playing(u))
1097 {
1098 aClient *ni = find(u);
1099
1100 aClient *battle = ni->stats->battle;
1101
1102 notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->stats->hp);
1103 notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->getNick(),
1104 battle->stats->hp);
1105
1106 notice(s_GameServ, u, "Here are your commands:");
1107 notice(s_GameServ, u, "/msg %s attack", s_GameServ);
1108 notice(s_GameServ, u, "/msg %s run", s_GameServ);
1109 notice(s_GameServ, u, "What will you do?");
1110 }
1111 }
1112
1113
1114 bool is_playing(char *u)
1115 {
1116 aClient *user;
1117 if (!(user = find(u)))
1118 {
1119 return false;
1120 }
1121 else
1122 {
1123 return user->stats != NULL;
1124 }
1125 }
1126
1127 bool is_fighting(char *u)
1128 {
1129 aClient *user;
1130
1131 if (!(user = find(u)))
1132 {
1133 return false;
1134 }
1135 else if (user->stats)
1136 {
1137 return user->stats->fight != NULL || user->stats->battle != NULL
1138 || user->stats->master != NULL;
1139 }
1140 else
1141 return false;
1142 }
1143
1144 bool player_fight(char *u)
1145 {
1146 aClient *user;
1147
1148 if (!(user = find(u)))
1149 return false;
1150 else if (user->stats)
1151 return user->stats->battle != NULL;
1152 else
1153 return false;
1154 }
1155
1156 bool master_fight(char *u)
1157 {
1158 aClient *user;
1159
1160 if (!(user = find(u)))
1161 return false;
1162 else if (user->stats)
1163 return user->stats->master != NULL;
1164 else
1165 return false;
1166 }
1167
1168 bool isnt_fighting(char *u)
1169 {
1170 return !is_fighting(u);
1171 }
1172
1173 void do_fight(char *u)
1174 {
1175 aClient *ni, *battle;
1176
1177 char *nick = strtok(NULL, " ");
1178
1179 if (!nick)
1180 {
1181 notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER");
1182 }
1183 else if (!(ni = find(u)))
1184 {
1185 return;
1186 }
1187 else if (!(battle = find(nick)))
1188 {
1189 notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
1190 }
1191 else if (!is_playing(u))
1192 {
1193 notice(s_GameServ, u, "You are not playing!");
1194 }
1195 /*
1196 * Offline fighting not implemented yet.
1197 * else if (!(fight = finduser(nick)))
1198 * {
1199 * ni->stats->battle = battle;
1200 * battle->battle = ni;
1201 * ni->yourturn = 1;
1202 * battle->yourturn = 0;
1203 * notice(s_GameServ, u, "You decide to fight %s while they're not online!",
1204 * battle->getNick());
1205 * display_players(u);
1206 * }
1207 */
1208 else if (is_playing(u) && is_playing(nick))
1209 {
1210 // Set your battle pointer to the other player
1211 ni->stats->battle = battle;
1212
1213 // Set the other player's battle pointer to you
1214 battle->stats->battle = ni;
1215
1216 // The initiator gets the first move (perhaps this should be 50/50)
1217 ni->stats->yourturn = 1;
1218 battle->stats->yourturn = 0;
1219
1220 // Initiate Battle sequence!
1221 notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getNick());
1222 notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", u);
1223 notice(s_GameServ, battle->getNick(), "%s gets to go first because he initiated!", u);
1224 notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", u);
1225 display_players(u);
1226 }
1227 }
1228 void do_run(char *u)
1229 {
1230 aClient *user;
1231 Player *p, *p2;
1232
1233 if (!(user = find(u)))
1234 {
1235 notice(s_GameServ, u, "Couldn't find you. Error. Contact a %S admin");
1236 return;
1237 }
1238
1239 p = user->stats;
1240
1241 if (p->battle)
1242 p2 = p->battle->stats;
1243
1244 if (!is_fighting(u))
1245 notice(s_GameServ, u, "You run in place... try fighting next time.");
1246 else if (!player_fight(u) && !master_fight(u))
1247 {
1248 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->fight->name);
1249 delete p->fight;
1250 p->fight = NULL;
1251 }
1252 else if (player_fight(u) && p->yourturn)
1253 {
1254 notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p2->name);
1255 notice(s_GameServ, p->battle->getNick(), "\ 2%s\ 2 ran away from you like a little baby!", p->name);
1256 p2->battle = NULL;
1257 }
1258 else if (player_fight(u) && !p->yourturn)
1259 {
1260 notice(s_GameServ, u, "It is not your turn. Please wait until \ 2%s\ 2 decides what to do.", p2->name);
1261 }
1262 else if (master_fight(u))
1263 {
1264 notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->master->name);
1265 }
1266 p->battle = NULL;
1267 }
1268 void do_attack(char *u)
1269 {
1270 int hit, mhit;
1271 aClient *ni, *battle; // The player and perhaps the player they're fighting
1272 Monster *fight; // The monster they may be fighting
1273
1274 if (!(ni = find(u)))
1275 {
1276 notice(s_GameServ, u, "You're not playing!");
1277 return;
1278 }
1279 else if (!ni->stats->fight && !ni->stats->battle && !ni->stats->master)
1280 {
1281 notice(s_GameServ, u, "You're not in battle!");
1282 return;
1283 }
1284 else
1285 {
1286 if (!ni->stats->master) // This is not a master fight
1287 fight = ni->stats->fight; // Monster Could be NULL
1288 else // This IS a master fight
1289 fight = ni->stats->master; // Master Could be NULL
1290
1291 battle = ni->stats->battle; // Player Could be NULL
1292
1293 // One has to be !NULL based on the previous else if
1294 // We wouldn't be here if they were all NULL
1295 }
1296
1297 if (!player_fight(u))
1298 {
1299 // Player's Hit
1300 hit = ((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1301 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon]) / 2));
1302
1303 // Opponent's Hit
1304 mhit = (fight->strength / 2) +
1305 (rand() % (fight->strength / 2) - (ni->stats->defense +
1306 arbonus[ni->stats->armor]));
1307 }
1308 else
1309 {
1310 // Opponent's Hit
1311 mhit = (((battle->stats->strength + webonus[battle->stats->weapon]) / 2) +
1312 (rand() % ((battle->stats->strength + webonus[battle->stats->weapon])) / 2) -
1313 (ni->stats->defense + arbonus[ni->stats->armor]));
1314
1315 // Player's Hit
1316 hit = (((ni->stats->strength + webonus[ni->stats->weapon]) / 2) +
1317 (rand() % ((ni->stats->strength + webonus[ni->stats->weapon])) / 2) -
1318 (battle->stats->defense + arbonus[battle->stats->armor]));
1319 }
1320
1321 if (!player_fight(u))
1322 {
1323 if (hit > 0)
1324 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", fight->name, hit);
1325 else
1326 notice(s_GameServ, u, "You miss \1f%s\1f completely!", fight->name);
1327
1328 if (hit >= fight->hp)
1329 {
1330 if (master_fight(u))
1331 notice(s_GameServ, u, "You have bested %s!", fight->name);
1332 else
1333 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", fight->name);
1334
1335 notice(s_GameServ, u, "%s", fight->death);
1336 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%d\ 2 gold!",
1337 fight->exp, fight->gold);
1338
1339 // If your new experience (or gold) will be greater than 2 billion,
1340 // then set your exp to 2bil. (2 billion max)... otherwise add them.
1341 // This could be a problem with overflowing out of the sign bit.
1342 // Unsigned long int maybe? Leave it for now.
1343 ni->stats->exp = ( (ni->stats->exp + fight->exp) > 2000000000 ? 2000000000 :
1344 ni->stats->exp + fight->exp);
1345 ni->stats->gold = (ni->stats->gold + fight->gold > 2000000000 ? 2000000000 :
1346 ni->stats->gold + fight->gold);
1347
1348 // They're dead so remove the pointer
1349 delete ni->stats->fight;
1350 ni->stats->fight = NULL;
1351
1352 if (master_fight(u))
1353 {
1354 notice(s_GameServ, u, "You are now level %d!", ni->stats->level + 1);
1355 notice(s_GameServ, u, "You gain %d Strength, and %d Defense points!",
1356 strbonus[ni->stats->level - 1], defbonus[ni->stats->level - 1]);
1357
1358 // Increase your level
1359 ni->stats->level++;
1360
1361 // Increase your maximum hit points
1362 ni->stats->maxhp += hpbonus[ni->stats->level - 1];
1363
1364 // Heal the player by setting hp to their max
1365 ni->stats->hp = ni->stats->maxhp;
1366
1367 // Add to your strength
1368 ni->stats->strength += strbonus[ni->stats->level - 1];
1369
1370 // Add to your defensive power
1371 ni->stats->defense += defbonus[ni->stats->level - 1];
1372
1373 // Clear the pointer for your master
1374 ni->stats->master = NULL;
1375 }
1376 return;
1377 }
1378 else
1379 {
1380 if (hit > 0)
1381 fight->hp -= hit;
1382 if (mhit > 0)
1383 {
1384 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1385 fight->name, fight->weapon, mhit);
1386 }
1387 else if (mhit <= 0)
1388 notice(s_GameServ, u, "%s completely misses you!", fight->name);
1389
1390 if (mhit >= ni->stats->hp)
1391 {
1392 if (!master_fight(u))
1393 {
1394 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", fight->name);
1395 notice(s_GameServ, u, "You lose all gold on hand and lose 10 percent "\
1396 "of your experience!");
1397 ni->stats->gold = 0;
1398 ni->stats->exp -= (long int)(ni->stats->exp * .10);
1399 ni->stats->fight = NULL;
1400 return;
1401 }
1402 else
1403 {
1404 notice(s_GameServ, u, "%s has bested you! You will have to wait "\
1405 "until tomorrow to try again", ni->stats->master->name);
1406 ni->stats->fight = NULL;
1407 ni->stats->master = NULL;
1408 return;
1409 }
1410 }
1411 else
1412 {
1413 if (mhit > 0)
1414 ni->stats->hp -= mhit;
1415 display_monster(u);
1416 return;
1417 }
1418 }
1419 }
1420 else if (player_fight(u))
1421 {
1422 /* Offline fighting not available yet
1423 if (!(online = finduser(ni->stats->battle->nick)) || !nick_identified(online))
1424 {
1425 if (hit > 0)
1426 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->nick, hit);
1427 else
1428 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->nick);
1429 if (hit >= battle->stats->hp)
1430 {
1431 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->nick);
1432 * notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1433 (long int)(battle->stats->exp * .10), battle->stats->gold);
1434 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1435 {
1436 ni->stats->exp += (long int)(battle->stats->exp * .10);
1437 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1438 }
1439 * else
1440 {
1441 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1442 ni->stats->exp = 2000000000;
1443 }
1444
1445 if (2000000000 - ni->stats->gold > battle->stats->gold)
1446 {
1447 * ni->stats->gold += battle->stats->gold;
1448 battle->stats->gold = 0;
1449 }
1450 else
1451 {
1452 battle->stats->gold = 2000000000 - ni->stats->gold;
1453 ni->stats->gold = 2000000000;
1454 }
1455 * ni->stats->battle->stats->alive = 0;
1456 ni->stats->battle->battle = NULL;
1457 ni->stats->battle = NULL;
1458 return;
1459 }
1460 else
1461 {
1462 if (hit > 0)
1463 * battle->stats->hp -= hit;
1464 if (mhit > 0)
1465 {
1466 notice(s_GameServ, u, "\1f%s\1f hits you with their \1f%s\1f for \ 2%d\ 2 damage!",
1467 battle->nick, weapons[battle->stats->weapon], mhit);
1468 }
1469 else if (mhit <= 0)
1470 notice(s_GameServ, u, "%s completely misses you!", battle->nick);
1471 *
1472 if (mhit >= ni->stats->hp)
1473 {
1474 notice(s_GameServ, u, "You have been \ 2\1fkilled\1f\ 2 by %s!", battle->nick);
1475 if (2000000000 - battle->stats->gold > ni->stats->gold)
1476 {
1477 notice(s_GameServ, u, "%s took all your gold!", battle->nick);
1478 battle->stats->gold += ni->stats->gold;
1479 * ni->stats->gold = 0;
1480 }
1481 else
1482 {
1483 notice(s_GameServ, u, "You're lucky, %s couldn't carry all your gold.",
1484 battle->nick);
1485 ni->stats->gold -= (2000000000 - battle->stats->gold);
1486 notice(s_GameServ, u, "You were left dead with %d gold.",
1487 * (long int)ni->stats->gold);
1488 battle->stats->gold = 2000000000;
1489 }
1490 ni->stats->battle->battle = NULL;
1491 ni->stats->battle = NULL;
1492 ni->stats->alive = 0;
1493 return;
1494 }
1495 * else
1496 {
1497 if (mhit > 0)
1498 ni->stats->hp -= mhit;
1499 display_players(u);
1500 return;
1501 }
1502 }
1503 }
1504 * end offline fighting */
1505
1506 if (is_playing(battle->getNick()))
1507 {
1508 if (ni->stats->yourturn == 0)
1509 {
1510 notice(s_GameServ, u, "Please wait until %s decides what to do!",
1511 battle->getNick());
1512 return;
1513 }
1514 if (hit > 0)
1515 {
1516 notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->getNick(), hit);
1517
1518 notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
1519 "\ 2%d\ 2 damage!", u, weapons[ni->stats->weapon],
1520 hit);
1521 ni->stats->yourturn = 0;
1522 battle->stats->yourturn = 1;
1523 display_players(battle->getNick());
1524 }
1525 else
1526 {
1527 notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->getNick());
1528 notice(s_GameServ, battle->getNick(), "%s misses you completely!", u);
1529 ni->stats->yourturn = 0;
1530 battle->stats->yourturn = 1;
1531 display_players(battle->getNick());
1532 }
1533 if (hit >= battle->stats->hp)
1534 {
1535 notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->getNick());
1536 notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
1537 (long int)(battle->stats->exp * .10), battle->stats->gold);
1538 notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", u);
1539 battle->stats->hp = 0;
1540 battle->stats->alive = 0;
1541
1542 if (2000000000 - ni->stats->exp > (long int)(battle->stats->exp * .10))
1543 {
1544 ni->stats->exp += (long int)(battle->stats->exp * .10);
1545 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1546 }
1547 else
1548 {
1549 battle->stats->exp -= (long int)(battle->stats->exp * .10);
1550 ni->stats->exp = 2000000000;
1551 }
1552
1553 if (2000000000 - ni->stats->gold > battle->stats->gold)
1554 {
1555 notice(s_GameServ, battle->getNick(), "You lose ten percent of experience and "\
1556 "all gold on hand!");
1557 ni->stats->gold += battle->stats->gold;
1558 battle->stats->gold = 0;
1559 }
1560 else
1561 {
1562 battle->stats->gold = 2000000000 - ni->stats->gold;
1563 notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
1564
1565 notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
1566 "gold.", u);
1567
1568 notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
1569 "left. All is not lost!", battle->stats->gold);
1570
1571 ni->stats->gold = 2000000000;
1572 }
1573 battle->stats->battle = NULL;
1574 ni->stats->battle = NULL;
1575 return;
1576 }
1577 else
1578 {
1579 if (hit > 0)
1580 battle->stats->hp -= hit;
1581 //display_players(battle->getNick());
1582 ni->stats->yourturn = 0;
1583 battle->stats->yourturn = 1;
1584 notice(s_GameServ, u, "Please wait while %s decides what to do!",
1585 battle->getNick());
1586
1587 return;
1588 }
1589 }
1590 }
1591 }
1592 void do_heal(char *u)
1593 {
1594 aClient *ni;
1595 char *amount = strtok(NULL, " ");
1596 int price, num;
1597
1598 if (!amount)
1599 {
1600 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1601 }
1602 else if (!(ni = find(u)) || !ni->stats)
1603 {
1604 notice(s_GameServ, u, "You aren't playing!");
1605 }
1606 else if (is_fighting(u))
1607 {
1608 notice(s_GameServ, u, "You can't heal in battle!");
1609 }
1610 else if (ni->stats->hp >= ni->stats->maxhp)
1611 {
1612 notice(s_GameServ, u, "You don't need healing!");
1613 }
1614 else if (stricmp(amount, "ALL") == 0)
1615 {
1616 price = ni->stats->level * 3;
1617 if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price)
1618 {
1619 notice(s_GameServ, u, "Healing \ 2%d\ 2 points for \ 2%d\ 2 gold per point.",
1620 (long int)ni->stats->gold/price, price);
1621 ni->stats->hp += ni->stats->gold / price;
1622 ni->stats->gold %= price;
1623 }
1624 else
1625 {
1626 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1627 "per point.", price);
1628 notice(s_GameServ, u, "\ 2%d\ 2 points healed for \ 2%ld\ 2 gold. HP at MAX!",
1629 (ni->stats->maxhp - ni->stats->hp),
1630 (price * (ni->stats->maxhp - ni->stats->hp)) );
1631 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1632 ni->stats->hp = ni->stats->maxhp;
1633 }
1634 }
1635 else if (isstringnum(amount))
1636 {
1637 num = stringtoint(amount);
1638 price = ni->stats->level * 3;
1639 if (ni->stats->gold < price * num)
1640 {
1641 notice(s_GameServ, u, "You only have enough gold to heal \ 2%d\ 2 points!",
1642 (long int)ni->stats->gold/price);
1643 }
1644 else if (num <= ni->stats->maxhp - ni->stats->hp)
1645 {
1646 notice(s_GameServ, u, "Healing \ 2%d\ 2 points at \ 2%d\ 2 gold per point.",
1647 num, price);
1648 ni->stats->hp += num;
1649 ni->stats->gold -= num * price;
1650 }
1651 else if (num > ni->stats->maxhp - ni->stats->hp)
1652 {
1653 notice(s_GameServ, u, "Healing all possible points at \ 2%d\ 2 gold "\
1654 "per point.", price);
1655 notice(s_GameServ, u, "\ 2%d\ 2 points healed. HP at MAX!",
1656 (ni->stats->maxhp - ni->stats->hp));
1657 ni->stats->gold -= price * (ni->stats->maxhp - ni->stats->hp);
1658 ni->stats->hp = ni->stats->maxhp;
1659 }
1660 }
1661 else if (amount[0] == '-')
1662 notice(s_GameServ, u, "You trying to cheat?");
1663 else
1664 notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
1665 }
1666
1667 int isstringnum(char *num)
1668 {
1669 int x;
1670 for (x = 0; x < strlen(num); x++)
1671 {
1672 if ((int)num[x] < 48 || (int)num[x] > 57)
1673 return 0;
1674 }
1675 return 1;
1676 }
1677
1678 long int stringtoint(char *number)
1679 {
1680 cout << "stringtoint: " << number << endl;
1681 long int x, len = strlen(number), sum = 0;
1682 if (len == 1)
1683 return chartoint(number[0]);
1684 sum += chartoint(number[len - 1]);
1685 for (x = len - 2; x >= 0; x--)
1686 {
1687 cout << "Adding: " << chartoint(number[x]) * pow(10, abs(x - len + 1)) <<
1688 endl;
1689 sum += chartoint(number[x]) * pow(10, abs(x - len + 1));
1690 }
1691 return sum;
1692 }
1693
1694 long int pow(int x, int y)
1695 {
1696 long int value = 0;
1697 int count = 0;
1698 value += x;
1699
1700 if (x != 0 && y != 0)
1701 {
1702 for (count = 1; count <= y - 1; count++)
1703 value *= x;
1704 }
1705 else
1706 return 1;
1707 return value;
1708 }
1709
1710 long int chartoint(char ch)
1711 {
1712 if (int(ch) >= 48 && int(ch) <= 57)
1713 return int(ch) - 48;
1714 else
1715 return 0;
1716 }
1717
1718 int save_gs_dbase()
1719 {
1720 ListNode<aClient> *ptr = players.First();
1721 Player *it;
1722 ofstream outfile;
1723
1724 outfile.open(playerdata);
1725
1726 if (!outfile)
1727 {
1728 cerr << "Error opening " << playerdata << endl;
1729 return 0;
1730 }
1731
1732 while(ptr)
1733 {
1734 it = ptr->getData()->stats;
1735 outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
1736 << it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
1737 << it->armor << ' ' << it->weapon << ' ' << (it->alive ? "alive" : "dead") << ' '
1738 << it->forest_fights << ' ' << it->player_fights << ' '
1739 << it->password << endl;
1740 ptr = ptr->Next();
1741 }
1742 outfile.close();
1743 }
1744
1745 int load_gs_dbase()
1746 {
1747 ifstream infile;
1748 aClient *temp;
1749 Player *p;
1750 char *alive, *tempname, *buf, *password;
1751 buf = new char[1023];
1752
1753 infile.open(playerdata);
1754
1755 if (infile.fail())
1756 {
1757 cerr << "Error opening " << playerdata << endl;
1758 return 0;
1759 }
1760
1761 while (infile.getline(buf, 1024, '\n'))
1762 {
1763 cout << "temp = new aClient;" << endl << flush;
1764 temp = new aClient;
1765 cout << "tempname = strtok(buf, " ");" << endl << flush;
1766 tempname = strtok(buf, " ");
1767
1768 cout << "temp->stats = new Player(tempname);" << endl << flush;
1769
1770 temp->stats = new Player(tempname);
1771
1772 cout << "p = temp->stats;" << endl << flush;
1773 p = temp->stats;
1774
1775 //Kain 1 1 0 500 10 10 0 0 1 1 alive 100 3
1776 p->level = stringtoint(strtok(NULL, " "));
1777 p->exp = stringtoint(strtok(NULL, " "));
1778 p->gold = stringtoint(strtok(NULL, " "));
1779 p->bank = stringtoint(strtok(NULL, " "));
1780 p->hp = stringtoint(strtok(NULL, " "));
1781 p->maxhp = stringtoint(strtok(NULL, " "));
1782 p->strength = stringtoint(strtok(NULL, " "));
1783 p->defense = stringtoint(strtok(NULL, " "));
1784 p->armor = stringtoint(strtok(NULL, " "));
1785 p->weapon = stringtoint(strtok(NULL, " "));
1786 alive = strtok(NULL, " ");
1787 p->alive = (stricmp(alive, "ALIVE") == 0 ? true : false);
1788 p->forest_fights = stringtoint(strtok(NULL, " "));
1789 p->player_fights = stringtoint(strtok(NULL, " "));
1790 password = strtok(NULL, " ");
1791 strcpy(p->password, password);
1792 temp->setNick("NULL");
1793
1794 printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d %s\n", p->name, p->level,
1795 p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon,
1796 alive, p->forest_fights, p->player_fights, p->password);
1797
1798 cout << "Inserting " << temp->stats->name << " at back of list" << endl;
1799 players.insertAtBack(temp);
1800 cout << temp->stats->name << " Inserted, now deleting" << endl;
1801 delete temp;
1802 cout << "Deleted" << endl;
1803 }
1804 delete [] buf;
1805 }
1806
1807 bool passcmp(char *encrypted, char *plaintext)
1808 {
1809 char salt[3];
1810 char *plaintext2, *plainToencrypt;
1811 bool same = false;
1812
1813 plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
1814 strcpy(plaintext2, plaintext);
1815
1816 salt[0] = encrypted[0];
1817 salt[1] = encrypted[1];
1818 salt[3] = '\0';
1819
1820 plainToencrypt = crypt(plaintext2, salt);
1821
1822 same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
1823
1824 delete []plaintext2;
1825
1826 return same;
1827 }
1828
1829 bool check_password(char *name, char *plaintext)
1830 {
1831 aClient *client;
1832
1833 if (!(client = findplayer(name)))
1834 return false;
1835 else
1836 {
1837 return passcmp(client->stats->password, plaintext);
1838 }
1839 }
1840
1841 void do_store(char *u)
1842 {
1843 char *cmd = strtok(NULL, " ");
1844 char *item = strtok(NULL, " ");
1845 char *num = strtok(NULL, " ");
1846 char *space;
1847 int wep;
1848 aClient *user;
1849 Player *p;
1850
1851 if (!is_playing(u) || !(user = find(u)))
1852 notice(s_GameServ, u, "You must be playing to use the store!");
1853 else if (!cmd || !item)
1854 {
1855 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
1856 notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
1857 notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
1858 }
1859 else if (stricmp(cmd, "LIST") == 0)
1860 {
1861 if (stricmp(item, "WEAPONS") == 0)
1862 {
1863 notice(s_GameServ, u, "Welcome to Kain's Armory");
1864 notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:");
1865 for (int x = 1; x < WNA; x++)
1866 {
1867 space = spaces(strlen(weapons[x]), ".");
1868 notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, weapons[x], space, prices[x - 1]);
1869 free(space);
1870 }
1871 notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2NUM\ 2.");
1872 notice(s_GameServ, u, "Where num. is the weapon number from the menu above.");
1873
1874 }
1875 else if (stricmp(item, "ARMOR") == 0)
1876 {
1877 notice(s_GameServ, u, "Welcome to Kain's Armory");
1878 notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:");
1879 for (int x = 1; x < WNA; x++)
1880 {
1881 space = spaces(strlen(armors[x]), ".");
1882 notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, armors[x], space, prices[x - 1]);
1883 free(space);
1884 }
1885 notice(s_GameServ, u, "To purchase armor, type /msg %S store buy armor num.");
1886 notice(s_GameServ, u, "Where num. is the armor number from the menu above.");
1887
1888
1889 }
1890 } else if (stricmp(cmd, "BUY") == 0) {
1891 if (!num)
1892 {
1893 notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
1894 return;
1895 }
1896 else if (!isstringnum(num))
1897 {
1898 notice(s_GameServ, u, "You must specify a number between 1 and %d. Not %s!", WNA - 1, num);
1899 return;
1900 }
1901 if (stricmp(item, "WEAPON") == 0)
1902 {
1903 wep = stringtoint(num);
1904 if (wep >= WNA || wep < 1)
1905 {
1906 notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
1907 return;
1908 }
1909
1910 p = user->stats;
1911
1912 if (p->weapon != 0)
1913 notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]);
1914 else if (p->gold < prices[wep - 1])
1915 notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]);
1916 else
1917 {
1918 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]);
1919 p->weapon = wep;
1920 p->gold -= prices[wep - 1];
1921 }
1922 }
1923 else if (stricmp(item, "ARMOR") == 0)
1924 {
1925 wep = stringtoint(num);
1926 if (wep >= WNA || wep < 1)
1927 {
1928 notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
1929 return;
1930 }
1931
1932 p = user->stats;
1933
1934 if (p->armor != 0)
1935 notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]);
1936 else if (p->gold < prices[wep - 1])
1937 notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]);
1938 else
1939 {
1940 notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]);
1941 p->armor = wep;
1942 p->gold -= prices[wep - 1];
1943 }
1944 }
1945 }
1946 else if (stricmp(cmd, "SELL" ) == 0)
1947 {
1948 p = user->stats;
1949
1950 if (stricmp(item, "WEAPON") == 0)
1951 {
1952 if (p->weapon == 0)
1953 {
1954 notice(s_GameServ, u, "You want me to chop off your hands?");
1955 return;
1956 }
1957 else if (p->gold == 2000000000)
1958 {
1959 notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
1960 p->weapon = 0;
1961 }
1962 else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2))
1963 {
1964 notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
1965 notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]);
1966 p->gold = 2000000000;
1967 p->weapon = 0;
1968 }
1969 else
1970 {
1971 notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2));
1972 p->gold += (prices[p->weapon - 1] / 2);
1973 p->weapon = 0;
1974 }
1975 }
1976 else if (stricmp(item, "ARMOR") == 0)
1977 {
1978 p = user->stats;
1979
1980 if (p->armor == 0)
1981 {
1982 notice(s_GameServ, u, "I don't think you can be any more naked...");
1983 return;
1984 }
1985 if (p->gold == 2000000000)
1986 {
1987 notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
1988 p->armor = 0;
1989 }
1990 else if (2000000000 - p->gold < (prices[p->armor - 1] / 2))
1991 {
1992 notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
1993 notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]);
1994 p->gold = 2000000000;
1995 p->armor = 0;
1996 }
1997 else
1998 {
1999 notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!",
2000 (prices[p->armor - 1] / 2));
2001
2002 p->gold += (prices[p->armor - 1] / 2);
2003 p->armor = 0;
2004 }
2005 }
2006 else
2007 {
2008 notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
2009 notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
2010 notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
2011 }
2012 }
2013 }
2014
2015 void do_bank(char *u)
2016 {
2017 char *cmd = strtok(NULL, " ");
2018 char *amount = strtok(NULL, " ");
2019 char *nick = strtok(NULL, " ");
2020
2021 aClient *user;
2022 Player *p;
2023
2024 if (!cmd || !amount || (stricmp(cmd, "TRANSFER") == 0 && !nick))
2025 {
2026 notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
2027 return;
2028 }
2029 else if (!is_playing(u) || !(user = find(u)))
2030 {
2031 notice(s_GameServ, u, "You must be playing to use the bank!");
2032 return;
2033 }
2034 else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0)
2035 {
2036 notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!");
2037 return;
2038 }
2039
2040 p = user->stats;
2041
2042 if (stricmp(cmd, "DEPOSIT") == 0)
2043 {
2044 if (p->bank == 2000000000)
2045 {
2046 notice(s_GameServ, u, "Your bank account is full, sire!");
2047 return;
2048 }
2049 else if (stricmp(amount, "ALL") == 0)
2050 {
2051 if (2000000000 - p->bank < p->gold)
2052 {
2053 notice(s_GameServ, u, "You don't have enough room for all of your gold.");
2054 notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->bank));
2055 p->gold -= (2000000000 - p->bank);
2056 p->bank = 2000000000;
2057 }
2058 else
2059 {
2060 notice(s_GameServ, u, "Depositing %ld gold into your account!", p->gold);
2061 p->bank += p->gold;
2062 p->gold = 0;
2063 }
2064 }
2065 else if (stringtoint(amount) > p->gold)
2066 {
2067 notice(s_GameServ, u, "Sire, you only have %ld gold!", p->gold);
2068 return;
2069 }
2070 else
2071 {
2072 if (2000000000 - p->bank < stringtoint(amount))
2073 {
2074 notice(s_GameServ, u, "You don't have room in your account for that much.");
2075 notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->bank));
2076 p->gold -= (2000000000 - p->bank);
2077 p->bank = 2000000000;
2078 }
2079 else
2080 {
2081 notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount));
2082 p->bank += stringtoint(amount);
2083 p->gold -= stringtoint(amount);
2084 }
2085 }
2086 }
2087 else if (stricmp(cmd, "WITHDRAW") == 0)
2088 {
2089 if (p->gold == 2000000000)
2090 {
2091 notice(s_GameServ, u, "You cannot carry any more gold, sire!");
2092 return;
2093 }
2094 else if (stricmp(amount, "ALL") == 0)
2095 {
2096 if (2000000000 - p->gold < p->bank)
2097 {
2098 notice(s_GameServ, u, "You don't have enough room to carry all that gold.");
2099 notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->gold));
2100 p->bank -= (2000000000 - p->gold);
2101 p->gold = 2000000000;
2102 }
2103 else
2104 {
2105 notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->bank);
2106 p->gold += p->bank;
2107 p->bank = 0;
2108 }
2109 }
2110 else if (stringtoint(amount) > p->bank)
2111 {
2112 notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->bank);
2113 return;
2114 }
2115 else
2116 {
2117 if (2000000000 - p->gold < stringtoint(amount))
2118 {
2119 notice(s_GameServ, u, "You don't enough have room to carry that much gold!");
2120 notice(s_GameServ, u, "You fill your pockets with %ld gold!",
2121 (2000000000 - p->gold));
2122 p->bank -= (2000000000 - p->gold);
2123 p->gold = 2000000000;
2124 }
2125 else
2126 {
2127 notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount));
2128 p->gold += stringtoint(amount);
2129 p->bank -= stringtoint(amount);
2130 }
2131 }
2132 }
2133
2134 }