]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
fixed some bugs with freebsd 5.3
[irc/gameservirc.git] / gameserv / gameserv.cpp
index ca0e951458b550cc26d8cbce41d0e8b49335dedb..8d6c5af101f95b2f042f910e1e283aa531002c3e 100644 (file)
@@ -678,7 +678,7 @@ void do_set(char *u)
   if (!(user = find(u)))
     {
       notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
-            "Buf: %s LOGOUT", u);
+                        "Buf: %s LOGOUT", u);
       return;
     }
   else if (isIgnore(user))
@@ -688,7 +688,7 @@ void do_set(char *u)
 #endif
       return;
     }
-  else if (!name)
+  else if (!name || !cmd)
     {
       notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
       return;
@@ -696,21 +696,26 @@ void do_set(char *u)
   else if (!(target = findplayer(name)))
     {
       // Back the pointers up... they didn't send a name probably
-      cmd2= cmd;
+      cmd2 = cmd;
       cmd = name;
       target = user;
-
+         
       if (!is_playing(user))
-       {
-         notice(s_GameServ, u, "You must be playing to set things for yourself!");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "You must be playing to set things for yourself!");
+                 return;
+               }
     }
   else
     {
       cmd2 = strtok(NULL, " ");
     }
-
+  if (!cmd2)
+       {
+         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
+         return;
+       }
+  
   // Regardless of the previous if/else, if it got here, we know we have the cmd pointer at the right spot.
   if (stricmp(cmd, "PASSWORD") == 0)
     {
@@ -718,296 +723,295 @@ void do_set(char *u)
       // If they're an admin, or it's theirself, allow it
       // cmd2 is pointing to the password now
       if (isAdmin(user) || user == target)
-       {
-         target->stats->setPassword(cmd2);
-         notice(s_GameServ, u, "Password successfully changed");
-       }
+               {
+                 target->stats->setPassword(cmd2);
+                 notice(s_GameServ, u, "Password successfully changed");
+               }
       else if (user != target && !isAdmin(user))
-       {
-         notice(s_GameServ, u, "You must be a %S admin to set other peoples' passwords.");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "You must be a %S admin to set other peoples' passwords.");
+                 return;
+               }
     }
   else if (stricmp(cmd, "BANK") == 0 || stricmp(cmd, "BALANCE") == 0)
     {
-        if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
-       else if (stricmp(cmd, "BANK") == 0)
-       {
-         cmd2 = strtok(NULL, " "); // Need an extra parameter for set bank balance
-       }
-       if (!cmd2)
-       {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>");
-           return;
-       }
-
-       target->stats->setBank(stringtoint(cmd2));
-
-       notice(s_GameServ, u, "Bank balance changed to %ld!", target->stats->getBank());
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
+         else if (stricmp(cmd, "BANK") == 0)
+               {
+                 cmd2 = strtok(NULL, " "); // Need an extra parameter for set bank balance
+               }
+         if (!cmd2)
+               {
+                 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] [BANK] BALANCE <NUMBER>");
+                 return;
+               }
+         
+         target->stats->setBank(stringtoint(cmd2));
+         
+         notice(s_GameServ, u, "Bank balance changed to %ld!", target->stats->getBank());
     }
   else if (stricmp(cmd, "PLAYER") == 0)
     {
       if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
       else if (stricmp(cmd2, "FIGHTS") != 0)
-       {
-         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
+                 return;
+               }
       else
-       {
-         cmd2 = strtok(NULL, " ");
-           if (!cmd2)
-           {
-               notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
-               return;
-           }
-         target->stats->setPlayerFights(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Player fights changed to %d!", target->stats->getPlayerFights());
-       }         
+               {
+                 cmd2 = strtok(NULL, " ");
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] PLAYER FIGHTS <NUMBER>");
+                         return;
+                       }
+                 target->stats->setPlayerFights(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Player fights changed to %d!", target->stats->getPlayerFights());
+               }         
     }
   else if (stricmp(cmd, "FOREST") == 0)
     {
       if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
       else if (stricmp(cmd2, "FIGHTS") != 0)
-       {
-         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <number>");
+                 return;
+               }
       else
-       {
-         cmd2 = strtok(NULL, " ");
-           if (!cmd2)
-           {
-               notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>");
-               return;
-           }
-
-         target->stats->setForestFights(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Forest fights changed to %d!", target->stats->getForestFights());
-       }         
+               {
+                 cmd2 = strtok(NULL, " ");
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] FOREST FIGHTS <NUMBER>");
+                         return;
+                       }
+                 
+                 target->stats->setForestFights(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Forest fights changed to %d!", target->stats->getForestFights());
+               }         
     }
   else if (stricmp(cmd, "GOLD") == 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] GOLD <NUMBER>");
