]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
Added a logout command and fixed some of the do_fight code
[irc/gameservirc.git] / gameserv / gameserv.cpp
index ea8d6fff213fed79b840da3d3c6ed768ee2e1047..f0d4c46f5407ae62649751b2968c8748c52431cb 100644 (file)
@@ -97,6 +97,7 @@ void do_inventory(char *u);
 void do_refresh(char *u);
 void do_register(char *u);
 void do_list(char *u);
+void do_logout(char *u);
 void do_master(char *u);
 void do_play(char *u);
 void do_quitg(char *u);
@@ -108,6 +109,7 @@ void do_tavern(char *u);
 void do_use(char *u);
 void see_master(char *u);
 
+void logout(aClient *user);
 void showstats(const char *u, const char *nick);
 void showinventory(aClient *from, aClient *to);
 void showBankBalance(const char *u);
@@ -206,6 +208,8 @@ void gameserv(char *source, char *buf)
        do_tavern(source);
     } else if (stricmp(cmd, "LIST") == 0) {
        do_list(source);
+    } else if (stricmp(cmd, "LOGOUT") == 0) {
+       do_logout(source);
     #ifdef DEBUGMODE
     } else if (stricmp(cmd, "PRINT") == 0) {
        cout << "Printing the clients list:" << endl;
@@ -554,6 +558,71 @@ void do_list(char *u)
        notice(s_GameServ, u, "No one is playing");
 }
 
+void do_logout(char *u)
+{
+    aClient *user;
+    if (!(user = find(u)))
+    {
+       notice(s_GameServ, u, "Fatal error. Cannot find aClient. "\
+               "Buf: %s LOGOUT", u);
+       log("Could not find aClient Buf: %s LOGOUT", 
+               u);
+    }
+    else if (!is_playing(user))
+    {
+       notice(s_GameServ, u, "You're not logged in!");
+    }
+    else
+    {
+       notice(s_GameServ, u, "You have left the fields. You have lived to kill another day!");
+       logout(user);
+    }
+}
+void logout(aClient *user)
+{
+    if (is_playing(user))
+    {
+       ListNode<aClient> *it;
+       aClient *temp;
+       it = players.Find(user);
+        if (!it)
+        {
+            notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
+               "%S Admin. Cannot find you in the players list.");
+           log("Error on logout(). Can't find %s in the players list",
+               #ifdef P10 
+                   user->getRealNick()
+               #else 
+                   user->getNick()
+               #endif
+               );
+            return;
+        }
+
+       temp = new aClient;
+       temp->stats = new Player;
+       temp->stats->setData(user->stats);
+       user->stats->user = NULL;
+       delete user->stats;
+       user->stats = NULL;
+       temp->stats->user = NULL;
+       #ifdef P10
+           temp->setRealNick("!NULL!");
+       #endif
+       temp->setNick("!NULL!");
+
+       it->setNewPtr(temp);
+       #ifdef DEBUGMODE
+           log("Logged out player %s",
+               #ifdef P10 
+                   user->getRealNick()
+               #else 
+                   user->getNick()
+               #endif 
+               );
+       #endif
+    }
+}
 void do_register(char *u)
 {
     char *password, *name;
@@ -620,45 +689,39 @@ void do_identify(char *u)
     }
     else if (!(p = findplayer(name)) || !p->stats)
            notice(s_GameServ, u, "Player %s not found", name);
