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 
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
Eris::Account::m_con
Connection * m_con
underlying connection instance
Definition: Account.h:284
Eris::Account::canCreateCharacter
bool canCreateCharacter()
pop up the game's character creation dialog, if present
Definition: Account.h:308
Eris::Account::getId
const std::string & getId() const
returns the account ID if logged in
Definition: Account.h:318
Eris::Timeout
Timeout
Definition: Timeout.h:12
Eris::Account::m_accountId
std::string m_accountId
the account ID
Definition: Account.h:288
Eris::Account::Account
Account(Connection *con)
Create a new Account associated with a Connection object.
Definition: Account.cpp:79
Eris::Account::GotAllCharacters
sigc::signal< void > GotAllCharacters
emitted when the entire character list had been updated
Definition: Account.h:203
Eris::Account::LOGGING_OUT
@ LOGGING_OUT
Sent a logout op, waiting for the INFO response.
Definition: Account.h:275
Eris::Connection::Failure
sigc::signal< void, const std::string & > Failure
Emitted when a non-fatal error occurs.
Definition: Connection.h:127
Eris::Account::GotCharacterInfo
sigc::signal< void, const Atlas::Objects::Entity::RootEntity & > GotCharacterInfo
emitted when a character has been retrieved from the server
Definition: Account.h:200
Eris::Account::getConnection
Connection * getConnection() const
Access the underlying Connection for this account.
Definition: Account.h:334
Eris::Account::getCharacterTypes
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
Eris::BaseConnection::Connected
sigc::signal< void > Connected
sent on successful negotiation of a game server connection
Definition: BaseConnection.h:88
Eris::Account::takeTransferredCharacter
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
Eris::Account::getUsername
const std::string & getUsername() const
Return the username of this account.
Definition: Account.h:323
Eris::Account::takeCharacter
Result takeCharacter(const std::string &id)
Enter the game using an existing character.
Definition: Account.cpp:313
Eris::Account::CREATING_CHAR
@ CREATING_CHAR
send a character CREATE op, awaiting INFO response
Definition: Account.h:278
Eris::Account::avatarLogoutRequested
void avatarLogoutRequested(Avatar *avatar)
Called when a logout of the avatar has been requested by the server.
Definition: Account.cpp:452
Eris::Account::Status
Status
Definition: Account.h:270
Eris::Account::deactivateCharacter
Result deactivateCharacter(Avatar *av)
Request de-activation of a character.
Definition: Account.cpp:345
Eris::Account::refreshCharacterInfo
Result refreshCharacterInfo()
Update the character list (based on changes to play).
Definition: Account.cpp:203
Eris::Account
Encapsulates all the state of an Atlas Account, and methods that operation on that state.
Definition: Account.h:44
Eris::Router
abstract interface for objects that can route Atlas data.
Definition: Router.h:10
Eris::Account::m_doingCharacterRefresh
bool m_doingCharacterRefresh
set if we're refreshing character data
Definition: Account.h:296
Eris::Avatar
The player's avatar representation.
Definition: Avatar.h:31
Eris::Account::AvatarFailure
sigc::signal< void, const std::string & > AvatarFailure
Emitted when creating or taking a character fails for some reason.
Definition: Account.h:232
Eris::Account::m_username
std::string m_username
The player's username ( != account object's ID)
Definition: Account.h:289
Eris::Account::DISCONNECTED
@ DISCONNECTED
Default state, no server account active.
Definition: Account.h:272
Eris::error
Definition: LogStream.h:55
Eris::Account::LogoutComplete
sigc::signal< void, bool > LogoutComplete
Emitted when a logout completes.
Definition: Account.h:220
Eris::Account::LoginFailure
sigc::signal< void, const std::string & > LoginFailure
Emitted when a server-side error occurs during account creation / login.
Definition: Account.h:210
Eris::BaseConnection::isConnected
bool isConnected() const
Ascertain whether or not the connection is usable for transport.
Definition: BaseConnection.h:65
Eris::AccountRouter
Definition: Account.cpp:35
Eris::Account::TAKING_CHAR
@ TAKING_CHAR
sent a LOOK op for a character, awaiting INFO response
Definition: Account.h:277
Eris::Account::AvatarDeactivated
sigc::signal< void, Avatar * > AvatarDeactivated
Emitted when an active avatar is deactivated.
Definition: Account.h:239
Eris::Account::isLoggedIn
bool isLoggedIn() const
Check if the account is logged in.
Definition: Account.cpp:351
Eris::Account::getParents
const std::list< std::string > & getParents() const
Gets the parent types of the account.
Definition: Account.h:328
Eris::InvalidOperation
Definition: Exceptions.h:28
Eris::Account::netConnected
void netConnected()
Callback for network re-establishment.
Definition: Account.cpp:671
Eris::Connection::unlock
void unlock()
Unlock the connection (permit status change).
Definition: Connection.cpp:217
Eris::Account::getActiveCharacters
const ActiveCharacterMap & getActiveCharacters() const
Gets a list of active characters, i.e.
Definition: Account.h:313
Eris::BaseConnection::DISCONNECTING
@ DISCONNECTING
clean disconnection in progress
Definition: BaseConnection.h:54
Eris::Account::m_status
Status m_status
what the Player is currently doing
Definition: Account.h:285
Eris::Connection::Disconnecting
sigc::signal< bool > Disconnecting
Emitted when the disconnection process is initiated.
Definition: Connection.h:119
Eris::Account::m_spawnPoints
SpawnPointMap m_spawnPoints
A map of available spawn points.
Definition: Account.h:305
Eris::BaseConnection::getStatus
Status getStatus() const
get the current status of the connection
Definition: BaseConnection.h:61
Eris::Connection::send
virtual void send(const Atlas::Objects::Root &obj)
Transmit an Atlas::Objects instance to the server.
Definition: Connection.cpp:147
Eris::debug
Definition: LogStream.h:35
Eris::Account::AvatarSuccess
sigc::signal< void, Avatar * > AvatarSuccess
Emitted when creating a character or taking an existing one succeeds.
Definition: Account.h:226
Eris::Account::login
Result login(const std::string &uname, const std::string &pwd)
Login to the server using user-supplied account information.
Definition: Account.cpp:107
Eris::Account::logout
Result logout()
Request logout from the server.
Definition: Account.cpp:159
Eris::Account::createCharacter
Result createCharacter(const Atlas::Objects::Entity::RootEntity &character)
enter the game using a new character
Definition: Account.cpp:238
Eris::Account::LOGGED_IN
@ LOGGED_IN
Fully logged into a server-side account.
Definition: Account.h:274
Eris::Account::createAccount
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
Eris::Connection
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:37
Eris::Account::getCharacters
const CharacterMap & getCharacters()
Get the characters owned by this account.
Definition: Account.cpp:195
Eris::Connection::lock
void lock()
Lock then connection's state.
Definition: Connection.cpp:212
Eris::Account::netDisconnecting
bool netDisconnecting()
help! the plug is being pulled!
Definition: Account.cpp:680
Eris::Account::LoginSuccess
sigc::signal< void > LoginSuccess
Emitted when login or character creation is successful.
Definition: Account.h:213
Eris::Account::getSpawnPoints
const SpawnPointMap & getSpawnPoints() const
Gets the available spawn points from where the client can create new characters.
Definition: Account.h:339
Eris::Account::LOGGING_IN
@ LOGGING_IN
Login sent, waiting for initial INFO response.
Definition: Account.h:273
Eris::Account::_characters
CharacterMap _characters
characters belonging to this player
Definition: Account.h:294