private void UpdateDisplayNameRequestHandler(IIncommingMessage message) { var userExtension = message.Peer.GetExtension <IUserPeerExtension>(); if (userExtension == null || userExtension.Account == null) { message.Respond("Invalid session", ResponseStatus.Unauthorized); return; } var newProfileData = new Dictionary <string, string>().FromBytes(message.AsBytes()); try { if (ProfilesList.TryGetValue(userExtension.Username, out ObservableServerProfile profile)) { profile.GetProperty <ObservableString>((short)ObservablePropertiyCodes.DisplayName).Set(newProfileData["displayName"]); profile.GetProperty <ObservableString>((short)ObservablePropertiyCodes.Avatar).Set(newProfileData["avatarUrl"]); message.Respond(ResponseStatus.Success); } else { message.Respond("Invalid session", ResponseStatus.Unauthorized); } } catch (Exception e) { message.Respond($"Internal Server Error: {e}", ResponseStatus.Error); } }
/// <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; }
private void UpdateGoldValueHandler(IIncommingMessage message) { var userExtension = message.Peer.GetExtension <IUserPeerExtension>(); if (userExtension == null || userExtension.Account == null) { message.Respond("Invalid session", ResponseStatus.Unauthorized); return; } var newProfileData = new Dictionary <string, float>().FromBytes(message.AsBytes()); try { if (ProfilesList.TryGetValue(userExtension.Username, out ObservableServerProfile profile)) { var goldProperty = profile.GetProperty <ObservableFloat>((short)ObservablePropertiyCodes.Gold); goldProperty.Add(newProfileData["gold"]); message.Respond(ResponseStatus.Success); } else { message.Respond("Invalid session", ResponseStatus.Unauthorized); } } catch (Exception e) { message.Respond($"Internal Server Error: {e}", ResponseStatus.Error); } }
//Unselect all buttons in the profile list private void UnselectAllButton_Click(object sender, EventArgs e) { for (int i = 0; i < ProfilesList.Items.Count; i++) { ProfilesList.SetItemChecked(i, false); } }
public ObservableServerProfile GetProfileByUsername(string username) { ObservableServerProfile profile; ProfilesList.TryGetValue(username, out profile); return(profile); }
//---------------------------------------- public void SettingUpFiles() { if (!File.Exists(ThereIsConstants.Path.AccountInfo_File_Path)) { AccountInfo myInfo = new AccountInfo(); AccountInfo.UpdateInfo(myInfo, ThereIsConstants.Path.AccountInfo_File_Path); if (File.Exists(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.ProfilesList_File_Name)) { File.Delete(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.ProfilesList_File_Name); } } else { AccountInfo theInfo = AccountInfo.FromFile(ThereIsConstants.Path.AccountInfo_File_Path); theInfo.LastLogin = ThereIsConstants.AppSettings.GlobalTiming.GetString(false).GetValue(); AccountInfo.UpdateInfo(theInfo, ThereIsConstants.Path.AccountInfo_File_Path); if (!File.Exists(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.ProfilesList_File_Name)) { File.Delete(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.AccountInfo_File_Name); AccountInfo myInfo = new AccountInfo(); AccountInfo.UpdateInfo(myInfo, ThereIsConstants.Path.AccountInfo_File_Path); } } if (!File.Exists(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.ProfilesList_File_Name)) { FileStream myFile = new FileStream(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.ProfilesList_File_Name, FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter writer = new BinaryWriter(myFile); ProfilesList myList = new ProfilesList(); for (int i = 0; i < ThereIsConstants.AppSettings.MAXIMUM_PROFILE; i++) { myFile.Position = i * ProfilesList.SIZE; writer.Write(myList.ProfileName); writer.Write(myList.LastLogin); writer.Write(myList.Description); } myFile.Close(); writer.Close(); myFile.Dispose(); writer.Dispose(); } if (!Directory.Exists(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.GameData_Directory_Name)) { Directory.CreateDirectory(ThereIsConstants.Path.main_Path + ThereIsConstants.Path.GameData_Directory_Name); } }
private void LoadProfiles(bool rebind) { GetProfiles(this, new EventArgs()); ProfilesList.DataSource = Model.PreviewProfiles; if (!IsPostBack || rebind) { ProfilesList.DataBind(); } }
/// <summary> /// Handles a message from game server, which includes player profiles updates /// </summary> /// <param name="message"></param> protected virtual void ProfileUpdateHandler(IIncommingMessage message) { if (!HasPermissionToEditProfiles(message.Peer)) { Logs.Error("Master server received an update for a profile, but peer who tried to " + "update it did not have sufficient permissions"); return; } var data = message.AsBytes(); using (var ms = new MemoryStream(data)) { using (var reader = new EndianBinaryReader(EndianBitConverter.Big, ms)) { // Read profiles count var count = reader.ReadInt32(); for (var i = 0; i < count; i++) { // Read username var username = reader.ReadString(); // Read updates length var updatesLength = reader.ReadInt32(); // Read updates var updates = reader.ReadBytes(updatesLength); try { if (ProfilesList.TryGetValue(username, out ObservableServerProfile profile)) { profile.ApplyUpdates(updates); } } catch (Exception e) { Logs.Error("Error while trying to handle profile updates from master server"); Logs.Error(e); } } } } }
/// <summary> /// Handles a request from game server to get a profile /// </summary> /// <param name="message"></param> protected virtual void GameServerProfileRequestHandler(IIncommingMessage message) { if (!HasPermissionToEditProfiles(message.Peer)) { message.Respond("Invalid permission level", ResponseStatus.Unauthorized); return; } var username = message.AsString(); ObservableServerProfile profile; ProfilesList.TryGetValue(username, out profile); if (profile == null) { message.Respond(ResponseStatus.Failed); return; } message.Respond(profile.ToBytes(), ResponseStatus.Success); }
private void Backup_Click(object sender, EventArgs e) { BackupButton.Enabled = false; RestoreButton.Enabled = true; SelectAllButton.Enabled = true; UnselectAllButton.Enabled = true; ProfilesList.Items.Clear(); string profilesPath = "C:\\Users\\"; foreach (string profile in Directory.GetDirectories(profilesPath)) { string temp = profile.Replace(profilesPath, ""); if (!temp.Equals("All Users") && !temp.Contains("Default") && !temp.Equals("Public")) { ProfilesList.Items.Add(temp); ProfilesList.SetItemChecked(ProfilesList.Items.Count - 1, true); } } TransferButton.Enabled = ArgumentsButton.Enabled = true; isBackup = true; }
/// <summary> /// Unloads profile after a period of time /// </summary> /// <param name="username"></param> /// <param name="delay"></param> /// <returns></returns> private async void UnloadProfile(string username, float delay) { // Wait for the delay await Task.Delay(Mathf.RoundToInt(delay < 0.01f ? 0.01f : delay * 1000)); // If user is not actually logged in, remove the profile if (authModule.IsUserLoggedIn(username)) { return; } ProfilesList.TryGetValue(username, out ObservableServerProfile profile); if (profile == null) { return; } // Remove profile ProfilesList.Remove(username); // Remove listeners profile.OnModifiedInServerEvent -= OnProfileChangedEventHandler; }
public static ProfilesList GetPeople(string institution = "", string facultyrank = "") { ProfilesList pl = new ProfilesList(); SessionManagement sm = new SessionManagement(); string listid = sm.Session().ListID; Framework.Utilities.DataIO dataio = new Framework.Utilities.DataIO(); using (SqlConnection sqlconnection = new SqlConnection(dataio.GetConnectionString())) { SqlCommand cmd = new SqlCommand("[Profile.Data].[List.GetPeople]", sqlconnection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parm = new SqlParameter("@UserID", SqlDbType.Int); parm.Direction = ParameterDirection.Input; parm.Value = listid; cmd.Parameters.Add(parm); parm = new SqlParameter("@ReturnInstitutions", SqlDbType.Bit); parm.Direction = ParameterDirection.Input; parm.Value = true; cmd.Parameters.Add(parm); parm = new SqlParameter("@ReturnFacultyRanks", SqlDbType.Bit); parm.Direction = ParameterDirection.Input; parm.Value = true; cmd.Parameters.Add(parm); if (!string.IsNullOrEmpty(institution)) { parm = new SqlParameter("@Institution", SqlDbType.VarChar); parm.Direction = ParameterDirection.Input; parm.Value = institution; cmd.Parameters.Add(parm); } if (!string.IsNullOrEmpty(facultyrank)) { parm = new SqlParameter("@FacultyRank", SqlDbType.VarChar); parm.Direction = ParameterDirection.Input; parm.Value = facultyrank; cmd.Parameters.Add(parm); } parm = new SqlParameter("@NumPeople", SqlDbType.Int); parm.Direction = ParameterDirection.Output; cmd.Parameters.Add(parm); sqlconnection.Open(); using (SqlDataReader dbreader = cmd.ExecuteReader()) { pl.Institutions = new List <GenericListItem>(); while (dbreader.Read()) { pl.Institutions.Add(new GenericListItem(dbreader["InstitutionName"].ToString(), dbreader["n"].ToString())); } dbreader.NextResult(); pl.FacultyRanks = new List <GenericListItem>(); while (dbreader.Read()) { pl.FacultyRanks.Add(new GenericListItem(dbreader["FacultyRank"].ToString(), dbreader["n"].ToString())); } dbreader.NextResult(); pl.ListItems = new List <ProfilesListItem>(); while (dbreader.Read()) { pl.ListItems.Add(new ProfilesListItem { PersonID = dbreader[0].ToString(), DisplayName = dbreader[1].ToString(), FirstName = dbreader[2].ToString(), LastName = dbreader[3].ToString(), InstitutionName = dbreader[4].ToString(), FacultyRank = dbreader[5].ToString(), DepartmentName = dbreader[6].ToString() }); } } sqlconnection.Close(); } return(pl); }