]> jfr.im git - irc/gameservirc.git/commitdiff
Added flags to the aClient structure to keep track of given client attributes. Switch...
authorkainazzzo <redacted>
Thu, 30 Oct 2003 19:07:20 +0000 (19:07 +0000)
committerkainazzzo <redacted>
Thu, 30 Oct 2003 19:07:20 +0000 (19:07 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@46 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/Makefile.in
gameserv/aClient.cpp
gameserv/aClient.h
gameserv/gameserv.cpp
gameserv/helpfiles/admin
gameserv/helpfiles/help
gameserv/helpfiles/load
gameserv/helpfiles/raw
gameserv/helpfiles/refresh
gameserv/helpfiles/save
gameserv/helpfiles/shutdown

index 97dd8548d96fd55b57bfcaf61a5be684a5bd6f4f..f95de0bbbf102cbd7d4306d9ca68998ad9e9b792 100644 (file)
@@ -44,7 +44,7 @@ sockhelp.o:   sockhelp.cpp aClient.h player.h extern.h  list.h listnode.h  sockhel
 aClient.o:     aClient.cpp aClient.h player.h extern.h  list.h listnode.h sockhelp.h
        $(CC) $(CFLAGS) -c aClient.cpp
 
 aClient.o:     aClient.cpp aClient.h player.h extern.h  list.h listnode.h sockhelp.h
        $(CC) $(CFLAGS) -c aClient.cpp
 
-gameserv.o:    gameserv.cpp aClient.h player.h extern.h list.h\
+gameserv.o:    gameserv.cpp aClient.h player.h extern.h flags.h list.h\
                listnode.h sockhelp.h
        $(CC) $(CFLAGS) -c gameserv.cpp
 
                listnode.h sockhelp.h
        $(CC) $(CFLAGS) -c gameserv.cpp
 
index e95c33243f620b13280d7757a7b75173e6c93ae5..64884d39117cdb276351894edf446954ab348abd 100644 (file)
@@ -8,6 +8,7 @@ aClient::aClient(char *n)
         << (n[0] == '\0' ? "NULL" : n) << endl;
     strcpy(nick, n);
     stats = NULL;
         << (n[0] == '\0' ? "NULL" : n) << endl;
     strcpy(nick, n);
     stats = NULL;
+    flags = 0;
 }
 
 aClient::aClient(const aClient &right)
 }
 
 aClient::aClient(const aClient &right)
@@ -15,12 +16,14 @@ aClient::aClient(const aClient &right)
     cout << "aClient created from another aClient: " << right.nick 
         << endl;
     stats = NULL;
     cout << "aClient created from another aClient: " << right.nick 
         << endl;
     stats = NULL;
+    flags = 0;
     setData(&right);
 }
 
 aClient::aClient()
 {
     aClient("");
     setData(&right);
 }
 
 aClient::aClient()
 {
     aClient("");
+    flags = 0;
 }
 
 aClient::~aClient()
 }
 
 aClient::~aClient()
@@ -31,6 +34,7 @@ aClient::~aClient()
        cout << ' ' << stats->name << ' ' << stats->password << endl << flush;
        delete stats;
     }
        cout << ' ' << stats->name << ' ' << stats->password << endl << flush;
        delete stats;
     }
+    flags = 0;
     cout << endl << flush;
 }
 
     cout << endl << flush;
 }
 
@@ -55,3 +59,21 @@ void aClient::setData(const aClient *right)
        }
     }
 }
        }
     }
 }
