Exemplo n.º 1
0
        /// <summary>
        /// Creates a new DSS-lobby with the given maximum number of operators.
        /// </summary>
        /// <param name="opCount">The maximum number of operators in the DSS (including the host itself).</param>
        /// <param name="network">The network interface that is used to connect.</param>
        /// <param name="simulatorIface">Interface of the local simulator implemented by the client module.</param>
        /// <param name="setupIface">Interface of the setup manager object implemented by the client module.</param>
        /// <remarks>The caller thread will be blocked during the whole lifetime of the DSS.</remarks>
        public static void CreateDSS(int opCount, INetwork network, ISimulator simulatorIface, IDssHostSetup setupIface)
        {
            if (opCount < 2)
            {
                throw new ArgumentOutOfRangeException("opCount");
            }
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (simulatorIface == null)
            {
                throw new ArgumentNullException("simulatorIface");
            }
            if (setupIface == null)
            {
                throw new ArgumentNullException("setupIface");
            }

            dssActive.WaitOne();

            try
            {
                DssHostRoot      hostRoot = new DssHostRoot(simulatorIface, setupIface, opCount);
                HostEventHandler eventHdl = new HostEventHandler(hostRoot);
                hostRoot.EventQueue.RegisterHandler(eventHdl);

                ILobbyServer server = network.CreateLobby(opCount, hostRoot.EventQueue);
                if (server == null)
                {
                    throw new DssException("Cannot create the lobby under the DSS!");
                }
                server.StartAnnouncing(); /// TODO: add ILobbyCustomDataProvider if necessary
                hostRoot.Lobby = server;
                hostRoot.EventQueue.EventLoop();
                server.Shutdown();

                hostRoot.Dispose();
            }
            catch (Exception ex)
            {
                TraceManager.WriteExceptionAllTrace(ex, false);
            }
            finally
            {
                dssActive.Release();
            }
        }