Eris 1.3.16
|
00001 #ifndef ERIS_PLAYER_H 00002 #define ERIS_PLAYER_H 00003 00004 #include <Eris/Types.h> 00005 00006 #include <Atlas/Objects/ObjectsFwd.h> 00007 00008 #include <sigc++/signal.h> 00009 00010 #include <vector> 00011 #include <map> 00012 #include <memory> 00013 00014 namespace Eris 00015 { 00016 00017 class Connection; 00018 class Avatar; 00019 class AccountRouter; 00020 class Timeout; 00021 class SpawnPoint; 00022 00024 typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap; 00025 00026 typedef std::map<std::string, Avatar*> ActiveCharacterMap; 00027 00031 typedef std::map<std::string, SpawnPoint> SpawnPointMap; 00032 00034 00042 class Account : virtual public sigc::trackable 00043 { 00044 public: 00046 00051 Account(Connection *con); 00052 00053 virtual ~Account(); 00054 00056 00065 Result login(const std::string &uname, const std::string &pwd); 00066 00068 /* Create a new account on the server, if possible. 00069 Server-side failures, such as an account already existing with the specified 00070 username, will cause the 'LoginFailure' signal to be emitted with an error message 00071 and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan. 00072 00073 @param uname The desired username of the account (eg 'ajr') 00074 @param fullName The real name of the user (e.g 'Al Riddoch') 00075 @param pwd The plaintext password for the new account 00076 */ 00077 00078 Result createAccount(const std::string &uname, 00079 const std::string &fullName, 00080 const std::string &pwd); 00081 00083 00086 Result logout(); 00087 00089 00090 bool isLoggedIn() const; 00091 00093 const std::vector< std::string > & getCharacterTypes(void) const; 00094 00096 00101 const CharacterMap& getCharacters(); 00102 00110 Result refreshCharacterInfo(); 00111 00113 00118 Result takeCharacter(const std::string &id); 00119 00121 Result createCharacter(const Atlas::Objects::Entity::RootEntity &character); 00122 00124 //void createCharacter(); 00125 00127 bool canCreateCharacter(); 00128 00133 const ActiveCharacterMap& getActiveCharacters() const; 00134 00139 const SpawnPointMap& getSpawnPoints() const; 00140 00145 Result deactivateCharacter(Avatar* av); 00146 00148 const std::string& getId() const; 00149 00151 const std::string& getUsername() const; 00152 00159 const std::list<std::string>& getParents() const; 00160 00162 Connection* getConnection() const; 00163 00164 // signals 00166 sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo; 00167 00169 sigc::signal<void> GotAllCharacters; 00170 00172 00176 sigc::signal<void, const std::string &> LoginFailure; 00177 00179 sigc::signal<void> LoginSuccess; 00180 00182 00186 sigc::signal<void, bool> LogoutComplete; 00187 00192 sigc::signal<void, Avatar*> AvatarSuccess; 00193 00198 sigc::signal<void, const std::string &> AvatarFailure; 00199 00205 sigc::signal<void, Avatar*> AvatarDeactivated; 00206 protected: 00207 friend class AccountRouter; 00208 friend class Avatar; // so avatar can call deactivateCharacter 00209 00210 void sightCharacter(const Atlas::Objects::Operation::RootOperation& op); 00211 00212 void loginComplete(const Atlas::Objects::Entity::Account &p); 00213 void loginError(const Atlas::Objects::Operation::Error& err); 00214 00215 Result internalLogin(const std::string &unm, const std::string &pwd); 00216 void internalLogout(bool clean); 00217 00219 void netConnected(); 00220 00222 bool netDisconnecting(); 00223 void netFailure(const std::string& msg); 00224 00225 void loginResponse(const Atlas::Objects::Operation::RootOperation& op); 00226 void logoutResponse(const Atlas::Objects::Operation::RootOperation& op); 00227 void avatarResponse(const Atlas::Objects::Operation::RootOperation& op); 00228 void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op); 00229 00230 void handleLogoutTimeout(); 00231 // void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo); 00232 00233 void handleLoginTimeout(); 00234 00235 typedef enum 00236 { 00237 DISCONNECTED = 0, 00238 LOGGING_IN, 00239 LOGGED_IN, 00240 LOGGING_OUT, 00241 00242 TAKING_CHAR, 00243 CREATING_CHAR 00244 } Status; 00245 00246 void internalDeactivateCharacter(Avatar* av); 00247 virtual void updateFromObject(const Atlas::Objects::Entity::Account &p); 00248 00249 Connection* m_con; 00250 Status m_status; 00251 AccountRouter* m_router; 00252 00253 std::string m_accountId; 00254 std::string m_username; 00255 std::string m_pass; 00256 00257 std::list< std::string > m_parents; 00258 std::vector< std::string > m_characterTypes; 00259 CharacterMap _characters; 00260 StringSet m_characterIds; 00261 bool m_doingCharacterRefresh; 00262 00263 ActiveCharacterMap m_activeCharacters; 00264 std::auto_ptr<Timeout> m_timeout; 00265 00270 SpawnPointMap m_spawnPoints; 00271 }; 00272 00273 inline bool Account::canCreateCharacter() 00274 { 00275 return false; 00276 } 00277 00278 inline const ActiveCharacterMap& Account::getActiveCharacters() const 00279 { 00280 return m_activeCharacters; 00281 } 00282 00283 inline const std::string& Account::getId() const 00284 { 00285 return m_accountId; 00286 } 00287 00288 inline const std::string& Account::getUsername() const 00289 { 00290 return m_username; 00291 } 00292 00293 inline const std::list<std::string>& Account::getParents() const 00294 { 00295 return m_parents; 00296 } 00297 00298 00299 inline Connection* Account::getConnection() const 00300 { 00301 return m_con; 00302 } 00303 00304 inline const SpawnPointMap& Account::getSpawnPoints() const 00305 { 00306 return m_spawnPoints; 00307 } 00308 00309 00310 } // of namespace Eris 00311 00312 #endif