Beispiel #1
0
    public MtaServer(
        Action <ServerBuilder> builderAction,
        Func <uint, INetWrapper, Client>?clientCreationMethod = null
        )
    {
        this.netWrappers          = new();
        this.clients              = new();
        this.clientCreationMethod = clientCreationMethod;

        this.root = new();
        this.serviceCollection = new();

        var builder = new ServerBuilder();

        builderAction(builder);

        this.configuration = builder.Configuration;
        this.Password      = this.configuration.Password;
        this.SetupDependencies(services => builder.LoadDependencies(services));

        this.serviceProvider = this.serviceCollection.BuildServiceProvider();
        this.packetReducer   = new(this.serviceProvider.GetRequiredService <ILogger>());

        this.resourceServer = this.serviceProvider.GetRequiredService <IResourceServer>();
        this.resourceServer.Start();

        this.elementRepository  = this.serviceProvider.GetRequiredService <IElementRepository>();
        this.elementIdGenerator = this.serviceProvider.GetService <IElementIdGenerator>();

        this.root.AssociateWith(this);

        builder.ApplyTo(this);
    }