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