Exemplo n.º 1
0
        /// <summary>
        /// Saves the specified configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void Save(ConnectServerDefinition configuration)
        {
            try
            {
                Log.Info($"requested to save configuration of connect server {configuration.ServerId}");
                DataModel.Configuration.ConnectServerDefinition currentConfiguration = null;
                if (this.servers.OfType <IConnectServer>().FirstOrDefault(s => s.Settings.GetId() == configuration.GetId()) is { } server)
                {
                    currentConfiguration = server.Settings as DataModel.Configuration.ConnectServerDefinition;
                }

                bool isNew = false;

                using (var configContext = this.persistenceContextProvider.CreateNewContext())
                {
                    if (currentConfiguration != null)
                    {
                        configContext.Attach(currentConfiguration);
                    }
                    else
                    {
                        currentConfiguration          = configContext.CreateNew <DataModel.Configuration.ConnectServerDefinition>();
                        currentConfiguration.ServerId = configuration.ServerId;
                        var existingConfigs = configContext.Get <DataModel.Configuration.ConnectServerDefinition>().ToList();
                        if (existingConfigs.Count > 0)
                        {
                            var newId = existingConfigs.Max(c => c.ServerId) + 1;
                            currentConfiguration.ServerId = (byte)newId;
                        }

                        isNew = true;
                    }

                    configuration.Adapt(currentConfiguration);
                    if (!Equals(currentConfiguration.Client, configuration.Client))
                    {
                        currentConfiguration.Client = configContext.GetById <DataModel.Configuration.GameClientDefinition>(configuration.Client.GetId());
                    }

                    configContext.SaveChanges();
                }

                if (isNew)
                {
                    this.changeListener?.ConnectionServerAdded(currentConfiguration);
                }
                else
                {
                    this.changeListener?.ConnectionServerChanged(currentConfiguration);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"An unexpected exception occured during saving the connect server configuration for server id {configuration.ServerId}", ex);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Restarts the connection server when its configuration has been changed and it's currently running.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void ConnectionServerChanged(ConnectServerDefinition configuration)
        {
            var server = this.servers.FirstOrDefault(s => s.Id == configuration.ServerId);

            if (server == null)
            {
                return;
            }

            if (server.ServerState == ServerState.Started)
            {
                server.Shutdown();
                server.Start();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConnectServerConfigurationViewItem"/> class.
 /// </summary>
 /// <param name="config">The configuration.</param>
 public ConnectServerConfigurationViewItem(ConnectServerDefinition config)
 {
     this.Configuration = config;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a connection server after a new configuration has been added.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void ConnectionServerAdded(ConnectServerDefinition configuration)
        {
            var connectServer = this.connectServerFactory.CreateConnectServer(configuration, new ClientVersion(configuration.Client.Season, configuration.Client.Episode, configuration.Client.Language), configuration.GetId());

            this.servers.Add(connectServer);
        }
        /// <summary>
        /// Adds a connection server after a new configuration has been added.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public void ConnectionServerAdded(ConnectServerDefinition configuration)
        {
            var connectServer = ConnectServerFactory.CreateConnectServer(configuration, this.stateObserver);

            this.servers.Add(connectServer);
        }
Exemplo n.º 6
0
        public ActionResult <Guid> Save([FromBody] ConnectServerDefinition configuration)
        {
            try
            {
                Log.Info($"requested to save configuration of connect server {configuration.ServerId}");
                DataModel.Configuration.ConnectServerDefinition currentConfiguration = null;
                if (this.servers.OfType <IConnectServer>().FirstOrDefault(s => s.Settings.GetId() == configuration.Id) is IConnectServer server)
                {
                    currentConfiguration = server.Settings as DataModel.Configuration.ConnectServerDefinition;
                }

                bool isNew = false;

                using (var configContext = this.persistenceContextProvider.CreateNewContext())
                {
                    if (currentConfiguration != null)
                    {
                        configContext.Attach(currentConfiguration);
                    }
                    else
                    {
                        currentConfiguration          = configContext.CreateNew <DataModel.Configuration.ConnectServerDefinition>();
                        currentConfiguration.ServerId = configuration.ServerId;
                        var existingConfigs = configContext.Get <DataModel.Configuration.ConnectServerDefinition>().ToList();
                        if (existingConfigs.Count > 0)
                        {
                            var newId = existingConfigs.Max(c => c.ServerId) + 1;
                            currentConfiguration.ServerId = (byte)newId;
                        }

                        isNew = true;
                    }

                    currentConfiguration.CheckMaxConnectionsPerAddress = configuration.CheckMaxConnectionsPerAddress;
                    currentConfiguration.ListenerBacklog          = configuration.ListenerBacklog;
                    currentConfiguration.MaxConnections           = configuration.MaxConnections;
                    currentConfiguration.MaxConnectionsPerAddress = configuration.MaxConnectionsPerAddress;
                    currentConfiguration.MaxFtpRequests           = configuration.MaxFtpRequests;
                    currentConfiguration.MaxIpRequests            = configuration.MaxIpRequests;
                    currentConfiguration.MaximumReceiveSize       = configuration.MaximumReceiveSize;
                    currentConfiguration.MaxServerListRequests    = configuration.MaxServerListRequests;
                    currentConfiguration.ClientListenerPort       = configuration.ClientListenerPort;
                    currentConfiguration.CurrentPatchVersion      = configuration.CurrentPatchVersion;
                    currentConfiguration.Timeout      = configuration.Timeout;
                    currentConfiguration.PatchAddress = configuration.PatchAddress;
                    currentConfiguration.Description  = configuration.Description;
                    currentConfiguration.DisconnectOnUnknownPacket = configuration.DisconnectOnUnknownPacket;
                    if (!Equals(currentConfiguration.Client, configuration.Client))
                    {
                        currentConfiguration.Client = configContext.GetById <DataModel.Configuration.GameClientDefinition>(configuration.RawClient.Id);
                    }

                    configContext.SaveChanges();
                }

                if (isNew)
                {
                    this.changeListener?.ConnectionServerAdded(currentConfiguration);
                }
                else
                {
                    this.changeListener?.ConnectionServerChanged(currentConfiguration);
                }

                if (this.serverListHubContext != null)
                {
                    Task.Run(() => ServerListHub.InitializeAllClients(this.serverListHubContext, this.servers, this.persistenceContextProvider).ConfigureAwait(false));
                }

                return(this.Ok(currentConfiguration.GetId()));
            }
            catch (Exception ex)
            {
                Log.Error($"An unexpected exception occured during saving the connect server configuration for server id {configuration.ServerId}", ex);
                throw;
            }
        }
Exemplo n.º 7
0
 public void ConnectionServerChanged(ConnectServerDefinition currentConfiguration)
 {
     // we do nothing
 }