/// <summary> /// Invoked, when user logs into the master server /// </summary> /// <param name="session"></param> /// <param name="accountData"></param> private async void OnUserLoggedInEventHandler(IUserPeerExtension user) { user.Peer.OnPeerDisconnectedEvent += OnPeerPlayerDisconnectedEventHandler; // Create a profile ObservableServerProfile profile; if (ProfilesList.ContainsKey(user.Username)) { // There's a profile from before, which we can use profile = ProfilesList[user.Username]; profile.ClientPeer = user.Peer; } else { // We need to create a new one profile = CreateProfile(user.Username, user.Peer); ProfilesList.Add(user.Username, profile); } // Restore profile data from database (only if not a guest) if (!user.Account.IsGuest) { await profileDatabaseAccessor.RestoreProfileAsync(profile); } // Save profile property user.Peer.AddExtension(new ProfilePeerExtension(profile, user.Peer)); // Listen to profile events profile.OnModifiedInServerEvent += OnProfileChangedEventHandler; }
/// <summary> /// Triggered when the user has successfully logged in /// </summary> /// <param name="session"></param> /// <param name="accountData"></param> protected virtual async void AuthModule_OnUserLoggedInEvent(IUserPeerExtension user) { user.Peer.OnPeerDisconnectedEvent += OnPeerPlayerDisconnectedEventHandler; // Create a profile ObservableServerProfile profile; if (profilesList.ContainsKey(user.UserId)) { // There's a profile from before, which we can use profile = profilesList[user.UserId]; profile.ClientPeer = user.Peer; } else { // We need to create a new one profile = CreateProfile(user.UserId, user.Peer); profilesList.Add(user.UserId, profile); } // Restore profile data from database await profileDatabaseAccessor.RestoreProfileAsync(profile); // Save profile property user.Peer.AddExtension(new ProfilePeerExtension(profile, user.Peer)); // Listen to profile events profile.OnModifiedInServerEvent += OnProfileChangedEventHandler; }