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