Eris  1.3.19
Account.h
1 #ifndef ERIS_PLAYER_H
2 #define ERIS_PLAYER_H
3 
4 #include <Eris/Types.h>
5 
6 #include "TransferInfo.h"
7 
8 #include <Atlas/Objects/ObjectsFwd.h>
9 
10 #include <sigc++/signal.h>
11 
12 #include <vector>
13 #include <map>
14 #include <memory>
15 
16 namespace Eris
17 {
18 
19 class Connection;
20 class Avatar;
21 class AccountRouter;
22 class Timeout;
23 class SpawnPoint;
24 
26 typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap;
27 
28 typedef std::map<std::string, Avatar*> ActiveCharacterMap;
29 
33 typedef std::map<std::string, SpawnPoint> SpawnPointMap;
34 
36 
44 class Account : virtual public sigc::trackable
45 {
46 public:
48 
53  Account(Connection *con);
54 
55  virtual ~Account();
56 
58 
67  Result login(const std::string &uname, const std::string &pwd);
68 
70  /* Create a new account on the server, if possible.
71  Server-side failures, such as an account already existing with the specified
72  username, will cause the 'LoginFailure' signal to be emitted with an error message
73  and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
74 
75  @param uname The desired username of the account (eg 'ajr')
76  @param fullName The real name of the user (e.g 'Al Riddoch')
77  @param pwd The plaintext password for the new account
78  */
79 
80  Result createAccount(const std::string &uname,
81  const std::string &fullName,
82  const std::string &pwd);
83 
85 
88  Result logout();
89 
91 
92  bool isLoggedIn() const;
93 
95  const std::vector< std::string > & getCharacterTypes(void) const;
96 
98 
103  const CharacterMap& getCharacters();
104 
112  Result refreshCharacterInfo();
113 
115 
119  Result takeTransferredCharacter(const std::string &id, const std::string &key);
120 
122 
127  Result takeCharacter(const std::string &id);
128 
130  Result createCharacter(const Atlas::Objects::Entity::RootEntity &character);
131 
133  //void createCharacter();
134 
136  bool canCreateCharacter();
137 
142  const ActiveCharacterMap& getActiveCharacters() const;
143 
148  const SpawnPointMap& getSpawnPoints() const;
149 
154  Result deactivateCharacter(Avatar* av);
155 
157  const std::string& getId() const;
158 
160  const std::string& getUsername() const;
161 
168  const std::list<std::string>& getParents() const;
169 
171  Connection* getConnection() const;
172 
182  void avatarLogoutRequested(Avatar* avatar);
183 
184 
185 // signals
187  sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
188 
190  sigc::signal<void> GotAllCharacters;
191 
193 
197  sigc::signal<void, const std::string &> LoginFailure;
198 
200  sigc::signal<void> LoginSuccess;
201 
203 
207  sigc::signal<void, bool> LogoutComplete;
208 
213  sigc::signal<void, Avatar*> AvatarSuccess;
214 
219  sigc::signal<void, const std::string &> AvatarFailure;
220 
226  sigc::signal<void, Avatar*> AvatarDeactivated;
227 
228 protected:
229  friend class AccountRouter;
230  friend class Avatar; // so avatar can call deactivateCharacter
231 
232  void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
233 
234  void loginComplete(const Atlas::Objects::Entity::Account &p);
235  void loginError(const Atlas::Objects::Operation::Error& err);
236 
237  Result internalLogin(const std::string &unm, const std::string &pwd);
238  void internalLogout(bool clean);
239 
241  void netConnected();
242 
244  bool netDisconnecting();
245  void netFailure(const std::string& msg);
246 
247  void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
248  void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
249  void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
250  void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
251 
252  void handleLogoutTimeout();
253 // void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
254 
255  void handleLoginTimeout();
256 
257  typedef enum
258  {
263 
266  } Status;
267 
268  void internalDeactivateCharacter(Avatar* av);
269  virtual void updateFromObject(const Atlas::Objects::Entity::Account &p);
270 
273  AccountRouter* m_router;
274 
275  std::string m_accountId;
276  std::string m_username;
277  std::string m_pass;
278 
279  std::list< std::string > m_parents;
280  std::vector< std::string > m_characterTypes;
281  CharacterMap _characters;
282  StringSet m_characterIds;
284 
285  ActiveCharacterMap m_activeCharacters;
286  std::auto_ptr<Timeout> m_timeout;
287 
292  SpawnPointMap m_spawnPoints;
293 };
294 
296 {
297  return false;
298 }
299 
300 inline const ActiveCharacterMap& Account::getActiveCharacters() const
301 {
302  return m_activeCharacters;
303 }
304 
305 inline const std::string& Account::getId() const
306 {
307  return m_accountId;
308 }
309 
310 inline const std::string& Account::getUsername() const
311 {
312  return m_username;
313 }
314 
315 inline const std::list<std::string>& Account::getParents() const
316 {
317  return m_parents;
318 }
319 
320 
322 {
323  return m_con;
324 }
325 
326 inline const SpawnPointMap& Account::getSpawnPoints() const
327 {
328  return m_spawnPoints;
329 }
330 
331 
332 } // of namespace Eris
333 
334 #endif