From: kainazzzo Date: Mon, 22 Jan 2007 04:52:34 +0000 (+0000) Subject: Added do_register.cpp, do_identify.cpp, do_list.cpp, do_help.cpp, do_refresh.cpp... X-Git-Url: https://jfr.im/git/irc/gameservirc.git/commitdiff_plain/0bbd37a7c2c3c7a634faa6f9d536e5a50d496c6f?hp=585b7bdee94740677f19c9c609cd626fdc0bc1b1 Added do_register.cpp, do_identify.cpp, do_list.cpp, do_help.cpp, do_refresh.cpp, and do_heal.cpp Updated dependencies git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@476 bc333340-6410-0410-a689-9d09f3c113fa --- diff --git a/gameserv/.depend b/gameserv/.depend index 7041eb1..2baf48e 100644 --- a/gameserv/.depend +++ b/gameserv/.depend @@ -16,6 +16,19 @@ do_equip.o: do_equip.cpp extern.h config.h options.h aClient.h player.h \ script.h pouch.h item.h level.h flags.h do_fight.o: do_fight.cpp extern.h config.h options.h aClient.h player.h \ script.h flags.h +do_heal.o: do_heal.cpp extern.h config.h options.h aClient.h player.h \ + script.h flags.h +do_help.o: do_help.cpp extern.h config.h options.h +do_identify.o: do_identify.cpp extern.h config.h options.h aClient.h \ + player.h script.h flags.h +do_inventory.o: do_inventory.cpp extern.h config.h options.h aClient.h \ + player.h script.h flags.h +do_list.o: do_list.cpp extern.h config.h options.h player.h script.h \ + aClient.h flags.h toplist.h +do_refresh.o: do_refresh.cpp extern.h config.h options.h aClient.h \ + player.h script.h flags.h +do_register.o: do_register.cpp extern.h config.h options.h aClient.h \ + player.h script.h flags.h pouch.h item.h level.h toplist.h find.o: find.cpp extern.h config.h options.h item.h level.h player.h \ script.h gameserv.o: gameserv.cpp aClient.h options.h player.h script.h config.h \ diff --git a/gameserv/Makefile.in b/gameserv/Makefile.in index 957984b..adf6fe8 100644 --- a/gameserv/Makefile.in +++ b/gameserv/Makefile.in @@ -31,6 +31,13 @@ TSRCS = aClient.cpp \ do_check.cpp \ do_equip.cpp \ do_fight.cpp \ + do_heal.cpp \ + do_help.cpp \ + do_identify.cpp \ + do_inventory.cpp \ + do_list.cpp \ + do_refresh.cpp \ + do_register.cpp \ find.cpp \ gameserv.cpp \ hash.cpp \ diff --git a/gameserv/do_heal.cpp b/gameserv/do_heal.cpp new file mode 100644 index 0000000..dac5cb2 --- /dev/null +++ b/gameserv/do_heal.cpp @@ -0,0 +1,103 @@ +#include "extern.h" +#include "aClient.h" +#include "config.h" +#include "flags.h" + +void do_heal(char *u) +{ + aClient *ni; + char *amount = strtok(NULL, " "); + int price, num; + + if (!amount) + { + notice(s_GameServ, u, "SYNTAX: /msg getNick()); + #endif + return; + } + else if (!is_playing(ni)) + { + notice(s_GameServ, u, "You aren't playing!"); + return; + } + else if (!isAlive(ni->stats)) + { + notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing."); + return; + } + else if (is_fighting(ni)) + { + notice(s_GameServ, u, "You can't heal in battle!"); + return; + } + else if (ni->stats->getHP() >= ni->stats->getMaxHP()) + { + notice(s_GameServ, u, "You don't need healing!"); + return; + } + + updateTS(ni->stats); + if (stricmp(amount, "ALL") == 0) + { + price = ni->stats->getLevel() * 3; + if (ni->stats->getGold() < (ni->stats->getMaxHP() - ni->stats->getHP()) * price) + { + notice(s_GameServ, u, "Healing %d points for %d gold per point.", + (long int)ni->stats->getGold()/price, price); + ni->stats->addHP(ni->stats->getGold() / price); + ni->stats->setGold(ni->stats->getGold() % price); + } + else + { + notice(s_GameServ, u, "Healing all possible points at %d gold "\ + "per point.", price); + notice(s_GameServ, u, "%d points healed for %ld gold. HP at MAX!", + (ni->stats->getMaxHP() - ni->stats->getHP()), + (price * (ni->stats->getMaxHP() - ni->stats->getHP())) ); + ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP())); + ni->stats->healall(); + } + } + else if (isstringnum(amount)) + { + num = stringtoint(amount); + price = ni->stats->getLevel() * 3; + if (ni->stats->getGold() < price * num) + { + notice(s_GameServ, u, "You only have enough gold to heal %d points!", + (long int)ni->stats->getGold()/price); + } + else if (num <= ni->stats->getMaxHP() - ni->stats->getHP()) + { + notice(s_GameServ, u, "Healing %d points at %d gold per point.", + num, price); + ni->stats->addHP(num); + ni->stats->subtractGold(num * price); + } + else if (num > ni->stats->getMaxHP() - ni->stats->getHP()) + { + notice(s_GameServ, u, "Healing all possible points at %d gold "\ + "per point.", price); + notice(s_GameServ, u, "%d points healed. HP at MAX!", + (ni->stats->getMaxHP() - ni->stats->getHP())); + ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP())); + ni->stats->healall(); + } + } + else if (amount[0] == '-') + notice(s_GameServ, u, "You trying to cheat?"); + else + notice(s_GameServ, u, "SYNTAX: /msg getNick()); +#endif + return; + } + else if (!(p = findplayer(name))) + { + notice(s_GameServ, u, "Player %s not found", name); + } + else if (is_playing(user)) + { + notice(s_GameServ, u, "You are already playing!"); + } + else if (is_playing(p->getClient()) && !isAdmin(user)) + { + notice(s_GameServ, u, "That player has already identified."); + } + else if (!check_password(name, password) && !isAdmin(user)) + { + notice(s_GameServ, u, "Password incorrect"); + } + else + { + list::iterator iter; + unsigned long hv = iHASH((unsigned char *) p->getName().c_str()); + + iter = find(players[hv].begin(), players[hv].end(), p); + + if (iter == players[hv].end()) + { + notice(s_GameServ, u, "Fatal error. Contact getClient()); + + user->stats = p; + p->setClient(user); + updateTS(p); + + +#ifdef DEBUGMODE + log("Player %s IRC: %s Identified", user->stats->getName().c_str(), + user->getNick()); +#endif + //Set the playing flag + setPlaying(user); + + // Update the last login time + user->stats->lastlogin = time(NULL); + + notice(s_GameServ, u, "Password Accepted. Identified."); + showNews(u, todaysnews); + } +} diff --git a/gameserv/do_inventory.cpp b/gameserv/do_inventory.cpp new file mode 100644 index 0000000..b884069 --- /dev/null +++ b/gameserv/do_inventory.cpp @@ -0,0 +1,30 @@ +#include "extern.h" +#include "config.h" +#include "aClient.h" +#include "flags.h" + +void do_inventory(char *u) +{ + aClient *user; + + if (!(user = find(u))) + { + notice(s_GameServ, u, "Fatal Error. Contact a getNick()); +#endif + return; + } + else if (!is_playing(user)) + { + notice(s_GameServ, u, "You must be playing to check your inventory!"); + return; + } + if (!is_fighting(user)) + updateTS(user->stats); + showinventory(user->stats, user); +} diff --git a/gameserv/do_list.cpp b/gameserv/do_list.cpp new file mode 100644 index 0000000..935ce83 --- /dev/null +++ b/gameserv/do_list.cpp @@ -0,0 +1,93 @@ +#include "extern.h" +#include "config.h" +#include "player.h" +#include "aClient.h" +#include "flags.h" +#include "toplist.h" + +void do_list(char *u) +{ + aClient *user; + Player *p; + char *cmd = strtok(NULL, " "); + + if (!(user = find(u))) + { + log("Fatal Error: Couldn't find %s in the client list", u); + return; + } + else if (isIgnore(user)) + { +#ifdef DEBUGMODE + log("Ignoring %s. Command LIST", user->getNick()); +#endif + return; + } + + if (cmd == NULL || stricmp(cmd, "TOP") == 0) + { + list::iterator iter; + bool header = false; + + if (myToplist.empty()) + { + notice(s_GameServ, u, "There are no players"); + return; + } + myToplist.sort(); + myToplist.reverse(); + + iter = myToplist.begin(); + + while (iter != myToplist.end()) + { + if (!header) + { + notice(s_GameServ, u, "Top Players"); + header = true; + + } + notice(s_GameServ, u, "Level: %2d Exp: %10d Name: %s", + (*iter).getLevel(), (*iter).getExp(), (*iter).getName().c_str()); + iter++; + } + } + else + { + + list::iterator iter; + bool header = false; + + for (unsigned long x = 0; x < U_TABLE_SIZE; x++) + { + iter = players[x].begin(); + if (!players[x].empty()) + { + while(iter != players[x].end()) + { + p = (*iter); + if (cmd || is_playing(p->getClient())) + { + if (!header) + { + notice(s_GameServ, u, "Players:"); + header = true; + } + #ifdef P10 + notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getRealNick() : "Not Playing"), + p->getName().c_str()); + #else + notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getNick() : "Not Playing"), + p->getName().c_str()); + #endif + } + iter++; + } + } + } + if (!header) + notice(s_GameServ, u, "No one is playing"); + else + notice(s_GameServ, u, "End of List"); + } +} diff --git a/gameserv/do_refresh.cpp b/gameserv/do_refresh.cpp new file mode 100644 index 0000000..dc54b41 --- /dev/null +++ b/gameserv/do_refresh.cpp @@ -0,0 +1,51 @@ +#include "extern.h" +#include "config.h" +#include "aClient.h" +#include "player.h" +#include "flags.h" + +void do_refresh(char *u) +{ + char *name = strtok(NULL, " "); + aClient *user; + Player *p; + + if (!(user = find(u))) + { + notice(s_GameServ, u, "Error: aClient not found. Contact a getNick()); +#endif + return; + } + else if (!isAdmin(user)) + { + notice(s_GameServ, u, "You must be a getName().c_str()); + refresh(p); + } + else + { + notice(s_GameServ, u, "Player %s not found.", name); + return; + } +} diff --git a/gameserv/do_register.cpp b/gameserv/do_register.cpp new file mode 100644 index 0000000..f79db5f --- /dev/null +++ b/gameserv/do_register.cpp @@ -0,0 +1,108 @@ +#include "extern.h" +#include "config.h" +#include "aClient.h" +#include "player.h" +#include "flags.h" +#include "pouch.h" +#include "item.h" +#include "toplist.h" + +void do_register(char *u) +{ + char *password, *name; + aClient *user; + Player *p; + name = strtok(NULL, " "); + password = strtok(NULL, " "); + + if (!name) + { + notice(s_GameServ, u, "SYNTAX: /msg maxnicklen) + { + notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen); + } + else if (!alphaNumeric(name)) + { + notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!"); + } + else if ((p = findplayer(name))) + { + notice(s_GameServ, u, "%s is already registered!", name); + notice(s_GameServ, u, "Choose another name!"); + } + else if (!(user = find(u))) + { + log("Fatal Error: Couldn't find %s in the clients list", u); + } + else if (isIgnore(user)) + { +#ifdef DEBUGMODE + log("Ignoring %s.", user->getNick()); +#endif + } + else + { + if (!is_playing(user)) + { + item *tempItem; + unsigned long hv = iHASH((unsigned char *) name); + + // First create the Player + user->stats = new Player(); + + // Set the backwards pointer + user->stats->setClient(user); + + // Set the player's password + user->stats->setPassword(password); + + // Set the player's name + user->stats->setName(name); + + // Make sure they have a proper time stamp + updateTS(user->stats); + + // Update the last login time + user->stats->lastlogin = time(NULL); + + // Send notification of success + notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->getName().c_str(), password); + notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!"); + + // Log the new player + log("Nickname %s registered player %s.", u, user->stats->getName().c_str()); + + // Log the player in + setPlaying(user); + + // Start the player at the beginning + reset(user->stats); + + // Add the stick and clothes + tempItem = findItemByID(3001); + user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick + user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes + + // Add the player to the list + players[hv].push_back(user->stats); + + // Attempt to add the player to the top list + // The class takes care of pruning the user out if they don't deserve to be in the list + myToplist.insertPlayer(user->stats); + } + else + { + notice(s_GameServ, u, "Already registered. Contact a getNick()); -#endif - return; - } - - if (cmd == NULL || stricmp(cmd, "TOP") == 0) - { - list::iterator iter; - bool header = false; - - if (myToplist.empty()) - { - notice(s_GameServ, u, "There are no players"); - return; - } - myToplist.sort(); - myToplist.reverse(); - - iter = myToplist.begin(); - - while (iter != myToplist.end()) - { - if (!header) - { - notice(s_GameServ, u, "Top Players"); - header = true; - - } - notice(s_GameServ, u, "Level: %2d Exp: %10d Name: %s", - (*iter).getLevel(), (*iter).getExp(), (*iter).getName().c_str()); - iter++; - } - } - else - { - - list::iterator iter; - bool header = false; - - for (unsigned long x = 0; x < U_TABLE_SIZE; x++) - { - iter = players[x].begin(); - if (!players[x].empty()) - { - while(iter != players[x].end()) - { - p = (*iter); - if (cmd || is_playing(p->getClient())) - { - if (!header) - { - notice(s_GameServ, u, "Players:"); - header = true; - } - #ifdef P10 - notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getRealNick() : "Not Playing"), - p->getName().c_str()); - #else - notice(s_GameServ, u, "IRC: %s Game: %s", (p->getClient() ? p->getClient()->getNick() : "Not Playing"), - p->getName().c_str()); - #endif - } - iter++; - } - } - } - if (!header) - notice(s_GameServ, u, "No one is playing"); - else - notice(s_GameServ, u, "End of List"); - } -} void do_set(char *u) { @@ -834,181 +740,6 @@ void do_logout(char *u) } } -void do_register(char *u) -{ - char *password, *name; - aClient *user; - Player *p; - name = strtok(NULL, " "); - password = strtok(NULL, " "); - - if (!name) - { - notice(s_GameServ, u, "SYNTAX: /msg maxnicklen) - { - notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen); - } - else if (!alphaNumeric(name)) - { - notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!"); - } - else if ((p = findplayer(name))) - { - notice(s_GameServ, u, "%s is already registered!", name); - notice(s_GameServ, u, "Choose another name!"); - } - else if (!(user = find(u))) - { - log("Fatal Error: Couldn't find %s in the clients list", u); - } - else if (isIgnore(user)) - { -#ifdef DEBUGMODE - log("Ignoring %s.", user->getNick()); -#endif - } - else - { - if (!is_playing(user)) - { - item *tempItem; - unsigned long hv = iHASH((unsigned char *) name); - - // First create the Player - user->stats = new Player(); - - // Set the backwards pointer - user->stats->setClient(user); - - // Set the player's password - user->stats->setPassword(password); - - // Set the player's name - user->stats->setName(name); - - // Make sure they have a proper time stamp - updateTS(user->stats); - - // Update the last login time - user->stats->lastlogin = time(NULL); - - // Send notification of success - notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->getName().c_str(), password); - notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!"); - - // Log the new player - log("Nickname %s registered player %s.", u, user->stats->getName().c_str()); - - // Log the player in - setPlaying(user); - - // Start the player at the beginning - reset(user->stats); - - // Add the stick and clothes - tempItem = findItemByID(3001); - user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick - user->stats->inventory->addItem(tempItem)->use(user->stats); // Add Clothes - - // Add the player to the list - players[hv].push_back(user->stats); - - // Attempt to add the player to the top list - // The class takes care of pruning the user out if they don't deserve to be in the list - myToplist.insertPlayer(user->stats); - } - else - { - notice(s_GameServ, u, "Already registered. Contact a getNick()); -#endif - return; - } - else if (!(p = findplayer(name))) - { - notice(s_GameServ, u, "Player %s not found", name); - } - else if (is_playing(user)) - { - notice(s_GameServ, u, "You are already playing!"); - } - else if (is_playing(p->getClient()) && !isAdmin(user)) - { - notice(s_GameServ, u, "That player has already identified."); - } - else if (!check_password(name, password) && !isAdmin(user)) - { - notice(s_GameServ, u, "Password incorrect"); - } - else - { - list::iterator iter; - unsigned long hv = iHASH((unsigned char *) p->getName().c_str()); - - iter = find(players[hv].begin(), players[hv].end(), p); - - if (iter == players[hv].end()) - { - notice(s_GameServ, u, "Fatal error. Contact getClient()); - - user->stats = p; - p->setClient(user); - updateTS(p); - - -#ifdef DEBUGMODE - log("Player %s IRC: %s Identified", user->stats->getName().c_str(), - user->getNick()); -#endif - //Set the playing flag - setPlaying(user); - - // Update the last login time - user->stats->lastlogin = time(NULL); - - notice(s_GameServ, u, "Password Accepted. Identified."); - showNews(u, todaysnews); - } -} - void do_stats(char *u) { char *nick; @@ -1200,108 +931,6 @@ void do_run(char *u) } } - -void do_heal(char *u) -{ - aClient *ni; - char *amount = strtok(NULL, " "); - int price, num; - - if (!amount) - { - notice(s_GameServ, u, "SYNTAX: /msg getNick()); - #endif - return; - } - else if (!is_playing(ni)) - { - notice(s_GameServ, u, "You aren't playing!"); - return; - } - else if (!isAlive(ni->stats)) - { - notice(s_GameServ, u, "You are dead. Wait until tomorrow for healing."); - return; - } - else if (is_fighting(ni)) - { - notice(s_GameServ, u, "You can't heal in battle!"); - return; - } - else if (ni->stats->getHP() >= ni->stats->getMaxHP()) - { - notice(s_GameServ, u, "You don't need healing!"); - return; - } - - updateTS(ni->stats); - if (stricmp(amount, "ALL") == 0) - { - price = ni->stats->getLevel() * 3; - if (ni->stats->getGold() < (ni->stats->getMaxHP() - ni->stats->getHP()) * price) - { - notice(s_GameServ, u, "Healing %d points for %d gold per point.", - (long int)ni->stats->getGold()/price, price); - ni->stats->addHP(ni->stats->getGold() / price); - ni->stats->setGold(ni->stats->getGold() % price); - } - else - { - notice(s_GameServ, u, "Healing all possible points at %d gold "\ - "per point.", price); - notice(s_GameServ, u, "%d points healed for %ld gold. HP at MAX!", - (ni->stats->getMaxHP() - ni->stats->getHP()), - (price * (ni->stats->getMaxHP() - ni->stats->getHP())) ); - ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP())); - ni->stats->healall(); - } - } - else if (isstringnum(amount)) - { - num = stringtoint(amount); - price = ni->stats->getLevel() * 3; - if (ni->stats->getGold() < price * num) - { - notice(s_GameServ, u, "You only have enough gold to heal %d points!", - (long int)ni->stats->getGold()/price); - } - else if (num <= ni->stats->getMaxHP() - ni->stats->getHP()) - { - notice(s_GameServ, u, "Healing %d points at %d gold per point.", - num, price); - ni->stats->addHP(num); - ni->stats->subtractGold(num * price); - } - else if (num > ni->stats->getMaxHP() - ni->stats->getHP()) - { - notice(s_GameServ, u, "Healing all possible points at %d gold "\ - "per point.", price); - notice(s_GameServ, u, "%d points healed. HP at MAX!", - (ni->stats->getMaxHP() - ni->stats->getHP())); - ni->stats->subtractGold(price * (ni->stats->getMaxHP() - ni->stats->getHP())); - ni->stats->healall(); - } - } - else if (amount[0] == '-') - notice(s_GameServ, u, "You trying to cheat?"); - else - notice(s_GameServ, u, "SYNTAX: /msg ::iterator item_iterator; @@ -1477,31 +1106,6 @@ void do_store(char *u) return; } } -void do_inventory(char *u) -{ - aClient *user; - - if (!(user = find(u))) - { - notice(s_GameServ, u, "Fatal Error. Contact a getNick()); -#endif - return; - } - else if (!is_playing(user)) - { - notice(s_GameServ, u, "You must be playing to check your inventory!"); - return; - } - if (!is_fighting(user)) - updateTS(user->stats); - showinventory(user->stats, user); -} void do_tavern(char *u) @@ -1868,12 +1472,6 @@ void do_reset(char *u) } } -void do_help(char *u) -{ - char *cmd = strtok(NULL, " "); - - display_help(u, cmd); -} diff --git a/gameserv/misc.cpp b/gameserv/misc.cpp index 09beb76..9197d51 100644 --- a/gameserv/misc.cpp +++ b/gameserv/misc.cpp @@ -75,51 +75,7 @@ void refresh(Player *p) clearMaster(p); } -void do_refresh(char *u) -{ - char *name = strtok(NULL, " "); - aClient *user; - Player *p; - - if (!(user = find(u))) - { - notice(s_GameServ, u, "Error: aClient not found. Contact a getNick()); -#endif - return; - } - else if (!isAdmin(user)) - { - notice(s_GameServ, u, "You must be a getName().c_str()); - refresh(p); - } - else - { - notice(s_GameServ, u, "Player %s not found.", name); - return; - } -} + void resetall()