]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
Fixed a major bug that had player fights core dumping the server
[irc/gameservirc.git] / gameserv / gameserv.cpp
index fb613340b24f26bb76d279a58506013e845f808d..6d84fe470214ff9a4c14b68aee15a0af7887c058 100644 (file)
@@ -10,6 +10,7 @@
 
 using std::ifstream;
 using std::ofstream;
+using std::ios;
 
 #if defined(HAVE_CRYPT_H)
 
@@ -46,7 +47,6 @@ int stricmp(const char *s1, const char *s2);
 int strnicmp(const char *s1, const char *s2, size_t len);
 // String Functions
 
-
 /********** Password functions **********/
 
 bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
@@ -58,6 +58,7 @@ bool check_password(char *name, char *plaintext); // Finds a password for the gi
 
 /********** GameServ Booleans **********/
 
+bool shuttingdown;
 bool is_playing(char *u); // True if the given nickname in the clients list is playing.
 bool is_playing(aClient *user);
 
@@ -243,6 +244,7 @@ void gameserv(char *source, char *buf)
            #else
                raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, source);
            #endif
+           shuttingdown = true;
        }
     } else if (stricmp(cmd, "SAVE") == 0) {
        aClient *user;
@@ -616,14 +618,14 @@ void logout(aClient *user)
        temp = new aClient;
        temp->stats = new Player;
        temp->stats->setData(user->stats);
-       user->stats->user = NULL;
+       user->stats->client = NULL;
 
        if (player_fight(user))
            user->stats->battle->stats->battle = NULL;
 
        delete user->stats;
        user->stats = NULL;
-       temp->stats->user = NULL;
+       temp->stats->client = NULL;
        #ifdef P10
            temp->setRealNick("!NULL!");
        #endif
@@ -674,7 +676,7 @@ void do_register(char *u)
         if (!user->stats && !p)
         {
            user->stats = new Player(user);
-           user->stats->user = user; // Set the backwards pointer
+           user->stats->client = user; // Set the backwards pointer
            strcpy(user->stats->password, crypt(password, salt));
            strcpy(user->stats->name, name);
            unsigned long hv = HASH((unsigned char *) name, U_TABLE_SIZE);
@@ -712,7 +714,7 @@ void do_identify(char *u)
     {
        notice(s_GameServ, u, "You are already playing!");
     }
-    else if (p->stats->user != NULL && !isAdmin(user))
+    else if (p->stats->client != NULL && !isAdmin(user))
     {
        notice(s_GameServ, u, "That player has already identified.");
     }
@@ -936,21 +938,15 @@ void display_monster(char *u)
 
 void display_players(char *u)
 {
-    if (is_playing(u))
+    aClient *user;
+    if (!(user = find(u)))
     {
-       aClient *ni = find(u);
-
-       aClient *battle = ni->stats->battle;
-
-       notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", ni->stats->hp);
-       notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->stats->name, 
-                                                       battle->stats->hp);
-       notice(s_GameServ, u, "Here are your commands:");
-       notice(s_GameServ, u, "/msg %S attack");
-       notice(s_GameServ, u, "/msg %S run");
-       notice(s_GameServ, u, "What will you do?");
+       log("Fatal error in display_players(): Couldn't find %s", u);
     }
+    else
+       display_players(user);
 }
+
 void display_players(aClient *user)
 {
     char *u = user->getNick();
@@ -1146,7 +1142,7 @@ void do_fight(char *u)
         notice(s_GameServ, battle->getNick(), "%s gets to go first "\
                        "because they initiated!", ni->stats->name);
         notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", ni->stats->name);
-        display_players(u);
+        display_players(ni);
     }
 }
 void do_use(char *u)
@@ -1633,7 +1629,7 @@ void do_attack(char *u)
                                              weapons[ni->stats->weapon], hit);
        clearYourTurn(ni->stats);
        setYourTurn(battle->stats);
-        display_players(battle->getNick());
+        display_players(battle);
     }
     else
     {
@@ -1641,7 +1637,7 @@ void do_attack(char *u)
         notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name);
        clearYourTurn(ni->stats);
        setYourTurn(battle->stats);
-        display_players(battle->getNick());
+        display_players(battle);
     }
     if (hit >= battle->stats->hp)
     {
@@ -1931,8 +1927,9 @@ int load_gs_dbase()
        tempname = strtok(NULL, " ");
        if (tempname)
            p->inventory.setHP(stringtoint(tempname));
-       temp->stats->user = NULL;
        unsigned long hv = HASH((unsigned char *) temp->stats->name, U_TABLE_SIZE);
+
+       temp->stats->client = NULL;
        players[hv].insertAtBack(temp);
        delete temp;
     }