Eris  1.3.23
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 
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(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(void) const;
109 
111 
116  const CharacterMap& getCharacters();
117 
125  Result refreshCharacterInfo();
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 
167  Result deactivateCharacter(Avatar* av);
168 
170  const std::string& getId() const;
171 
173  const std::string& getUsername() const;
174 
181  const std::list<std::string>& getParents() const;
182 
184  Connection* getConnection() const;
185 
195  void avatarLogoutRequested(Avatar* avatar);
196 
197 
198 // signals
200  sigc::signal<void, const Atlas::Objects::Entity::RootEntity&> GotCharacterInfo;
201 
203  sigc::signal<void> GotAllCharacters;
204 
206 
210  sigc::signal<void, const std::string &> LoginFailure;
211 
213  sigc::signal<void> LoginSuccess;
214 
216 
220  sigc::signal<void, bool> LogoutComplete;
221 
226  sigc::signal<void, Avatar*> AvatarSuccess;
227 
232  sigc::signal<void, const std::string &> AvatarFailure;
233 
239  sigc::signal<void, Avatar*> AvatarDeactivated;
240 
241 protected:
242  friend class AccountRouter;
243  friend class Avatar; // so avatar can call deactivateCharacter
244 
245  void sightCharacter(const Atlas::Objects::Operation::RootOperation& op);
246 
247  void loginComplete(const Atlas::Objects::Entity::Account &p);
248  void loginError(const Atlas::Objects::Operation::Error& err);
249 
250  Result internalLogin(const std::string &unm, const std::string &pwd);
251  void internalLogout(bool clean);
252 
254  void netConnected();
255 
257  bool netDisconnecting();
258  void netFailure(const std::string& msg);
259 
260  void loginResponse(const Atlas::Objects::Operation::RootOperation& op);
261  void logoutResponse(const Atlas::Objects::Operation::RootOperation& op);
262  void avatarResponse(const Atlas::Objects::Operation::RootOperation& op);
263  void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation& op);
264 
265  void handleLogoutTimeout();
266 // void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
267 
268  void handleLoginTimeout();
269 
270  typedef enum
271  {
276 
279  } Status;
280 
281  void internalDeactivateCharacter(Avatar* av);
282  virtual void updateFromObject(const Atlas::Objects::Entity::Account &p);
283 
285  Status m_status;
286  AccountRouter* m_router;
287 
288  std::string m_accountId;
289  std::string m_username;
290  std::string m_pass;
291 
292  std::list< std::string > m_parents;
293  std::vector< std::string > m_characterTypes;
294  CharacterMap _characters;
295  StringSet m_characterIds;
297 
298  ActiveCharacterMap m_activeCharacters;
299  std::unique_ptr<Timeout> m_timeout;
300 
305  SpawnPointMap m_spawnPoints;
306 };
307 
309 {
310  return false;
311 }
312 
313 inline const ActiveCharacterMap& Account::getActiveCharacters() const
314 {
315  return m_activeCharacters;
316 }
317 
318 inline const std::string& Account::getId() const
319 {
320  return m_accountId;
321 }
322 
323 inline const std::string& Account::getUsername() const
324 {
325  return m_username;
326 }
327 
328 inline const std::list<std::string>& Account::getParents() const
329 {
330  return m_parents;
331 }
332 
333 
335 {
336  return m_con;
337 }
338 
339 inline const SpawnPointMap& Account::getSpawnPoints() const
340 {
341  return m_spawnPoints;
342 }
343 
344 
345 } // of namespace Eris
346 
347 #endif
Result takeCharacter(const std::string &id)
Enter the game using an existing character.
Definition: Account.cpp:313
Result createCharacter(const Atlas::Objects::Entity::RootEntity &character)
enter the game using a new character
Definition: Account.cpp:238
void avatarLogoutRequested(Avatar *avatar)
Called when a logout of the avatar has been requested by the server.
Definition: Account.cpp:452
Default state, no server account active.
Definition: Account.h:272
const std::vector< std::string > & getCharacterTypes(void) const
Returns a container of character types that the client is allowed to create.
Definition: Account.cpp:190
Result refreshCharacterInfo()
Update the character list (based on changes to play).
Definition: Account.cpp:203
Login sent, waiting for initial INFO response.
Definition: Account.h:273
Result deactivateCharacter(Avatar *av)
Request de-activation of a character.
Definition: Account.cpp:345
Connection * m_con
underlying connection instance
Definition: Account.h:284
sigc::signal< void, const std::string & > AvatarFailure
Emitted when creating or taking a character fails for some reason.
Definition: Account.h:232
bool isLoggedIn() const
Check if the account is logged in.
Definition: Account.cpp:351
send a character CREATE op, awaiting INFO response
Definition: Account.h:278
sent a LOOK op for a character, awaiting INFO response
Definition: Account.h:277
Account(Connection *con)
Create a new Account associated with a Connection object.
Definition: Account.cpp:79
const ActiveCharacterMap & getActiveCharacters() const
Gets a list of active characters, i.e.
Definition: Account.h:313
sigc::signal< void > GotAllCharacters
emitted when the entire character list had been updated
Definition: Account.h:203
sigc::signal< void, Avatar * > AvatarSuccess
Emitted when creating a character or taking an existing one succeeds.
Definition: Account.h:226
const std::list< std::string > & getParents() const
Gets the parent types of the account.
Definition: Account.h:328
sigc::signal< void > LoginSuccess
Emitted when login or character creation is successful.
Definition: Account.h:213
SpawnPointMap m_spawnPoints
A map of available spawn points.
Definition: Account.h:305
Result login(const std::string &uname, const std::string &pwd)
Login to the server using user-supplied account information.
Definition: Account.cpp:107
Definition: Account.cpp:35
Connection * getConnection() const
Access the underlying Connection for this account.
Definition: Account.h:334
CharacterMap _characters
characters belonging to this player
Definition: Account.h:294
Status m_status
what the Player is currently doing
Definition: Account.h:285
bool canCreateCharacter()
pop up the game&#39;s character creation dialog, if present
Definition: Account.h:308
Definition: Account.cpp:33
Sent a logout op, waiting for the INFO response.
Definition: Account.h:275
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:274
sigc::signal< void, Avatar * > AvatarDeactivated
Emitted when an active avatar is deactivated.
Definition: Account.h:239
Status
Definition: Account.h:270
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:122
bool m_doingCharacterRefresh
set if we&#39;re refreshing character data
Definition: Account.h:296
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&#39;s username ( != account object&#39;s ID)
Definition: Account.h:289
std::string m_accountId
the account ID
Definition: Account.h:288
const std::string & getUsername() const
Return the username of this account.
Definition: Account.h:323
const SpawnPointMap & getSpawnPoints() const
Gets the available spawn points from where the client can create new characters.
Definition: Account.h:339
sigc::signal< void, const std::string & > LoginFailure
Emitted when a server-side error occurs during account creation / login.
Definition: Account.h:210
const std::string & getId() const
returns the account ID if logged in
Definition: Account.h:318
Result logout()
Request logout from the server.
Definition: Account.cpp:159
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:285
void netConnected()
Callback for network re-establishment.
Definition: Account.cpp:671
const CharacterMap & getCharacters()
Get the characters owned by this account.
Definition: Account.cpp:195
sigc::signal< void, bool > LogoutComplete
Emitted when a logout completes.
Definition: Account.h:220
The player&#39;s avatar representation.
Definition: Avatar.h:31
bool netDisconnecting()
help! the plug is being pulled!
Definition: Account.cpp:680
sigc::signal< void, const Atlas::Objects::Entity::RootEntity & > GotCharacterInfo
emitted when a character has been retrieved from the server
Definition: Account.h:200