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
Connection * getConnection() const
Access the underlying Connection for this account.
Definition: Account.h:321
Result takeCharacter(const std::string &id)
Enter the game using an existing character.
Definition: Account.cpp:310
Result createCharacter(const Atlas::Objects::Entity::RootEntity &character)
enter the game using a new character
Definition: Account.cpp:235
void avatarLogoutRequested(Avatar *avatar)
Called when a logout of the avatar has been requested by the server.
Definition: Account.cpp:449
Default state, no server account active.
Definition: Account.h:259
const std::list< std::string > & getParents() const
Gets the parent types of the account.
Definition: Account.h:315
Result refreshCharacterInfo()
Update the character list (based on changes to play).
Definition: Account.cpp:200
Login sent, waiting for initial INFO response.
Definition: Account.h:260
const std::vector< std::string > & getCharacterTypes(void) const
Returns a container of character types that the client is allowed to create.
Definition: Account.cpp:187
Result deactivateCharacter(Avatar *av)
Request de-activation of a character.
Definition: Account.cpp:342
Connection * m_con
underlying connection instance
Definition: Account.h:271
sigc::signal< void, const std::string & > AvatarFailure
Emitted when creating or taking a character fails for some reason.
Definition: Account.h:219
send a character CREATE op, awaiting INFO response
Definition: Account.h:265
sent a LOOK op for a character, awaiting INFO response
Definition: Account.h:264
const std::string & getId() const
returns the account ID if logged in
Definition: Account.h:305
Account(Connection *con)
Create a new Account associated with a Connection object.
Definition: Account.cpp:81
sigc::signal< void > GotAllCharacters
emitted when the entire character list had been updated
Definition: Account.h:190
const SpawnPointMap & getSpawnPoints() const
Gets the available spawn points from where the client can create new characters.
Definition: Account.h:326
sigc::signal< void, Avatar * > AvatarSuccess
Emitted when creating a character or taking an existing one succeeds.
Definition: Account.h:213
sigc::signal< void > LoginSuccess
Emitted when login or character creation is successful.
Definition: Account.h:200
SpawnPointMap m_spawnPoints
A map of available spawn points.
Definition: Account.h:292
Result login(const std::string &uname, const std::string &pwd)
Login to the server using user-supplied account information.
Definition: Account.cpp:109
const std::string & getUsername() const
Return the username of this account.
Definition: Account.h:310
Definition: Account.cpp:37
CharacterMap _characters
characters belonging to this player
Definition: Account.h:281
Status m_status
what the Player is currently doing
Definition: Account.h:272
bool canCreateCharacter()
pop up the game's character creation dialog, if present
Definition: Account.h:295
Sent a logout op, waiting for the INFO response.
Definition: Account.h:262
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:37
Fully logged into a server-side account.
Definition: Account.h:261
sigc::signal< void, Avatar * > AvatarDeactivated
Emitted when an active avatar is deactivated.
Definition: Account.h:226
Status
Definition: Account.h:257
Result createAccount(const std::string &uname, const std::string &fullName, const std::string &pwd)
Attempt to create a new account on the server and log into it.
Definition: Account.cpp:124
bool m_doingCharacterRefresh
set if we're refreshing character data
Definition: Account.h:283
Encapsulates all the state of an Atlas Account, and methods that operation on that state...
Definition: Account.h:44
std::string m_username
The player's username ( != account object's ID)
Definition: Account.h:276
std::string m_accountId
the account ID
Definition: Account.h:275
sigc::signal< void, const std::string & > LoginFailure
Emitted when a server-side error occurs during account creation / login.
Definition: Account.h:197
Result logout()
Request logout from the server.
Definition: Account.cpp:156
const ActiveCharacterMap & getActiveCharacters() const
Gets a list of active characters, i.e.
Definition: Account.h:300
Result takeTransferredCharacter(const std::string &id, const std::string &key)
Transfer all characters to this account and then do all steps in takeCharacter()
Definition: Account.cpp:282
void netConnected()
Callback for network re-establishment.
Definition: Account.cpp:667
const CharacterMap & getCharacters()
Get the characters owned by this account.
Definition: Account.cpp:192
bool isLoggedIn() const
Check if the account is logged in.
Definition: Account.cpp:348
sigc::signal< void, bool > LogoutComplete
Emitted when a logout completes.
Definition: Account.h:207
The player's avatar representation.
Definition: Avatar.h:31
bool netDisconnecting()
help! the plug is being pulled!
Definition: Account.cpp:676
sigc::signal< void, const Atlas::Objects::Entity::RootEntity & > GotCharacterInfo
emitted when a character has been retrieved from the server
Definition: Account.h:187