+delete [] buf;
+infile.close();
+return 1;
+}
+
+bool passcmp(char *encrypted, char *plaintext)
+{
+ char salt[3];
+ char *plaintext2, *plainToencrypt;
+ bool same = false;
+
+ plaintext2 = new char[strlen(encrypted) + strlen(plaintext)]; // Extra
+ strcpy(plaintext2, plaintext);
+
+ salt[0] = encrypted[0];
+ salt[1] = encrypted[1];
+ salt[3] = '\0';
+
+ plainToencrypt = crypt(plaintext2, salt);
+
+ same = (strcmp((const char *)encrypted, plainToencrypt) == 0 ? true : false);
+
+ delete []plaintext2;
+
+ return same;
+}
+
+bool check_password(char *name, char *plaintext)
+{
+ aClient *client;
+
+ if (!(client = findplayer(name)))
+ return false;
+ else
+ {
+ return passcmp(client->stats->password, plaintext);
+ }
+}
+
+void do_store(char *u)
+{
+ char *cmd = strtok(NULL, " ");
+ char *item = strtok(NULL, " ");
+ char *num = strtok(NULL, " ");
+ char *space;
+ int wep;
+ aClient *user;
+ Player *p;
+
+ if (!cmd || !item)
+ {
+ notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
+ notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
+ notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
+ return;
+ }
+ else if (!(user = find(u)) || !is_playing(user))
+ {
+ notice(s_GameServ, u, "You must be playing to use the store!");
+ return;
+ }
+ else if (!isAlive(user->stats))
+ {
+ notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!");
+ return;
+ }
+ updateTS(user->stats);
+
+ if (stricmp(cmd, "LIST") == 0)
+ {
+ if (stricmp(item, "WEAPONS") == 0)
+ {
+ notice(s_GameServ, u, "Welcome to Kain's Armory");
+ notice(s_GameServ, u, "Here are the weapons we have available for the killing, sire:");
+ for (int x = 1; x < WNA; x++)
+ {
+ space = spaces(strlen(weapons[x]), ".");
+ notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, weapons[x], space, prices[x - 1]);
+ free(space);
+ }
+ notice(s_GameServ, u, "To purchase a weapon, type /msg %S STORE BUY \ 2NUM\ 2.");
+ notice(s_GameServ, u, "Where num. is the weapon number from the menu above.");
+
+ }
+ else if (stricmp(item, "ARMOR") == 0)
+ {
+ notice(s_GameServ, u, "Welcome to Kain's Armory");
+ notice(s_GameServ, u, "I hope you enjoy the fine armor we have available for your protection:");
+ for (int x = 1; x < WNA; x++)
+ {
+ space = spaces(strlen(armors[x]), ".");
+ notice(s_GameServ, u, "%s%d. %s%s%d",(x < 10 ? " " : ""), x, armors[x], space, prices[x - 1]);
+ free(space);
+ }
+ notice(s_GameServ, u, "To purchase armor, type /msg %S store buy armor num.");
+ notice(s_GameServ, u, "Where num. is the armor number from the menu above.");
+
+
+ }
+ } else if (stricmp(cmd, "BUY") == 0) {
+ if (!num)
+ {
+ notice(s_GameServ, u, "SYNTAX: \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
+ return;
+ }
+ else if (!isstringnum(num))
+ {
+ notice(s_GameServ, u, "You must specify a number between 1 and %d. Not %s!", WNA - 1, num);
+ return;
+ }
+ if (stricmp(item, "WEAPON") == 0)
+ {
+ wep = stringtoint(num);
+ if (wep >= WNA || wep < 1)
+ {
+ notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
+ return;
+ }
+
+ p = user->stats;
+
+ if (p->weapon != 0)
+ notice(s_GameServ, u, "You have to sell your %s first!", weapons[p->weapon]);
+ else if (p->gold < prices[wep - 1])
+ notice(s_GameServ, u, "You don't have enough gold for %s!", weapons[wep]);
+ else
+ {
+ notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", weapons[wep]);
+ p->weapon = wep;
+ p->gold -= prices[wep - 1];
+ }
+ }
+ else if (stricmp(item, "ARMOR") == 0)
+ {
+ wep = stringtoint(num);
+ if (wep >= WNA || wep < 1)
+ {
+ notice(s_GameServ, u, "The number %d is out of range. The number you provide must be between 1 and %d.", wep, WNA - 1);
+ return;
+ }
+
+ p = user->stats;
+
+ if (p->armor != 0)
+ notice(s_GameServ, u, "You have to sell your %s first!", armors[p->armor]);
+ else if (p->gold < prices[wep - 1])
+ notice(s_GameServ, u, "You don't have enough gold for %s!", armors[wep]);
+ else
+ {
+ notice(s_GameServ, u, "You have purchased %s! Thanks for the gold!", armors[wep]);
+ p->armor = wep;
+ p->gold -= prices[wep - 1];
+ }
+ }
+ }
+ else if (stricmp(cmd, "SELL" ) == 0)
+ {
+ p = user->stats;
+
+ if (stricmp(item, "WEAPON") == 0)
+ {
+ if (p->weapon == 0)
+ {
+ notice(s_GameServ, u, "You want me to chop off your hands?");
+ return;
+ }
+ else if (p->gold == 2000000000)
+ {
+ notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
+ p->weapon = 0;
+ }
+ else if (2000000000 - p->gold < (prices[p->weapon - 1] / 2))
+ {
+ notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
+ notice(s_GameServ, u, "However, you have no weapon... can I interest you in the %s?", weapons[WNA - 1]);
+ p->gold = 2000000000;
+ p->weapon = 0;
+ }
+ else
+ {
+ notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no weapon!", (prices[p->weapon - 1] / 2));
+ p->gold += (prices[p->weapon - 1] / 2);
+ p->weapon = 0;
+ }
+ }
+ else if (stricmp(item, "ARMOR") == 0)
+ {
+ p = user->stats;
+
+ if (p->armor == 0)
+ {
+ notice(s_GameServ, u, "I don't think you can be any more naked...");
+ return;
+ }
+ if (p->gold == 2000000000)
+ {
+ notice(s_GameServ, u, "You have enough gold. I'll just take that off your hands, sire.");
+ p->armor = 0;
+ }
+ else if (2000000000 - p->gold < (prices[p->armor - 1] / 2))
+ {
+ notice(s_GameServ, u, "Thank you for your business! You now have as much gold as you can carry.");
+ notice(s_GameServ, u, "However, you have no armor... can I interest you in %s?", armors[WNA - 1]);
+ p->gold = 2000000000;
+ p->armor = 0;
+ }
+ else
+ {
+ notice(s_GameServ, u, "Thank you for your business! You now have %d more gold but no armor!",
+ (prices[p->armor - 1] / 2));
+
+ p->gold += (prices[p->armor - 1] / 2);
+ p->armor = 0;
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
+ notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
+ notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
+ }
+ }
+}
+void do_inventory(char *u)
+{
+ aClient *user;
+
+ if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Fatal Error. Contact a %S admin!");
+ return;
+ }
+ else if (!is_playing(user))
+ {
+ notice(s_GameServ, u, "You must be playing to check your inventory!");
+ return;
+ }
+ updateTS(user->stats);
+ showinventory(user, user);
+}
+void showinventory(aClient *from, aClient *to)
+{
+ char *nick = to->getNick();
+
+ if (!to)
+ to = from;
+ if (is_playing(from))
+ {
+ Pouch *p = &from->stats->inventory;
+ notice(s_GameServ, nick, "Inventory for %s:", from->stats->name);
+ notice(s_GameServ, nick, " Healing Potions: %d", p->Healing());
+ notice(s_GameServ, nick, "Strength Potions: %d", p->Strength());
+ notice(s_GameServ, nick, " Defense Potions: %d", p->Defense());
+ notice(s_GameServ, nick, " HP Potions: %d", p->HP());
+ }
+}
+void do_tavern(char *u)
+{
+ char *cmd = strtok(NULL, " ");
+ long int price;
+
+ aClient *user;
+ Player *p;
+ if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Fatal Error. See a %S admin for help");
+ return;
+ }
+ else if (!is_playing(user))
+ {
+ notice(s_GameServ, u, "You must be playing to go to the Tavern");
+ return;
+ }
+ else if (is_fighting(user))
+ {
+ notice(s_GameServ, u, "You cannot go to the Tavern during a fight!");
+ return;
+ }
+
+ updateTS(user->stats);
+ p = user->stats;
+
+ if (!cmd)
+ {
+ notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary");
+ notice(s_GameServ, u, "Your commands:");
+ notice(s_GameServ, u, "/msg %S TAVERN {LIST | BUY} [NUMBER]");
+ notice(s_GameServ, u, "What'll it be?");
+ }
+ else if (stricmp(cmd, "LIST") == 0)
+ {
+ notice(s_GameServ, u, "Here is a list of what we have to offer:");
+ notice(s_GameServ, u, "1. Healing Potions for %ld Gold", 1000 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "2. Strength Potions for %ld Gold", 2050 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "3. Defense Potions for %ld Gold", 2000 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "4. HP Potions for %ld Gold", 2300 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #");
+ notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!");
+ notice(s_GameServ, u, "By something will ya!");
+ }
+ else if (stricmp(cmd, "BUY") == 0)
+ {
+ char *chnum = strtok(NULL, " ");
+ int num = stringtoint(chnum);
+
+ if (!chnum)
+ {
+ notice(s_GameServ, u, "SYNTAX: TAVERN BUY #");
+ notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1");
+ return;
+ }
+ if (num < 1 || num > 4)
+ {
+ notice(s_GameServ, u, "Invalid Choice!");
+ notice(s_GameServ, u, "Here is a list of what we have to offer:");
+ notice(s_GameServ, u, "1. Healing Potions for %ld Gold", 1000 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "2. Strength Potions for %ld Gold", 2050 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "3. Defense Potions for %ld Gold", 2000 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "4. HP Potions for %ld Gold", 2300 * p->level + (p->exp / 10));
+ notice(s_GameServ, u, "To buy a potion, type /msg %S TAVERN BUY #");
+ notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1 buys a healing potion!");
+ return;
+ }
+ switch(num)
+ {
+ case 1:
+ price = (1000 * p->level) + (p->exp / 10);
+ if (p->gold >= price)
+ {
+ notice(s_GameServ, u, "One healing potion coming right up!");
+ p->inventory.incHealing();
+ p->gold -= price;
+ }
+ else
+ notice(s_GameServ, u, "You don't have enough gold!");
+ break;
+ case 2:
+ price = (2050 * p->level) + (p->exp / 10);
+ if (p->gold >= price)
+ {
+ notice(s_GameServ, u, "One strength boost coming right up!");
+ p->inventory.incStrength();
+ p->gold -= price;
+ }
+ else
+ notice(s_GameServ, u, "You don't have enough gold!");
+ break;
+ case 3:
+ price = (2000 * p->level) + (p->exp / 10);
+ if (p->gold >= price)
+ {
+ notice(s_GameServ, u, "One defense boost coming right up!");
+ p->inventory.incDefense();
+ p->gold -= price;
+ }
+ else
+ notice(s_GameServ, u, "You don't have enough gold!");
+ break;
+ case 4:
+ price = (2300 * p->level) + (p->exp / 10);
+ if (p->gold >= price)
+ {
+ notice(s_GameServ, u, "One HP Potion coming right up!");
+ p->inventory.incHP();
+ p->gold -= price;
+ }
+ else
+ notice(s_GameServ, u, "You don't have enough gold!");
+ break;
+ default:
+ notice(s_GameServ, u, "Logical Error. See a %S admin for help!");
+ break;
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "Improper Syntax.");
+ notice(s_GameServ, u, "Type /msg %S HELP TAVERN for help");
+ }
+}
+
+void do_bank(char *u)
+{
+ char *cmd = strtok(NULL, " ");
+ char *amount = strtok(NULL, " ");
+ char *nick = strtok(NULL, " ");
+
+ aClient *user;
+ Player *p;
+
+ if (!cmd || (!amount && stricmp(cmd, "BALANCE") != 0) || (stricmp(cmd, "TRANSFER") == 0 && !nick))
+ {
+ notice(s_GameServ, u, "BANK {WITHDRAW | DEPOSIT} {ALL | AMOUNT}");
+ notice (s_GameServ, u, "BANK BALANCE");
+ return;
+ }
+ else if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) %S "\
+ " admin for help");
+ log("Fatal Error. Couldn't find %s while executing do_bank()", u);
+ return;
+ }
+ else if (!is_playing(user))
+ {
+ notice(s_GameServ, u, "You must be playing to use the bank!");
+ return;
+ }
+
+ updateTS(user->stats);
+ if (stricmp(cmd, "BALANCE") == 0)
+ {
+ showBankBalance(u);
+ return;
+ }
+ else if (!isAlive(user->stats))
+ {
+ notice(s_GameServ, u, "You are dead. We don't accept gold from dead folk! Wait 'til tomorrow!");
+ return;
+ }
+ else if (!isstringnum(amount) && stricmp(amount, "ALL") != 0)
+ {
+ notice(s_GameServ, u, "I don't know how to convert alphabet letters into currency, sire!");
+ return;
+ }
+
+ p = user->stats;
+
+ if (stricmp(cmd, "DEPOSIT") == 0)
+ {
+ if (p->bank == 2000000000)
+ {
+ notice(s_GameServ, u, "Your bank account is full, sire!");
+ return;
+ }
+ else if (stricmp(amount, "ALL") == 0)
+ {
+ if (2000000000 - p->bank < p->gold)
+ {
+ notice(s_GameServ, u, "You don't have enough room for all of your gold.");
+ notice(s_GameServ, u, "Depositing %ld gold into your account", (2000000000 - p->bank));
+ p->gold -= (2000000000 - p->bank);
+ p->bank = 2000000000;
+ showBankBalance(u);
+ }
+ else
+ {
+ notice(s_GameServ, u, "Depositing %ld gold into your account!", p->gold);
+ p->bank += p->gold;
+ p->gold = 0;
+ showBankBalance(u);
+ }
+ }
+ else if (stringtoint(amount) > p->gold)
+ {
+ notice(s_GameServ, u, "Sire, you only have %ld gold!", p->gold);
+ showBankBalance(u);
+ return;
+ }
+ else
+ {
+ if (2000000000 - p->bank < stringtoint(amount))
+ {
+ notice(s_GameServ, u, "You don't have room in your account for that much.");
+ notice(s_GameServ, u, "Capping off your account with %ld gold!", (2000000000 - p->bank));
+ p->gold -= (2000000000 - p->bank);
+ p->bank = 2000000000;
+ showBankBalance(u);
+ }
+ else
+ {
+ notice(s_GameServ, u, "Depositing %d gold into your account!", stringtoint(amount));
+ p->bank += stringtoint(amount);
+ p->gold -= stringtoint(amount);
+ showBankBalance(u);
+ }
+ }
+ }
+ else if (stricmp(cmd, "WITHDRAW") == 0)
+ {
+ if (p->gold == 2000000000)
+ {
+ notice(s_GameServ, u, "You cannot carry any more gold, sire!");
+ showBankBalance(u);
+ return;
+ }
+ else if (stricmp(amount, "ALL") == 0)
+ {
+ if (2000000000 - p->gold < p->bank)
+ {
+ notice(s_GameServ, u, "You don't have enough room to carry all that gold.");
+ notice(s_GameServ, u, "Withdrawing %ld gold from your account", (2000000000 - p->gold));
+ p->bank -= (2000000000 - p->gold);
+ p->gold = 2000000000;
+ showBankBalance(u);
+ }
+ else
+ {
+ notice(s_GameServ, u, "Withdrawing %ld gold from your account!", p->bank);
+ p->gold += p->bank;
+ p->bank = 0;
+ showBankBalance(u);
+ }
+ }
+ else if (stringtoint(amount) > p->bank)
+ {
+ notice(s_GameServ, u, "Sire, you only have %ld gold in the bank!", p->bank);
+ showBankBalance(u);
+ return;
+ }
+ else
+ {
+ if (2000000000 - p->gold < stringtoint(amount))
+ {
+ notice(s_GameServ, u, "You don't enough have room to carry that much gold!");
+ notice(s_GameServ, u, "You fill your pockets with %ld gold!",
+ (2000000000 - p->gold));
+ p->bank -= (2000000000 - p->gold);
+ p->gold = 2000000000;
+ showBankBalance(u);
+ }
+ else
+ {
+ notice(s_GameServ, u, "Withdrawing %d gold from your account!", stringtoint(amount));
+ p->gold += stringtoint(amount);
+ p->bank -= stringtoint(amount);
+ showBankBalance(u);
+ }
+ }
+ }
+
+}
+
+void do_master(char *u)
+{
+ aClient *user;
+ user = find(u);
+
+ if (!user)
+ {
+ notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
+ return;
+ }
+ else if (is_fighting(user))
+ {
+ notice(s_GameServ, u, "You're in the middle of a fight! Pay attention!");
+ return;
+ }
+ else if (!isAlive(user->stats))
+ {
+ notice(s_GameServ, u, "You're dead. Wait until tomorrow to see your master!");
+ return;
+ }
+ else if (!is_playing(user))
+ {
+ notice(s_GameServ, u, "You must be playing to see your master!");
+ return;
+ }
+
+ updateTS(user->stats);
+ char *cmd = strtok(NULL, " ");
+ Player *p = user->stats;
+ long int need = 0;
+
+ if (seenMaster(p))
+ {
+ notice(s_GameServ, u, "You have already seen your master today. Wait until tomorrow to try again");
+ return;
+ }
+
+ if (cmd != NULL)
+ {
+ switch(p->level)
+ {
+ case 1:
+ need = 100;
+ break;
+ case 2:
+ need = 400;
+ break;
+ case 3:
+ need = 1000;
+ break;
+ case 4:
+ need = 4000;
+ break;
+ case 5:
+ need = 10000;
+ break;
+ case 6:
+ need = 40000;
+ break;
+ case 7:
+ need = 100000;
+ break;
+ case 8:
+ need = 400000;
+ break;
+ case 9:
+ need = 1000000;
+ break;
+ case 10:
+ need = 4000000;
+ break;
+ case 11:
+ need = 10000000;
+ break;
+ case 12:
+ need = p->exp + 1;
+ notice(s_GameServ, u, "You are at level 12. You are the master. What's left? The DRAGON!");
+ break;
+ default:
+ need = p->exp + 1; // Unknown level... don't let them fight a fake master!
+ break;
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
+ return;
+ }
+
+ if (stricmp(cmd, "FIGHT") == 0)
+ {
+ if (p->exp >= need)
+ {
+ setMaster(p);
+ see_master(u);
+ }
+ else
+ notice(s_GameServ, u, "You are not worthy of fighting %s! You need %ld more experience.", masters[p->level - 1]->name, (need - p->exp));
+ return;
+ }
+ else if (stricmp(cmd, "QUESTION") == 0)
+ {
+ if (p->exp >= need)
+ 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);
+ else
+ notice(s_GameServ, u, "You pathetic fool! You are no match for %s, %s!", masters[p->level - 1]->name, p->name);
+
+ return;
+ }
+ else
+ {
+ notice(s_GameServ, u, "SYNTAX: MASTER {FIGHT | QUESTION}");
+ }
+}
+
+void see_master(char *u)
+{
+ aClient *user;
+
+ if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
+ return;
+ }
+
+ if (!is_fighting(user) && is_playing(user))
+ {
+ Player *p = user->stats;
+ p->master = new Monster(masters[p->level - 1]);
+ p->fight = p->master;
+ display_monster(u); // Since master is the same structure, use this function
+ }
+}
+
+void showBankBalance(const char *u)
+{
+ aClient *user;
+ Player *p;
+
+ if (!(user = find(u)))
+ return;
+
+ p = user->stats;
+
+ if (!p)
+ return;
+
+ notice(s_GameServ, u, "Account Balance: %ld Gold On hand: %ld", p->bank, p->gold);
+
+}
+
+void refreshall()
+{
+ ListNode <aClient> *it;
+ Player *p;
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ it = players[x].First();
+
+ while (it)
+ {
+ p = it->getData()->stats;
+ refresh(p);
+ it = it->Next();
+ }
+ }
+}
+
+void refresh(Player *p)
+{
+ if (!p)
+ return;
+
+ if (p->hp < p->maxhp)
+ p->hp = p->maxhp;
+ p->forest_fights = forestfights;
+ p->player_fights = 3;
+ setAlive(p);
+ clearMaster(p);
+}
+
+void do_refresh(char *u)
+{
+ char *nick = strtok(NULL, " ");
+ aClient *user;
+
+ if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
+ log("Error: aClient not found: %s", u);
+ return;
+ }
+ else if (!isAdmin(user))
+ {
+ notice(s_GameServ, u, "You must be a %S admin to use this command!");
+ return;
+ }
+ if (!nick)
+ {
+ notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}");
+ return;
+ }
+ else if (stricmp(nick, "ALL") == 0)
+ {
+ notice(s_GameServ, u, "Refreshing everyone's stats!");
+ refreshall();
+ }
+ else if ((user = findbyrealnick(nick)))
+ {
+ if (is_playing(user))
+ {
+ #ifdef P10
+ notice(s_GameServ, u, "Refreshing %s.", user->getRealNick());
+ #else
+ notice(s_GameServ, u, "Refreshing %s.", user->getNick());
+ #endif
+ refresh(user->stats);
+ }
+ else
+ {
+ #ifdef P10
+ notice(s_GameServ, u, "%s is not playing.", user->getRealNick());
+ #else
+ notice(s_GameServ, u, "%s is not playing.", user->getNick());
+ #endif
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "Nick %s not found.", nick);
+ return;
+ }
+}
+
+
+void resetall()
+{
+ ListNode <aClient> *it;
+ Player *p;
+
+ for (unsigned long x = 0; x < U_TABLE_SIZE; x++)
+ {
+ it = players[x].First();
+
+ while (it)
+ {
+ p = it->getData()->stats;
+ reset(p);
+ it = it->Next();
+ }
+ }
+}
+
+void reset(Player *p)
+{
+ if (!p)
+ return;
+
+ p->reset();
+}
+
+void updateTS(Player *p)
+{
+ if (!p)
+ return;
+ p->lastcommand = time(NULL);
+}
+
+bool timedOut(Player *p)
+{
+ if (!p)
+ return false;
+ else
+ return ((time(NULL) - p->lastcommand) >= maxidletime);
+}
+
+void timeOutEvent(Player *p)
+{
+ aClient *user = p->client;
+
+ if (!user) // then they're not playing
+ return;
+
+ char *nick = user->getNick();
+
+ notice(s_GameServ, nick, "You just idle timed out");
+ logout(user);
+}
+
+void do_reset(char *u)
+{
+ char *nick = strtok(NULL, " ");
+ aClient *user;
+
+ if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
+ log("Error: aClient not found: %s", u);
+ return;
+ }
+ else if (!isAdmin(user))
+ {
+ notice(s_GameServ, u, "You must be a %S admin to use this command!");
+ return;
+ }
+ if (!nick)
+ {
+ notice(s_GameServ, u, "SYNTAX: RESET {ALL | NICK}");
+ return;
+ }
+ else if (stricmp(nick, "ALL") == 0)
+ {
+ notice(s_GameServ, u, "Resetting everyone's stats!");
+ resetall();
+ }
+ else if ((user = findbyrealnick(nick)))
+ {
+ if (is_playing(user))
+ {
+ #ifdef P10
+ notice(s_GameServ, u, "Resetting %s.", user->getRealNick());
+ #else
+ notice(s_GameServ, u, "Resetting %s.", user->getNick());
+ #endif
+ reset(user->stats);
+ }
+ else
+ {
+ #ifdef P10
+ notice(s_GameServ, u, "%s is not playing.", user->getRealNick());
+ #else
+ notice(s_GameServ, u, "%s is not playing.", user->getNick());
+ #endif
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "Nick %s not found.", nick);
+ return;
+ }
+}
+
+void do_help(char *u)
+{
+ char *cmd = strtok(NULL, " ");
+
+ display_help(u, cmd);
+}
+
+void display_help(char *u, char *file)
+{
+ ifstream infile;
+ char *buf;
+
+ if (!file)
+ {
+ infile.open("helpfiles/help");
+ if (infile.fail())
+ {
+ log("Error opening helpfiles/help");
+ notice(s_GameServ, u, "Error opening helpfiles/help");
+ return;
+ }
+ buf = new char[1024];
+ while(infile.getline(buf, 1024))
+ {
+ // Written this way, it will process %S in the helpfiles
+ // Instead of notice(s_GameServ, u, "%s", buf);
+ notice(s_GameServ, u, buf);
+ }
+
+ // Minor recursion
+ aClient *user = find(u);
+ if (user && isAdmin(user))
+ display_help(u, "admin_commands");
+ }
+ else
+ {
+ char *filename;
+ filename = new char[strlen(file) + 11];
+ strcpy(filename, "helpfiles/");
+ strcat(filename, file);
+
+ for (unsigned int x = 10; x < strlen(filename); x++)
+ filename[x] = tolower(filename[x]);
+
+ infile.open(filename);
+ delete [] filename;
+ if (infile.fail())
+ {
+ notice(s_GameServ, u, "No help for \ 2%s\ 2", file);
+ return;
+ }
+ buf = new char[1024];
+ while(infile.getline(buf, 1024))
+ {
+ // Written this way, it will process %S in the helpfiles
+ // Instead of notice(s_GameServ, u, "%s", buf);
+ notice(s_GameServ, u, buf);
+ }
+ }
+ infile.close();
+ delete [] buf;
+}
+
+void do_admin(char *u)
+{
+ aClient *user;
+ char *pass = strtok(NULL, " ");
+
+ if (!(user = find(u)))
+ {
+ log("Error: aClient not found: %s", u);
+ notice(s_GameServ, u, "Error: aClient not found. Contact %S admin.");
+ return;
+ }
+ if (!pass)
+ {
+ notice(s_GameServ, u, "SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2");
+ return;
+ }
+
+ if (isAdmin(user))
+ {
+ notice(s_GameServ, u, "You already have administrator privledges.");
+ return;
+ }
+ else if (strcmp(pass, adminpass) == 0)
+ {
+ notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
+ setAdmin(user);
+ #ifdef P10
+ log("%s became an administrator.", user->getRealNick());
+ #else
+ log("%s became an administrator.", user->getNick());
+ #endif
+ }
+ else
+ {
+ notice(s_GameServ, u, "Invalid password. Remember: case sensitive");
+ return;
+ }
+}
+
+bool load_monsters()
+{
+ ifstream infile;
+ infile.open("monsters.dat");
+
+ char *buf;
+
+ if (infile.fail())
+ {
+ log("Error opening monsters.dat");
+ return false;
+ }
+ init_monsters();
+ buf = new char[2048];
+
+ #ifdef DEBUGMODE
+ log("Loading monsters from monsters.dat");
+ #endif
+
+ for (int l = 0; l < REALLEVELS; l++)
+ {
+ for (int m = 0; m < MONSTERS;)
+ {
+ infile.getline(buf, 2048);
+ if (buf[0] == '\n' || buf[0] == '\0' || buf[0] == '#')
+ continue;
+ else
+ {
+ strcpy(monsters[l][m]->name, strtok(buf, "~"));
+ strcpy(monsters[l][m]->weapon, strtok(NULL, "~"));
+ monsters[l][m]->strength = stringtoint(strtok(NULL, "~"));
+ monsters[l][m]->gold = stringtoint(strtok(NULL, "~"));
+ monsters[l][m]->exp = stringtoint(strtok(NULL, "~"));
+ monsters[l][m]->maxhp = stringtoint(strtok(NULL, "~"));
+ monsters[l][m]->hp = monsters[l][m]->maxhp;
+ strcpy(monsters[l][m]->death, strtok(NULL, ""));
+ m++;
+ }
+ }
+ }
+ delete [] buf;
+return true;
+}
+
+// this will be hash.cpp start
+// thank you wcampbel
+unsigned long HASH(const unsigned char *name, int size_of_table)
+{
+ unsigned long h = 0, g;
+
+ while (*name)
+ {
+ #ifdef P10
+ h = (h << 4) + (*name++); // Case sensitive for numerics
+ #else
+ h = (h << 4) + tolower(*name++);
+ #endif
+ if ((g = (h & 0xF0000000)))
+ h ^= g >> 24;
+ h &= ~g;
+ }
+ return h % size_of_table;