-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
202 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using NetScape.Abstractions.FileSystem; | ||
using System; | ||
using System.IO; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace NetScape.Core | ||
{ | ||
public class FileSystem : IFileSystem | ||
{ | ||
private readonly FileSystemConfig _fileConfig; | ||
|
||
public FileSystem(IConfigurationRoot configurationRoot) | ||
{ | ||
_fileConfig = configurationRoot.GetSection("FileSystem").Get<FileSystemConfig>(); | ||
BasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), | ||
_fileConfig.BaseFolder); | ||
} | ||
|
||
public string BasePath { get; } | ||
|
||
public string CachePath => Path.Combine(BasePath, _fileConfig.CacheFolder); | ||
} | ||
|
||
public class FileSystemConfig | ||
{ | ||
public string BaseFolder { get; set; } | ||
public string CacheFolder { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="Nuget.Projects.props" /> | ||
<PropertyGroup> | ||
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
<Target DependsOnTargets="ResolveReferences" Name="CopyProjectReferencesToPackage"> | ||
<ItemGroup> | ||
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" /> | ||
<PackageReference Include="Autofac" Version="6.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NetScape.GameServer\NetScape.Modules.Server.csproj" /> | ||
<ProjectReference Include="..\NetScape.Modules.Cache\NetScape.Modules.Cache.csproj" /> | ||
<ProjectReference Include="..\NetScape.Modules.DAL\NetScape.Modules.DAL.csproj" /> | ||
<ProjectReference Include="..\NetScape.Modules.Logging.SeriLog\NetScape.Modules.Logging.SeriLog.csproj" /> | ||
<ProjectReference Include="..\NetScape.Modules.Region.Collision\NetScape.Modules.Region.Collision.csproj" /> | ||
<ProjectReference Include="..\NetScape.Modules.World\NetScape.Modules.World.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<IsPackable>true</IsPackable> | ||
<PublishRepositoryUrl>true</PublishRepositoryUrl> | ||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<RepositoryUrl>https://github.com/jayarrowz/NetScape</RepositoryUrl> | ||
<IncludeSymbols>true</IncludeSymbols> | ||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile> | ||
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression> | ||
<PackageTags>NetScape</PackageTags> | ||
<PackageDescription>NetScape Core Libraries</PackageDescription> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<SignAssembly>true</SignAssembly> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="../LICENSE.txt" Pack="true" PackagePath="LICENSE.txt"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NetScape.Abstractions.FileSystem; | ||
using NetScape.Abstractions.Game; | ||
using NetScape.Abstractions.Interfaces.IO; | ||
using NetScape.Abstractions.Server; | ||
using NetScape.Modules.Cache; | ||
using NetScape.Modules.DAL; | ||
using NetScape.Modules.Logging.SeriLog; | ||
using NetScape.Modules.Region; | ||
using NetScape.Modules.Region.Collision; | ||
using NetScape.Modules.Server; | ||
using NetScape.Modules.World; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace NetScape.Core | ||
{ | ||
public static class ServerHandler | ||
{ | ||
public static ILifetimeScope RunServer(string configFileName, Action<DbContextOptionsBuilder, IConfigurationRoot> dbOptions, List<Module> modules) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
var config = ConfigureServices(serviceCollection, configFileName, dbOptions); | ||
var containerBuilder = new ContainerBuilder(); | ||
containerBuilder.Populate(serviceCollection); | ||
ConfigureAutofac(containerBuilder, config, modules); | ||
containerBuilder.RegisterBuildCallback(t => t.Resolve<ContainerProvider>().Container = (IContainer)t); | ||
var container = containerBuilder.Build(); | ||
var serviceProvider = new AutofacServiceProvider(container); | ||
|
||
ILifetimeScope scope = container.BeginLifetimeScope(); | ||
var gameServer = serviceProvider.GetRequiredService<IGameServer>(); | ||
_ = gameServer.BindAsync(); | ||
return scope; | ||
} | ||
|
||
public static void ConfigureCore(this ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot) | ||
{ | ||
containerBuilder.RegisterModule(new SeriLogModule(configurationRoot)); | ||
containerBuilder.RegisterModule(new CacheModule()); | ||
containerBuilder.RegisterModule(new DALModule()); | ||
containerBuilder.RegisterModule(new GameServerModule(configurationRoot["BindAddr"], ushort.Parse(configurationRoot["BindPort"]))); | ||
containerBuilder.RegisterModule(new WorldModule()); | ||
containerBuilder.RegisterModule(new RegionModule()); | ||
containerBuilder.RegisterModule(new CollisionModule()); | ||
containerBuilder.RegisterType<WalkingQueueHandler>(); | ||
containerBuilder.RegisterType<FileSystem>().As<IFileSystem>(); | ||
containerBuilder.RegisterType<ContainerProvider>().SingleInstance(); | ||
} | ||
|
||
private static void ConfigureAutofac(ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot, List<Module> modules) | ||
{ | ||
foreach (var module in modules) | ||
{ | ||
containerBuilder.RegisterModule(module); | ||
} | ||
|
||
containerBuilder.ConfigureCore(configurationRoot); | ||
} | ||
|
||
public static IConfigurationRoot ConfigureServices(this IServiceCollection serviceCollection, string configFileName, Action<DbContextOptionsBuilder, IConfigurationRoot> optionsAction) | ||
{ | ||
var configurationRoot = CreateConfigurationRoot(configFileName); | ||
|
||
// Add logging | ||
serviceCollection.AddLogging(); | ||
|
||
//Build DB Connection | ||
serviceCollection.AddDbContextFactory<DatabaseContext>(opts => optionsAction(opts, configurationRoot)); | ||
|
||
// Add access to generic IConfigurationRoot | ||
serviceCollection.AddSingleton(configurationRoot); | ||
return configurationRoot; | ||
} | ||
|
||
public static IConfigurationRoot CreateConfigurationRoot(string fileName) | ||
{ | ||
return new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) | ||
.AddJsonFile(fileName, false) | ||
.Build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,41 @@ | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using System; | ||
using Autofac; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NetScape.Abstractions.FileSystem; | ||
using NetScape.Abstractions.Game; | ||
using NetScape.Abstractions.Interfaces.IO; | ||
using NetScape.Abstractions.Server; | ||
using NetScape.Modules.Cache; | ||
using NetScape.Core; | ||
using NetScape.Modules.DAL; | ||
using NetScape.Modules.Logging.SeriLog; | ||
using NetScape.Modules.Messages; | ||
using NetScape.Modules.Messages.Models; | ||
using NetScape.Modules.Region; | ||
using NetScape.Modules.Region.Collision; | ||
using NetScape.Modules.Server; | ||
using NetScape.Modules.ThreeOneSeven.Game; | ||
using NetScape.Modules.ThreeOneSeven.LoginProtocol; | ||
using NetScape.Modules.ThreeOneSeven.World.Updating; | ||
using NetScape.Modules.World; | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
namespace NetScape | ||
{ | ||
public class Kernel | ||
{ | ||
public static IConfigurationRoot ConfigurationRoot { get; set; } | ||
public static void Main(string[] args) | ||
{ | ||
var serviceCollection = new ServiceCollection(); | ||
ConfigureServices(serviceCollection); | ||
|
||
var containerBuilder = new ContainerBuilder(); | ||
containerBuilder.Populate(serviceCollection); | ||
ConfigureAutofac(containerBuilder, args); | ||
containerBuilder.RegisterBuildCallback(t => t.Resolve<ContainerProvider>().Container = (IContainer)t); | ||
var container = containerBuilder.Build(); | ||
var serviceProvider = new AutofacServiceProvider(container); | ||
|
||
using (ILifetimeScope scope = container.BeginLifetimeScope()) | ||
List<Module> modules = new() | ||
{ | ||
var gameServer = serviceProvider.GetRequiredService<IGameServer>(); | ||
_ = gameServer.BindAsync(); | ||
|
||
//TODO Make better | ||
Console.ReadLine(); | ||
} | ||
new ThreeOneSevenGameModule(), | ||
new MessagesModule( | ||
typeof(ThreeOneSevenEncoderMessages.Types), | ||
typeof(ThreeOneSevenDecoderMessages.Types) | ||
), | ||
new ThreeOneSevenLoginModule(), | ||
new ThreeOneSevenUpdatingModule() | ||
}; | ||
ServerHandler.RunServer("appsettings.json", BuildDbOptions, modules); | ||
Console.ReadLine(); | ||
} | ||
|
||
private static void BuildDbOptions(DbContextOptionsBuilder optionsBuilder) | ||
private static void BuildDbOptions(DbContextOptionsBuilder optionsBuilder, IConfigurationRoot configurationRoot) | ||
{ | ||
optionsBuilder.UseNpgsql(ConfigurationRoot.GetConnectionString("NetScape"), | ||
optionsBuilder.UseNpgsql(configurationRoot.GetConnectionString("NetScape"), | ||
x => x.MigrationsAssembly(typeof(DatabaseContext) | ||
.Assembly.GetName().Name)); | ||
.Assembly.FullName)); | ||
} | ||
|
||
private static void ConfigureAutofac(ContainerBuilder containerBuilder, string[] args) | ||
{ | ||
containerBuilder.RegisterModule(new ThreeOneSevenGameModule()); | ||
containerBuilder.RegisterModule(new MessagesModule( | ||
typeof(ThreeOneSevenEncoderMessages.Types), | ||
typeof(ThreeOneSevenDecoderMessages.Types)) | ||
); | ||
containerBuilder.RegisterModule(new ThreeOneSevenLoginModule()); | ||
containerBuilder.RegisterModule(new ThreeOneSevenUpdatingModule()); | ||
|
||
containerBuilder.RegisterModule(new SeriLogModule(ConfigurationRoot)); | ||
containerBuilder.RegisterModule(new CacheModule()); | ||
containerBuilder.RegisterModule(new DALModule()); | ||
containerBuilder.RegisterModule(new GameServerModule(ConfigurationRoot["BindAddr"], ushort.Parse(ConfigurationRoot["BindPort"]))); | ||
containerBuilder.RegisterModule(new WorldModule()); | ||
containerBuilder.RegisterModule(new RegionModule()); | ||
containerBuilder.RegisterModule(new CollisionModule()); | ||
containerBuilder.RegisterType<WalkingQueueHandler>(); | ||
containerBuilder.RegisterType<FileSystem>().As<IFileSystem>(); | ||
containerBuilder.RegisterType<ContainerProvider>().SingleInstance(); | ||
} | ||
|
||
public static void SetConfigRoot() | ||
{ | ||
ConfigurationRoot = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) | ||
.AddJsonFile("appsettings.json", false) | ||
.Build(); | ||
} | ||
|
||
private static void ConfigureServices(IServiceCollection serviceCollection) | ||
{ | ||
SetConfigRoot(); | ||
|
||
// Add logging | ||
serviceCollection.AddLogging(); | ||
|
||
//Build DB Connection | ||
serviceCollection.AddDbContextFactory<DatabaseContext>(BuildDbOptions); | ||
|
||
// Add access to generic IConfigurationRoot | ||
serviceCollection.AddSingleton(ConfigurationRoot); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters