X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FNetworkGame.cs;fp=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FNetworkGame.cs;h=792d16d2063e8b2fe3f756bd216cc442ca7d819f;hp=72a588cf62f6fcbab846b40794fd387dbf529a52;hb=87550d29aa4aa52e9c3e413e58877b494d7d7017;hpb=0e2cd798178ca471d26ea33ee849365c3b9b593e diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs index 72a588c..792d16d 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs @@ -36,6 +36,21 @@ namespace CS_3505_Project_06 public delegate void FoundSessionsDelegate(AvailableNetworkSessionCollection sessions, NetworkGame networkGame); + /// + /// Called when an exception is thrown during an asynchronous operation. + /// + /// The exception that was thrown. + /// The NetworkGame that errored. + public delegate void CaughtErrorDelegate(Exception exception, NetworkGame networkGame); + + /// + /// Get and set the error delegate, called when an exception is thrown during + /// and asynchronous operation. This will occur if you try to create or join a + /// session without being logged into a profile. + /// + public CaughtErrorDelegate ErrorDelegate; + + /// /// Construct a NetworkGame with a lobby and a game. /// @@ -101,11 +116,20 @@ namespace CS_3505_Project_06 { Debug.Assert(mNetworkSession == null); - mNetworkSession = NetworkSession.EndCreate(result); - mNetworkSession.AllowHostMigration = true; - mNetworkSession.AllowJoinInProgress = false; - mNetworkSession.GameStarted += new EventHandler(mNetworkSession_GameStarted); + try + { + mNetworkSession = NetworkSession.EndCreate(result); + mNetworkSession.AllowHostMigration = true; + mNetworkSession.AllowJoinInProgress = false; + mNetworkSession.GameStarted += new EventHandler(mNetworkSession_GameStarted); + } + catch (Exception e) + { + if (ErrorDelegate != null) ErrorDelegate(e, this); + return; + } mJoinedSessionDelegate(mNetworkSession, this); + mJoinedSessionDelegate = null; } @@ -142,8 +166,18 @@ namespace CS_3505_Project_06 } private void FindSessionsEnd(IAsyncResult result) { - AvailableNetworkSessionCollection sessions = NetworkSession.EndFind(result); + AvailableNetworkSessionCollection sessions; + try + { + sessions = NetworkSession.EndFind(result); + } + catch (Exception e) + { + if (ErrorDelegate != null) ErrorDelegate(e, this); + return; + } mFoundSessionsDelegate(sessions, this); + mFoundSessionsDelegate = null; } /// @@ -163,12 +197,18 @@ namespace CS_3505_Project_06 { Debug.Assert(mNetworkSession == null); - mNetworkSession = NetworkSession.EndJoin(result); - + try + { + mNetworkSession = NetworkSession.EndJoin(result); + mNetworkSession.GameStarted += new EventHandler(mNetworkSession_GameStarted); + } + catch (Exception e) + { + if (ErrorDelegate != null) ErrorDelegate(e, this); + return; + } mJoinedSessionDelegate(mNetworkSession, this); mJoinedSessionDelegate = null; - - mNetworkSession.GameStarted += new EventHandler(mNetworkSession_GameStarted); }