Eris  1.4.0
Account.h
1 #ifndef ERIS_PLAYER_H
2 #define ERIS_PLAYER_H
3 
4 #include "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 TimedEvent;
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  explicit 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 
84  /* Create a new account on the server, if possible.
85  Server-side failures, such as an account already existing with the specified
86  username, will cause the 'LoginFailure' signal to be emitted with an error message
87  and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
88 
89  This variant allows you to specify your own Account op, which is useful when you
90  want to create an account different from the standard one.
91 
92  @param accountOp The account operation, which will be wrapped in a "Create" op.
93  */
94  Result createAccount(const Atlas::Objects::Entity::Account& accountOp);
95 
96 
98 
101  Result logout();
102 
104 
105  bool isLoggedIn() const;
106 
108  const std::vector<std::string> & getCharacterTypes() const;
109 
111 
116  const CharacterMap& getCharacters();
117 
126 
128 
132  Result takeTransferredCharacter(const std::string &id, const std::string &key);
133 
135 
140  Result takeCharacter(const std::string &id);
141 
143  Result createCharacter(const Atlas::Objects::Entity::RootEntity &character);
144 
146  //void createCharacter();
147 
149  bool canCreateCharacter();
150 
155  const ActiveCharacterMap& getActiveCharacters() const;
156 
161  const SpawnPointMap& getSpawnPoints() const;
162 
168 
170  const std::string& getId() const;
171 
173  const std::string& getUsername() const;
174 
178  const std::string& getParent() const;
179 
181  Connection* getConnection() const;
182 
192  void avatarLogoutRequested(Avatar* avatar);
193 
194 
195 // signals
197  sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
198 
200  sigc::signal<void> GotAllCharacters;
201 
203 
207  sigc::signal<void, const std::string &> LoginFailure;
208 
210  sigc::signal<void> LoginSuccess;
211 
213 
217  sigc::signal<void, bool> LogoutComplete;
218 
223  sigc::signal<void, Avatar*> AvatarSuccess;
224 
229  sigc::signal<void, const std::string &> AvatarFailure;
230 
236  sigc::signal<void, Avatar*> AvatarDeactivated;
237 
241  sigc::signal<void, const std::string&> ErrorMessage;
242 
243 protected:
244  friend class AccountRouter;
245  friend class Avatar; // so avatar can call deactivateCharacter
246 
247  void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
248 
249  void loginComplete(const Atlas::Objects::Entity::Account &p);
250  void loginError(const Atlas::Objects::Operation::Error& err);
251 
252  Result internalLogin(const std::string &unm, const std::string &pwd);
253  void internalLogout(bool clean);
254 
256  void netConnected();
257 
259  bool netDisconnecting();
260  void netFailure(const std::string& msg);
261 
262  void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
263  void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
264  void possessResponse(const Atlas::Objects::Operation::RootOperation& op);
265  void avatarCreateResponse(const Atlas::Objects::Operation::RootOperation& op);
266  void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
267 
276  void destroyAvatar(const std::string& avatarId);
277 
278  void handleLogoutTimeout();
279 // void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
280 
281  void handleLoginTimeout();
282 
283  typedef enum
284  {
289 
292  } Status;
293 
294  void internalDeactivateCharacter(Avatar* av);
295  virtual void updateFromObject(const Atlas::Objects::Entity::Account &p);
296 
298  Status m_status;
299  AccountRouter* m_router;
300 
301  std::string m_accountId;
302  std::string m_username;
303  std::string m_pass;
304 
305  std::string m_parent;
306  std::vector< std::string > m_characterTypes;
307  CharacterMap _characters;
308  StringSet m_characterIds;
310 
311  ActiveCharacterMap m_activeCharacters;
312  std::unique_ptr<TimedEvent> m_timeout;
313 
318  SpawnPointMap m_spawnPoints;
319 };
320 
322 {
323  return false;
324 }
325 
326 inline const ActiveCharacterMap& Account::getActiveCharacters() const
327 {
328  return m_activeCharacters;
329 }
330 
331 inline const std::string& Account::getId() const
332 {
333  return m_accountId;
334 }
335 
336 inline const std::string& Account::getUsername() const
337 {
338  return m_username;
339 }
340 
341 inline const std::string& Account::getParent() const
342 {
343  return m_parent;
344 }
345 
346 
348 {
349  return m_con;
350 }
351 
352 inline const SpawnPointMap& Account::getSpawnPoints() const
353 {
354  return m_spawnPoints;
355 }
356 
357 
358 } // of namespace Eris
359 
360 #endif
Result takeCharacter(const std::string &id)
Enter the game using an existing character.
Definition: Account.cpp:328
Result createCharacter(const Atlas::Objects::Entity::RootEntity &character)
enter the game using a new character
Definition: Account.cpp:248
void avatarLogoutRequested(Avatar *avatar)
Called when a logout of the avatar has been requested by the server.
Definition: Account.cpp:465
const std::vector< std::string > & getCharacterTypes() const
Returns a container of character types that the client is allowed to create.
Definition: Account.cpp:201
Default state, no server account active.
Definition: Account.h:285
sigc::signal< void, const std::string & > ErrorMessage
Emitted when an error message is received.
Definition: Account.h:241
Result refreshCharacterInfo()
Update the character list (based on changes to play).
Definition: Account.cpp:214
Login sent, waiting for initial INFO response.
Definition: Account.h:286
Result deactivateCharacter(Avatar *av)
Request de-activation of a character.
Definition: Account.cpp:361
Connection * m_con
underlying connection instance
Definition: Account.h:297
sigc::signal< void, const std::string & > AvatarFailure
Emitted when creating or taking a character fails for some reason.
Definition: Account.h:229
bool isLoggedIn() const
Check if the account is logged in.
Definition: Account.cpp:367
send a character CREATE op, awaiting INFO response
Definition: Account.h:291
sent a LOOK op for a character, awaiting INFO response
Definition: Account.h:290
Account(Connection *con)
Create a new Account associated with a Connection object.
Definition: Account.cpp:91
const ActiveCharacterMap & getActiveCharacters() const
Gets a list of active characters, i.e.
Definition: Account.h:326
sigc::signal< void > GotAllCharacters
emitted when the entire character list had been updated
Definition: Account.h:200
void destroyAvatar(const std::string &avatarId)
Destroys the avatar with the specified id, if available.
Definition: Account.cpp:471
sigc::signal< void, Avatar * > AvatarSuccess
Emitted when creating a character or taking an existing one succeeds.
Definition: Account.h:223
const std::string & getParent() const
Gets the parent type of the account.
Definition: Account.h:341
sigc::signal< void > LoginSuccess
Emitted when login or character creation is successful.
Definition: Account.h:210
SpawnPointMap m_spawnPoints
A map of available spawn points.
Definition: Account.h:318
Result login(const std::string &uname, const std::string &pwd)
Login to the server using user-supplied account information.
Definition: Account.cpp:119
Definition: Account.cpp:36
Connection * getConnection() const
Access the underlying Connection for this account.
Definition: Account.h:347
Represents a possible spawn point as described by the server. When a new character is created on the ...
Definition: SpawnPoint.h:30
CharacterMap _characters
characters belonging to this player
Definition: Account.h:307
Status m_status
what the Player is currently doing
Definition: Account.h:298
bool canCreateCharacter()
pop up the game&#39;s character creation dialog, if present
Definition: Account.h:321
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
Sent a logout op, waiting for the INFO response.
Definition: Account.h:288
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:36
Fully logged into a server-side account.
Definition: Account.h:287
sigc::signal< void, Avatar * > AvatarDeactivated
Emitted when an active avatar is deactivated.
Definition: Account.h:236
Status
Definition: Account.h:283
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:134
bool m_doingCharacterRefresh
set if we&#39;re refreshing character data
Definition: Account.h:309
Encapsulates all the state of an Atlas Account, and methods that operation on that state...
Definition: Account.h:44
std::map< std::string, SpawnPoint > SpawnPointMap
A store of spawn points.
Definition: Account.h:33
std::string m_username
The player&#39;s username ( != account object&#39;s ID)
Definition: Account.h:302
std::string m_accountId
the account ID
Definition: Account.h:301
Result
Result codes returned from various methods.
Definition: Types.h:34
const std::string & getUsername() const
Return the username of this account.
Definition: Account.h:336
const SpawnPointMap & getSpawnPoints() const
Gets the available spawn points from where the client can create new characters.
Definition: Account.h:352
std::map< std::string, Atlas::Objects::Entity::RootEntity > CharacterMap
Type used to return available characters.
Definition: Account.h:23
sigc::signal< void, const std::string & > LoginFailure
Emitted when a server-side error occurs during account creation / login.
Definition: Account.h:207
const std::string & getId() const
returns the account ID if logged in
Definition: Account.h:331
Result logout()
Request logout from the server.
Definition: Account.cpp:170
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:298
void netConnected()
Callback for network re-establishment.
Definition: Account.cpp:720
const CharacterMap & getCharacters()
Get the characters owned by this account.
Definition: Account.cpp:206
sigc::signal< void, bool > LogoutComplete
Emitted when a logout completes.
Definition: Account.h:217
The player&#39;s avatar representation.
Definition: Avatar.h:34
bool netDisconnecting()
help! the plug is being pulled!
Definition: Account.cpp:729
sigc::signal< void, const Atlas::Objects::Entity::RootEntity & > GotCharacterInfo
emitted when a character has been retrieved from the server
Definition: Account.h:197