Eris  1.3.19
Account.h
00001 #ifndef ERIS_PLAYER_H
00002 #define ERIS_PLAYER_H
00003 
00004 #include <Eris/Types.h>
00005 
00006 #include "TransferInfo.h"
00007 
00008 #include <Atlas/Objects/ObjectsFwd.h>
00009 
00010 #include <sigc++/signal.h>
00011 
00012 #include <vector>
00013 #include <map>
00014 #include <memory>
00015 
00016 namespace Eris
00017 {
00018 
00019 class Connection;
00020 class Avatar;
00021 class AccountRouter;
00022 class Timeout;
00023 class SpawnPoint;
00024 
00026 typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap;
00027 
00028 typedef std::map<std::string, Avatar*> ActiveCharacterMap;
00029 
00033 typedef std::map<std::string, SpawnPoint> SpawnPointMap;
00034 
00036 
00044 class Account : virtual public sigc::trackable
00045 {
00046 public:
00048 
00053     Account(Connection *con);
00054 
00055     virtual ~Account();
00056 
00058 
00067     Result login(const std::string &uname, const std::string &pwd);
00068 
00070     /* Create a new account on the server, if possible.
00071     Server-side failures, such as an account already existing with the specified
00072     username, will cause the 'LoginFailure' signal to be emitted with an error message
00073     and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
00074 
00075     @param uname The desired username of the account (eg 'ajr')
00076     @param fullName The real name of the user (e.g 'Al Riddoch')
00077     @param pwd The plaintext password for the new account
00078     */
00079 
00080     Result createAccount(const std::string &uname,
00081         const std::string &fullName,
00082         const std::string &pwd);
00083 
00085 
00088     Result logout();
00089 
00091 
00092     bool isLoggedIn() const;
00093 
00095     const std::vector< std::string > & getCharacterTypes(void) const;
00096 
00098 
00103     const CharacterMap& getCharacters();
00104 
00112     Result refreshCharacterInfo();
00113 
00115 
00119     Result takeTransferredCharacter(const std::string &id, const std::string &key);
00120 
00122 
00127     Result takeCharacter(const std::string &id);
00128 
00130     Result createCharacter(const Atlas::Objects::Entity::RootEntity &character);
00131 
00133     //void createCharacter();
00134 
00136     bool canCreateCharacter();
00137 
00142     const ActiveCharacterMap& getActiveCharacters() const;
00143 
00148     const SpawnPointMap& getSpawnPoints() const;
00149 
00154     Result deactivateCharacter(Avatar* av);
00155 
00157     const std::string& getId() const;
00158 
00160     const std::string& getUsername() const;
00161 
00168     const std::list<std::string>& getParents() const;
00169 
00171     Connection* getConnection() const;
00172 
00182     void avatarLogoutRequested(Avatar* avatar);
00183 
00184 
00185 // signals
00187     sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
00188 
00190     sigc::signal<void> GotAllCharacters;
00191 
00193 
00197     sigc::signal<void, const std::string &> LoginFailure;
00198 
00200     sigc::signal<void> LoginSuccess;
00201 
00203 
00207     sigc::signal<void, bool> LogoutComplete;
00208 
00213     sigc::signal<void, Avatar*> AvatarSuccess;
00214 
00219     sigc::signal<void, const std::string &> AvatarFailure;
00220 
00226     sigc::signal<void, Avatar*> AvatarDeactivated;
00227 
00228 protected:
00229     friend class AccountRouter;
00230     friend class Avatar; // so avatar can call deactivateCharacter
00231 
00232     void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
00233 
00234     void loginComplete(const Atlas::Objects::Entity::Account &p);
00235     void loginError(const Atlas::Objects::Operation::Error& err);
00236 
00237     Result internalLogin(const std::string &unm, const std::string &pwd);
00238     void internalLogout(bool clean);
00239 
00241     void netConnected();
00242 
00244     bool netDisconnecting();
00245     void netFailure(const std::string& msg);
00246 
00247     void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
00248     void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00249     void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
00250     void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00251 
00252     void handleLogoutTimeout();
00253 //  void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
00254 
00255     void handleLoginTimeout();
00256 
00257     typedef enum
00258     {
00259         DISCONNECTED = 0,   
00260         LOGGING_IN,         
00261         LOGGED_IN,          
00262         LOGGING_OUT,         
00263 
00264         TAKING_CHAR,        
00265         CREATING_CHAR       
00266     } Status;
00267 
00268     void internalDeactivateCharacter(Avatar* av);
00269     virtual void updateFromObject(const Atlas::Objects::Entity::Account &p);
00270 
00271     Connection* m_con;  
00272     Status m_status;    
00273     AccountRouter* m_router;
00274 
00275     std::string m_accountId;    
00276     std::string m_username; 
00277     std::string m_pass;
00278 
00279     std::list< std::string > m_parents;
00280     std::vector< std::string > m_characterTypes;
00281     CharacterMap _characters;   
00282     StringSet m_characterIds;
00283     bool m_doingCharacterRefresh; 
00284 
00285     ActiveCharacterMap m_activeCharacters;
00286     std::auto_ptr<Timeout> m_timeout;
00287 
00292     SpawnPointMap m_spawnPoints;
00293 };
00294 
00295 inline bool Account::canCreateCharacter()
00296 {
00297     return false;
00298 }
00299 
00300 inline const ActiveCharacterMap& Account::getActiveCharacters() const
00301 {
00302     return m_activeCharacters;
00303 }
00304 
00305 inline const std::string& Account::getId() const
00306 {
00307     return m_accountId;
00308 }
00309 
00310 inline const std::string& Account::getUsername() const
00311 {
00312     return m_username;
00313 }
00314 
00315 inline const std::list<std::string>& Account::getParents() const
00316 {
00317     return m_parents;
00318 }
00319 
00320 
00321 inline Connection* Account::getConnection() const
00322 {
00323     return m_con;
00324 }
00325 
00326 inline const SpawnPointMap& Account::getSpawnPoints() const
00327 {
00328     return m_spawnPoints;
00329 }
00330 
00331 
00332 } // of namespace Eris
00333 
00334 #endif