]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
updated the Change log w/ new additions
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 9180b7337a9305dcd514fd5d40d7d2a2f4c448f6..05ac73953b5b33518fc5e1718163c5d05e633b1e 100644 (file)
@@ -4,7 +4,6 @@
 #include "player.h"
 #include "pouch.h"
 #include "flags.h"
-#include "list.h"
 #include "level.h"
 #include "sockhelp.h"
 #include "item.h"
@@ -440,7 +439,7 @@ void showstats(const char *u, const char *nick)
          {
         notice(s_GameServ, u, "%s not found", nick);
          }
-    else if (is_playing(p->getClient()))
+    else
          {
         notice(s_GameServ, sender->getNick(), "Stats for %s:", p->getName().c_str());
                
@@ -481,10 +480,7 @@ void showstats(const char *u, const char *nick)
                        showinventory(p, sender);
                  }
          }
-    else
-         {
-               notice(s_GameServ, u, "%s is not playing!", p->getName().c_str());
-         }
+
     delete [] buf;
 }
 
@@ -1140,52 +1136,59 @@ void do_logout(char *u)
 
 void logout(aClient *user)
 {
-  if (is_playing(user))
+  if (user != NULL)
     {
-         list<Player*>::iterator iter;
-         unsigned long hv = iHASH((unsigned char *) user->stats->getName().c_str());
-         iter = find(players[hv].begin(), players[hv].end(), user->stats);
-         
-         if (iter == players[hv].end())
-        {
-                 notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
-                                "%S Admin. Cannot find you in the players list. This should NEVER happen");
-                 log("Error on logout(). Can't find %s in the players list",
+         if (user->stats != NULL)
+               {
+               
+                 list<Player*>::iterator iter;
+                 unsigned long hv = iHASH((unsigned char *) user->stats->getName().c_str());
+                 iter = find(players[hv].begin(), players[hv].end(), user->stats);
+                 
+                 if (iter == players[hv].end())
+                       {
+                         notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
+                                        "%S Admin. Cannot find you in the players list. This should NEVER happen");
+                         log("Error on logout(). Can't find %s in the players list",
 #ifdef P10 
-                         user->getRealNick()
+                                 user->getRealNick()
 #else 
-                         user->getNick()
+                                 user->getNick()
 #endif
-                         );
-                 return;
-        }
-         user->stats->delMonster();
-         user->stats->delMaster();
-         user->stats->delBattle();
-         clearDragonFight(user->stats);
-         clearYourTurn(user->stats);
-         clearPlaying(user);
-
-         user->stats->setClient(NULL);
-         user->stats = NULL;
-         
-         if (player_fight(user))
-               {
-                 clearYourTurn(user->stats->getBattle()->stats);
-                 user->stats->getBattle()->stats->delBattle();
-               }
-
+                                 );
+                         user->stats = NULL;
+                         
+                         return;
+                       }
+                 user->stats->delMonster();
+                 user->stats->delMaster();
+                 user->stats->delBattle();
+                 clearDragonFight(user->stats);
+                 clearYourTurn(user->stats);
+                 clearPlaying(user);
+                 
+                 user->stats->setClient(NULL);
+                 
+                 
+                 if (player_fight(user))
+                       {
+                         clearYourTurn(user->stats->getBattle()->stats);
+                         user->stats->getBattle()->stats->delBattle();
+                       }
+                 
 #ifdef DEBUGMODE
-         log("Logged out player %s",
+                 log("Logged out player %s",
 #ifdef P10 
-                 user->getRealNick()
+                         user->getRealNick()
 #else 
-                 user->getNick()
+                         user->getNick()
 #endif 
-                 );
+                         );
 #endif
-    }
-
+               }
+       }
+  if (user)
+       user->stats = NULL;
 }
 
 void do_register(char *u)
@@ -1208,6 +1211,10 @@ void do_register(char *u)
     {
          notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
     }
+  else if (strlen(name) > maxnicklen)
+       {
+         notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen);
+       }
   else if (!alphaNumeric(name))
        {
          notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
@@ -1262,6 +1269,9 @@ void do_register(char *u)
                  // Log the player in
                  setPlaying(user);
 
+                 // Start the player at the beginning
+                 reset(user->stats);
+                 
                  // Add the stick and clothes
                  tempItem = findItemByID(3001);
                  user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
@@ -1380,7 +1390,8 @@ void do_stats(char *u)
                }
          else
                {
-                 updateTS(user->stats);
+                 if (!is_fighting(user))
+                       updateTS(user->stats);
                  showstats(u, user->stats->getName().c_str());
                }
     }
