Exemple #1
0
        private static LidgrenSession EndCreateOrJoin(IAsyncResult result)
        {
            LidgrenSession session = null;

            try
            {
                var asyncResult = (AsyncResult)result;

                result.AsyncWaitHandle.WaitOne();

                if (asyncResult.AsyncDelegate is AsynchronousCreate)
                {
                    session = ((AsynchronousCreate)asyncResult.AsyncDelegate).EndInvoke(result);
                }
                else if (asyncResult.AsyncDelegate is AsynchronousJoin)
                {
                    session = ((AsynchronousJoin)asyncResult.AsyncDelegate).EndInvoke(result);
                }
            }
            finally
            {
                result.AsyncWaitHandle.Close();
            }

            return(session);
        }
        /// <summary>
        /// Creates a wide area network session
        /// </summary>
        /// <param name="maxPlayers">The total maximum players for this session</param>
        /// <param name="sessionProperties">The SessionProperties that will be used to find this session on the network. Can be null</param>
        /// <remarks>it doesn't yet support multiple local players</remarks>
        public override void CreateWanSession(int maxPlayers, SessionProperties sessionProperties)
        {
            IPAddress ipAddress;
            var       host = NetUtility.GetMyAddress(out ipAddress);

            _networkSessionLocker = CreatingSession;
            LidgrenSession.BeginCreate(host.ToString(), SessionType.WideAreaNetwork, 1, maxPlayers, 0, sessionProperties, OnLidgrenSessionCreated, _networkSessionLocker);
        }
        private void OnLidgrenSessionsFound(IAsyncResult ar)
        {
            var foundSessions = new List <AvailableSession>(LidgrenSession.EndFind(ar));

            // cleanup the temp session, this might could be reused.
            CurrentSession.EndSession(); // not sure if this is needed
            CurrentSession = null;

            OnSessionsFound(foundSessions);
        }
        /// <summary>
        /// Sends a Find query on the network interface to look for AvailableSession instances asynchrnously
        /// </summary>
        /// <param name="sessionType">The SessionType we're looking for</param>
        /// <param name="maxLocalPlayers">The Maximum local players that can be added to the session used to filter sessions that have a limited number of opened public slots</param>
        /// <param name="sessionProperties">The SessionProperties that will be used to filter query results. Can be null</param>
        /// <param name="host">The for WAN session discovery</param>
        /// <param name="port">The for WAN session discovery</param>
        public void FindSessionsWan(SessionType sessionType, int maxLocalPlayers, SessionProperties sessionProperties, string host = null, int port = ServerPort)
        {
            if (CurrentSession != null)
            {
                throw new CoreException("Session is already running");
            }

            _networkSessionLocker = FindingSessions;
            LidgrenSession.BeginFindWan(sessionType, maxLocalPlayers, sessionProperties, host, port, OnLidgrenSessionsFound, _networkSessionLocker);
        }
Exemple #5
0
        /// <summary>
        /// Sends a Join query to the Session asynchronously
        /// </summary>
        /// <param name="availableSession">The Session we are trying to join</param>
        public override void JoinSession(AvailableSession availableSession)
        {
            if (CurrentSession != null)
            {
                throw new CoreException("Session is already running");
            }

            _networkSessionLocker = JoiningSession;
            LidgrenSession.BeginJoin(availableSession as LidgrenAvailableSession, OnLidgrenSessionJoined, _networkSessionLocker);
        }
