]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/gameserv.cpp
Added flags to the aClient structure to keep track of given client attributes. Switch...
[irc/gameservirc.git] / gameserv / gameserv.cpp
index 0dafb9e62c640afe06390fc022f320cd48f92f89..90379fa3c5ac8e70917e1ae1e57db4a2ff2bbf1c 100644 (file)
@@ -1,8 +1,10 @@
+#include "aClient.h"
 #include "config.h"
 #include "extern.h"
-#include "sockhelp.h"
-#include "aClient.h"
+#include "flags.h"
 #include "list.h"
+#include "sockhelp.h"
+
 #include <cctype>
 #include <fstream.h>
 
@@ -72,6 +74,7 @@ void init_monsters();
 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);
@@ -159,16 +162,10 @@ void gameserv(char *source, char *buf)
        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) {
-       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();
@@ -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) {
-       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
        {
-           notice(s_GameServ, source, "SYNTAX: /msg %S SHUTDOWN <password>");
+           save_gs_dbase();
+           raw("SQUIT %s :leaving", servername);
        }
     } 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();
         }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S SAVE <password>");
-        }
     } 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();
        }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S LOAD <password>");
-        }
     } 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);
        }
-        else
-        {
-            notice(s_GameServ, source, "SYNTAX: /msg %S RAW <password> <raw>");
-        }
     } 
 
    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;
 
+    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)
     {
-       notice(s_GameServ, u, "SYNTAX: REFRESH <password> {ALL | NICK}");
+       notice(s_GameServ, u, "SYNTAX: REFRESH {ALL | NICK}");
        return;
     }
     else if (stricmp(nick, "ALL") == 0)
@@ -3120,7 +3152,9 @@ void display_help(char *u, char *file)
        }
 
        // Minor recursion
-       display_help(u, "admin");
+       aClient *user = find(u);
+       if (user && isAdmin(user))
+           display_help(u, "admin_commands");
     }
     else
     {
@@ -3145,3 +3179,32 @@ void display_help(char *u, char *file)
     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;
+    }
+}