]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
updated the Change log w/ new additions
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 55da3f5acf0addfaf924d8d847001a84796fc01a..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"
@@ -1137,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)
@@ -1205,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!");
@@ -1510,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;
     }
@@ -1559,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;
 }
@@ -3171,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);
 }
@@ -3316,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
     }
 }
@@ -3508,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);
   
 }
 
@@ -3532,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
@@ -3552,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;
                }
@@ -3770,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;
@@ -3793,6 +3808,8 @@ bool load_monsters()
          if (!infile)
                {
                  log("Error opening %s", filename);
+                 delete []filename;
+                 delete []buf;
                  return false;
                }