]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
P10 is now functional. The game is playable, but it does not display text nicknames...
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 1c6a600c3efbfca31bb6c4ceb6f56aa631f1d5c0..b711e28696e3b0feccbb5d95c65749a9a0cf1234 100644 (file)
@@ -6,7 +6,10 @@
 #include "sockhelp.h"
 
 #include <cctype>
-#include <fstream.h>
+#include <fstream>
+
+using std::ifstream;
+using std::ofstream;
 
 #if defined(HAVE_CRYPT_H)
 
@@ -19,6 +22,7 @@
 #endif
 
 List<aClient> players;
+
 Monster *monsters[LEVELS][MONSTERS];   // Monsters per level. Total = MONSTERS * LEVELS
 
 Monster *masters[LEVELS];              // A master for each level
@@ -104,7 +108,7 @@ void do_use(char *u);
 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);
 
@@ -117,7 +121,7 @@ char *weapons[WNA] = {  "Fists", "Stick", "Dagger", "Quarterstaff",  "Short Swor
 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};
@@ -133,10 +137,17 @@ void gameserv(char *source, char *buf)
     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)
@@ -187,22 +198,15 @@ void gameserv(char *source, char *buf)
        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) {
@@ -217,7 +221,7 @@ monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
        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))
        {
@@ -234,7 +238,7 @@ monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
        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))
        {
@@ -250,7 +254,7 @@ monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
        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))
        {
@@ -278,7 +282,7 @@ monsters[0][xx]->gold << ' ' << monsters[0][xx]->death << endl;
        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))
        {
@@ -404,8 +408,11 @@ void raw(const char *fmt, ...)
        }
 
     }
+    #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);
@@ -425,11 +432,23 @@ void notice(const char *source, const char *dest, const char *fmt, ...)
     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++)
     {
@@ -450,8 +469,10 @@ void notice(const char *source, const char *dest, const char *fmt, ...)
        }
 
     }
+    #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);
@@ -516,8 +537,9 @@ void do_list(char *u)
 
 void do_register(char *u)
 {
-    char *password;
+    char *password, *name;
     aClient *user, *p;
+    name = strtok(NULL, " ");
     password = strtok(NULL, " ");
 
     static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
@@ -527,9 +549,13 @@ void do_register(char *u)
     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)))
     {
@@ -539,9 +565,11 @@ void do_register(char *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
        {
@@ -562,7 +590,10 @@ void do_identify(char *u)
        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))
@@ -587,9 +618,14 @@ void do_identify(char *u)
                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);
 
@@ -615,6 +651,7 @@ void do_stats(char *u)
        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))
@@ -630,8 +667,16 @@ void do_stats(char *u)
 }
 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;
 
@@ -665,7 +710,7 @@ void init_masters()
 
     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;
@@ -674,7 +719,7 @@ void init_masters()
 
     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;
@@ -683,7 +728,7 @@ void init_masters()
 
     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;
@@ -693,7 +738,7 @@ void init_masters()
 
     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;
@@ -702,7 +747,7 @@ void init_masters()
 
     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;
@@ -721,7 +766,7 @@ void init_masters()
 
     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;
@@ -740,7 +785,12 @@ void init_masters()
 
 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();
@@ -2172,7 +2222,7 @@ void do_use(char *u)
        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();
     }
@@ -2183,13 +2233,26 @@ void do_use(char *u)
            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}");
@@ -2797,7 +2860,7 @@ int save_gs_dbase()
 
     if (!outfile)
     {
-       cout << "Error opening " << playerdata << endl;
+       log("Error opening %s", playerdata);
        return 0;
     }
 
@@ -2809,7 +2872,7 @@ int save_gs_dbase()
                << 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();
@@ -2828,7 +2891,7 @@ int load_gs_dbase()
 
     if (infile.fail())
     {
-       cout << "Error opening " << playerdata << endl;
+       log("Error opening %s", playerdata);
        return 0;
     }
 
@@ -2857,14 +2920,25 @@ int load_gs_dbase()
        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;
@@ -3115,6 +3189,7 @@ void showinventory(aClient *from, aClient *to)
        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)
@@ -3153,6 +3228,7 @@ 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!");
@@ -3168,13 +3244,14 @@ void do_tavern(char *u)
            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;
@@ -3214,6 +3291,17 @@ void do_tavern(char *u)
                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;
@@ -3235,7 +3323,7 @@ void do_bank(char *u)
     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");
@@ -3556,7 +3644,7 @@ void do_refresh(char *u)
     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))
@@ -3625,7 +3713,7 @@ void do_reset(char *u)
     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))
@@ -3679,7 +3767,7 @@ void display_help(char *u, char *file)
        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;
        }
@@ -3732,7 +3820,7 @@ void do_admin(char *u)
 
     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;
     }
@@ -3751,6 +3839,7 @@ void do_admin(char *u)
     {
        notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
        setAdmin(user);
+       log("%s became an administrator.", user->getNick());
     }
     else
     {
@@ -3768,12 +3857,16 @@ bool load_monsters()
 
     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;)