Account.h

00001 #ifndef ERIS_PLAYER_H
00002 #define ERIS_PLAYER_H
00003 
00004 #include <vector>
00005 #include <map>
00006 #include <backward/auto_ptr.h>
00007 
00008 #include <Eris/Types.h>
00009 #include <Eris/Timeout.h>
00010 #include <sigc++/trackable.h>
00011 #include <Atlas/Objects/ObjectsFwd.h>
00012 
00013 namespace Eris
00014 {
00015 
00016 class Connection;
00017 class Avatar;
00018 class AccountRouter;
00019 
00021 typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap;
00022 
00023 typedef std::map<std::string, Avatar*> ActiveCharacterMap;
00024 
00026 
00034 class Account : virtual public sigc::trackable
00035 {
00036 public:
00038 
00043     Account(Connection *con);
00044 
00045      ~Account();
00046 
00048 
00057     Result login(const std::string &uname, const std::string &pwd);
00058 
00060     /* Create a new account on the server, if possible.
00061     Server-side failures, such as an account already existing with the specified
00062     username, will cause the 'LoginFailure' signal to be emitted with an error message
00063     and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
00064 
00065     @param uname The desired username of the account (eg 'ajr')
00066     @param fullName The real name of the user (e.g 'Al Riddoch')
00067     @param pwd The plaintext password for the new account
00068     */
00069 
00070     Result createAccount(const std::string &uname,
00071         const std::string &fullName,
00072         const std::string &pwd);
00073 
00075 
00078     Result logout();
00079 
00081 
00082     bool isLoggedIn() const;
00083 
00085     const std::vector< std::string > & getCharacterTypes(void) const;
00086 
00088 
00093     const CharacterMap& getCharacters();
00094 
00102     Result refreshCharacterInfo();
00103 
00105 
00110     Result takeCharacter(const std::string &id);
00111 
00113     Result createCharacter(const Atlas::Objects::Entity::RootEntity &character);
00114 
00116     //void createCharacter();
00117 
00119     bool canCreateCharacter() {return false;}
00120 
00121     const ActiveCharacterMap& getActiveCharacters() const
00122     { return m_activeCharacters; }
00123 
00128     Result deactivateCharacter(Avatar* av);
00129 
00131     const std::string& getId() const
00132     {
00133         return m_accountId;
00134     }
00135 
00137     const std::string& getUsername() const
00138     { return m_username; }
00139 
00141     Connection* getConnection() const
00142     {
00143         return m_con;
00144     }
00145 
00146 // signals
00148     sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
00149 
00151     sigc::signal<void> GotAllCharacters;
00152 
00154 
00158     sigc::signal<void, const std::string &> LoginFailure;
00159 
00161     sigc::signal<void> LoginSuccess;
00162 
00164 
00168     sigc::signal<void, bool> LogoutComplete;
00169 
00174     sigc::signal<void, Avatar*> AvatarSuccess;
00175 
00180     sigc::signal<void, const std::string &> AvatarFailure;
00181 
00187     sigc::signal<void, Avatar*> AvatarDeactivated;
00188 protected:
00189     friend class AccountRouter;
00190     friend class Avatar; // so avatar can call deactivateCharacter
00191 
00192     void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
00193 
00194     void loginComplete(const Atlas::Objects::Entity::Account &p);
00195     void loginError(const Atlas::Objects::Operation::Error& err);
00196 
00197     Result internalLogin(const std::string &unm, const std::string &pwd);
00198     void internalLogout(bool clean);
00199 
00201     void netConnected();
00202 
00204     bool netDisconnecting();
00205     void netFailure(const std::string& msg);
00206 
00207     void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
00208     void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00209     void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
00210     void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00211 
00212     void handleLogoutTimeout();
00213 //  void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
00214 
00215     void handleLoginTimeout();
00216 
00217     typedef enum
00218     {
00219         DISCONNECTED = 0,   
00220         LOGGING_IN,         
00221         LOGGED_IN,          
00222         LOGGING_OUT,         
00223 
00224         TAKING_CHAR,        
00225         CREATING_CHAR       
00226     } Status;
00227 
00228     void internalDeactivateCharacter(Avatar* av);
00229     void updateFromObject(const Atlas::Objects::Entity::Account &p);
00230 
00231     Connection* m_con;  
00232     Status m_status;    
00233     AccountRouter* m_router;
00234 
00235     std::string m_accountId;    
00236     std::string m_username; 
00237     std::string m_pass;
00238 
00239     std::vector< std::string > m_characterTypes;
00240     CharacterMap _characters;   
00241     StringSet m_characterIds;
00242     bool m_doingCharacterRefresh; 
00243 
00244     ActiveCharacterMap m_activeCharacters;
00245     std::auto_ptr<Timeout> m_timeout;
00246 };
00247 
00248 } // of namespace Eris
00249 
00250 #endif

Generated for Eris by  doxygen 1.5.4