예제 #1
0
        public void Run(EventWaitHandle serverStartWaitHandle)
        {
            this.World.TickStarted  += OnTickStarted;
            this.World.TickEnded    += OnTickEnded;
            this.World.TurnStarting += OnTurnStarting;
            this.World.TurnEnded    += OnTurnEnded;

            PipeConnectionListener.StartListening(_OnNewConnection);
            TcpConnectionListener.StartListening(_OnNewConnection, "SNet");
            DirectConnectionListener.StartListening(_OnNewConnection);

            trace.TraceInformation("The server is ready.");

            if (serverStartWaitHandle != null)
            {
                serverStartWaitHandle.Set();
            }

            CheckForStartTick();

            // Enter the main loop

            m_dispatcher.Run(MainWork);

            trace.TraceInformation("Server exiting");

            DirectConnectionListener.StopListening();
            TcpConnectionListener.StopListening();
            PipeConnectionListener.StopListening();

            this.World.TurnEnded    -= OnTurnEnded;
            this.World.TurnStarting -= OnTurnStarting;
            this.World.TickEnded    -= OnTickEnded;
            this.World.TickStarted  -= OnTickStarted;

            // Need to disconnect the sockets
            foreach (var user in m_users)
            {
                if (user.IsConnected)
                {
                    user.Disconnect();
                }
            }

            trace.TraceInformation("Server exit");
        }