]> jfr.im git - irc/gameservirc.git/commitdiff
Fixed some p10, bugs, and gameserv is now running as a true daemon with pid outputtin...
authorkainazzzo <redacted>
Thu, 26 Feb 2004 07:40:58 +0000 (07:40 +0000)
committerkainazzzo <redacted>
Thu, 26 Feb 2004 07:40:58 +0000 (07:40 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@111 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/Changes
gameserv/TODO
gameserv/aClient.cpp
gameserv/aClient.h
gameserv/extern.h
gameserv/gameserv.cpp
gameserv/monsters.dat
gameserv/player.cpp
gameserv/run [deleted file]
gameserv/tcpclient.cpp

index 25fb221c3073421f890215f7605d1db692f277de..b5951d2f43a4261b979a9e9ece067357b3872c0d 100644 (file)
@@ -1,5 +1,10 @@
-Version 1.1.7
+Version 1.1.8
+* Made gameserv load as a true daemon. gameserv.pid now contains the pid 
+    for the gameserv process. No more run script.
+* Fixed a bug that caused the identify function to segfault.
+* Fixed some P10 Functionality
 * Merged in the Hybrid patch
+Version 1.1.7
 * Added P10 Functionality (ircu-2.10.11.x)
 * Created Monsters for level 8
 * Increased the size of the monster struct to account for longer names,
index 7cef9f5cef3f0469632a7f1a2c344ff5a9b857ff..24a62397d2589eef05f76e98fd306a34f7582012 100644 (file)
@@ -18,7 +18,7 @@ X = Finsihed
 
 * Make database and config file version numbers
 
-- Make GameServ a true daemon instead of using nohup
+X Make GameServ a true daemon instead of using nohup
     X No output unless it's a loading error
 
 * Take out most of the output except if in debug mode.
index ceb149aa908ebec5c691369853b8da844a4b6317..2ca249ad93fa399f590f23076eee627819b12780 100644 (file)
@@ -10,9 +10,26 @@ aClient::aClient(char *n)
        log("aClient created: %s", (n[0] == '\0' ? "NULL" : n));
     #endif
     strcpy(nick, n);
+
+    #ifdef P10
+       strcpy(realnick, n);
+    #endif
+
     stats = NULL;
     flags = 0;
 }
