diff options
Diffstat (limited to 'src/account-server')
-rw-r--r-- | src/account-server/accounthandler.hpp | 4 | ||||
-rw-r--r-- | src/account-server/guild.cpp | 63 | ||||
-rw-r--r-- | src/account-server/guild.hpp | 154 | ||||
-rw-r--r-- | src/account-server/guildmanager.cpp | 78 | ||||
-rw-r--r-- | src/account-server/guildmanager.hpp | 133 |
5 files changed, 212 insertions, 220 deletions
diff --git a/src/account-server/accounthandler.hpp b/src/account-server/accounthandler.hpp index d7058906..cb4c266b 100644 --- a/src/account-server/accounthandler.hpp +++ b/src/account-server/accounthandler.hpp @@ -127,9 +127,9 @@ class AccountHandler : public ConnectionHandler void handleCharacterDeleteMessage(AccountClient &computer, MessageIn &msg); - + /** - * Send guild join for each guild the player belongs to + * Send guild join for each guild the player belongs to. */ void handleGuildJoining(AccountClient &computer, CharacterData *character); diff --git a/src/account-server/guild.cpp b/src/account-server/guild.cpp index 2e339ec1..cf864161 100644 --- a/src/account-server/guild.cpp +++ b/src/account-server/guild.cpp @@ -1,31 +1,23 @@ /* - * guild.cpp - * A file part of The Mana World + * The Mana World Server + * Copyright 2004 The Mana World Development Team * - * Created by David Athay on 01/03/2007. - * - * Copyright (c) 2007, The Mana World Development Team - * All rights reserved. + * This file is part of The Mana World. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * My name may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. * - * $Id$ + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ */ #include "guild.hpp" @@ -36,12 +28,10 @@ Guild::Guild(const std::string &name) : mName(name) { - } Guild::~Guild() { - } void Guild::addMember(CharacterData* player) @@ -54,17 +44,15 @@ void Guild::removeMember(CharacterData* player) mMembers.remove(player); } -bool Guild::checkLeader(CharacterData* player) +bool Guild::checkLeader(CharacterData *player) { - CharacterData* leader = mMembers.front(); - if(leader == player) - return true; - return false; + CharacterData *leader = mMembers.front(); + return leader == player; } bool Guild::checkInvited(const std::string &name) { - return (std::find(mInvited.begin(), mInvited.end(), name) != mInvited.end()); + return std::find(mInvited.begin(), mInvited.end(), name) != mInvited.end(); } void Guild::addInvited(const std::string &name) @@ -72,19 +60,14 @@ void Guild::addInvited(const std::string &name) mInvited.push_back(name); } -const std::string& Guild::getName() const -{ - return mName; -} - std::string Guild::getMember(int i) const { int x = 0; - for(guildMembers::const_iterator itr = mMembers.begin(); + for (guildMembers::const_iterator itr = mMembers.begin(); itr != mMembers.end(); ++itr, ++x) { - if(x == i) + if (x == i) { CharacterData *player = (*itr); return player->getName(); @@ -95,10 +78,10 @@ std::string Guild::getMember(int i) const bool Guild::checkInGuild(const std::string &name) { - for(guildMembers::iterator itr = mMembers.begin(); itr != mMembers.end(); ++itr) + for (guildMembers::iterator itr = mMembers.begin(); itr != mMembers.end(); ++itr) { CharacterData *player = (*itr); - if(player->getName() == name) + if (player->getName() == name) { return true; } diff --git a/src/account-server/guild.hpp b/src/account-server/guild.hpp index c91b6467..2116e1ef 100644 --- a/src/account-server/guild.hpp +++ b/src/account-server/guild.hpp @@ -28,82 +28,88 @@ class CharacterData; +/** + * A guild and its members. + */ class Guild { -public: - typedef std::list<CharacterData*> guildMembers; - Guild(const std::string &name); - ~Guild(); - - /** - * Add a member to the guild. - */ - void addMember(CharacterData* player); - - /** - * Remove a member from the guild. - */ - void removeMember(CharacterData* player); - - /** - * Check player is the leader of the guild. - */ - bool checkLeader(CharacterData* player); - - /** - * Set the ID of the guild. - */ - void setId(short id) - { - mId = id; - } - - /** - * Check if player has been invited to the guild. - */ - bool checkInvited(const std::string &name); - - /** - * Add a player to the invite list. - */ - void addInvited(const std::string &name); - - /** - * Returns the name of the guild. - */ - const std::string& getName() const; - - /** - * Returns the ID of the guild. - */ - short getId() const - { - return mId; - } - - /** - * Returns the total number of members in the guild. - */ - short totalMembers() const - { - return mMembers.size(); - } - - /** - * Get a member in the guild - */ - std::string getMember(int i) const; - - /** - * Find member by name - */ - bool checkInGuild(const std::string &name); - -private: - short mId; - std::string mName; - std::list<CharacterData*> mMembers; - std::list<std::string> mInvited; + public: + typedef std::list<CharacterData*> guildMembers; + + /** + * Constructor. + */ + Guild(const std::string &name); + + /** + * Destructor. + */ + ~Guild(); + + /** + * Add a member to the guild. + */ + void addMember(CharacterData* player); + + /** + * Remove a member from the guild. + */ + void removeMember(CharacterData* player); + + /** + * Check player is the leader of the guild. + */ + bool checkLeader(CharacterData* player); + + /** + * Set the ID of the guild. + */ + void setId(short id) + { mId = id; } + + /** + * Check if player has been invited to the guild. + */ + bool checkInvited(const std::string &name); + + /** + * Add a player to the invite list. + */ + void addInvited(const std::string &name); + + /** + * Returns the name of the guild. + */ + const std::string& getName() const + { return mName; } + + /** + * Returns the ID of the guild. + */ + short getId() const + { return mId; } + + /** + * Returns the total number of members in the guild. + */ + short totalMembers() const + { return mMembers.size(); } + + /** + * Get a member in the guild. + */ + std::string getMember(int i) const; + + /** + * Find member by name. + */ + bool checkInGuild(const std::string &name); + + private: + short mId; + std::string mName; + std::list<CharacterData*> mMembers; + std::list<std::string> mInvited; }; #endif diff --git a/src/account-server/guildmanager.cpp b/src/account-server/guildmanager.cpp index 9fbec8c1..6105704c 100644 --- a/src/account-server/guildmanager.cpp +++ b/src/account-server/guildmanager.cpp @@ -1,31 +1,23 @@ /* - * guildmanager.cpp - * A file part of The Mana World + * The Mana World Server + * Copyright 2004 The Mana World Development Team * - * Created by David Athay on 01/03/2007. - * - * Copyright (c) 2007, The Mana World Development Team - * All rights reserved. + * This file is part of The Mana World. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * My name may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. * - * $Id$ + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ */ #include "guildmanager.hpp" @@ -43,32 +35,32 @@ GuildManager::GuildManager() GuildManager::~GuildManager() { - for(std::list<Guild*>::iterator itr = mGuilds.begin(); itr != mGuilds.end(); ++itr) + for (std::list<Guild*>::iterator itr = mGuilds.begin(); + itr != mGuilds.end(); ++itr) { - Guild *guild = (*itr); - delete guild; + delete *itr; } } -short GuildManager::createGuild(const std::string &name, CharacterData* player) +short GuildManager::createGuild(const std::string &name, CharacterData *player) { Guild *guild = new Guild(name); // Add guild to db Storage &store = Storage::instance("tmw"); store.addGuild(guild); - - // Make sure to add guild to mGuilds before searching for it - // to add the player + + // Make sure to add guild to mGuilds before searching for it to add the + // player mGuilds.push_back(guild); addGuildMember(guild->getId(), player); - + return guild->getId(); } void GuildManager::removeGuild(short guildId) { Guild *guild = findById(guildId); - if(!guild) + if (!guild) return; Storage &store = Storage::instance("tmw"); store.removeGuild(guild); @@ -77,7 +69,7 @@ void GuildManager::removeGuild(short guildId) void GuildManager::addGuildMember(short guildId, CharacterData *player) { Guild *guild = findById(guildId); - if(!guild) + if (!guild) return; Storage &store = Storage::instance("tmw"); store.addGuildMember(guildId, player->getName()); @@ -87,7 +79,7 @@ void GuildManager::addGuildMember(short guildId, CharacterData *player) void GuildManager::removeGuildMember(short guildId, CharacterData *player) { Guild *guild = findById(guildId); - if(!guild) + if (!guild) return; Storage &store = Storage::instance("tmw"); store.removeGuildMember(guildId, player->getName()); @@ -100,10 +92,11 @@ void GuildManager::removeGuildMember(short guildId, CharacterData *player) Guild *GuildManager::findById(short id) { - for(std::list<Guild*>::iterator itr = mGuilds.begin(); itr != mGuilds.end(); ++itr) + for (std::list<Guild*>::iterator itr = mGuilds.begin(); + itr != mGuilds.end(); ++itr) { Guild *guild = (*itr); - if(guild->getId() == id) + if (guild->getId() == id) { return guild; } @@ -113,11 +106,11 @@ Guild *GuildManager::findById(short id) Guild *GuildManager::findByName(const std::string &name) { - std::list<Guild*>::iterator itr = mGuilds.begin(); - for(; itr != mGuilds.end(); ++itr) + for (std::list<Guild*>::iterator itr = mGuilds.begin(); + itr != mGuilds.end(); ++itr) { Guild *guild = (*itr); - if(guild->getName() == name) + if (guild->getName() == name) { return guild; } @@ -127,10 +120,5 @@ Guild *GuildManager::findByName(const std::string &name) bool GuildManager::doesExist(const std::string &name) { - Guild *guild = findByName(name); - if(guild) - { - return true; - } - return false; + return findByName(name) != NULL; } diff --git a/src/account-server/guildmanager.hpp b/src/account-server/guildmanager.hpp index 97ec87c3..60df3d79 100644 --- a/src/account-server/guildmanager.hpp +++ b/src/account-server/guildmanager.hpp @@ -1,31 +1,23 @@ /* - * guildmanager.hpp - * A file part of The Mana World + * The Mana World Server + * Copyright 2004 The Mana World Development Team * - * Created by David Athay on 05/03/2007. - * - * Copyright (c) 2007, The Mana World Development Team - * All rights reserved. + * This file is part of The Mana World. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * My name may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * The Mana World is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or any later version. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + * The Mana World is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. * - * $Id$ + * You should have received a copy of the GNU General Public License along + * with The Mana World; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ */ #include <list> @@ -33,44 +25,67 @@ class Guild; class CharacterData; +/** + * Guild manager takes care of creating, removing and modifying guilds. + */ class GuildManager { -public: - /* - * Constructor/Destructor - */ - GuildManager(); - ~GuildManager(); - - /* - * Create/Remove guild - */ - short createGuild(const std::string &name, CharacterData *player); - void removeGuild(short guildId); - - /* - * Add member to guild - */ - void addGuildMember(short guildId, CharacterData *player); - - /* - * Remove member from guild - */ - void removeGuildMember(short guildId, CharacterData *player); - - /* - * Search for guilds - */ - Guild *findById(short id); - Guild *findByName(const std::string &name); - - /* - * Check if guild exists - */ - bool doesExist(const std::string &name); - -private: - std::list<Guild*> mGuilds; + public: + /** + * Constructor. + */ + GuildManager(); + + /** + * Destructor. + */ + ~GuildManager(); + + /** + * Creates a guild. + */ + short createGuild(const std::string &name, CharacterData *player); + + /** + * Removes a guild. + */ + void removeGuild(short guildId); + + /** + * Adds a member to a guild. + */ + void addGuildMember(short guildId, CharacterData *player); + + /** + * Removes a member from a guild. + */ + void removeGuildMember(short guildId, CharacterData *player); + + /** + * Returns the guild with the given id. O(n) + * + * @todo <b>b_lindeijer:</b> Since this method is used so often, its + * efficiency should be improved, probably by storing the guilds + * in a map<int,Guild*> instead of list<Guild*>. + * + * @return the guild with the given id, or NULL if it doesn't exist + */ + Guild *findById(short id); + + /** + * Returns the guild with the given name. O(n) + * + * @return the guild with the given name, or NULL if it doesn't exist + */ + Guild *findByName(const std::string &name); + + /** + * Returns whether a guild exists. + */ + bool doesExist(const std::string &name); + + private: + std::list<Guild*> mGuilds; }; extern GuildManager *guildManager; |