Ejemplo n.º 1
0
        public void Host(ServerListenParameters listenParameters)
        {
            Name       = listenParameters.Name;
            MaxPlayers = listenParameters.MaxPlayers;

            if (IsListening)
            {
                throw new Exception("Server is already listening.");
            }

            string hostName = listenParameters.Host;
            ushort port     = listenParameters.Port;

            Address address = new Address {
                Port = port
            };

            if (!address.SetHost(hostName))
            {
                throw new Exception($"Failed to resolve host: \"{hostName}\"");
            }

            var host = GetOrCreateHost();

            try
            {
                host.Create(address, MaxPlayersUpperLimit, ChannelUpperLimit);
            }
            catch (Exception ex)
            {
                m_Logger.LogError($"Failed to host server. Is port {listenParameters.Port} already being used?", ex);
                Environment.Exit(1);
                return;
            }

            StartListening();

            m_Logger.LogInformation($"Hosted server: {hostName}:{listenParameters.Port}");
            StartPingThread();

            m_MapManager.ChangeMap(listenParameters.Map);

            m_EventBus.Emit(this, new ServerInitializedEvent(listenParameters));
            m_EventBus.Subscribe <ENetNetworkEvent>(this, OnNetworkEvent);
        }
Ejemplo n.º 2
0
 public ServerInitializedEvent(ServerListenParameters listenParameters)
 {
     ListenParameters = listenParameters;
 }