11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _USERCLIENT_H_
13 #define _USERCLIENT_H_
14 #include "RNLobby/Inc/BaseTransportServer.h"
15 #include "RNXPSockets/Inc/XPSocket.h"
19 namespace RNReplicaNet
32 int GetLoginID(
void)
const;
33 std::string GetName(
void)
const;
42 kState_Friend = (1<<0),
43 kState_FriendRequest = (1<<2),
44 kState_Online = (1<<3),
45 kState_GameInvite = (1<<5),
46 kState_Speaking = (1<<6),
47 kState_Ignored = (1<<7),
48 kState_InARoom = (1<<8),
49 kState_PlayingAGame = (1<<9)
54 std::string GetGameInvite(
void)
const;
56 std::string GetLastOnlineTime(
void)
const;
58 std::string GetPlayingAGameURL(
void)
const;
64 std::string mGameInvite;
65 std::string mLastOnlineTime;
66 std::string mPlayingAGameURL;
94 bool CreateLoginUser(
const char *name,
const char *password,
const char *emailAddress =
"",
const char *optionalID =
"");
99 bool LoginUser(
const char *name,
const char *password);
101 bool ChangePassword(
const char *password =
"");
103 bool ChangeEmail(
const char *emailAddress =
"");
119 bool SendMessageTo(
const int loginID,
const char *message =
"");
134 void AnswerMessage(
const int fromLoginID = UserInfo::kAnyLoginID);
138 kReason_ClientForcedLogout = 0,
139 kReason_ServerForcedLogout,
140 kReason_ChatRoomFull,
141 kReason_ChatRoomUserLeft,
142 kReason_ChatRoomClosed,
143 kReason_ChatRoomKickedByAdmin,
144 kReason_ChatRoomWrongPassword,
145 kReason_ChatRoomDoesNotExist,
146 kReason_ChatRoomBanned,
147 kReason_IncorrectLoginDetails,
148 kReason_AccountBlocked
153 kState_Online = (1<<0),
154 kState_FriendRequest = (1<<1),
155 kState_GameInvite = (1<<2),
156 kState_Message = (1<<3)
164 bool SendGameInvite(
const int friendLoginID,
const char *invite =
"");
175 kPrivateReadWrite = 1,
176 kPublicReadPrivateReadWrite = 2,
177 kPublicReadPrivateRead = 3
182 bool SetVariable(
const int section,
const char *name,
const char *value = 0,
const VariableAccess access = kPrivateReadWrite);
186 bool GetVariable(
const int section,
const char *name,
const VariableAccess access = kPrivateReadWrite);
190 bool GetVariable(
const int loginID,
const int section,
const char *name,
const VariableAccess access = kPublicReadPrivateRead);
196 bool AddUserInfo(
const int loginID,
const bool useCache =
true,
const bool trackChanges =
false);
215 bool EnterChatRoom(
const int chatRoomID,
const char *password = 0);
228 bool ChatRoomSay(
const char *text,
const unsigned int flags = 0);
233 bool ChatRoomWhisper(
const int loginID,
const char *text,
const unsigned int flags = 0);
238 bool ChatRoomKickUser(
const int loginID,
const bool ban =
false,
const char *reason =
"");
243 bool GlobalKickUser(
const int loginID,
const bool ban =
false,
const char *reason =
"");
257 bool PlayingAGame(
const bool playing =
false,
const char *url =
"");
275 int GetPendingGetVariableRequests(
void);
315 virtual void CallbackGotVariable(
const int loginID,
const int section,
const char *name,
const char *value,
const VariableAccess access) {}
329 virtual void CallbackChatRoomCreated(
const int chatRoomID) {}
331 virtual void CallbackChatRoomEntered(
const int chatRoomID) {}
333 virtual void CallbackChatRoomEnterFailed(
const int chatRoomID,
const Reason reason) {}
335 virtual void CallbackChatRoomLeft(
const Reason reason) {}
339 virtual void CallbackChatRoomUserEntered(
const UserInfo &user) {}
343 virtual void CallbackChatRoomMessage(
const char *text,
const UserInfo &user,
const bool whispered,
const bool isAdminMessage,
const unsigned int flags) {}
345 virtual void CallbackChatRoomKicked(
const char *reason,
bool banned,
const UserInfo &user) {}
347 virtual void CallbackGlobalKicked(
const char *reason,
bool banned,
const UserInfo &user) {}
349 virtual void CallbackPasswordChanged(
void) {}
351 virtual void CallbackCannotChangePassword(
void) {}
353 virtual void CallbackEmailChanged(
void) {}
355 virtual void CallbackCannotChangeEmail(
void) {}
357 virtual void CallbackGotUserNonce(
const char *userNonce,
const int seconds) {}
384 void InitInternalState(
void);
391 std::set<int> mPendingFriendIDs;
395 std::map<int,UserInfo> mUsers;
398 bool mMessagePending;
399 bool mGameInvitePending;
401 void DoStateChangeCalc(
void);
406 std::string mMyLoginName;
407 bool mServerAddressSet;
408 bool mLastPlayingAGame;
409 std::string mLastOnlineTime;
410 std::string mLastPlayingAGameURL;
412 int mPendingGetVariables;
bool CancelGameInvite(const int friendLoginID)
Cancel a game invite to a friend.
bool Start(void)
Because this uses a TransportUDP connection it will call XPURL::RegisterDefaultTransports() ...
Definition: Transport.h:35
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 AuthoriseFriendRequest(const int friendLoginID)
Authorise a friend request from a UserInfo that has the bit kState_FriendRequest set in mState...
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...
Definition: UserClient.h:318
A server base class that handles encrypted messages to and from a transport.
Definition: BaseTransportServer.h:30
std::string GetLoginName(void)
Returns the login name as stored on the server when the user is logged in.
virtual void CallbackUserLogout(const Reason reason)
A virtual callback that is triggered when the user logs out.
Definition: UserClient.h:290
bool CreateLoginUser(const char *name, const char *password, const char *emailAddress="", const char *optionalID="")
bool ChatRoomKickUser(const int loginID, const bool ban=false, const char *reason="")
bool GetVariable(const int section, const char *name, const VariableAccess access=kPrivateReadWrite)
bool EnterChatRoom(const int chatRoomID, const char *password=0)
Definition: XPSocket.h:91
virtual void CallbackNamesLike(const UserInfo &user)
A virtual callback that is triggered when RequestNamesLike is used.
Definition: UserClient.h:368
void AnswerMessage(const int fromLoginID=UserInfo::kAnyLoginID)
Call this to clear the state for a received message.
bool DenyFriendRequest(const int friendLoginID)
Deny a friend request from a UserInfo that has the bit kState_FriendRequest set in mState...
virtual void CallbackConnectionEstablished(Transport *transport)
User extensible callbacks.
Definition: UserClient.h:281
virtual void CallbackFriendUpdated(const UserInfo &user)
A virtual callback that is triggered when a UserInfo is changed.
Definition: UserClient.h:309
std::string GetLastOnlineTime(void)
Gets the last time this user account logged in.
bool CallbackParseValidMessage(Transport *transport, DynamicMessageHelper &message, const size_t length)
int GetLoginID(void)
Returns the login ID when the user is logged in or UserInfo::kAnyLoginID when the user is not logged ...
virtual void CallbackMessageReceived(const int fromLoginID, const char *message)
Definition: UserClient.h:300
bool IsSuperAdmin(void)
If the user is a super admin this will return true.
bool RemoveUserInfo(const int loginID)
Stops tracking a loginID for changes that have been requested from using AddUserInfo(). If the user is a friend this will not remove the user from the friend list.
bool SetVariable(const int section, const char *name, const char *value=0, const VariableAccess access=kPrivateReadWrite)
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...
bool CreateChatRoom(const char *password=0)
Create a new chat room and if successful makes this user join the room as the room admin...
virtual void CallbackFriendDeleted(const int loginID)
A virtual callback that is triggered when the user deletes a friend.
Definition: UserClient.h:303
virtual void CallbackNewStatsAvailable(const int lastUpdatedTitleID)
A virtual callback that is triggered when the StatServer updates any variables for this user...
Definition: UserClient.h:360
bool AddFriend(const int friendLoginID)
Request to add someone as a friend.
bool LoginUser(const char *name, const char *password)
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...
std::string GetPlayingAGameURL(void)
Gets the url state set by PlayingAGame()
bool ChatRoomAdminMessage(const char *text, const unsigned int flags=0)
bool RemoveFriend(const int friendLoginID)
Remove a user from the friend list. The user info changes will stop tracking.
void SetServer(const XPAddress &address)
bool RequestUserNonce(const int seconds)
bool ChatRoomSay(const char *text, const unsigned int flags=0)
bool RequestNamesLike(const char *match="", const bool banned=false)
virtual void CallbackUserInfoDeleted(const int loginID)
A virtual callback that is triggered when the user deletes a user info request.
Definition: UserClient.h:321
virtual void CallbackNamesLikeBegin(const char *match, const bool banned)
Definition: UserClient.h:365
int GetCurrentRoom(void)
Returns the current chatRoomID.
virtual void CallbackUserLogin(const int loginID)
A virtual callback that is triggered when the user successfully logs in.
Definition: UserClient.h:284
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.
virtual void CallbackUserInfoUpdated(const UserInfo &user)
A virtual callback that is triggered when a UserInfo is changed.
Definition: UserClient.h:327
bool GetPlayingAGame(void)
Gets the state set by PlayingAGame()
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...
Definition: UserClient.h:315
Definition: ThreadClass.h:39
This class is used to communicate with the UserServer class.
Definition: UserClient.h:26
virtual void CallbackUserInfoAdded(const UserInfo &user)
A virtual callback that is triggered when a AddUserInfo request has succeeded.
Definition: UserClient.h:324
bool GlobalRestoreUser(const int loginID)
If a user account has been globally banned this will restore the account to active service...
bool ChatRoomWhisper(const int loginID, const char *text, const unsigned int flags=0)
bool PlayingAGame(const bool playing=false, const char *url="")
bool AddUserInfo(const int loginID, const bool useCache=true, const bool trackChanges=false)
virtual void CallbackStateChange(const int previousState, const int newState)
A virtual callback that is triggered when the state changes for this instance.
Definition: UserClient.h:312
virtual void CallbackFriendAdded(const UserInfo &user)
A virtual callback that is triggered when a friend UserInfo is added. A UserInfo can be added when Us...
Definition: UserClient.h:306
Definition: MessageHelper.h:211
virtual void CallbackUserAlreadyExists(const int loginID)
A virtual callback that is triggered when the user account already exists.
Definition: UserClient.h:293
bool LogoutUser(void)
Logs out a user.
bool GlobalKickUser(const int loginID, const bool ban=false, const char *reason="")
bool GetUserInfo(const int loginID, UserInfo *result)
virtual void CallbackNamesLikeEnd(void)
A virtual callback that is triggered when RequestNamesLike is used.
Definition: UserClient.h:371
virtual void CallbackUserLoginFromOtherClient(void)
A virtual callback that is triggered when the user is logged out due to the same account being logged...
Definition: UserClient.h:296
virtual void CallbackUserLoginFailed(const Reason reason)
A virtual callback that is triggered when the user login attempt fails.
Definition: UserClient.h:287
Definition: UserClient.h:71
bool IsRoomAdmin(void)
If the user is a room admin this will return true.