GamerCollection.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.ObjectModel;
  2. namespace Microsoft.Xna.Framework.Net
  3. {
  4. /// <summary>
  5. /// Collection of network gamers in a session.
  6. /// </summary>
  7. public class GamerCollection : ReadOnlyCollection<NetworkGamer>
  8. {
  9. internal GamerCollection(IList<NetworkGamer> list) : base(list) { }
  10. /// <summary>
  11. /// Finds a gamer by their gamertag.
  12. /// </summary>
  13. /// <param name="gamertag">The gamertag to search for.</param>
  14. /// <returns>The gamer with the specified gamertag, or null if not found.</returns>
  15. public NetworkGamer FindGamerById(string id)
  16. {
  17. foreach (var gamer in this)
  18. {
  19. if (gamer.Id == id)
  20. return gamer;
  21. }
  22. return null;
  23. }
  24. /// <summary>
  25. /// Gets the host gamer of the session.
  26. /// </summary>
  27. public NetworkGamer Host
  28. {
  29. get
  30. {
  31. foreach (var gamer in this)
  32. {
  33. if (gamer.IsHost)
  34. return gamer;
  35. }
  36. return null;
  37. }
  38. }
  39. }
  40. }