#include "sockhelp.h"
#include <cctype>
-#include <fstream.h>
+#include <fstream>
+
+using std::ifstream;
+using std::ofstream;
#if defined(HAVE_CRYPT_H)
#endif
List<aClient> players;
+
Monster *monsters[LEVELS][MONSTERS]; // Monsters per level. Total = MONSTERS * LEVELS
Monster *masters[LEVELS]; // A master for each level
void see_master(char *u);
void showstats(const char *u, const char *nick);
-void showinventory(aClient *from, aClient *to = NULL);
+void showinventory(aClient *from, aClient *to);
void showBankBalance(const char *u);
void end_turn(aClient *user);
char *armors[WNA] = { "Nothing", "Clothes", "Leather Vest", "Chain Mail", "Plate Armor",
"Full Body Armor", "Magic Mail", "Graphite Suit", "Steel Suit",
"Force Field", "Armor of Light", "Mythril Vest", "DemiGod Armor",
- "Hades' Cloak", "Dragon Scales", "Mystical Armor"};
+ "Hades' Cloak", "Dragon Scales", "Adamantium"};
int prices[WNA - 1] = {200, 1000, 3000, 10000, 30000, 100000, 150000, 200000, 400000,
1000000, 4000000, 10000000, 40000000, 100000000, 400000000};
char *cmd;
cmd = strtok(buf, " ");
- source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
- cmd++; // Get rid of that : at the beginning of the :text (command)
+ #ifndef P10
+ source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
+ #endif
+
+ if (cmd[0] == ':')
+ cmd++; // Get rid of that : at the beginning of the :text (command)
+
+ #ifdef DEBUGMODE
+ log("Source: %s Command: %s", source, cmd);
+ #endif
- cout << "Source: " << source << "\ncmd: " << cmd << endl;
long int mn = midnight() - 12 * 3600; // 12 noon ;)
if (mn > timestamp)
do_reset(source);
} else if (stricmp(cmd, "TAVERN") == 0) {
do_tavern(source);
+ } else if (stricmp(cmd, "LIST") == 0) {
+ do_list(source);
+ #ifdef DEBUGMODE
} else if (stricmp(cmd, "PRINT") == 0) {
- cout << "Printing Clients List: " << endl;
+ cout << "Printing the clients list:" << endl;
clients.print();
- cout << "\nPrinting Player List: " << endl;
+ cout << "\nPrinting the players list:" << endl;
players.print();
- cout << "\nPrinting Level 1 of monsters:" << endl;
- for (int xx = 0; xx < 12; xx++)
- {
- cout << monsters[0][xx]->name << ' ' <<
-monsters[0][xx]->weapon << ' ' << monsters[0][xx]->hp << '/' <<
-monsters[0][xx]->maxhp << ' ' <<
-monsters[0][xx]->strength << ' ' << monsters[0][xx]->exp << ' ' <<
-monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
- }
- } else if (stricmp(cmd, "LIST") == 0) {
- do_list(source);
+ #endif
} else if (stricmp(cmd, "REGISTER") == 0) {
do_register(source);
} else if (stricmp(cmd, "IDENTIFY") == 0) {
if (!(user = find(source)))
{
notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << source << endl;
+ log("Error: aClient not found: %s", source);
}
else if (!isAdmin(user))
{
else
{
save_gs_dbase();
- raw("SQUIT %s :leaving", servername);
+ #ifdef P10
+ raw("SQ %s 0 :leaving", servername);
+ #else
+ raw("SQUIT %s :leaving", servername);
+ #endif
}
} else if (stricmp(cmd, "SAVE") == 0) {
aClient *user;
if (!(user = find(source)))
{
notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << source << endl;
+ log("Error: aClient not found: %s", source);
}
else if (!isAdmin(user))
{
if (!(user = find(source)))
{
notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << source << endl;
+ log("Error: aClient not found: %s", source);
}
else if (!isAdmin(user))
{
if (!(user = find(source)))
{
notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << source << endl;
+ log("Error: aClient not found: %s", source);
}
else if (!isAdmin(user))
{
}
}
+ #ifdef DEBUGMODE
+ log("Input: %s", input);
+ #endif
+
sprintf(input, "%s%s", input, "\r\n");
- cout << "input: " << input << flush;
sock_puts(sock, input);
delete [] input;
va_end(args);
if (dest[0] == ':')
{
dest++;
+
+ #if !defined(P10)
sprintf(input, ":%s NOTICE %s :", source, dest);
+ #else
+ sprintf(input, "%s O %s :", gsnum, dest);
+ #endif
+
dest--;
}
else
+ {
+ #if !defined(P10)
sprintf(input, ":%s NOTICE %s :", source, dest);
+ #else
+ sprintf(input, "%s O %s :", gsnum, dest);
+ #endif
+ }
for (; *t; t++)
{
}
}
+ #ifdef DEBUGMODE
+ log("Input: %s", input);
+ #endif
sprintf(input, "%s%s", input, "\r\n");
- cout << "input: " << input << flush;
sock_puts(sock, input);
delete [] input;
va_end(args);
void do_register(char *u)
{
- char *password;
+ char *password, *name;
aClient *user, *p;
+ name = strtok(NULL, " ");
password = strtok(NULL, " ");
static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
salt[1] = saltChars[rand() % strlen(saltChars)];
salt[2] = '\0';
- if (!password)
+ if (!name)
{
- notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
+ notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
+ }
+ else if (!password)
+ {
+ notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
}
else if ((user = find(u)))
{
user->stats = new Player(user);
user->stats->user = user; // Set the backwards pointer
strcpy(user->stats->password, crypt(password, salt));
+ strcpy(user->stats->name, name);
players.insertAtBack(user);
notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password);
notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
+ log("Nickname %s registered player %s.", u, user->stats->name);
}
else
{
notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD");
}
else if (!user)
- notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
+ {
+ notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
+ log("Error: aClient not found: %s", u);
+ }
else if (!(p = findplayer(name)) || !p->stats)
notice(s_GameServ, u, "Player %s not found", name);
else if (!check_password(name, password) && !isAdmin(user))
return;
}
user->stats = new Player(p->stats->name);
- cout << "Setting data for identified" << endl;
+ #ifdef DEBUGMODE
+ log("Setting data for identified");
+ #endif
user->stats->setData(p->stats);
- cout << "Player Identified" << endl << flush;
+
+ #ifdef DEBUGMODE
+ log("Player Identified");
+ #endif
temp->setPtr(user);
if (!(user = find(u)))
{
notice(s_GameServ, u, "Fatal Error in do_stats(). Contact a %S admin for help!");
+ log("Error: aClient not found: %s", u);
return;
}
else if (!is_playing(user))
}
void init_masters()
{
+ #ifdef DEBUGMODE
+ log("Calling delete_masters()");
+ #endif
+
delete_masters();
+ #ifdef DEBUGMODE
+ log("Initializing masters");
+ #endif
+
for (int x = 0; x < LEVELS; x++)
masters[x] = new Monster;
strcpy(masters[3]->name, "Mr. Miagi");
strcpy(masters[3]->weapon, "Petrified Bonsai");
- masters[3]->strength = 100;
+ masters[3]->strength = 120;
masters[3]->gold = 0;
masters[3]->exp = 0;
masters[3]->maxhp = 120;
strcpy(masters[4]->name, "Jackie Chan");
strcpy(masters[4]->weapon, "Kung Fu Kick");
- masters[4]->strength = 125;
+ masters[4]->strength = 135;
masters[4]->gold = 0;
masters[4]->exp = 0;
masters[4]->maxhp = 200;
strcpy(masters[5]->name, "Jet Li");
strcpy(masters[5]->weapon, "Motorcycle");
- masters[5]->strength = 150;
+ masters[5]->strength = 160;
masters[5]->gold = 0;
masters[5]->exp = 0;
masters[5]->maxhp = 400;
strcpy(masters[6]->name, "Muhammad Ali");
strcpy(masters[6]->weapon, "Quick Jab");
- masters[6]->strength = 175;
+ masters[6]->strength = 185;
masters[6]->gold = 0;
masters[6]->exp = 0;
masters[6]->maxhp = 600;
strcpy(masters[7]->name, "Li Mu Bai");
strcpy(masters[7]->weapon, "Green Destiny");
- masters[7]->strength = 200;
+ masters[7]->strength = 210;
masters[7]->gold = 0;
masters[7]->exp = 0;
masters[7]->maxhp = 800;
strcpy(masters[9]->name, "Wong Fei Hung");
strcpy(masters[9]->weapon, "Drunken Boxing");
- masters[9]->strength = 350;
+ masters[9]->strength = 360;
masters[9]->gold = 0;
masters[9]->exp = 0;
masters[9]->maxhp = 1800;
void init_monsters()
{
+ #ifdef DEBUGMODE
+ log("Calling delete_monsters");
+ #endif
+
delete_monsters();
+
for (int x = 0; x < LEVELS; x++)
for (int y = 0; y < MONSTERS; y++)
monsters[x][y] = new Monster();
int oldstrength = user->stats->strength;
notice(s_GameServ, u, "As you grip the flask containing pure power, you feel adrenaline coarse through your veins!");
notice(s_GameServ, u, "In one swallow you drink the potion and feel your muscle fibers bulging andgrowing!");
- user->stats->strength += rand() % 3;
+ user->stats->strength += 1 + rand() % 2; // 1 - 2 Strength Added
notice(s_GameServ, u, "You gain %d Strength points!", user->stats->strength - oldstrength);
p->decStrength();
}
notice(s_GameServ, u, "You are out of Defense Potions!");
return;
}
- int olddefense = user->stats->strength;
+ int olddefense = user->stats->defense;
notice(s_GameServ, u, "You drink the foul tasting viscous liquid while pinching your nose in disgust.");
notice(s_GameServ, u, "It tasted bad, but you feel like you are unbeatable!");
- user->stats->defense += rand() % 3;
+ user->stats->defense += 1 + rand() % 2; // 1 - 2 Defense Added
notice(s_GameServ, u, "You gain %d Defense points!", user->stats->defense - olddefense);
p->decDefense();
}
+ else if (stricmp(item, "HP") == 0)
+ {
+ if (p->HP() <= 0)
+ {
+ notice(s_GameServ, u, "You are out of HP Potions!");
+ return;
+ }
+ int oldHP = user->stats->maxhp;
+ notice(s_GameServ, u, "You feel your life growing longer as you drink the green glowing liquid.");
+ user->stats->maxhp += 1 + rand() % 5; // 1 - 5 Maxhp
+ notice(s_GameServ, u, "You gain %d Maximum hit points!", user->stats->maxhp - oldHP);
+ p->decHP();
+ }
else
{
notice(s_GameServ, u, "SYNTAX: /msg %S USE {HEALTH | STRENGTH | DEFENSE}");
if (!outfile)
{
- cout << "Error opening " << playerdata << endl;
+ log("Error opening %s", playerdata);
return 0;
}
<< it->armor << ' ' << it->weapon << ' '
<< it->forest_fights << ' ' << it->player_fights << ' '
<< it->getFlags() << ' ' << it->password << ' ' << it->inventory.Healing()
- << ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << endl;
+ << ' ' << it->inventory.Strength() << ' ' << it->inventory.Defense() << ' ' << it->inventory.HP() << endl;
ptr = ptr->Next();
}
outfile.close();
if (infile.fail())
{
- cout << "Error opening " << playerdata << endl;
+ log("Error opening %s", playerdata);
return 0;
}
strcpy(p->password, password);
temp->setNick("!NULL!");
+ p->inventory.reset(); // Set inventory to all 0s
// Old player databases didn't have these three extra values
// If they come up null, leave them to 0 as the default.
// On the next gameserv database save, it will save the values.
tempname = strtok(NULL, " ");
- cout << tempname << endl;
- p->inventory.setHealing(stringtoint(tempname));
- p->inventory.setStrength(stringtoint(strtok(NULL, " ")));
- p->inventory.setDefense(stringtoint(strtok(NULL, " ")));
+ if (tempname)
+ p->inventory.setHealing(stringtoint(tempname));
+
+ tempname = strtok(NULL, " ");
+ if (tempname)
+ p->inventory.setStrength(stringtoint(tempname));
+
+ tempname = strtok(NULL, " ");
+ if (tempname)
+ p->inventory.setDefense(stringtoint(tempname));
+
+ tempname = strtok(NULL, " ");
+ if (tempname)
+ p->inventory.setHP(stringtoint(tempname));
players.insertAtBack(temp);
delete temp;
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)
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!");
notice(s_GameServ, u, "Example: /msg %S TAVERN BUY 1");
return;
}
- if (num < 1 || num > 3)
+ 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;
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;
aClient *user;
Player *p;
- if (!cmd || !amount || (stricmp(cmd, "TRANSFER") == 0 && !nick))
+ 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");
if (!(user = find(u)))
{
notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << u << endl;
+ log("Error: aClient not found: %s", u);
return;
}
else if (!isAdmin(user))
if (!(user = find(u)))
{
notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
- cout << "Error: aClient not found: " << u << endl;
+ log("Error: aClient not found: %s", u);
return;
}
else if (!isAdmin(user))
infile.open("helpfiles/help");
if (infile.fail())
{
- cout << "Error opening helpfiles/help" << endl;
+ log("Error opening helpfiles/help");
notice(s_GameServ, u, "Error opening helpfiles/help");
return;
}
if (!(user = find(u)))
{
- cout << "Error: aClient not found: " << u << endl;
+ log("Error: aClient not found: %s", u);
notice(s_GameServ, u, "Error: aClient not found. Contact %S admin.");
return;
}
{
notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
setAdmin(user);
+ log("%s became an administrator.", user->getNick());
}
else
{
if (infile.fail())
{
- cout << "Error opening monsters.dat" << endl;
+ 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;)