+
+long int aClient::setFlags(long int newflags)
+{
+    flags = newflags;
+    return getFlags();
+}
+
+long int aClient::addFlag(long int flag)
+{
+    flags |= flag;
+    return getFlags();
+}
+
+long int aClient::remFlag(long int flag)
+{
+    flags &= ~flag;
+    return getFlags();
+}
index da007b6fc6b40c0673abc7574de3ef8ac1bfd93f..05c3bbd4011d6aa06b950e6140adc1f910b3e36d 100644 (file)
@@ -13,19 +13,29 @@ class aClient {
        friend ostream &operator<<( ostream &output, const aClient &c);
 
     public:
        friend ostream &operator<<( ostream &output, const aClient &c);
 
     public:
-        aClient(char *);
-       aClient(const aClient &);
-        aClient();
-        ~aClient();
+        aClient(char *);               // Constructor takes a char for the nick
+       aClient(const aClient &);       // Copy constructor
+        aClient();                     // Default constructor
+        ~aClient();                    // Destructor
 
 
+       // Sets the client's player struct data to the same thing as another aClient's 
+       // player struct data
        void setData(const aClient *);
        void setData(const aClient *);
-        void setNick(char *n) { strcpy(nick, n);};
-        //const char *getNick() { return nick; };
-        char *getNick() { return nick; };
-       Player *stats;
+
+        void setNick(char *n) { strcpy(nick, n);};     // Sets the client's nick
+        char *getNick() { return nick; };              // Returns the client's nick
+       Player *stats;                                  // Pointer to the client's player struct
+
+       long int getFlags() { return flags; };          // Returns the Client's current flags
+
+       // Functions also return the flags after modifying them
+       long int setFlags(long int);    // Sets the clients flags to a new value
+       long int addFlag(long int);     // Adds a flag to the client's flags
+       long int remFlag(long int);     // Removes a flag from the client's current flags
 
     private:
 
     private:
-        char nick[32];
+        char nick[32];         // Client's current nickname.
+       long int flags;         // Client's current flags.
 };
 
 #endif
 };
 
 #endif
index 0dafb9e62c640afe06390fc022f320cd48f92f89..90379fa3c5ac8e70917e1ae1e57db4a2ff2bbf1c 100644 (file)
@@ -1,8 +1,10 @@
+#include "aClient.h"
 #include "config.h"
 #include "extern.h"
 #include "config.h"
 #include "extern.h"
-#include "sockhelp.h"
-#include "aClient.h"
+#include "flags.h"
 #include "list.h"
 #include "list.h"
+#include "sockhelp.h"
+
 #include <cctype>
 #include <fstream.h>
 
 #include <cctype>
 #include <fstream.h>
 
@@ -72,6 +74,7 @@ void init_monsters();
 void delete_monsters();
 void delete_masters();
 
 void delete_monsters();
 void delete_masters();
 
+void do_admin(char *u);
 void do_attack(char *u);
 void do_bank(char *u);
 void do_fight(char *u);
 void do_attack(char *u);
 void do_bank(char *u);
 void do_fight(char *u);