+                         return;
+                       }
+                 target->stats->setGold(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Gold set to %ld", target->stats->getGold());
+                 return;
+               }
        }
-         target->stats->setGold(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Gold set to %ld", target->stats->getGold());
-         return;
-       }
-  }
   else if (stricmp(cmd, "STRENGTH") == 0 && stricmp(cmd2, "POTIONS") != 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] STRENGTH <NUMBER>");
+                         return;
+                       }
+                 
+                 target->stats->setStrength(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Strength set to %d", target->stats->getStrength());
+                 return;
+               }
        }
-
-         target->stats->setStrength(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Strength set to %d", target->stats->getStrength());
-         return;
-       }
-  }
   else if (stricmp(cmd, "DEFENSE") == 0 && stricmp(cmd2, "POTIONS") != 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] DEFENSE <NUMBER>");
+                         return;
+                       }
+                 
+                 target->stats->setDefense(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Defense set to %d", target->stats->getDefense());
+                 return;
+               }
        }
-
-         target->stats->setDefense(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Defense set to %d", target->stats->getDefense());
-         return;
-       }
-  }
   else if (stricmp(cmd, "HP") == 0 && stricmp(cmd2, "POTIONS") != 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] HP <NUMBER>");
+                         return;
+                       }
+                 target->stats->setHP(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "HP set to %d", target->stats->getHP());
+                 return;
+               }
        }
-         target->stats->setHP(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "HP set to %d", target->stats->getHP());
-         return;
-       }
-  }
   else if (stricmp(cmd, "MAXHP") == 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] MAXHP <NUMBER>");
+                         return;
+                       }
+                 target->stats->setMaxHP(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "MaxHP set to %d", target->stats->getMaxHP());
+                 return;
+               }
        }
-         target->stats->setMaxHP(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "MaxHP set to %d", target->stats->getMaxHP());
-         return;
-       }
-  }
   else if (stricmp(cmd, "EXPERIENCE") == 0 || stricmp(cmd, "EXP") == 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {EXPERIENCE|EXP} <NUMBER>");
+                         return;
+                       }
+                 
+                 target->stats->setExp(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Exp set to %ld", target->stats->getExp());
+                 return;
+               }
        }
-
-         target->stats->setExp(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Exp set to %ld", target->stats->getExp());
-         return;
-       }
-  }
   else if (stricmp(cmd, "LEVEL") == 0)
-  {
-    if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;         
-       }
-    else
-       {
-       if (!cmd2)
        {
-           notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>");
-           return;
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;         
+               }
+         else
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] LEVEL <NUMBER>");
+                         return;
+                       }
+                 target->stats->setLevel(stringtoint(cmd2));
+                 
+                 notice(s_GameServ, u, "Level set to %d", target->stats->getLevel());
+                 return;
+               }
        }
-         target->stats->setLevel(stringtoint(cmd2));
-
-         notice(s_GameServ, u, "Level set to %d", target->stats->getLevel());
-         return;
-       }
-  }
   else if (stricmp(cmd, "ALIVE") == 0)
