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 
00127     Result deactivateCharacter(Avatar* av);
00128 
00130     const std::string& getId() const
00131     {
00132         return m_accountId;
00133     }
00134 
00136     const std::string& getUsername() const
00137     { return m_username; }
00138 
00140     Connection* getConnection() const
00141     {
00142         return m_con;
00143     }
00144 
00145 // signals
00147     sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
00148 
00150     sigc::signal<void> GotAllCharacters;
00151 
00153 
00157     sigc::signal<void, const std::string &> LoginFailure;
00158 
00160     sigc::signal<void> LoginSuccess;
00161 
00163 
00167     sigc::signal<void, bool> LogoutComplete;
00168 
00173     sigc::signal<void, Avatar*> AvatarSuccess;
00174 
00179     sigc::signal<void, const std::string &> AvatarFailure;
00180 
00186     sigc::signal<void, Avatar*> AvatarDeactivated;
00187 protected:
00188     friend class AccountRouter;
00189     friend class Avatar; // so avatar can call deactivateCharacter
00190 
00191     void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
00192 
00193     void loginComplete(const Atlas::Objects::Entity::Account &p);
00194     void loginError(const Atlas::Objects::Operation::Error& err);
00195 
00196     Result internalLogin(const std::string &unm, const std::string &pwd);
00197     void internalLogout(bool clean);
00198 
00200     void netConnected();
00201 
00203     bool netDisconnecting();
00204     void netFailure(const std::string& msg);
00205 
00206     void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
00207     void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00208     void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
00209     void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
00210 
00211     void handleLogoutTimeout();
00212 //  void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
00213 
00214     void handleLoginTimeout();
00215 
00216     typedef enum
00217     {
00218         DISCONNECTED = 0,   
00219         LOGGING_IN,         
00220         LOGGED_IN,          
00221         LOGGING_OUT,         
00222 
00223         TAKING_CHAR,        
00224         CREATING_CHAR       
00225     } Status;
00226 
00227     void internalDeactivateCharacter(Avatar* av);
00228     void updateFromObject(const Atlas::Objects::Entity::Account &p);
00229 
00230     Connection* m_con;  
00231     Status m_status;    
00232     AccountRouter* m_router;
00233 
00234     std::string m_accountId;    
00235     std::string m_username; 
00236     std::string m_pass;
00237 
00238     std::vector< std::string > m_characterTypes;
00239     CharacterMap _characters;   
00240     StringSet m_characterIds;
00241     bool m_doingCharacterRefresh; 
00242 
00243     ActiveCharacterMap m_activeCharacters;
00244     std::auto_ptr<Timeout> m_timeout;
00245 };
00246 
00247 } // of namespace Eris
00248 
00249 #endif

Generated on Tue Mar 18 00:36:52 2008 for Eris by  doxygen 1.5.4