@@ -159,16 +162,10 @@ void gameserv(char *source, char *buf)
        do_store(source);
     } else if (stricmp(cmd, "BANK") == 0) {
        do_bank(source);
        do_store(source);
     } else if (stricmp(cmd, "BANK") == 0) {
        do_bank(source);
+    } else if (stricmp(cmd, "ADMIN") == 0) {
+       do_admin(source);
     } else if (stricmp(cmd, "REFRESH") == 0) {
     } else if (stricmp(cmd, "REFRESH") == 0) {
-       char *pass = strtok(NULL, " ");
-       if (pass != NULL && (stricmp(pass, adminpass) == 0))
-       {
-           do_refresh(source);
-       }
-       else
-       {
-           notice(s_GameServ, source, "SYNTAX: /msg %S REFRESH <password> {ALL | NICK}");
-       }
+       do_refresh(source);
     } else if (stricmp(cmd, "PRINT") == 0) {
        cout << "Printing Clients List: " << endl;
        clients.print();
     } else if (stricmp(cmd, "PRINT") == 0) {
        cout << "Printing Clients List: " << endl;
        clients.print();
@@ -185,47 +182,71 @@ void gameserv(char *source, char *buf)
     } else if (stricmp(cmd, "STATS") == 0) {
        do_stats(source);
     } else if (stricmp(cmd, "SHUTDOWN") == 0) {
     } else if (stricmp(cmd, "STATS") == 0) {
        do_stats(source);
     } else if (stricmp(cmd, "SHUTDOWN") == 0) {
-       char *pass = strtok(NULL, " ");
-       if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       aClient *user;
+
+       if (!(user = find(source)))
        {
        {
-           save_gs_dbase();
-           raw("SQUIT %s :leaving", servername);
+           notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
+           cout << "Error: aClient not found: " << source << endl;
+       }
+       else if (!isAdmin(user))
+       {
+           notice(s_GameServ, source, "You must be a %S admin to use this command!");
        }
        else
        {
        }
        else
        {
-           notice(s_GameServ, source, "SYNTAX: /msg %S SHUTDOWN <password>");
+           save_gs_dbase();
+           raw("SQUIT %s :leaving", servername);
        }
     } else if (stricmp(cmd, "SAVE") == 0) {
        }
     } else if (stricmp(cmd, "SAVE") == 0) {
-        char *pass = strtok(NULL, " ");
-        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       aClient *user;
+
+       if (!(user = find(source)))
+       {
+           notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
+           cout << "Error: aClient not found: " << source << endl;
+       }
+       else if (!isAdmin(user))
+       {
+           notice(s_GameServ, source, "You must be a %S admin to use this command!");
+       }
+       else
         {
            save_gs_dbase();
         }
         {
            save_gs_dbase();
         }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S SAVE <password>");
-        }
     } else if (stricmp(cmd, "LOAD") == 0) {
     } else if (stricmp(cmd, "LOAD") == 0) {
-        char *pass = strtok(NULL, " ");
-        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       aClient *user;
+
+       if (!(user = find(source)))
+       {
+           notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
+           cout << "Error: aClient not found: " << source << endl;
+       }
+       else if (!isAdmin(user))
+       {
+           notice(s_GameServ, source, "You must be a %S admin to use this command!");
+       }
+       else
         {
            load_gs_dbase();
        }
         {
            load_gs_dbase();
        }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S LOAD <password>");
-        }
     } else if (stricmp(cmd, "RAW") == 0) {
     } else if (stricmp(cmd, "RAW") == 0) {
-        char *pass = strtok(NULL, " ");
-        if (pass != NULL && (stricmp(pass, adminpass) == 0))
+       aClient *user;
+
+       if (!(user = find(source)))
+       {
+           notice(s_GameServ, source, "Error: aClient not found. Contact a %S admin");
+           cout << "Error: aClient not found: " << source << endl;
+       }
+       else if (!isAdmin(user))
+       {
+           notice(s_GameServ, source, "You must be a %S admin to use this command!");
+       }
+       else
         {
            char *rest = strtok(NULL, "");
            raw("%s", rest);
        }
         {
            char *rest = strtok(NULL, "");
            raw("%s", rest);
        }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S RAW <password> <raw>");
-        }
     } 
 
    source--;  // Bring the ':' back so we don't leak memory
     } 
 
    source--;  // Bring the ':' back so we don't leak memory
@@ -3058,9 +3079,20 @@ void do_refresh(char *u)
     char *nick = strtok(NULL, " ");
     aClient *user;
 
     char *nick = strtok(NULL, " ");
     aClient *user;
 
+    if (!(user = find(u)))
+    {
+       notice(s_GameServ, u, "Error: aClient not found. Contact a %S admin");
+       cout << "Error: aClient not found: " << u << endl;
+       return;
+    }
+    else if (!isAdmin(user))
+    {
+       notice(s_GameServ, u, "You must be a %S admin to use this command!");
+       return;
+    }
     if (!nick)
     {
     if (!nick)
     {
-       notice(s_GameServ, u, "SYNTAX: REFRESH <password> {ALL | NICK}");
+       notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}");
        return;
     }
     else if (stricmp(nick, "ALL") == 0)
        return;
     }
     else if (stricmp(nick, "ALL") == 0)
@@ -3120,7 +3152,9 @@ void display_help(char *u, char *file)
        }
 
        // Minor recursion
        }
 
        // Minor recursion
-       display_help(u, "admin");
+       aClient *user = find(u);
+       if (user && isAdmin(user))
+           display_help(u, "admin_commands");
     }
     else
     {
     }
     else
     {
@@ -3145,3 +3179,32 @@ void display_help(char *u, char *file)
     infile.close();
     delete [] buf;
 }
     infile.close();
     delete [] buf;
 }