+#ifdef P10
+aClient::aClient(char *n, char *rn)
+{
+    #ifdef DEBUGMODE
+       log("aClient created: %s", (n[0] == '\0' ? "NULL" : n));
+    #endif
+    strcpy(nick, n);
+    strcpy(realnick, rn);
+    stats = NULL;
+    flags = 0;
+}
+#endif
 
 aClient::aClient(const aClient &right)
 {
@@ -28,7 +45,6 @@ aClient::aClient(const aClient &right)
 aClient::aClient()
 {
     aClient("");
-    flags = 0;
 }
 
 aClient::~aClient()
@@ -62,6 +78,9 @@ void aClient::setData(const aClient *right)
     if (right != this)
     {
        strcpy(nick, right->nick);
+       #ifdef P10
+           strcpy(realnick, right->realnick);
+       #endif
        if (right->stats)
        {
            if (!stats)
index 79b92904694ccf6ea544f146748fe821cf41a3cb..dbc41c9f1f71b3d84d5e3edb96aba3421f6ac527 100644 (file)
@@ -2,6 +2,7 @@
 #define ACLIENT_H
 
 #include <string.h>
+#include "options.h"
 #include "player.h"
 #include <iostream>
 using std::ostream;
@@ -14,6 +15,11 @@ class aClient {
 
     public:
         aClient(char *);               // Constructor takes a char for the nick
+
+       #ifdef P10
+           aClient(char *, char *);    // Constructor takes a char for the nick and realnick
+       #endif
+
        aClient(const aClient &);       // Copy constructor
         aClient();                     // Default constructor
         ~aClient();                    // Destructor
@@ -24,6 +30,12 @@ class aClient {
 
         void setNick(char *n) { strcpy(nick, n);};     // Sets the client's nick
         char *getNick() { return nick; };              // Returns the client's nick
+
+       #ifdef P10
+           void setRealNick(char *rn) { strcpy(realnick, rn);}; // Sets the client's realnick
+           char *getRealNick() { return realnick; };   // Returns the client's real nick
+       #endif
+
        Player *stats;                                  // Pointer to the client's player struct
 
        long int getFlags() { return flags; };          // Returns the Client's current flags
@@ -34,6 +46,9 @@ class aClient {
        long int remFlag(long int);     // Removes a flag from the client's current flags
 
     private:
+       #ifdef P10
+           char realnick[32];  // Client's text nickname. Not the numeric
+       #endif
         char nick[32];         // Client's current nickname. Numeric if P10 is used
        long int flags;         // Client's current flags.
 };
index 57ed1840aa2a09d00f3fa947d2f01832525e9c15..d1b6f946efccd4f95eaeb04908bba55d67c3cd49 100644 (file)
@@ -74,6 +74,9 @@ E aClient *findbynick(char *nick);
 E aClient *findbynick(const char *nick);
 E aClient *findplayer(const char *name);
 E aClient *findIRCplayer(const char *nick);
+#ifdef P10
+E aClient *findbyrealnick(char *realnick);
+#endif
 
 /** Sock writing functions **/
 E void notice(const char *source, const char *dest, const char *fmt, ...);
index 55401dc443e39fcf1a3f564a89b863fb437a7766..494481f3ed4d63f0bbe4923de7a4a4a97f8060f3 100644 (file)
@@ -231,9 +231,9 @@ void gameserv(char *source, char *buf)
        {
            save_gs_dbase();
            #ifdef P10
-               raw("[] SQ %s 0 :leaving", servername);
+               raw("[] SQ %s 0 :leaving: %s used the Shutdown command.", servername, user->getRealNick());
            #else
-               raw("SQUIT %s :leaving", servername);
+               raw("SQUIT %s :leaving: %s used the Shutdown command.", servername, u);
            #endif
        }
     } else if (stricmp(cmd, "SAVE") == 0) {
@@ -530,7 +530,15 @@ void do_list(char *u)
        notice(s_GameServ, u, "People Playing:");
        while(temp)
        {
-           notice(s_GameServ, u, "IRC: %s     Game: %s", temp->getData()->getNick(), temp->getData()->stats->name);
+
+           #ifdef P10
+           notice(s_GameServ, u, "IRC: %s     Game: %s", temp->getData()->getRealNick(), 
+                  temp->getData()->stats->name);
+           #else
+           notice(s_GameServ, u, "IRC: %s     Game: %s", temp->getData()->getNick(), 
+                  temp->getData()->stats->name);
+           #endif
+
            temp = temp->Next();
        }
        notice(s_GameServ, u, "End of List");
@@ -1998,9 +2006,8 @@ void display_players(char *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->getNick()
+       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");
@@ -2014,7 +2021,7 @@ void display_players(aClient *user)
     {
        aClient *battle = user->stats->battle;
        notice(s_GameServ, u, "Your Hitpoints: \ 2%d\ 2", user->stats->hp);
-       notice(s_GameServ, u, "%s's Hitpoints: \ 2%d\ 2", battle->getNick(), battle->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");
@@ -2118,7 +2125,7 @@ void do_fight(char *u)
        notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
        return;
     }
-    else if (!(battle = find(nick)))
+    else if (!(battle = findbyrealnick(nick)))
     {
        notice(s_GameServ, u, "You can't attack %s while they aren't playing!", nick);
        return;
@@ -2137,7 +2144,7 @@ void do_fight(char *u)
  *       ni->yourturn = 1;
  *       battle->yourturn = 0;
  *       notice(s_GameServ, u, "You decide to fight %s while they're not online!",
- *                battle->getNick());
+ *                battle->stats->name);
  *       display_players(u);
  *   }
  */
@@ -2169,10 +2176,10 @@ void do_fight(char *u)
        clearYourTurn(battle->stats);
 
        // Initiate Battle sequence!
-        notice(s_GameServ, u, "You challenge %s to an online duel!", battle->getNick());
-        notice(s_GameServ, battle->getNick(), "%s has challenged you to an online duel!", u);
-        notice(s_GameServ, battle->getNick(), "%s gets to go first because he initiated!", u);
-        notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", u);
+        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);
+        notice(s_GameServ, battle->getNick(), "%s gets to go first because he initiated!", ni->stats->name);
+        notice(s_GameServ, battle->getNick(), "Please wait while %s decides what to do.", ni->stats->name);
         display_players(u);
     }
 }
@@ -2637,39 +2644,40 @@ void do_attack(char *u)
    }
 * end offline fighting */
 
-   if (is_playing(battle->getNick()))
+   if (is_playing(battle))
    {
     if (!isYourTurn(ni->stats))
     {
         notice(s_GameServ, u, "Please wait until %s decides what to do!", 
-               battle->getNick());
+               battle->stats->name);
         return;
     }
     if (hit > 0)
     {
-        notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->getNick(), hit);
+        notice(s_GameServ, u, "You attack \1f%s\1f for \ 2%d\ 2 points!", battle->stats->name, hit);
 
         notice(s_GameServ, battle->getNick(), "%s has hit you with their %s for "\
-                                             "\ 2%d\ 2 damage!", u, weapons[ni->stats->weapon]
-                                             hit);
+                                             "\ 2%d\ 2 damage!", ni->stats->name
+                                             weapons[ni->stats->weapon], hit);
        clearYourTurn(ni->stats);
        setYourTurn(battle->stats);
         display_players(battle->getNick());
     }
     else
     {
-        notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->getNick());
-        notice(s_GameServ, battle->getNick(), "%s misses you completely!", u);
+        notice(s_GameServ, u, "You miss \1f%s\1f completely!", battle->stats->name);
+        notice(s_GameServ, battle->getNick(), "%s misses you completely!", ni->stats->name);
        clearYourTurn(ni->stats);
        setYourTurn(battle->stats);
         display_players(battle->getNick());
     }
     if (hit >= battle->stats->hp)
     {
-        notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->getNick());
+        notice(s_GameServ, u, "You have killed \ 2%s\ 2!", battle->stats->name);
         notice(s_GameServ, u, "You recieve \ 2%d\ 2 experience and \ 2%ld\ 2 gold!",
                 (long int)(battle->stats->exp * .10), battle->stats->gold);