@@ -1509,16 +1520,19 @@ bool is_playing(char *u)
 
 bool is_playing(aClient *user)
 {
-  
-  if (!user || !user->stats)
+  if (!user)
     {
          return false;
     }
-  else if (user->stats->getClient() != user)
+  else if (!user->stats)
+       {
+         return false;
+       }
+  else if (!FL_is_playing(user))
     {
          return false;
     }
-  else if (!FL_is_playing(user))
+  else if (user->stats->getClient() != user)
     {
          return false;
     }
@@ -1558,9 +1572,9 @@ bool player_fight(aClient *user)
 {
   if (!is_playing(user))
        return false;
-  else if (user->stats->getBattle() != NULL && is_playing(user->stats->getBattle()))
+  else if (is_playing(user->stats->getBattle()))
     {
-         return user->stats->getBattle()->stats != NULL;
+         return true;
     }
   return false;
 }
@@ -1774,7 +1788,8 @@ void do_equip(char *u)
       return;
     }
   id = stringtoint(item);
-  updateTS(user->stats);
+  if (!is_fighting(user))
+       updateTS(user->stats);
   p = user->stats->inventory;
 
 
@@ -1797,16 +1812,18 @@ void do_equip(char *u)
                equip->use(user->stats);
       }
 }
+
 void do_use(char *u)
 {
   aClient *user;
   pouch *p;
   
   char *item = strtok(NULL, " ");
-  int id;
+  char *numuse = strtok(NULL, " ");
+  int id, num;
   itemContainer *used;
   
-  if (!item || int(item[0]) < 48 || int(item[0]) > 57)
+  if (!item || int(item[0]) < 48 || int(item[0]) > 57 || (numuse && (int(numuse[0]) < 48 || int(numuse[0]) > 57)))
     {
          notice(s_GameServ, u, "SYNTAX: USE ####");
          notice(s_GameServ, u, "Type /msg %S HELP USE for more information.");
@@ -1830,10 +1847,20 @@ void do_use(char *u)
          return;
     }
   id = stringtoint(item);
+  
+  if (!numuse)
+       {
+         num = 1;
+       }
+  else
+       {
+         num = stringtoint(numuse);
+       }
+  
   updateTS(user->stats);
   p = user->stats->inventory;
   
-  
+
   if (!(used = p->Find(id)))
        {
          if (!p->isEmpty())
@@ -1848,15 +1875,39 @@ void do_use(char *u)
        }
   else
        {
-         // Use the item
-         notice(s_GameServ, u, "You used %s.", used->getItem()->getName().c_str());
-         used->use(user->stats);
-         if (used->getUses() <= 0)
+         // Use the item(s)
+         if (num <= 1 || is_fighting(user))
                {
-                 p->deleteItem(used->getItem());
+                 notice(s_GameServ, u, "You used %s.", used->getItem()->getName().c_str());
+                 used->use(user->stats);
+                 if (used->getUses() <= 0)
+                       {
+                         p->deleteItem(used->getItem());
+                       }
+                 end_turn(user);
                }
-         end_turn(user);
-       }   
+         else if (num > 1)
+               {
+                 int count;
+                 const char *name = used->getItem()->getName().c_str();
+                 for (count = 0; count < num; count++)
+                       {
+                         if (!(used = p->Find(id)))
+                               {
+                                 break;
+                               }
+                         else
+                               {
+                                 used->use(user->stats);
+                                 if (used->getUses() == 0)
+                                       {
+                                         p->deleteItem(used->getItem());
+                                       }
+                               }
+                       }
+                 notice(s_GameServ, u, "You used %d %s's", count, name);
+               }
+       }
 }
 void do_run(char *u)
 {
@@ -2428,8 +2479,9 @@ int load_gs_dbase()
          p->setExp(stringtoint(strtok(NULL, " ")));
          p->setGold(stringtoint(strtok(NULL, " ")));
          p->setBank(stringtoint(strtok(NULL, " ")));
-         p->setHP(stringtoint(strtok(NULL, " ")));
+         tempnum = stringtoint(strtok(NULL, " "));
          p->setMaxHP(stringtoint(strtok(NULL, " ")));
+         p->setHP(tempnum);
          p->setStrength(stringtoint(strtok(NULL, " ")));
          p->setDefense(stringtoint(strtok(NULL, " ")));
          p->setForestFights(stringtoint(strtok(NULL, " ")));
@@ -2485,14 +2537,12 @@ int load_gs_dbase()
                                {
                                  // Don't sort every time you add an item or it eats CPU
                                  p->inventory->addItemNoChecks((*item_iter))->setUses(uses);
-                                 log("Inventory Count: %d", p->inventory->getCount());
                                }
                          item_iter++;
                        }
                }
          p->inventory->sort();
          players[hv].push_back(p);
