+#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>
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);
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();
} 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
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)
}
// Minor recursion
- display_help(u, "admin");
+ aClient *user = find(u);
+ if (user && isAdmin(user))
+ display_help(u, "admin_commands");
}
else
{
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;
+ }
+}