+
+void do_admin(char *u)
+{
+    aClient *user;
+    char *pass = strtok(NULL, " ");
+
+    if (!(user = find(u)))
+    {
+       cout << "Error: aClient not found: " << u << endl;
+       notice(s_GameServ, u, "Error: aClient not found. Contact %S admin.");
+       return;
+    }
+    if (!pass)
+    {
+       notice(s_GameServ, u, "SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2");
+       return;
+    }
+
+    if (strcmp(pass, adminpass) == 0)
+    {
+       notice(s_GameServ, u, "Password accepted. You now have administrator privledges.");
+       setAdmin(user);
+    }
+    else
+    {
+       notice(s_GameServ, u, "Invalid password. Remember: case sensitive");
+       return;
+    }
+}
index c3c20c51e31be3ebd65fc0ce74b23364d1e2decf..d3605dab5126163e828c2b2c74f38dd4bf968a1f 100644 (file)
@@ -1,13 +1,7 @@
-The following commands are available to %S administrators:
+This command enables you to identify yourself as a(n) %S administrator.
+After you identify this way, you can perform all administrator commands listed in:
+/msg %S \ 2HELP\ 2 \ 2\1fadmin_commands\1f\ 2
+-
+SYNTAX: \ 2ADMIN\ 2 \ 2\1fpassword\1f\ 2
+Example: /msg %S \ 2ADMIN\ 2 \ 2\1ffakepass\1f\ 2
 
 
-    \ 2REFRESH\ 2        \1fRefresh one or all players in the realm\1f
-    \ 2SHUTDOWN\ 2       \1fShut down %S and save data\1f
-    \ 2SAVE\ 2           \1fManually save the %S database\1f
-    \ 2LOAD\ 2           \1fManually load the %S database\1f
-    \ 2RAW\ 2            \1fSend a raw string through the pseudo server (CAREFUL)\1f
-
-All %S administrative commands require the use of an administrator password.
-
-SYNTAX: \ 2COMMAND\ 2 \ 2\1fpassword\1f\ 2 \ 2\1fparameters\1f\ 2
-
-Further help on individual commands can be accessed by typing /msg %S \ 2HELP\ 2 \ 2\1fcommand\1f\ 2
index ba7402ef9929a6a95f3f9395645b8068e82638e0..fc72d2b48f739eacfcdd816c34264f9c294f51f9 100644 (file)
@@ -2,18 +2,19 @@ Welcome to %S!
 
 Here are the basic commands available to everyone:
 
 
 Here are the basic commands available to everyone:
 
-    \ 2HELP\ 2            \1fBrings up this help menu\1f
-    \ 2LIST\ 2            \1fList who is currently in the realm\1f
-    \ 2SEARCH\ 2          \1fSearch the forest for a monster to kill\1f
     \ 2ATTACK\ 2          \1fAttack with your weapon while in battle\1f
     \ 2ATTACK\ 2          \1fAttack with your weapon while in battle\1f
-    \ 2RUN\ 2             \1fFlee from battle to save yourself\1f
-    \ 2FIGHT\ 2           \1fFight another player in the realm\1f
+    \ 2ADMIN\ 2           \1fIdentify yourself as a gameserv administrator\1f
     \ 2BANK\ 2            \1fWithdraw and deposit gold from your bank account\1f
     \ 2BANK\ 2            \1fWithdraw and deposit gold from your bank account\1f
+    \ 2FIGHT\ 2           \1fFight another player in the realm\1f
     \ 2HEAL\ 2            \1fHeal yourself. Replenishes Hit points\1f
     \ 2HEAL\ 2            \1fHeal yourself. Replenishes Hit points\1f
-    \ 2STORE\ 2           \1fBuy and Sell weapons and armor\1f
+    \ 2HELP\ 2            \1fBrings up this help menu\1f
+    \ 2IDENTIFY\ 2        \1fIdentify yourself with a previously registered login\1f
+    \ 2LIST\ 2            \1fList who is currently in the realm\1f
     \ 2MASTER\ 2          \1fQuestion and fight your master to gain a level\1f
     \ 2REGISTER\ 2        \1fRegister a login and join the realm\1f
     \ 2MASTER\ 2          \1fQuestion and fight your master to gain a level\1f
     \ 2REGISTER\ 2        \1fRegister a login and join the realm\1f
-    \ 2IDENTIFY\ 2        \1fIdentify yourself with a previously registered login\1f
+    \ 2RUN\ 2             \1fFlee from battle to save yourself\1f
+    \ 2SEARCH\ 2          \1fSearch the forest for a monster to kill\1f
     \ 2STATS\ 2           \1fGet a stats listing of you or another player in the realm\1f
     \ 2STATS\ 2           \1fGet a stats listing of you or another player in the realm\1f
