2
0

NetworkErrorScreen.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // NetworkErrorScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Diagnostics;
  12. using Microsoft.Xna.Framework.GamerServices;
  13. using Microsoft.Xna.Framework.Net;
  14. using GameStateManagement;
  15. #endregion
  16. namespace CatapultGame
  17. {
  18. /// <summary>
  19. /// Specialized message box subclass, used to display network error messages.
  20. /// </summary>
  21. class NetworkErrorScreen : MessageBoxScreen
  22. {
  23. #region Initialization
  24. /// <summary>
  25. /// Constructs an error message box from the specified exception.
  26. /// </summary>
  27. public NetworkErrorScreen(Exception exception)
  28. : base(GetErrorMessage(exception), false)
  29. { }
  30. /// <summary>
  31. /// Converts a network exception into a user friendly error message.
  32. /// </summary>
  33. static string GetErrorMessage(Exception exception)
  34. {
  35. Debug.WriteLine("Network operation threw " + exception);
  36. // Is this a GamerPrivilegeException?
  37. if (exception is GamerPrivilegeException)
  38. {
  39. if (Guide.IsTrialMode)
  40. return Resources.ErrorTrialMode;
  41. else
  42. return Resources.ErrorGamerPrivilege;
  43. }
  44. // Is it a NetworkSessionJoinException?
  45. NetworkSessionJoinException joinException = exception as
  46. NetworkSessionJoinException;
  47. if (joinException != null)
  48. {
  49. switch (joinException.JoinError)
  50. {
  51. case NetworkSessionJoinError.SessionFull:
  52. return Resources.ErrorSessionFull;
  53. case NetworkSessionJoinError.SessionNotFound:
  54. return Resources.ErrorSessionNotFound;
  55. case NetworkSessionJoinError.SessionNotJoinable:
  56. return Resources.ErrorSessionNotJoinable;
  57. }
  58. }
  59. // Is this a NetworkNotAvailableException?
  60. if (exception is NetworkNotAvailableException)
  61. {
  62. return Resources.ErrorNetworkNotAvailable;
  63. }
  64. // Is this a NetworkException?
  65. if (exception is NetworkException)
  66. {
  67. return Resources.ErrorNetwork;
  68. }
  69. // Otherwise just a generic error message.
  70. return Resources.ErrorUnknown;
  71. }
  72. #endregion
  73. }
  74. }