/// <summary> /// Performs tasks related to the running of the server. /// </summary> public void Running() { while (Status == ServerStatus.Running) { try { // Don't allow anymore connections if we have hit our limit. if (ServerDirector.ConnectedPlayers.Count < MaxConnections) { ServerDirector.AddConnection(Socket.Accept()); } } catch { // Swallow for now. } // Let's add the Auto-Save feature while the server is running. - MC // TODO I removed this due to being hard-coded to a internal engine Type. // If a developer creates a custom copy (as we will for our game as well) then the game won't ever have this called. - JS // var eGame = Game as EngineGame; if (Game != null) { if (Game.LastSave.CompareTo((DateTime.Now.Subtract(TimeSpan.FromMinutes(30.0)))) < 0) { // eGame.Save(); } } } }
/// <summary> /// Starts the server. Once completed, it will listen for incoming connections /// </summary> /// <param name="maxConnections">Maximum connections this server will allow</param> /// <param name="maxQueueSize">Maximum queue size this server will allow</param> /// <param name="game">The game that the server will reference.</param> public void Start(Int32 maxConnections, Int32 maxQueueSize, IGame game) { Log.Info(string.Format("Game Server System Starting on port {0}", Port)); // Logger.WriteLine("Game Server System Starting on port " + Port.ToString()); // If the server is already running, abort. if (Status != ServerStatus.Stopped) { return; } // Set the status to starting Status = ServerStatus.Starting; // Store our reference to the Game Game = game; // Instance a new copy of ServerDirector ServerDirector = new ServerDirector(this); try { // Setup our network socket. Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ip = new IPEndPoint(IPAddress.Any, this.Port); // Bind to the host and listen for incoming connections Socket.Bind(ip); Socket.Listen(this.MaxQueuedConnections); // Set the status to running this.Status = ServerStatus.Running; this.Enabled = true; // Pass the new client off onto a new thread and allow it to run. ServerThread = new Thread(Running); ServerThread.Start(); Log.Info("Server status: Running"); // Logger.WriteLine("Server status: Running"); } catch { Log.Fatal("Failed to start the Engines Networking Server!"); // Logger.WriteLine("Failed to star the Engines Networking Server!"); this.Status = ServerStatus.Stopped; Log.Fatal("Server status: Stopped"); // Logger.WriteLine("Server status: Stopped"); } }
/// <summary> /// Stops the server if it is running /// </summary> public void Stop() { Status = ServerStatus.Stopped; Enabled = false; // Disconnect all of the players ServerDirector.DisconnectAll(); // Close our network connection Socket.Close(); // Socket = null; // Kill the server thread ServerThread.Abort(); }
public GenderSelect(ServerDirector serverDirector) { director = serverDirector; }
public MainMenuState(ServerDirector director) { Director = director; }
public CreateNewCharacter(ServerDirector serverDirector) { director = serverDirector; currentState = CurrentState.InitialWelcome; }
public ClientLoginState(ServerDirector serverDirector) { director = serverDirector; currentState = CurrentState.EnteringName; }
public ClientConnectState(ServerDirector serverDirector) { director = serverDirector; }
public CreationManager(ServerDirector serverDirector, CreationState initialState) { currentCreationState = initialState; director = serverDirector; }