/// <summary> /// /// Returns true if the steamid was found in the players file /// /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool IdPresent(Steamworks.SteamId id) { StreamReader reader = new StreamReader(playersPath); if (reader.EndOfStream) { reader.Close(); return(false); } string[] players = reader.ReadToEnd().Split('\n'); reader.Close(); for (int i = 0; i < players.Length; i++) { if (players[i] == id.ToString()) { return(true); } i++; } return(false); }
/// <summary> /// Checks if the steamid is in the file specified /// </summary> /// <param name="id"></param> /// <returns></returns> public static bool IdPresent(Steamworks.SteamId id, string path) { Debug.Log("Checking if ID is present in file."); Debug.Log("ID: " + id.ToString()); Debug.Log("Path: " + path); Debug.Log("Creating stream reader"); StreamReader reader = new StreamReader(path); Debug.Log("Stream reader created"); bool present = false; if (!reader.EndOfStream) { string[] ids = reader.ReadLine().Split(' '); Debug.Log("Read ids"); if (ids != null && ids.Length > 0) { foreach (var idString in ids) { if (idString.Length > 1) { Debug.Log("Reading id: " + idString); Debug.Log("Converting to ulong"); if (System.Convert.ToUInt64(idString) == id) { present = true; } } } } } reader.Close(); return(present); }
/// <summary> /// Removes a player entry from the players file /// </summary> /// <param name="id"></param> /// <returns></returns> public static void RemovePlayer(Steamworks.SteamId id) { StreamReader reader = new StreamReader(playersPath); if (reader.EndOfStream) { reader.Close(); return; } string[] players = reader.ReadToEnd().Split('\n'); reader.Close(); string updated = ""; // Add all players to the updated string except for the player to remove if (players != null && players.Length > 0) { for (int i = 0; i < players.Length; i++) { if (players[i].Length >= 1) { if (players[i] != id.ToString()) { updated += players[i] + '\n' + players[i + 1] + '\n'; } i++; } } } else { Debug.Log("Players file was null or empty."); } StreamWriter writer = new StreamWriter(playersPath, false); writer.Write(updated); writer.Close(); }
/// <summary> /// Gets the name associated with the steamid found in the players file /// </summary> /// <param name="id"></param> /// <returns></returns> public static string GetName(Steamworks.SteamId id) { StreamReader reader = new StreamReader(playersPath); if (reader.EndOfStream) { reader.Close(); return(""); } string[] players = reader.ReadToEnd().Split('\n'); string name = ""; // Add all players to the updated string except for the player to remove if (players != null && players.Length > 0) { for (int i = 0; i < players.Length; i++) { if (players[i].Length >= 1) { if (players[i] == id.ToString()) { name = players[i + 1]; break; } i++; } } } reader.Close(); if (name == "") { Debug.Log("Couldn't find the name associated with the id " + id + ". " + playersPath + " may be corrupt."); } return(name); }
public override string ToString() { return($"{Name} ({Id.ToString()})"); }