eris  1.4.0
A WorldForge client library.
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  class Connection;
19 
20  class Avatar;
21 
22  class AccountRouter;
23 
24  class TimedEvent;
25 
26  struct SpawnPoint;
27 
29  typedef std::map<std::string, Atlas::Objects::Entity::RootEntity> CharacterMap;
30 
31  typedef std::map<std::string, std::unique_ptr<Avatar>> ActiveCharacterMap;
32 
34 
42  class Account : virtual public sigc::trackable {
43  public:
45 
50  explicit Account(Connection &con);
51 
52  virtual ~Account();
53 
55 
64  Result login(const std::string &uname, const std::string &pwd);
65 
67  /* Create a new account on the server, if possible.
68  Server-side failures, such as an account already existing with the specified
69  username, will cause the 'LoginFailure' signal to be emitted with an error message
70  and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
71 
72  @param uname The desired username of the account (eg 'ajr')
73  @param fullName The real name of the user (e.g 'Al Riddoch')
74  @param pwd The plaintext password for the new account
75  */
76 
77  Result createAccount(const std::string &uname,
78  const std::string &fullName,
79  const std::string &pwd);
80 
81  /* Create a new account on the server, if possible.
82  Server-side failures, such as an account already existing with the specified
83  username, will cause the 'LoginFailure' signal to be emitted with an error message
84  and a code. As for 'login', LoginSuccess wil be emitted if everything goes as plan.
85 
86  This variant allows you to specify your own Account op, which is useful when you
87  want to create an account different from the standard one.
88 
89  @param accountOp The account operation, which will be wrapped in a "Create" op.
90  */
91  Result createAccount(const Atlas::Objects::Entity::Account &accountOp);
92 
93 
95 
98  Result logout();
99 
101 
102  bool isLoggedIn() const;
103 
105 
110  const CharacterMap &getCharacters();
111 
120 
122 
126  Result takeTransferredCharacter(const std::string &id, const std::string &key);
127 
129 
134  Result takeCharacter(const std::string &id);
135 
137  Result createCharacterThroughEntity(const Atlas::Objects::Entity::RootEntity &character);
138 
139  Result createCharacterThroughOperation(const Atlas::Objects::Operation::Create &c);
140 
142  //void createCharacter();
143 
145  bool canCreateCharacter();
146 
151  const ActiveCharacterMap &getActiveCharacters() const;
152 
157  const std::vector<SpawnPoint> &getSpawnPoints() const;
158 
160  const std::string &getId() const;
161 
163  const std::string &getUsername() const;
164 
168  const std::string &getParent() 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 
224  sigc::signal<void, const std::string &> AvatarDeactivated;
225 
229  sigc::signal<void, const std::string &> ErrorMessage;
230 
231  protected:
232  friend class AccountRouter;
233 
234  friend class Avatar; // so avata can call destroyCharacter
235 
236  void sightCharacter(const Atlas::Objects::Operation::RootOperation &op);
237 
238  void loginComplete(const Atlas::Objects::Entity::Account &p);
239 
240  void loginError(const Atlas::Objects::Operation::Error &err);
241 
242  Result internalLogin(const std::string &unm, const std::string &pwd);
243 
244  void internalLogout(bool clean);
245 
247  void netConnected();
248 
250  bool netDisconnecting();
251 
252  void netFailure(const std::string &msg);
253 
254  void loginResponse(const Atlas::Objects::Operation::RootOperation &op);
255 
256  void logoutResponse(const Atlas::Objects::Operation::RootOperation &op);
257 
258  void possessResponse(const Atlas::Objects::Operation::RootOperation &op);
259 
260  void avatarCreateResponse(const Atlas::Objects::Operation::RootOperation &op);
261 
262  void avatarLogoutResponse(const Atlas::Objects::Operation::RootOperation &op);
263 
272  void destroyAvatar(const std::string &avatarId);
273 
274  void handleLogoutTimeout();
275 // void recvRemoteLogout(const Atlas::Objects::Operation::Logout &lo);
276 
277  void handleLoginTimeout();
278 
279  enum class Status {
280  DISCONNECTED = 0,
281  LOGGING_IN,
282  LOGGED_IN,
283  LOGGING_OUT,
284 
285  TAKING_CHAR,
286  CREATING_CHAR,
287  CREATED_CHAR
288  };
289 
290  void internalDeactivateCharacter(const std::string& avatarId);
291 
292  virtual void updateFromObject(const Atlas::Objects::Entity::Account &p);
293 
296  std::unique_ptr<AccountRouter> m_router;
297 
298  std::string m_accountId;
299  std::string m_username;
300  std::string m_pass;
301 
302  std::string m_parent;
303  CharacterMap _characters;
304  std::set<std::string> m_characterIds;
306 
307  ActiveCharacterMap m_activeAvatars;
308  std::unique_ptr<TimedEvent> m_timeout;
309 
314  std::vector<SpawnPoint> m_spawnPoints;
315  };
316 
318  return false;
319  }
320 
321  inline const ActiveCharacterMap &Account::getActiveCharacters() const {
322  return m_activeAvatars;
323  }
324 
325  inline const std::string &Account::getId() const {
326  return m_accountId;
327  }
328 
329  inline const std::string &Account::getUsername() const {
330  return m_username;
331  }
332 
333  inline const std::string &Account::getParent() const {
334  return m_parent;
335  }
336 
337 
339  return m_con;
340  }
341 
342  inline const std::vector<SpawnPoint> &Account::getSpawnPoints() const {
343  return m_spawnPoints;
344  }
345 
346 
347 } // of namespace Eris
348 
349 #endif
sigc::signal< void, const std::string & > AvatarDeactivated
Definition: Account.h:224
Result takeCharacter(const std::string &id)
Enter the game using an existing character.
Definition: Account.cpp:296
void avatarLogoutRequested(Avatar *avatar)
Called when a logout of the avatar has been requested by the server.
Definition: Account.cpp:418
a character was created, we now need to possess it
Result refreshCharacterInfo()
Definition: Account.cpp:201
sigc::signal< void, const std::string & > AvatarFailure
Definition: Account.h:219
Account(Connection &con)
Create a new Account associated with a Connection object.
Definition: Account.cpp:89
bool isLoggedIn() const
Check if the account is logged in.
Definition: Account.cpp:324
sigc::signal< void, const Atlas::Objects::Entity::RootEntity & > GotCharacterInfo
emitted when a character has been retrieved from the server
Definition: Account.h:187
Default state, no server account active.
Connection & getConnection() const
Access the underlying Connection for this account.
Definition: Account.h:338
sent a LOOK op for a character, awaiting INFO response
const ActiveCharacterMap & getActiveCharacters() const
Gets a list of active characters, i.e. entities on the server which the account can control...
Definition: Account.h:321
sigc::signal< void > GotAllCharacters
emitted when the entire character list had been updated
Definition: Account.h:190
void destroyAvatar(const std::string &avatarId)
Destroys the avatar with the specified id, if available.
Definition: Account.cpp:422
const std::string & getParent() const
Gets the parent type of the account.
Definition: Account.h:333
sigc::signal< void > LoginSuccess
Definition: Account.h:200
Result login(const std::string &uname, const std::string &pwd)
Login to the server using user-supplied account information.
Definition: Account.cpp:114
sigc::signal< void, const std::string & > ErrorMessage
Definition: Account.h:229
CharacterMap _characters
characters belonging to this player
Definition: Account.h:303
Status m_status
what the Player is currently doing
Definition: Account.h:295
bool canCreateCharacter()
pop up the game&#39;s character creation dialog, if present
Definition: Account.h:317
Definition: Account.cpp:33
Result createCharacterThroughEntity(const Atlas::Objects::Entity::RootEntity &character)
enter the game using a new character
Definition: Account.cpp:235
Login sent, waiting for initial INFO response.
Fully logged into a server-side account.
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:128
bool m_doingCharacterRefresh
set if we&#39;re refreshing character data
Definition: Account.h:305
Encapsulates all the state of an Atlas Account, and methods that operation on that state...
Definition: Account.h:42
std::string m_username
The player&#39;s username ( != account object&#39;s ID)
Definition: Account.h:299
std::string m_accountId
the account ID
Definition: Account.h:298
Result
Definition: Types.h:22
Sent a logout op, waiting for the INFO response.
std::vector< SpawnPoint > m_spawnPoints
A map of available spawn points. These are points from which a new avatar can be created.
Definition: Account.h:314
const std::string & getUsername() const
Definition: Account.h:329
Connection & m_con
underlying connection instance
Definition: Account.h:294
std::map< std::string, Atlas::Objects::Entity::RootEntity > CharacterMap
Definition: Account.h:26
sigc::signal< void, const std::string & > LoginFailure
Emitted when a server-side error occurs during account creation / login.
Definition: Account.h:197
const std::string & getId() const
returns the account ID if logged in
Definition: Account.h:325
const std::vector< SpawnPoint > & getSpawnPoints() const
Gets the available spawn points from where the client can create new characters.
Definition: Account.h:342
Result logout()
Request logout from the server.
Definition: Account.cpp:163
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:267
Represents a possible spawn point as described by the server. When a new character is created on the ...
Definition: SpawnPoint.h:56
void netConnected()
Callback for network re-establishment.
Definition: Account.cpp:679
const CharacterMap & getCharacters()
Get the characters owned by this account.
Definition: Account.cpp:194
sigc::signal< void, Avatar * > AvatarSuccess
Definition: Account.h:213
sigc::signal< void, bool > LogoutComplete
Emitted when a logout completes.
Definition: Account.h:207
send a character CREATE op, awaiting INFO response
bool netDisconnecting()
help! the plug is being pulled!
Definition: Account.cpp:687