Beispiel #1
0
        /// <summary>
        /// Creates a new LiNGS Server instance. The server starts immediately.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown when any param is null.</exception>
        /// <param name="properties">Properties of this server instance. The properties are not changeable at runtime.</param>
        /// <param name="networkedGame">The instance of your game logic.</param>
        public LiNGSServer(ServerProperties properties, INetworkedGame networkedGame)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("Server properties cannot be null.");
            }

            if (networkedGame == null)
            {
                throw new ArgumentNullException("NetworkedGame cannot be null.");
            }

            this.updateManager = new UpdateManager();
            ServerProperties   = new ServerProperties(properties);

            NetworkManager         = new NetworkManager(this, properties.ListenPort);
            Manager                = new Manager(this, properties.MaxClients);
            Router                 = new Router(this);
            MessageAggregator      = new MessageAggregator(this);
            GameLogicProcessor     = new GameLogicProcessor(this);
            StateManager           = new StateManager(this);
            PersistentStateManager = new PersistentStateManager(this);
            Analyzer               = new Analyzer(this);
            Dispatcher             = new Dispatcher(this);
            NetworkedGameInstance  = networkedGame;

            this.updateManager.AddUpdatable(MessageAggregator);
            this.updateManager.AddUpdatable(StateManager);
            this.updateManager.AddUpdatable(Dispatcher);
            this.updateManager.AddUpdatable(Manager);
            this.updateManager.AddUpdatable(Analyzer);
            this.updateManager.AddUpdatable(GameLogicProcessor);
        }
Beispiel #2
0
 /// <summary>
 /// Disconnects all clients, terminates all connections and releases server resources
 /// </summary>
 public void Shutdown()
 {
     NetworkManager.Shutdown();
     Manager.Shutdown();
     if (ServerProperties.DeleteSessionFilesOnExit)
     {
         PersistentStateManager.ClearStates();
     }
 }