-        notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", u);
+        notice(s_GameServ, battle->getNick(), "You have been killed by \ 2%s\ 2!", 
+               ni->stats->name);
         battle->stats->hp = 0;
         clearAlive(battle->stats);
 
@@ -2697,7 +2705,7 @@ void do_attack(char *u)
             notice(s_GameServ, battle->getNick(), "You lose ten percent of your experience!");
 
             notice(s_GameServ, battle->getNick(), "However, %s could not carry all of your "\
-                       "gold.", u);
+                       "gold.", ni->stats->name);
 
             notice(s_GameServ, battle->getNick(), "Luckily, you still have \ 2%ld\ 2 gold "\
                        "left. All is not lost!", battle->stats->gold);
@@ -2715,13 +2723,14 @@ void do_attack(char *u)
        clearYourTurn(ni->stats);
        setYourTurn(battle->stats);
         notice(s_GameServ, u, "Please wait while %s decides what to do!", 
-               battle->getNick());
+               battle->stats->name);
 
         return;
     }
    }
   }
 }
+
 void do_heal(char *u)
 {
     aClient *ni;
@@ -2923,6 +2932,9 @@ int load_gs_dbase()
        password = strtok(NULL, " ");
        strcpy(p->password, password);
        temp->setNick("!NULL!");
+       #ifdef P10
+       temp->setRealNick("!NULL!");
+       #endif
 
        p->inventory.reset(); // Set inventory to all 0s
        // Old player databases didn't have these three extra values
@@ -3189,7 +3201,7 @@ void showinventory(aClient *from, aClient *to)
     if (is_playing(from))
     {
        Pouch *p = &from->stats->inventory;
-       notice(s_GameServ, nick, "Inventory for %s:", from->getNick());
+       notice(s_GameServ, nick, "Inventory for %s:", from->stats->name);
        notice(s_GameServ, nick, " Healing Potions: %d", p->Healing());
        notice(s_GameServ, nick, "Strength Potions: %d", p->Strength());
        notice(s_GameServ, nick, " Defense Potions: %d", p->Defense());
@@ -3666,16 +3678,24 @@ void do_refresh(char *u)
        notice(s_GameServ, u, "Refreshing everyone's stats!");
        refreshall();
     }
-    else if ((user = find(nick)))
+    else if ((user = findbyrealnick(nick)))
     {
        if (is_playing(user))
        {
+           #ifdef P10
+           notice(s_GameServ, u, "Refreshing %s.", user->getRealNick());
+           #else
            notice(s_GameServ, u, "Refreshing %s.", user->getNick());
+           #endif
            refresh(user->stats);
        }
        else
        {
+           #ifdef P10
+           notice(s_GameServ, u, "%s is not playing.", user->getRealNick());
+           #else
            notice(s_GameServ, u, "%s is not playing.", user->getNick());
+           #endif
        }
     }
     else
@@ -3735,16 +3755,24 @@ void do_reset(char *u)
        notice(s_GameServ, u, "Resetting everyone's stats!");
        resetall();
     }
