UserClient Class Reference

#include <UserClient.h>

Inheritance diagram for UserClient:

Inheritance graph
[legend]
Collaboration diagram for UserClient:

Collaboration graph
[legend]

List of all members.

Public Types

enum  Reason {
  kReason_ClientForcedLogout = 0, kReason_ServerForcedLogout, kReason_ChatRoomFull, kReason_ChatRoomUserLeft,
  kReason_ChatRoomClosed, kReason_ChatRoomKickedByAdmin, kReason_ChatRoomWrongPassword, kReason_ChatRoomDoesNotExist
}
enum  { kState_Online = (1<<0), kState_FriendRequest = (1<<1), kState_GameInvite = (1<<2), kState_Message = (1<<3) }
enum  VariableAccess { kPrivateRead = 0, kPrivateReadWrite = 1, kPublicReadPrivateReadWrite = 2, kPublicReadPrivateRead = 3 }

Public Member Functions

bool Start (void)
 Because this uses a TransportUDP connection it will call XPURL::RegisterDefaultTransports().
bool Stop (void)
void SetServer (const XPAddress &address)
bool CreateLoginUser (const char *name, const char *password="", const char *emailAddress="")
bool LoginUser (const char *name, const char *password="")
int GetLoginID (void)
 Returns the login ID when the user is logged in.
bool LogoutUser (void)
 Logs out a user.
bool DeleteUser (void)
 Deletes a user that is currently logged in.
bool SendMessageTo (const int loginID, const char *message="")
 Sends a message from a logged in user to a login ID.
bool AddFriend (const int friendLoginID)
 Request to add someone as a friend.
bool AuthoriseFriendRequest (const int friendLoginID)
 Authorise a friend request from a UserInfo that has the bit kState_FriendRequest set in mState.
bool DenyFriendRequest (const int friendLoginID)
 Deny a friend request from a UserInfo that has the bit kState_FriendRequest set in mState.
bool RemoveFriend (const int friendLoginID)
 Remove a user from the friend list.
void AnswerMessage (const int fromLoginID=UserInfo::kAnyLoginID)
 Call this to clear the state for a received message.
int GetState (void)
bool SendGameInvite (const int friendLoginID, const char *invite="")
 Sends a game invite to a friend. Only friends can receive game invites from a user.
bool CancelGameInvite (const int friendLoginID)
 Cancel a game invite to a friend.
bool AnswerGameInvite (const int friendLoginID=UserInfo::kAnyLoginID)
 Call this to clear the state for a received game invite from a specific friend or by default all game invites.
bool SetVariable (const int section, const char *name, const char *value=0, const VariableAccess access=kPrivateReadWrite)
 Only allow write access to our own variable space. Setting a null value will erase that value if there is access to do so.
bool GetVariable (const int section, const char *name, const VariableAccess access=kPrivateReadWrite)
 Invokes CallbackGotVariable() when the variable is retrieved from the server.
bool GetVariable (const int loginID, const int section, const char *name, const VariableAccess access=kPublicReadPrivateRead)
 Invokes CallbackGotVariable() when the variable is retrieved from the server.
bool AddUserInfo (const int loginID, const bool useCache=true, const bool trackChanges=false)
bool RemoveUserInfo (const int loginID)
 Stops tracking a loginID for changes that have been requested from using AddUserInfo() and if the user is a friend this will remove the user from the friend list.
bool GetUserInfo (const int loginID, UserInfo *result)
bool CreateChatRoom (const char *password=0)
 Create a new chat room and if successful makes this user join the room as the room admin. The user will be notified of the chatRoomID by CallbackChatRoomCreated().
bool LeaveChatRoom (void)
 Leave a chat room. If the user created the room and the room has no admins left then the room will be closed. All users in the room will be receive CallbackChatRoomLeft() with a reason of kReason_ChatRoomClosed.
bool EnterChatRoom (const int chatRoomID, const char *password=0)
 Attempts to join a room. CallbackChatRoomEntered() will be called if successful and CallbackChatRoomEnterFailed() will be called if not successful.
int GetCurrentRoom (void)
 Returns the current chatRoomID.
bool ChatRoomAdminMessage (const char *text)
bool ChatRoomSay (const char *text)
bool ChatRoomWhisper (const int loginID, const char *text)

Protected Member Functions

virtual void CallbackConnectionEstablished (Transport *transport)
 User extendible callbacks.
virtual void CallbackUserLogin (const int loginID)
 A virtual callback that is triggered when the user successfully logs in.
virtual void CallbackUserLoginFailed (void)
 A virtual callback that is triggered when the user login attempt fails.
virtual void CallbackUserLogout (const Reason reason)
 A virtual callback that is triggered when the user logs out.
virtual void CallbackUserAlreadyExists (const int loginID)
 A virtual callback that is triggered when the user account already exists.
virtual void CallbackUserLoginFromOtherClient (void)
 A virtual callback that is triggered when the user is logged out due to the same account being logged in on another instance.
virtual void CallbackMessageReceived (const int fromLoginID, const char *message)
virtual void CallbackFriendDeleted (const int loginID)
 A virtual callback that is triggered when the user deletes a friend.
virtual void CallbackFriendAdded (const UserInfo &user)
 A virtual callback that is triggered when a friend UserInfo is added. A UserInfo can be added when UserInfo::GetState() has kState_FriendRequest set for a pending friend request.
