void OnApplicationQuit() { // If no matchmaking active just disconnect. if (_matchmakeTicket == null) { // Lets gracefully disconnect from the server. _client.Disconnect(); return; } // If matchmaking active stop matchmaking then disconnect. var message = NMatchmakeRemoveMessage.Default(_matchmakeTicket); _client.Send(message, (bool done) => { // The user is now removed from the matchmaker pool. Debug.Log("Matchmaking stopped."); // Lets gracefully disconnect from the server. _client.Disconnect(); }, (INError error) => { Debug.LogErrorFormat("Send error: code '{1}' with '{0}'.", error.Message, error.Code); // Lets gracefully disconnect from the server. _client.Disconnect(); }); }
public void MatchmakeRemove() { ManualResetEvent evt = new ManualResetEvent(false); INError error = null; INMatchmakeMatched res1 = null; INMatchmakeMatched res2 = null; client1.OnMatchmakeMatched = (INMatchmakeMatched matched) => { res1 = matched; evt.Set(); }; client2.OnMatchmakeMatched = (INMatchmakeMatched matched) => { res2 = matched; evt.Set(); }; client1.Send(NMatchmakeAddMessage.Default(2), (INMatchmakeTicket ticket1) => { client1.Send(NMatchmakeRemoveMessage.Default(ticket1), (bool done) => { client2.Send(NMatchmakeAddMessage.Default(2), (INMatchmakeTicket ticket2) => { // No action. }, (INError err) => { error = err; }); }, (INError err) => { error = err; }); }, (INError err) => { error = err; }); evt.WaitOne(2000, false); Assert.IsNull(error); Assert.IsNull(res1); Assert.IsNull(res2); }