+    \ 2STORE\ 2           \1fBuy and Sell weapons and armor\1f
 
 Further help on individual commands can be accessed by typing /msg %S \ 2HELP\ 2 \ 2\1fcommand\1f\ 2
 
 Further help on individual commands can be accessed by typing /msg %S \ 2HELP\ 2 \ 2\1fcommand\1f\ 2
index 59ee6716102f62ae69cfbfcd31d80cca5b762769..22b510f202f8a0453ef5762e4242d0a846fe732e 100644 (file)
@@ -1,3 +1,3 @@
 This command manually loads the %S database file with all player stats.
 This command manually loads the %S database file with all player stats.
-SYNTAX: \ 2LOAD\ 2 \ 2\1fadminpassword\1f\ 2
-Example: /msg %S \ 2LOAD\ 2 \ 2\1fadminpassword\1f\ 2
+SYNTAX: \ 2LOAD\ 2
+Example: /msg %S \ 2LOAD\ 2
index db5446634d015458e413b4430a2e9d1ef9eb79aa..fccfa8d28a5b0e297b6e48cba5b140c775dd0356 100644 (file)
@@ -1,3 +1,3 @@
 Sends a string of unformatted text to the uplink via %S's server link.
 Sends a string of unformatted text to the uplink via %S's server link.
-SYNTAX: \ 2RAW \1fpassword\1f \1ftext\1f\ 2
-Example: /msg %S \ 2RAW\ 2 \1ffakepass\1f :%S PRIVMSG #Channel :Hello Everyone :)
+SYNTAX: \ 2RAW \1ftext\1f\ 2
+Example: /msg %S \ 2RAW\ 2 :%S PRIVMSG #Channel :Hello Everyone :)
index f967f4bfaffc71113d265fe761c8c8498a3e7e5c..bf1a1f3b70601338569ad5a1250497354834ae27 100644 (file)
@@ -1,5 +1,5 @@
 This command refreshes all or one of the people playing in the realm.
 Forest fights, player fights, master fight, and your hit points are maxed out.
 This command refreshes all or one of the people playing in the realm.
 Forest fights, player fights, master fight, and your hit points are maxed out.
-SYNTAX: \ 2REFRESH\ 2 \ 2\1fadminpassword\1f\ 2 {\ 2\1fALL\1f\ 2 | \ 2\1fNICK\1f\ 2}
-Example: /msg %S \ 2REFRESH\ 2 \ 2\1fadminpassword\1f\ 2 \ 2\1fall\1f\ 2
-Example: /msg %S \ 2REFRESH\ 2 \ 2\1fadminpassword\1f\ 2 \ 2\1fkiller\1f\ 2
+SYNTAX: \ 2REFRESH\ 2 {\ 2\1fALL\1f\ 2 | \ 2\1fNICK\1f\ 2}
+Example: /msg %S \ 2REFRESH\ 2 \ 2\1fall\1f\ 2
+Example: /msg %S \ 2REFRESH\ 2 \ 2\1fkiller\1f\ 2
index c32d5412c4e234ed87cef24c569007c58b4b33d9..7347c36d7dae94de4f0215fc0c094a1c1b9b036d 100644 (file)
@@ -1,3 +1,3 @@
 This command manually saves the %S players' statistical database.
 This command manually saves the %S players' statistical database.
-SYNTAX: \ 2SAVE\ 2 \ 2\1fadminpass\1f\ 2
-Example: /msg %S \ 2SAVE\ 2 \ 2\1fadminpass\1f\ 2
+SYNTAX: \ 2SAVE\ 2
+Example: /msg %S \ 2SAVE\ 2
index 52b360450a2253a3c837dd85d1816a7ea4a3d37d..ea3a33982a1861ed1f15c8a3f3d4d2f23ae5a08c 100644 (file)
@@ -1,3 +1,3 @@
 This command shuts down %S while saving the database of player statistics for later.
 This command shuts down %S while saving the database of player statistics for later.
-SYNTAX: \ 2SHUTDOWN\ 2 \ 2\1fadminpass\1f\ 2
-Example: /msg %S \ 2SHUTDOWN\ 2 \ 2\1fadminpass\1f\ 2
+SYNTAX: \ 2SHUTDOWN\ 2
+Example: /msg %S \ 2SHUTDOWN\ 2