-  {
-     if (!isAdmin(user))
        {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
-     else
-       {
-         cmd2 = strtok(NULL, " ");
-         if (!cmd2 || (stricmp(cmd2, "TRUE") != 0 && stricmp(cmd2, "FALSE") != 0))
-         {
-            notice(s_GameServ, u, "SYNTAX: /msg %S SET ALIVE TRUE|FALSE");
-            return;
-         }
-         else if (stricmp(cmd2, "TRUE") == 0)
-         {
-            notice(s_GameServ, u, "%s has been Resurrected!", target->stats->getName().c_str());
-            setAlive(target->stats);
-         }
+         if (!isAdmin(user))
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
          else
-         {
-            notice(s_GameServ, u, "%s is now dead!", target->stats->getName().c_str());
-            clearAlive(target->stats);
-         }
+               {
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] ALIVE TRUE|FALSE");
+                         return;
+                       }
+                 else if (stricmp(cmd2, "TRUE") == 0)
+                       {
+                         notice(s_GameServ, u, "%s has been Resurrected!", target->stats->getName().c_str());
+                         setAlive(target->stats);
+                       }
+                 else
+                       {
+                         notice(s_GameServ, u, "%s is now dead!", target->stats->getName().c_str());
+                         clearAlive(target->stats);
+                       }
+               }
        }
-  }
   else if (stricmp(cmd, "SEEN") == 0)
     {
       if (!isAdmin(user))
-       {
-         notice(s_GameServ, u, "Admins Only!");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "Admins Only!");
+                 return;
+               }
       else if (stricmp(cmd2, "MASTER") != 0)
-       {
-         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}");
-         return;
-       }
+               {
+                 notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] SEEN MASTER {TRUE|FALSE}");
+                 return;
+               }
       else
-       {
-         cmd2 = strtok(NULL, " ");
-         if (!cmd2 || (stricmp(cmd2, "TRUE") != 0 && stricmp(cmd2, "FALSE") != 0))
-         {
-            notice(s_GameServ, u, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}");
-            return;
-         }
-         else if (stricmp(cmd2, "TRUE") == 0)
-         {
-            notice(s_GameServ, u, "%s has seen their master now.", target->stats->getName().c_str());
-            target->addFlag(FLAG_MASTER);
-         }
-         else
-         {
-            notice(s_GameServ, u, "%s has not seen their master now.", target->stats->getName().c_str());
-            target->remFlag(FLAG_MASTER);
-         }
-       }         
+               {
+                 cmd2 = strtok(NULL, " ");
+                 if (!cmd2)
+                       {
+                         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NICK] SEEN MASTER {TRUE|FALSE}");
+                         return;
+                       }
+                 else if (stricmp(cmd2, "TRUE") == 0)
+                       {
+                         notice(s_GameServ, u, "%s has seen their master now.", target->stats->getName().c_str());
+                         target->stats->addFlag(FLAG_MASTER);
+                       }
+                 else
+                       {
+                         notice(s_GameServ, u, "%s has not seen their master now.", target->stats->getName().c_str());
+                         target->stats->remFlag(FLAG_MASTER);
+                       }
+               }         
     }
   else
-  {
-     notice(s_GameServ, u, "Unknown command: SET %s", cmd);
-     notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
-     return;
-  }
+       {
+         notice(s_GameServ, u, "Unknown command: SET %s", cmd);
+         notice(s_GameServ, u, "SYNTAX: /msg %S SET [NAME] {PASSWORD|BANK BALANCE|PLAYER FIGHTS|FOREST FIGHTS|GOLD|STRENGTH|DEFENSE|HP|MAXHP|EXP|LEVEL|ALIVE|SEEN MASTER} {STRING|NUMBER|TRUE|FALSE}");
+         return;
+       }
 }
 
 void do_logout(char *u)
@@ -1178,8 +1182,8 @@ void do_register(char *u)
                  log("Nickname %s registered player %s.", u, user->stats->getName().c_str());
                  setPlaying(user); // set the playing flag
                  tempItem = findItemByID(3001);