-         log("Inventory Count: %d", p->inventory->getCount());
        }
 
   delete [] buf;
@@ -2728,7 +2778,8 @@ void do_inventory(char *u)
          notice(s_GameServ, u, "You must be playing to check your inventory!");
          return;
     }
-  updateTS(user->stats);
+  if (!is_fighting(user))
+       updateTS(user->stats);
   showinventory(user->stats, user);
 }
 
@@ -2893,7 +2944,6 @@ void do_tavern(char *u)
                                {
                                  notice(s_GameServ, u, "One %s coming right up!", tempItem->getItem()->getName().c_str());
                                  user->stats->subtractGold(tempItem->getItem()->price());
-                                 notice(s_GameServ, u, "%d", user->stats->inventory->getCount());
                                }
                        }
                }
@@ -3134,7 +3184,7 @@ void do_dragon(char *u)
   notice(s_GameServ, u, "Just then you notice the eye begin to "\
                 "glare orange! The tooth is moving... but it is still too "\
                 "dark for you to make out.... THE DRAGON! You see it!");
-  p->setMonster(new Monster(dragon));
+  p->setMonster(&dragon);
   setDragonFight(p);
   display_monster(u);
 }
@@ -3279,11 +3329,9 @@ void see_master(char *u)
   
   if (!is_fighting(user) && is_playing(user))
     {
-         Monster *temp;
          Player *p = user->stats;
-         temp = new Monster(levels[p->getLevel() - 1].master);
-         p->setMyMaster(temp);
-         p->setMonster(temp);
+         p->setMyMaster(&levels[p->getLevel() - 1].master);
+         p->setMonster(&levels[p->getLevel() - 1].master);
          display_monster(u);  // Since master is the same structure, use this function
     }
 }
@@ -3448,14 +3496,15 @@ void resetall()
 void reset(Player *p)
 {
   item *tempItem;
+
   if (!p)
        return;
   
   p->reset();
+  // Add the stick and clothes
   tempItem = findItemByID(3001);
   p->inventory->addItem((*Items.begin()))->use(p); // Add the stick
-  p->inventory->addItem(tempItem)->use(p); // Add Clothes
-  
+  p->inventory->addItem(tempItem)->use(p); // Add Clothes      
 }
 
 void updateTS(Player *p)
@@ -3470,6 +3519,7 @@ void updateTS(Player *p)
 #ifdef DEBUGMODE
   log("New timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
 #endif
+  PF_cleartimedout(p);
   
 }
 
@@ -3494,12 +3544,12 @@ void timeOutEvent(Player *p)
        return;
   
   char *nick = p->getClient()->getNick();
-  
+
   if (player_fight(p->getClient()) && isYourTurn(p))
     {
          // Check to see if they were the idler or if it was the other 
          // person
-         if (p->lastcommand != p->getBattle()->stats->lastcommand)
+         if (!PF_timedout(p->getBattle()->stats))
                {
                  // This person's last command was given earlier,
                  // so this person is the idler
@@ -3514,7 +3564,7 @@ void timeOutEvent(Player *p)
                  // Chance to wake up, but if the other player doesn't
                  // Attack now, they both get logged out.
                  updateTS(p);
-                 p->getBattle()->stats->lastcommand = p->lastcommand;
+                 PF_settimedout(p);
                  display_players(p->getBattle());
                  return;
                }
@@ -3732,7 +3782,10 @@ bool load_levels()
     {
          sprintf(filename, "data/levels/level%d.dat", x);
          if (levels[x - 1].loadLevel(filename) == false)
-           return false;
+               {
+                 delete []filename;
+                 return false;
+               }
     }
   
   delete []filename;
@@ -3755,6 +3808,8 @@ bool load_monsters()
          if (!infile)
                {
                  log("Error opening %s", filename);
+                 delete []filename;
+                 delete []buf;
                  return false;
                }