/// <summary> /// Creates a new server manager, which will listen for clients /// on a given port. /// </summary> /// <param name="port">Port to listen on.</param> /// <param name="teamSize">Team Size as specified by login.</param> /// <param name="tokens">User tokens for connection.</param> public ServerManager(int port, int teamSize, int[] tokens) { GameMaster.State = GameMaster.GameState.Loading; GameMaster.StartMasterTimer(); // Initialise teams Trace.WriteLine("Initialising Teams."); Trace.Indent(); Settings.MaxTeamSize = teamSize; Team teamA = new Team(); Team teamB = new Team(); Trace.Unindent(); Trace.WriteLine("Teams initialised."); // Register ECS systems Trace.WriteLine("Registering ECS Systems."); Trace.Indent(); // Networking ECS.RegisterSystem(new NetworkingSystem()); ECS.RegisterSystem(new NetworkingClientSystem()); // World partioning ECS.RegisterSystem(new WorldSystem()); // Game systems (Alphabetical order). ECS.RegisterSystem(new AnimationSystem()); ECS.RegisterSystem(new BlachholeSystem()); ECS.RegisterSystem(new CombatSystem()); ECS.RegisterSystem(new EngineSystem()); ECS.RegisterSystem(new PositionSystem()); ECS.RegisterSystem(new ResourceSystem()); ECS.RegisterSystem(new ShipLimiterSystem()); ECS.RegisterSystem(new TeamSystem()); ECS.RegisterSystem(new WeaponSystem()); ECS.RegisterSystem(new LifetimeSystem()); ECS.RegisterSystem(new ProjectileSystem()); // Create networking component without an entity NetworkState = new NetworkingComponent(port, tokens, teamA, teamB); ECS.RegisterComponentToSystem( ComponentSystemId.NetworkingSystem, ECS.GetNextId(), NetworkState ); Trace.Unindent(); Trace.WriteLine("ECS Registered."); // Load map data Trace.WriteLine("Loading map data."); Trace.Indent(); MapData.SpawnWorld(teamA, teamB); Trace.Unindent(); Trace.WriteLine("Map loaded."); // Register to State event handlers GameMaster.OnStartCountdown += HandleOnCountdown; GameMaster.OnStartGame += HandleOnGameStart; GameMaster.OnEndGame += HandleOnGameEnd; // Start timers Timer = new Stopwatch(); Timer.Start(); FrameTimer = new Stopwatch(); FrameTimer.Start(); GameMaster.State = GameMaster.GameState.WaitingForPlayers; }