From: kainazzzo Date: Thu, 30 Oct 2003 19:07:20 +0000 (+0000) Subject: Added flags to the aClient structure to keep track of given client attributes. Switch... X-Git-Url: https://jfr.im/git/irc/gameservirc.git/commitdiff_plain/96f71fee914dfe6be488b27f2f66a59cf3d901ff?hp=9cc5ab579f517bb3601928b22552b4ac41ffb054 Added flags to the aClient structure to keep track of given client attributes. Switched the gameserv admin functions to make use of the new system. git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@46 bc333340-6410-0410-a689-9d09f3c113fa --- diff --git a/gameserv/Makefile.in b/gameserv/Makefile.in index 97dd854..f95de0b 100644 --- a/gameserv/Makefile.in +++ b/gameserv/Makefile.in @@ -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 -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 diff --git a/gameserv/aClient.cpp b/gameserv/aClient.cpp index e95c332..64884d3 100644 --- a/gameserv/aClient.cpp +++ b/gameserv/aClient.cpp @@ -8,6 +8,7 @@ aClient::aClient(char *n) << (n[0] == '\0' ? "NULL" : n) << endl; strcpy(nick, n); stats = NULL; + flags = 0; } 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; + flags = 0; setData(&right); } aClient::aClient() { aClient(""); + flags = 0; } aClient::~aClient() @@ -31,6 +34,7 @@ aClient::~aClient() cout << ' ' << stats->name << ' ' << stats->password << endl << flush; delete stats; } + flags = 0; 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(); +} diff --git a/gameserv/aClient.h b/gameserv/aClient.h index da007b6..05c3bbd 100644 --- a/gameserv/aClient.h +++ b/gameserv/aClient.h @@ -13,19 +13,29 @@ class aClient { 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 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: - char nick[32]; + char nick[32]; // Client's current nickname. + long int flags; // Client's current flags. }; #endif diff --git a/gameserv/gameserv.cpp b/gameserv/gameserv.cpp index 0dafb9e..90379fa 100644 --- a/gameserv/gameserv.cpp +++ b/gameserv/gameserv.cpp @@ -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 #include @@ -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 {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 "); + 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 "); - } } 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 "); - } } 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 "); - } } 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 {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: ADMIN password"); + 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; + } +} diff --git a/gameserv/helpfiles/admin b/gameserv/helpfiles/admin index c3c20c5..d3605da 100644 --- a/gameserv/helpfiles/admin +++ b/gameserv/helpfiles/admin @@ -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 HELP admin_commands +- +SYNTAX: ADMIN password +Example: /msg %S ADMIN fakepass - REFRESH Refresh one or all players in the realm - SHUTDOWN Shut down %S and save data - SAVE Manually save the %S database - LOAD Manually load the %S database - RAW Send a raw string through the pseudo server (CAREFUL) - -All %S administrative commands require the use of an administrator password. - -SYNTAX: COMMAND password parameters - -Further help on individual commands can be accessed by typing /msg %S HELP command diff --git a/gameserv/helpfiles/help b/gameserv/helpfiles/help index ba7402e..fc72d2b 100644 --- a/gameserv/helpfiles/help +++ b/gameserv/helpfiles/help @@ -2,18 +2,19 @@ Welcome to %S! Here are the basic commands available to everyone: - HELP Brings up this help menu - LIST List who is currently in the realm - SEARCH Search the forest for a monster to kill ATTACK Attack with your weapon while in battle - RUN Flee from battle to save yourself - FIGHT Fight another player in the realm + ADMIN Identify yourself as a gameserv administrator BANK Withdraw and deposit gold from your bank account + FIGHT Fight another player in the realm HEAL Heal yourself. Replenishes Hit points - STORE Buy and Sell weapons and armor + HELP Brings up this help menu + IDENTIFY Identify yourself with a previously registered login + LIST List who is currently in the realm MASTER Question and fight your master to gain a level REGISTER Register a login and join the realm - IDENTIFY Identify yourself with a previously registered login + RUN Flee from battle to save yourself + SEARCH Search the forest for a monster to kill STATS Get a stats listing of you or another player in the realm + STORE Buy and Sell weapons and armor Further help on individual commands can be accessed by typing /msg %S HELP command diff --git a/gameserv/helpfiles/load b/gameserv/helpfiles/load index 59ee671..22b510f 100644 --- a/gameserv/helpfiles/load +++ b/gameserv/helpfiles/load @@ -1,3 +1,3 @@ This command manually loads the %S database file with all player stats. -SYNTAX: LOAD adminpassword -Example: /msg %S LOAD adminpassword +SYNTAX: LOAD +Example: /msg %S LOAD diff --git a/gameserv/helpfiles/raw b/gameserv/helpfiles/raw index db54466..fccfa8d 100644 --- a/gameserv/helpfiles/raw +++ b/gameserv/helpfiles/raw @@ -1,3 +1,3 @@ Sends a string of unformatted text to the uplink via %S's server link. -SYNTAX: RAW password text -Example: /msg %S RAW fakepass :%S PRIVMSG #Channel :Hello Everyone :) +SYNTAX: RAW text +Example: /msg %S RAW :%S PRIVMSG #Channel :Hello Everyone :) diff --git a/gameserv/helpfiles/refresh b/gameserv/helpfiles/refresh index f967f4b..bf1a1f3 100644 --- a/gameserv/helpfiles/refresh +++ b/gameserv/helpfiles/refresh @@ -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. -SYNTAX: REFRESH adminpassword {ALL | NICK} -Example: /msg %S REFRESH adminpassword all -Example: /msg %S REFRESH adminpassword killer +SYNTAX: REFRESH {ALL | NICK} +Example: /msg %S REFRESH all +Example: /msg %S REFRESH killer diff --git a/gameserv/helpfiles/save b/gameserv/helpfiles/save index c32d541..7347c36 100644 --- a/gameserv/helpfiles/save +++ b/gameserv/helpfiles/save @@ -1,3 +1,3 @@ This command manually saves the %S players' statistical database. -SYNTAX: SAVE adminpass -Example: /msg %S SAVE adminpass +SYNTAX: SAVE +Example: /msg %S SAVE diff --git a/gameserv/helpfiles/shutdown b/gameserv/helpfiles/shutdown index 52b3604..ea3a339 100644 --- a/gameserv/helpfiles/shutdown +++ b/gameserv/helpfiles/shutdown @@ -1,3 +1,3 @@ This command shuts down %S while saving the database of player statistics for later. -SYNTAX: SHUTDOWN adminpass -Example: /msg %S SHUTDOWN adminpass +SYNTAX: SHUTDOWN +Example: /msg %S SHUTDOWN