Exemple #6
0
        /// <summary>
        /// Sends a Find query on the network interface to look for AvailableSession instances asynchrnously
        /// </summary>
        /// <param name="sessionType">The SessionType we're looking for</param>
        /// <param name="maxLocalPlayers">The Maximum local players that can be added to the session used to filter sessions that have a limited number of opened public slots</param>
        /// <param name="sessionProperties">The SessionProperties that will be used to filter query results. Can be null</param>
        public override void FindSessions(SessionType sessionType, int maxLocalPlayers, SessionProperties sessionProperties)
        {
            if (CurrentSession != null)
            {
                throw new CoreException("Session is already running");
            }

            _networkSessionLocker = FindingSessions;
            LidgrenSession.BeginFind(sessionType, maxLocalPlayers, sessionProperties, OnLidgrenSessionsFound, _networkSessionLocker);
        }
        /// <summary>
        /// Creates a Single Player Session
        /// </summary>
        /// <remarks>No network resources will be used</remarks>
        public override void CreateSinglePlayerSession()
        {
            if (CurrentSession != null)
            {
                throw new CoreException("Session is already running");
            }

            IPAddress ipAddress;
            var       host = NetUtility.GetMyAddress(out ipAddress);

            _networkSessionLocker = CreatingSession;
            LidgrenSession.BeginCreate(host.ToString(), SessionType.SinglePlayer, 1, 1, 0, new SessionProperties(), OnLidgrenSessionCreated, _networkSessionLocker);
        }
        /// <summary>
        /// Sends a Find query on the network interface to look for AvailableSession instances asynchrnously
        /// </summary>
        /// <param name="sessionType">The SessionType we're looking for</param>
        /// <param name="maxLocalPlayers">The Maximum local players that can be added to the session used to filter sessions that have a limited number of opened public slots</param>
        /// <param name="sessionProperties">The SessionProperties that will be used to filter query results. Can be null</param>
        public override void FindSessions(SessionType sessionType, int maxLocalPlayers, SessionProperties sessionProperties)
        {
            if (CurrentSession != null)
            {
                throw new CoreException("Session is already running");
            }

            if (sessionType == SessionType.WideAreaNetwork)
            {
                throw new NotImplementedException("Use FindSessionsWan method instead");
            }

            // Create a temporary session to listen for discovery messages
            CurrentSession = new LidgrenSession(sessionType, maxLocalPlayers, 0, sessionProperties);

            _networkSessionLocker = FindingSessions;
            LidgrenSession.BeginFind(sessionType, maxLocalPlayers, sessionProperties, OnLidgrenSessionsFound, _networkSessionLocker);
        }
Exemple #9
0
        internal static LidgrenSession Join(LidgrenAvailableSession availableSession)
        {
            var session = new LidgrenSession(availableSession.HostName, availableSession.SessionType, availableSession.CurrentGamerCount + availableSession.OpenPublicSlots + availableSession.OpenPrivateSlots, 0, availableSession.Properties, false);

            return session;
        }
Exemple #10
0
        private static LidgrenSession Create(string serverHost, SessionType sessionType, int maxGamers, int privateReservedSlots, SessionProperties sessionProperties, bool isHost)
        {
            var session = new LidgrenSession(serverHost, sessionType, maxGamers, privateReservedSlots, sessionProperties, isHost);

            return session;
        }
Exemple #11
0
        private static LidgrenSession Create(string serverHost, SessionType sessionType, int maxGamers, int privateReservedSlots, SessionProperties sessionProperties, bool isHost)
        {
            var session = new LidgrenSession(serverHost, sessionType, maxGamers, privateReservedSlots, sessionProperties, isHost);

            return(session);
        }
Exemple #12
0
        internal static LidgrenSession Join(LidgrenAvailableSession availableSession)
        {
            var session = new LidgrenSession(availableSession.HostName, availableSession.SessionType, availableSession.CurrentGamerCount + availableSession.OpenPublicSlots + availableSession.OpenPrivateSlots, 0, availableSession.Properties, false);

            return(session);
        }
 private void OnLidgrenSessionCreated(IAsyncResult result)
 {
     CurrentSession = LidgrenSession.EndCreate(result);
 }
 private void OnLidgrenSessionJoined(IAsyncResult ar)
 {
     CurrentSession = LidgrenSession.EndJoin(ar);
     OnSessionJoined();
 }
Exemple #15
0
        private void OnLidgrenSessionsFound(IAsyncResult ar)
        {
            var foundSessions = new List <AvailableSession>(LidgrenSession.EndFind(ar));

            OnSessionsFound(foundSessions);
        }
        /// <summary>
        /// Sends a Find query on the network interface to look for AvailableSession instances asynchrnously
        /// </summary>
        /// <param name="sessionType">The SessionType we're looking for</param>
        /// <param name="maxLocalPlayers">The Maximum local players that can be added to the session used to filter sessions that have a limited number of opened public slots</param>
        /// <param name="sessionProperties">The SessionProperties that will be used to filter query results. Can be null</param>
        public override void FindSessions(SessionType sessionType, int maxLocalPlayers, SessionProperties sessionProperties)
        {

            if (CurrentSession != null)
                throw new CoreException("Session is already running");

            if (sessionType == SessionType.WideAreaNetwork)
                throw new NotImplementedException("Use FindSessionsWan method instead");

            // Create a temporary session to listen for discovery messages
            CurrentSession = new LidgrenSession(sessionType, maxLocalPlayers, 0, sessionProperties);

            _networkSessionLocker = FindingSessions;
            LidgrenSession.BeginFind(sessionType, maxLocalPlayers, sessionProperties, OnLidgrenSessionsFound, _networkSessionLocker);
        }