NetworkErrorScreen.cs 2.6 KB

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