virtual void CallbackFriendUpdated (const UserInfo &user)
 A virtual callback that is triggered when a UserInfo is changed.
virtual void CallbackStateChange (const int previousState, const int newState)
 A virtual callback that is triggered when the state changes for this instance.
virtual void CallbackGotVariable (const int loginID, const int section, const char *name, const char *value, const VariableAccess access)
 A virtual callback that is triggered when GetVariable() has read a variable from the server.
virtual void CallbackVariableNotFound (const int loginID, const int section, const char *name, const VariableAccess access)
 A virtual callback that is triggered when GetVariable() has failed to read a variable from the server.
virtual void CallbackUserInfoDeleted (const int loginID)
 A virtual callback that is triggered when the user deletes a user info request.
virtual void CallbackUserInfoAdded (const UserInfo &user)
 A virtual callback that is triggered when a AddUserInfo request has succeeded.
virtual void CallbackUserInfoUpdated (const UserInfo &user)
 A virtual callback that is triggered when a UserInfo is changed.
virtual void CallbackChatRoomCreated (const int chatRoomID)
virtual void CallbackChatRoomEntered (const int chatRoomID)
virtual void CallbackChatRoomEnterFailed (const int chatRoomID, const Reason reason)
virtual void CallbackChatRoomLeft (const Reason reason)
virtual void CallbackChatRoomUserEntered (const UserInfo &user)
virtual void CallbackChatRoomUserLeft (const RNReplicaNet::RNLobby::UserInfo &user, const Reason reason)
virtual void CallbackChatRoomMessage (const char *text, const UserInfo &user, const bool whispered, const bool isAdminMessage)
void CallbackTidy (void)
bool CallbackPoll (void)
bool CallbackParseValidMessage (Transport *transport, DynamicMessageHelper &message, const size_t length)


Detailed Description

Maintains a connection to the UserServer. This allows access to user accounts, friends and user persistent data for each title.

Member Function Documentation

bool Stop ( void   )  [virtual]

Stops the thread. If this function is overridden then this base implementation must also be called. This will not generate CallbackDisconnected() events for any existing connections.

Returns:
Success returns true, failure returns false.

Reimplemented from BaseTransportServer.

void SetServer ( const XPAddress address  ) 

Sets the address and port of the server. The default for the instance of the class is localhost and port UserServer::kDefaultPort

Parameters:
address The new address and port number to use for the server

bool CreateLoginUser ( const char *  name,
const char *  password = "",
const char *  emailAddress = "" 
)

Will try to create an account and then login if it was created. If the account already exists then CallbackUserAlreadyExists() is called and the user should try to use LoginUser() instead. When creating a login the duplicate name check is not case sensitive so that if someone has the name "Fred" then someone else will not be able to create the name "fred".

bool LoginUser ( const char *  name,
const char *  password = "" 
)

Will try to login an existing account. CallbackUserLogin() will be called if the name and password are correct. CallbackUserLoginFailed() will be called if the name or password were incorrect.

Parameters:
name The name of the user. This is case sensitive.
password The password of the user. This is case sensitive.

int GetState ( void   ) 

Returns a state for this instance that can be displayed as an icon on the screen.

Returns:
A combination of kState_*

bool AddUserInfo ( const int  loginID,
const bool  useCache = true,
const bool  trackChanges = false 
)

Requests UserInfo from a loginID. CallbackUserInfo() is triggered when a request succeeds and CallbackUserInfoFailed() on failure. This is useful for maintaining a list of recent players the user has encountered.

Parameters:
loginID The loginID to request information for.
useCache When true if possible use the cached information.
trackChanges When true this asks the server to send any changes of the loginID to this user. The server will expire old requests to avoid too much server load. ForgetUserInfo() can be used to forget tracking user changes for a loginID.

bool GetUserInfo ( const int  loginID,
UserInfo result 
)

Using the currently known list of users and friends this will try to instantly return the most up to date UserInfo.

Parameters:
loginID The loginID to search for.
result If not null this is a pointer to the resultant UserInfo.
Returns:
Returns true if the loginID was found. If false is returned the contents of result is unchanged.

virtual void CallbackConnectionEstablished ( Transport transport  )  [inline, protected, virtual]

User extendible callbacks.

A virtual callback that is triggered when the UserClient connects the the UserServer.

virtual void CallbackMessageReceived ( const int  fromLoginID,
const char *  message 
) [inline, protected, virtual]

A virtual callback that is triggered when the user receives message from another user.

Parameters:
message The pointer to the message will be freed as soon as this callback returns so do not store the pointer, store the contents of the pointer instead.

void CallbackTidy ( void   )  [protected, virtual]

This callback may be used to tidy allocation of objects when the thread terminates. The class mutex is locked when executing this callback.

Reimplemented from BaseTransportServer.

bool CallbackPoll ( void   )  [protected, virtual]

Called from the scope of the thread but without the class mutex being locked. This can be called with or without a valid mTransport

Reimplemented from BaseTransportServer.

bool CallbackParseValidMessage ( Transport transport,
DynamicMessageHelper message,
const size_t  length 
) [protected, virtual]

Called from the scope of the thread but without the class mutex being locked. If a MessageHelper::Exception() is caught by this server class the connection will be terminated.

Reimplemented from BaseTransportServer.


Generated on Sat Jun 28 22:02:35 2008 for ReplicaNet and RNLobby by  doxygen 1.5.3