+
+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 (!is_alive(user))
+ {
+ 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;
+ }
+
+ 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;
+
+ it = players.First();
+
+ while (it)
+ {
+ p = it->getData()->stats;
+ refresh(p);
+ it = it->Next();
+ }
+}
+
+void refresh(Player *p)
+{
+ if (!p)
+ return;
+
+ p->hp = p->maxhp;
+ p->forest_fights = 100;
+ p->player_fights = 3;
+ p->alive = true;
+ 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");
+ cout << "Error: aClient not found: " << u << endl;
+ 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 = find(nick)))
+ {
+ if (is_playing(user))
+ {
+ notice(s_GameServ, u, "Refreshing %s.", user->getNick());
+ refresh(user->stats);
+ }
+ else
+ {
+ notice(s_GameServ, u, "%s is not playing.", user->getNick());
+ }
+ }
+ else
+ {
+ notice(s_GameServ, u, "Nick %s not found.", nick);
+ return;
+ }
+}
+
+void do_help(char *u)
+{
+ char *cmd = strtok(NULL, " ");
+
+ if (cmd)
+ for (unsigned int x = 0; x < strlen(cmd); x++)
+ cmd[x] = tolower(cmd[x]);
+ display_help(u, cmd);
+}
+
+void display_help(char *u, char *file)
+{
+ ifstream infile;
+ char *buf;
+
+ if (!file)
+ {
+ infile.open("helpfiles/help");
+ if (infile.fail())
+ {
+ cout << "Error opening helpfiles/help" << endl;
+ 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) + 12];
+ sprintf(filename, "helpfiles/%s", file);
+ 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)))
+ {
+ cout << "Error: aClient not found: " << u << endl;
+ 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);
+ }
+ else
+ {
+ notice(s_GameServ, u, "Invalid password. Remember: case sensitive");
+ return;
+ }
+}
+