Account.h

00001 #ifndef ERIS_PLAYER_H
00002 #define ERIS_PLAYER_H
00003 
00004 #include <vector>
00005 #include <map>
00006 
00007 #include <Eris/Types.h>
00008 #include <Eris/Timeout.h>
00009 #include <sigc++/trackable.h>
00010 #include <Atlas/Objects/ObjectsFwd.h>
00011 
00012 namespace Eris
00013 {
00014         
00015 class Connection;
00016 class Avatar;
00017 class AccountRouter;
00018 
00020 typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap;
00021 
00022 typedef std::map<std::string, Avatar*> ActiveCharacterMap;
00023 
00025 
00033 class Account : virtual public sigc::trackable
00034 {
00035 public:
00037 
00042     Account(Connection *con);
00043    
00044      ~Account();
00045 
00047 
00056     Result login(const std::string &uname, const std::string &pwd);
00057 
00059     /* Create a new account on the server, if possible.
00060     Server-side failures, such as an account already existing with the specified
00061     username, will cause the 'LoginFailure' signal to be emitted with an error message
00062     and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan. 
00063    
00064     @param uname The desired username of the account (eg 'ajr')
00065     @param fullName The real name of the user (e.g 'Al Riddoch')
00066     @param pwd The plaintext password for the new account
00067     */
00068 
00069     Result createAccount(const std::string &uname,
00070         const std::string &fullName,
00071         const std::string &pwd);
00072         
00074 
00077     Result logout();
00078 
00080 
00081     bool isLoggedIn() const;
00082         
00084         const std::vector< std::string > & getCharacterTypes(void) const;
00085     
00087 
00092     const CharacterMap& getCharacters();
00093 
00101     Result refreshCharacterInfo();
00102 
00104 
00109     Result takeCharacter(const std::string &id);
00110 
00112     Result createCharacter(const Atlas::Objects::Entity::RootEntity &character);
00113 
00115         //void createCharacter();
00116 
00118         bool canCreateCharacter() {return false;}
00119 
00120     const ActiveCharacterMap& getActiveCharacters() const
00121     { return m_activeCharacters; }
00122 
00124     const std::string& getId() const
00125     {
00126         return m_accountId;
00127     }
00128 
00130     const std::string& getUsername() const
00131     { return m_username; }
00132 
00134     Connection* getConnection() const 
00135     {
00136         return m_con;
00137     }
00138 
00139 // signals
00141     sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
00142     
00144     sigc::signal<void> GotAllCharacters;
00145     
00147 
00151     sigc::signal<void, const std::string &> LoginFailure;
00152     
00154     sigc::signal<void> LoginSuccess;
00155     
00157 
00161     sigc::signal<void, bool> LogoutComplete;
00162 
00167     sigc::signal<void, Avatar*> AvatarSuccess;
00168 
00169     sigc::signal<void, const std::string &> AvatarFailure;
00170 
00171 protected:
00172     friend class AccountRouter;
00173     friend class Avatar; // so avatar can call deactivateCharacter
00174     
00175     void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
00176     
00177     void loginComplete(const Atlas::Objects::Entity::Account &p);
00178     void loginError(const Atlas::Objects::Operation::Error& err);
00179 
00180     Result internalLogin(const std::string &unm, const std::string &pwd);
00181     void internalLogout(bool clean);
00182 
00184         void netConnected();
00185         
00187         bool netDisconnecting();
00188         void netFailure(const std::string& msg);
00189 
00190     void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
00191     void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00192     void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
00193     
00194         void handleLogoutTimeout();
00195 //      void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
00196 
00197     void handleLoginTimeout();
00198     
00199     typedef enum
00200     {
00201         DISCONNECTED = 0,   
00202         LOGGING_IN,         
00203         LOGGED_IN,          
00204         LOGGING_OUT,         
00205         
00206         TAKING_CHAR,        
00207         CREATING_CHAR       
00208     } Status;
00209         
00210     void deactivateCharacter(Avatar* av);
00211 private:
00212     Connection* m_con;  
00213     Status m_status;    
00214     AccountRouter* m_router;
00215     
00216     std::string m_accountId;    
00217     std::string m_username;     
00218     std::string m_pass;
00219     
00220         std::vector< std::string > m_characterTypes;
00221     CharacterMap _characters;   
00222     StringSet m_characterIds;
00223     bool m_doingCharacterRefresh; 
00224     
00225     ActiveCharacterMap m_activeCharacters;
00226     std::auto_ptr<Timeout> m_timeout;
00227 };
00228         
00229 } // of namespace Eris
00230 
00231 #endif

Generated on Tue Feb 7 13:20:24 2006 for Eris by  doxygen 1.4.6