-                 user->stats->inventory->addItem((*Items.begin())); // Add the stick
-                 user->stats->inventory->addItem(tempItem); // Add Clothes
+                 user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
+                 user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes
                }
          else
                {
@@ -1781,7 +1785,7 @@ void do_run(char *u)
   
   if (!is_fighting(user))
        notice(s_GameServ, u, "You run in place... try fighting next time.");
-  else if (!player_fight(user) && !master_fight(user))
+  else if (!player_fight(user) && !master_fight(user) && !dragon_fight(user))
     {
          notice(s_GameServ, u, "You run away from \ 2%s\ 2 like a little baby!", p->getMonster()->name.c_str());
          p->delMonster();
@@ -1801,7 +1805,10 @@ void do_run(char *u)
     {
          notice(s_GameServ, u, "You cannot run from \ 2%s\ 2! FIGHT!", p->getMaster()->name.c_str());
     }
-  p->delBattle();
+  else if (dragon_fight(user))
+       {
+         notice(s_GameServ, u, "You cannot run from %s! FIGHT!", dragon.name.c_str());
+       }
 }
 
 void end_turn(aClient *user)
@@ -2334,7 +2341,7 @@ int load_gs_dbase()
   
   
   password = strtok(NULL, " ");
-  p->setPassword(password);
+  p->setRawPassword(password);
   temp->setNick("Not Playing");
 #ifdef P10
   temp->setRealNick("Not Playing");
@@ -2715,11 +2722,12 @@ void do_tavern(char *u)
     }
   else if (stricmp(cmd, "BUY") == 0)
     {
-         int amt;
+         int amt = 1;
       char *chid = strtok(NULL, " ");
          char *amount = strtok(NULL, " ");
 
-         amt = stringtoint(amount);
+         if (amount)
+               amt = stringtoint(amount);
       
       if (!chid)
                {
@@ -3167,7 +3175,7 @@ void see_master(char *u)
          Player *p = user->stats;
          temp = new Monster(levels[p->getLevel() - 1].master);
          p->setMyMaster(temp);
-         p->setMonster(p->getMaster());
+         p->setMonster(temp);
          display_monster(u);  // Since master is the same structure, use this function
     }
 }
@@ -3366,8 +3374,8 @@ void reset(Player *p)
   
   p->reset();
   tempItem = findItemByID(3001);
-  p->inventory->addItem((*Items.begin())); // Add the stick
-  p->inventory->addItem(tempItem); // Add Clothes
+  p->inventory->addItem((*Items.begin()))->use(p); // Add the stick
+  p->inventory->addItem(tempItem)->use(p); // Add Clothes
 }
 
 void updateTS(Player *p)
@@ -3376,11 +3384,11 @@ void updateTS(Player *p)
        return;
   
 #ifdef DEBUGMODE
-  log("Old timestamp for %s: %ld", p->name.c_str(), p->lastcommand);
+  log("Old timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
 #endif
   p->lastcommand = time(NULL);
 #ifdef DEBUGMODE
-  log("New timestamp for %s: %ld", p->name.c_str(), p->lastcommand);
+  log("New timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
 #endif
   
 }
@@ -3402,7 +3410,6 @@ bool timedOut(Player *p)
 
 void timeOutEvent(Player *p)
 {
-  item *tempItem;
   aClient *user = findplayer(p->getName().c_str());
   
   if (!user || !p->getClient()) // then they're not playing
@@ -3450,9 +3457,6 @@ void timeOutEvent(Player *p)
     }
   else if (!player_fight(user))
     {
-         tempItem = findItemByID(3001);
-         user->stats->inventory->addItem((*Items.begin())); // Add the stick
-         user->stats->inventory->addItem(tempItem); // Add Clothes
          if (isAlive(user->stats) && user->stats->getGold() > 0)
                {
                  // Place fun stuff here :)