Exemplo n.º 1
0
        /// <summary>
        /// Attempts to join a session asynchronously.
        /// </summary>
        /// <param name="session">The AvailableSession to join.</param>
        /// <param name="initializeFunction">The optional function to call to initialize the session.</param>
        public static void JoinSessionAsync(AvailableSession session, ActiveSession.ActiveSessionDelegate initializeFunction, Action<bool> callback)
        {
            if (IsLocked)
            {
                if (callback != null)
                    callback(false);
                return;
            }
            #if DEBUG
            Log.Trace(String.Format("Joining session hosted by {0}...", session.HostName), 2.0f);
            #endif
            joinAsyncFunction = initializeFunction;
            joinAsyncCallback = callback;

            try
            {
                joinAsync = NetworkSession.BeginJoin(session.NativeSession, JoinAsyncFinished, null);
            }
            catch (Exception e)
            {
                ReportError(e.Message);
                if (joinAsyncCallback != null)
                    joinAsyncCallback(false);
                JoinAsyncClear();
            }
        }
Exemplo n.º 2
0
 private int SortSessions(AvailableSession a, AvailableSession b)
 {
     return Math.Sign(a.OpenPublicSlots - b.OpenPublicSlots);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Attempts to join a session.
 /// </summary>
 /// <param name="session">The AvailableSession to join.</param>
 /// <param name="initializeFunction">The optional function to call to initialize the session.</param>
 public static bool JoinSession(AvailableSession session, ActiveSession.ActiveSessionDelegate initializeFunction)
 {
     if (IsLocked)
         return false;
     #if DEBUG
     Log.Trace(String.Format("Joining session hosted by {0}...", session.HostName), 2.0f);
     #endif
     try
     {
         NetworkSession newSession = NetworkSession.Join(session.NativeSession);
         ActiveSession = new ActiveSession(newSession, initializeFunction);
         return true;
     }
     catch (Exception e)
     {
         ReportError(e.Message);
         ActiveSession.EndSession();
         return false;
     }
 }