+    else if (is_playing(user))
+    {
+       notice(s_GameServ, u, "You are already playing!");
+    }
     else if (p->stats->user != NULL && !isAdmin(user))
     {
        notice(s_GameServ, u, "That player has already identified.");
-       return;
     }
     else if (!check_password(name, password) && !isAdmin(user))
     {
            notice(s_GameServ, u, "Password incorrect");
     }
     else {
-       if (!user->stats)
-        {
-           ListNode<aClient> *temp;
-           temp = players.Find(p);
-           if (!temp)
-           {
-               notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s", 
-                       strtok(NULL, ""));
-               return;
-           }
-           user->stats = new Player(p->stats->name);
-           #ifdef DEBUGMODE
-               log("Setting data for identified");
-           #endif
-           user->stats->setData(p->stats);
-
-           #ifdef DEBUGMODE
-               log("Player Identified");
-           #endif
-
-           temp->setPtr(user);
-
-           notice(s_GameServ, u, "Password Accepted. Identified.");        
-
-       }
-       else
+       ListNode<aClient> *temp;
+       temp = players.Find(p);
+       if (!temp)
        {
-           notice(s_GameServ, u, "Already identified. Contact a %S admin for help.");
+           notice(s_GameServ, u, "Fatal error. Contact %S Admin. Buf: %s", 
+               strtok(NULL, ""));
+           return;
        }
+       user->stats = new Player(p->stats->name);
+       #ifdef DEBUGMODE
+           log("Setting data for identified");
+       #endif
+       user->stats->setData(p->stats);
+
+       #ifdef DEBUGMODE
+           log("Player Identified");
+       #endif
+
+       temp->setPtr(user);
+       notice(s_GameServ, u, "Password Accepted. Identified.");            
     }
 }
 
@@ -976,17 +1039,18 @@ void do_fight(char *u)
     else if (!(ni = find(u)))
     {
        notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
-       return;
     }
     else if (!is_playing(ni))
     {
        notice(s_GameServ, u, "You are not playing!");
-       return;
     }
     else if (!(battle = findplayer(nick)))
+    {
+       notice(s_GameServ, u, "Player %s not found!", nick);
+    }
+    else if (!is_playing(battle))
     {
        notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
-       return;
     }
 /*
  * Offline fighting not implemented yet.
@@ -1004,22 +1068,22 @@ void do_fight(char *u)
     else if (!isAlive(ni->stats))
     {
        notice(s_GameServ, u, "You are dead. Wait until tomorrow to fight others!");
-       return;
+    }
+    else if (stricmp(ni->stats->name, battle->stats->name) == 0)
+    {
+       notice(s_GameServ, u, "Are you trying to commit suicide!?");
     }
     else if (!isAlive(battle->stats))
     {
         notice(s_GameServ, u, "They are dead. Cannot fight dead players!");
-        return;
     }
     else if (player_fight(battle))
     {
        notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->battle->stats->name);
-       return;
     }
     else if (is_fighting(battle))
     {
        notice(s_GameServ, u, "%s is fighting %s already!", battle->stats->name, battle->stats->fight->name);
-       return;
     }
     else if (ni->stats->level - battle->stats->level > maxbfightdistance)
     {
@@ -1027,7 +1091,6 @@ void do_fight(char *u)
        // level 12 can fight level (12 - X) but not < (12 - X)
        notice(s_GameServ, u, "You may not fight %s. You're too strong!", 
                battle->stats->level);
-       return;
     }
     else if (battle->stats->level - ni->stats->level > maxafightdistance)
     {
@@ -1035,9 +1098,8 @@ void do_fight(char *u)
        // level 1 can fight level (1 + X), but not > (1 + X)
        notice(s_GameServ, u, "%s, do you really have a death wish? Try the forest you "\
                "weakling!", ni->stats->name);
-       return;
     }
-    else if (is_playing(ni) && is_playing(battle) && stricmp(ni->stats->name, battle->stats->name) != 0)
+    else
     {
        // Set your battle pointer to the other player
         ni->stats->battle = battle;
@@ -1050,7 +1112,7 @@ void do_fight(char *u)
        clearYourTurn(battle->stats);
 
        // Initiate Battle sequence!
-       battle->stats->player_fights -= 1;
+       ni->stats->player_fights -= 1;
 
         notice(s_GameServ, u, "You challenge %s to an online duel!", battle->stats->name);
         notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", ni->stats->name);