]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
removed server.txt
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 1faf5e3fc5468f483c79455d83c4dab3cd2cebfc..dc733ee25e9e8c9b40b8a6123b9e2d3e9e1da075 100644 (file)
@@ -22,6 +22,7 @@ using std::ofstream;
 #endif
 
 List<aClient> players;
+
 Monster *monsters[LEVELS][MONSTERS];   // Monsters per level. Total = MONSTERS * LEVELS
 
 Monster *masters[LEVELS];              // A master for each level
@@ -136,8 +137,12 @@ void gameserv(char *source, char *buf)
     char *cmd;
     cmd = strtok(buf, " ");
 
-    source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
-    cmd++;    // Get rid of that : at the beginning of the :text  (command)
+    #ifndef P10
+        source++; // Get rid of that : at the beginning of a :Nick privmsg Gameserv :text
+    #endif
+
+    if (cmd[0] == ':')
+        cmd++;    // Get rid of that : at the beginning of the :text  (command)
 
     #ifdef DEBUGMODE
        log("Source: %s  Command: %s", source, cmd);
@@ -195,6 +200,13 @@ void gameserv(char *source, char *buf)
        do_tavern(source);
     } else if (stricmp(cmd, "LIST") == 0) {
        do_list(source);
+    #ifdef DEBUGMODE
+    } else if (stricmp(cmd, "PRINT") == 0) {
+       cout << "Printing the clients list:" << endl;
+       clients.print();
+       cout << "\nPrinting the players list:" << endl;
+       players.print();
+    #endif
     } else if (stricmp(cmd, "REGISTER") == 0) {
        do_register(source);
     } else if (stricmp(cmd, "IDENTIFY") == 0) {
@@ -209,9 +221,7 @@ void gameserv(char *source, char *buf)
        if (!(user = find(source)))
        {
            notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
-           #ifdef DEBUGMODE
                log("Error: aClient not found: %s", source);
-           #endif
        }
        else if (!isAdmin(user))
        {
@@ -220,7 +230,11 @@ void gameserv(char *source, char *buf)
        else
        {
            save_gs_dbase();
-           raw("SQUIT %s :leaving", servername);
+           #ifdef P10
+               raw("SQ %s 0 :leaving", servername);
+           #else
+               raw("SQUIT %s :leaving", servername);
+           #endif
        }
     } else if (stricmp(cmd, "SAVE") == 0) {
        aClient *user;
@@ -228,9 +242,7 @@ void gameserv(char *source, char *buf)
        if (!(user = find(source)))
        {
            notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
-           #ifdef DEBUGMODE
                log("Error: aClient not found: %s", source);
-           #endif
        }
        else if (!isAdmin(user))
        {
@@ -246,9 +258,7 @@ void gameserv(char *source, char *buf)
        if (!(user = find(source)))
        {
            notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
-           #ifdef DEBUGMODE
-               log("Error: aClient not found: %s", source);
-           #endif
+           log("Error: aClient not found: %s", source);
        }
        else if (!isAdmin(user))
        {
@@ -276,9 +286,7 @@ void gameserv(char *source, char *buf)
        if (!(user = find(source)))
        {
            notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
-           #ifdef DEBUGMODE
                log("Error: aClient not found: %s", source);
-           #endif
        }
        else if (!isAdmin(user))
        {
@@ -428,11 +436,23 @@ void notice(const char *source, const char *dest, const char *fmt, ...)
     if (dest[0] == ':')
     {
        dest++;
+
+      #if !defined(P10)
        sprintf(input, ":%s NOTICE %s :", source, dest);
+      #else
+       sprintf(input, "%s O %s :", gsnum, dest);
+      #endif
+
        dest--;
     }
     else
+    {
+      #if !defined(P10)
        sprintf(input, ":%s NOTICE %s :", source, dest);
+      #else
+       sprintf(input, "%s O %s :", gsnum, dest);
+      #endif
+    }
 
     for (; *t; t++)
     {
@@ -521,8 +541,9 @@ void do_list(char *u)
 
 void do_register(char *u)
 {
-    char *password;
+    char *password, *name;
     aClient *user, *p;
+    name = strtok(NULL, " ");
     password = strtok(NULL, " ");
 
     static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
@@ -532,9 +553,13 @@ void do_register(char *u)
     salt[1] = saltChars[rand() % strlen(saltChars)];
     salt[2] = '\0';
 
-    if (!password)
+    if (!name)
     {
-       notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
+       notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
+    }
+    else if (!password)
+    {
+       notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
     }
     else if ((user = find(u)))
     {
@@ -544,9 +569,11 @@ void do_register(char *u)
            user->stats = new Player(user);
            user->stats->user = user; // Set the backwards pointer
            strcpy(user->stats->password, crypt(password, salt));
+           strcpy(user->stats->name, name);
            players.insertAtBack(user);
            notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password);
            notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
+           log("Nickname %s registered player %s.", u, user->stats->name);
        }
        else
        {
@@ -567,7 +594,10 @@ void do_identify(char *u)
        notice(s_GameServ, u, "SYNTAX: /msg %S IDENTIFY NAME PASSWORD");
     }
     else if (!user)
-           notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
+    {
+       notice(s_GameServ, u, "Fatal error. Cannot find aClient. Buf: %s", strtok(NULL, ""));
+       log("Error: aClient not found: %s", u);
+    }
     else if (!(p = findplayer(name)) || !p->stats)
            notice(s_GameServ, u, "Player %s not found", name);
     else if (!check_password(name, password) && !isAdmin(user))
@@ -625,6 +655,7 @@ void do_stats(char *u)
        if (!(user = find(u)))
        {
            notice(s_GameServ, u, "Fatal Error in do_stats(). Contact a %S admin for help!");
+           log("Error: aClient not found: %s", u);
            return;
        }
        else if (!is_playing(user))
@@ -640,8 +671,16 @@ void do_stats(char *u)
 }
 void init_masters()
 {
+    #ifdef DEBUGMODE
+       log("Calling delete_masters()");
+    #endif
+
     delete_masters();
 
+    #ifdef DEBUGMODE
+       log("Initializing masters");
+    #endif
+
     for (int x = 0; x < LEVELS; x++)
        masters[x] = new Monster;
 
@@ -750,7 +789,12 @@ void init_masters()
 
 void init_monsters()
 {
+    #ifdef DEBUGMODE
+       log("Calling delete_monsters");
+    #endif
+
     delete_monsters();
+
     for (int x = 0; x < LEVELS; x++)
        for (int y = 0; y < MONSTERS; y++)
            monsters[x][y] = new Monster();
@@ -3604,9 +3648,7 @@ void do_refresh(char *u)
     if (!(user = find(u)))
     {
        notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
-       #ifdef DEBUGMODE
-           log("Error: aClient not found: %s", u);
-       #endif
+       log("Error: aClient not found: %s", u);
        return;
     }
     else if (!isAdmin(user))
@@ -3675,9 +3717,7 @@ void do_reset(char *u)
     if (!(user = find(u)))
     {
        notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
-       #ifdef DEBUGMODE
-           log("Error: aClient not found: %s", u);
-       #endif
+       log("Error: aClient not found: %s", u);
        return;
     }
     else if (!isAdmin(user))
@@ -3784,9 +3824,7 @@ void do_admin(char *u)
 
     if (!(user = find(u)))
     {
-       #ifdef DEBUGMODE
-           log("Error: aClient not found: %s", u);
-       #endif
+       log("Error: aClient not found: %s", u);
        notice(s_GameServ, u, "Error: aClient not found. Contact %S admin.");
        return;
     }
@@ -3805,6 +3843,7 @@ void do_admin(char *u)
     {
        notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
        setAdmin(user);
+       log("%s became an administrator.", user->getNick());
     }
     else
     {
@@ -3828,6 +3867,10 @@ bool load_monsters()
     init_monsters();
     buf = new char[2048];
 
+    #ifdef DEBUGMODE
+       log("Loading monsters from monsters.dat");
+    #endif
+
   for (int l = 0; l < REALLEVELS; l++)
   {
     for (int m = 0; m < MONSTERS;)