account.cpp

Go to the documentation of this file.
00001 /*
00002  *  The Mana World Server
00003  *  Copyright 2004 The Mana World Development Team
00004  *
00005  *  This file is part of The Mana World.
00006  *
00007  *  The Mana World  is free software; you can redistribute  it and/or modify it
00008  *  under the terms of the GNU General  Public License as published by the Free
00009  *  Software Foundation; either version 2 of the License, or any later version.
00010  *
00011  *  The Mana  World is  distributed in  the hope  that it  will be  useful, but
00012  *  WITHOUT ANY WARRANTY; without even  the implied warranty of MERCHANTABILITY
00013  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00014  *  more details.
00015  *
00016  *  You should  have received a  copy of the  GNU General Public  License along
00017  *  with The Mana  World; if not, write to the  Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  *  $Id: account.cpp 3167 2007-03-05 03:32:59Z rogier_polak $
00021  */
00022 
00023 #include "account-server/account.hpp"
00024 
00025 #include <cassert>
00026 
00027 #include "account-server/accountclient.hpp"
00028 #include "utils/functors.h"
00029 
00033 Account::Account(const std::string& name,
00034                  const std::string& password,
00035                  const std::string& email,
00036                  int id)
00037         : mID(id),
00038           mName(name),
00039           mPassword(password),
00040           mEmail(email),
00041           mCharacters(),
00042           mLevel(AL_NORMAL)
00043 {
00044     // NOOP
00045 }
00046 
00047 
00051 Account::Account(const std::string& name,
00052                  const std::string& password,
00053                  const std::string& email,
00054                  const Characters& characters)
00055         : mName(name),
00056           mPassword(password),
00057           mEmail(email),
00058           mCharacters(characters),
00059           mLevel(AL_NORMAL)
00060 {
00061     // NOOP
00062 }
00063 
00064 
00068 Account::~Account()
00069 {
00070     // mCharacters is a list of smart pointers which will take care about
00071     // deallocating the memory so nothing to deallocate here :)
00072 }
00073 
00074 
00078 void
00079 Account::setName(const std::string& name)
00080 {
00081     mName = name;
00082 }
00083 
00084 
00088 const std::string&
00089 Account::getName(void) const
00090 {
00091     return mName;
00092 }
00093 
00094 
00098 void
00099 Account::setPassword(const std::string& password)
00100 {
00101     mPassword = password;
00102 }
00103 
00104 
00108 const std::string
00109 Account::getPassword(void) const
00110 {
00111     return mPassword;
00112 }
00113 
00114 
00118 void
00119 Account::setEmail(const std::string& email)
00120 {
00121     // Email validity is checked by Accounthandler
00122     mEmail = email;
00123 }
00124 
00125 
00129 const std::string&
00130 Account::getEmail(void) const
00131 {
00132     return mEmail;
00133 }
00134 
00135 
00139 void
00140 Account::setLevel(AccountLevel level)
00141 {
00142     mLevel = level;
00143 }
00144 
00145 
00149 AccountLevel
00150 Account::getLevel(void) const
00151 {
00152     return mLevel;
00153 }
00154 
00155 
00159 void
00160 Account::setCharacters(const Characters& characters)
00161 {
00162     mCharacters = characters;
00163 }
00164 
00165 
00169 void
00170 Account::addCharacter(CharacterPtr character)
00171 {
00172     if (character.get() != 0) {
00173         mCharacters.push_back(character);
00174     }
00175 }
00176 
00180 bool Account::delCharacter(std::string const &name)
00181 {
00182     Characters::iterator
00183         end = mCharacters.end(),
00184         it = std::find_if(mCharacters.begin(), end,
00185                           std::bind2nd(obj_name_is<CharacterPtr>(), name));
00186 
00187     if (it == end) return false;
00188     mCharacters.erase(it);
00189     return true;
00190 }
00191 
00192 
00196 Characters &Account::getCharacters()
00197 {
00198     return mCharacters;
00199 }
00200 
00201 
00205 CharacterPtr Account::getCharacter(const std::string& name)
00206 {
00207     Characters::iterator
00208         end = mCharacters.end(),
00209         it = std::find_if(mCharacters.begin(), end,
00210                           std::bind2nd(obj_name_is<CharacterPtr>(), name));
00211 
00212     if (it != end) return *it;
00213     return CharacterPtr();
00214 }
00215 
00216 void Account::setID(int id)
00217 {
00218     assert(mID < 0);
00219     mID = id;
00220 }

Generated on Fri Mar 30 15:39:15 2007 for TMW Server by  doxygen 1.3.9.1