-    else if ((user = find(nick)))
+    else if ((user = findbyrealnick(nick)))
     {
        if (is_playing(user))
        {
+           #ifdef P10
+           notice(s_GameServ, u, "Resetting %s.", user->getRealNick());
+           #else
            notice(s_GameServ, u, "Resetting %s.", user->getNick());
+           #endif
            reset(user->stats);
        }
        else
        {
+           #ifdef P10
+           notice(s_GameServ, u, "%s is not playing.", user->getRealNick());
+           #else
            notice(s_GameServ, u, "%s is not playing.", user->getNick());
+           #endif
        }
     }
     else
@@ -3843,7 +3871,11 @@ void do_admin(char *u)
     {
        notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
        setAdmin(user);
+       #ifdef P10
+       log("%s became an administrator.", user->getRealNick());
+       #else
        log("%s became an administrator.", user->getNick());
+       #endif
     }
     else
     {
index 8cc0206325f3d19ea5496103dc9533eff8e71a37..0b49756ca6fdb75c64a02d8257b27cf131c135f8 100644 (file)
@@ -110,7 +110,10 @@ Red Neck of the East~Trailer Hitch~350~1000~670~700~If you go to your family reu
 Decomposed Corpse~Horrid Stench~375~2140~1204~890~Your stomach churns as you flee from this vile creature's twice killed carcus!
 Empty Armor~Translucent Sword~380~13010~930~560~The armor falls into a pile as your finishing blow misses completely! Where did it go?
 Liquid Gold Man~Sword Arm~399~50102~900~2420~He was tough, and you were greedy, but the payoff is wonderful!
-# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die)
-# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die)
-# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die)
-# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die)
+# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die) level 9
+Iron Maiden~Hell and Fire~450~60021~1234~2000~666! THE NUMBER OF THE BEAST!
+Black Eye~Blank Stare~
+Bill Gates~Blue Screen of Death~500~100000~1700~2400~format c: /q ... He's DEAD!
+# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die) level 10
+# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die) level 11
+# Name~Weapon~Strength~Gold~Experience~(Hit points)~Death Phrase (said when they die) level 12
index 763755b771eb538721db39311ea53e2113ac0727..c9f219580b91b4b4d8e59ec796269a612c282dfe 100644 (file)
@@ -7,8 +7,8 @@
 
 void Player::reset()
 {
-    memset(name, 0, 255);
-    memset(password, 0, 255);
+    memset(name, 0, 256);
+    memset(password, 0, 256);
 
     exp = 1;
     gold = 0;
@@ -65,11 +65,11 @@ Player::~Player()
 {   
     #ifdef DEBUGMODE
        char *output;
-       output = new char[strlen(name) + strlen(password) + 2];
+       output = new char[strlen(name) + strlen(password) + 48];
        strcpy(output, "Deleting Player");
     #endif
  
-    if (name)
+    if (name != NULL)
     {
        #ifdef DEBUGMODE
            sprintf(output, "%s: %s", output, name);
@@ -77,15 +77,19 @@ Player::~Player()
 
        delete [] name;
     }
-    if (password)
+
+    if (password != NULL)
     {
        #ifdef DEBUGMODE
-           sprintf(output, "%s   Password: %s", output, password);
+           sprintf(output, "%s    Password: %s", output, password);
        #endif
+
        delete [] password;
     }
+
     #ifdef DEBUGMODE
        log ("%s", output);
+       delete [] output;
     #endif
 }
 
diff --git a/gameserv/run b/gameserv/run
deleted file mode 100755 (executable)
index 1b9808c..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-./gameserv >> error.log &
index d3cc364f76771b6f0124a9741f321fb41fb8a4f6..b8b2752d783c864c71a884066ab78555c8736ec9 100644 (file)
 #include <string.h>
 #include <fstream>
 #include <stdlib.h>
+#include <fcntl.h>
+#include <signal.h>
+//#include <sys/types.h>
+//#include <sys/wait.h>
+//#include <errno.h>
+
+
 
 using std::ofstream;
 using std::ifstream;
+using std::cerr;
+using std::endl;
 
 char *PACKAGE = "GameServ";
-char *VERSION = "1.1.7";
+char *VERSION = "1.1.8";
 
 int sock;
 long timestamp;
@@ -37,6 +46,12 @@ List<aClient> clients;
 void save_timestamp();
 void load_timestamp();
 
+// Make this a daemon
+int daemon(int nochdir, int noclose);
+
+// Close all file descriptors from >= fd
+void closeall(int fd);
+
 int main()
 {
   char buffer[1024], buf[1024];
@@ -47,6 +62,13 @@ int main()
 
   load_config_file();          // default = gameserv.conf
 
+    // Turn into a daemon
+    if (daemon(1,0) < 0)
+    {
+        perror("Could not turn into a daemon");
+        exit(2);
+    }
+
   ignore_pipe();
   sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
   if (sock == -1) {
@@ -191,9 +213,10 @@ int main()
       #else
        } else if (stricmp(cmd, "N") == 0 && strlen(source) == 2) {
            {   
-               char *nick;
+               char *nick, *realnick;
+               realnick = strtok(NULL, " ");
 
-               for (int x = 0; x < 6; x++)
+               for (int x = 0; x < 5; x++)
                      nick = strtok(NULL, " ");
 
                if (nick[0] == '+')
@@ -218,9 +241,19 @@ int main()
 
                nick = strtok(NULL, " ");
 
-               newuser = new aClient(nick);
+               #ifdef P10
+                   newuser = new aClient(nick, realnick);
+               #else
+                   newuser = new aClient(nick);
+               #endif
+
+
                if (loaded)
+               #ifdef P10
+                   notice(s_GameServ, nick, welcomemsg, realnick);
+               #else
                    notice(s_GameServ, nick, welcomemsg, nick);
+               #endif
 
                clients.insertAtBack(newuser);
                delete newuser;
@@ -342,6 +375,26 @@ aClient *find(const char *nick)
        return findbynick(nick);
 }
 
+#ifdef P10
+
+aClient *findbyrealnick(char *realnick)
+{
+   ListNode <aClient> *newPtr;
+    newPtr = clients.First();
+
+    aClient *client = NULL;
+
+    while (newPtr)
+    {
+       client = newPtr->getData();
+           if (stricmp(client->getRealNick(), realnick) == 0)
+           return client;
+       client = NULL;
+       newPtr = newPtr->Next();
+    }
+    return client;    
+}
+#endif
 
 aClient *findbynick(char *nick)
 {
@@ -468,3 +521,68 @@ long int midnight(long int offset)
 {
     return (time(NULL) - (time(NULL) % 86400)) + (offset * 3600);
 }
+
+/* daemon() - detach process from user and disappear into the background
+ * returns -1 on failure, but you can't do much except exit in that case
+ * since we may already have forked. This is based on the BSD version,
+ * so the caller is responsible for things like the umask, etc.
+ */
+
+/* believed to work on all Posix systems */
+
+int daemon(int nochdir, int noclose)
+{
+    pid_t pid;
+    switch (pid = fork())
+    {
+        case 0:  break;
+        case -1: return -1;
+        default: _exit(0);          /* exit the original process */
+    }
+
+    if (setsid() < 0)               /* shoudn't fail */
+      return -1;
+
+    /* dyke out this switch if you want to acquire a control tty in */
+    /* the future -- not normally advisable for daemons */
+
+    switch (pid = fork())
+    {
+        case 0:  break;
+        case -1: return -1;
+        default: 
+               ofstream outfile;
+               outfile.open("gameserv.pid");
+               if (outfile.fail())
+                   cerr << "Unable to open gameserv.pid" << endl;
+               outfile << pid << endl;
+               outfile.close();
+
+       _exit(0);
+    }
+
+    if (!nochdir)
+      chdir("/");
+
+    if (!noclose)
+    {
+        closeall(0);
+        open("/dev/null",O_RDWR);
+        dup(0); dup(0);
+    }
+
+    return 0;
+}
+
+
+/* closeall() -- close all FDs >= a specified value */
+
+void closeall(int fd)
+{
+    int fdlimit = sysconf(_SC_OPEN_MAX);
+
+    while (fd < fdlimit)
+      close(fd++);
+}
+
+