Skip to content

Commit

Permalink
Add presence server base
Browse files Browse the repository at this point in the history
  • Loading branch information
FeTetra committed Nov 2, 2024
1 parent f1fe542 commit 060a4a3
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ProjectLighthouse.Servers.GameServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
logging.AddProvider(new AspNetToLighthouseLoggerProvider());
});

await builder.Build().RunAsync();
await builder.Build().RunAsync();
22 changes: 22 additions & 0 deletions ProjectLighthouse.Servers.Presence/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using LBPUnion.ProjectLighthouse;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Logging.Loggers.AspNet;
using LBPUnion.ProjectLighthouse.Servers.Presence.Startup;
using LBPUnion.ProjectLighthouse.Types.Misc;

await StartupTasks.Run(ServerType.Presence);

IHostBuilder builder = Host.CreateDefaultBuilder();
builder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<PresenceStartup>();
webBuilder.UseUrls(ServerConfiguration.Instance.PresenceListenUrl);
});

builder.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddProvider(new AspNetToLighthouseLoggerProvider());
});

await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>LBPUnion.ProjectLighthouse.Servers.Presence</AssemblyName>
<RootNamespace>LBPUnion.ProjectLighthouse.Servers.Presence</RootNamespace>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Responses\" />
</ItemGroup>

</Project>
48 changes: 48 additions & 0 deletions ProjectLighthouse.Servers.Presence/Startup/PresenceStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Middlewares;
using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.EntityFrameworkCore;

namespace LBPUnion.ProjectLighthouse.Servers.Presence.Startup;

public class PresenceStartup
{
public PresenceStartup(IConfiguration configuration)
{
this.Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();

services.AddMvc
(
options =>
{
options.OutputFormatters.Add(new JsonOutputFormatter());
}
);

services.AddDbContext<DatabaseContext>(builder =>
{
builder.UseMySql(ServerConfiguration.Instance.DbConnectionString,
MySqlServerVersion.LatestSupportedServerVersion);
});
}

public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
#if DEBUG
app.UseDeveloperExceptionPage();
#endif

app.UseMiddleware<RequestLogMiddleware>();

app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapControllers());
}
}
15 changes: 15 additions & 0 deletions ProjectLighthouse.Servers.Presence/Startup/PresenceTestStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using LBPUnion.ProjectLighthouse.Middlewares;

namespace LBPUnion.ProjectLighthouse.Servers.Presence.Startup;

public class PresenceTestStartup : PresenceStartup
{
public PresenceTestStartup(IConfiguration configuration) : base(configuration)
{}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMiddleware<FakeRemoteIPAddressMiddleware>();
base.Configure(app, env);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions ProjectLighthouse.Servers.Presence/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
21 changes: 14 additions & 7 deletions ProjectLighthouse.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Tests.Gam
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Tests.WebsiteTests", "ProjectLighthouse.Tests.WebsiteTests\ProjectLighthouse.Tests.WebsiteTests.csproj", "{CF65EB5B-5364-4D2A-8639-F147A67F08E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Servers.API", "ProjectLighthouse.Servers.API\ProjectLighthouse.Servers.API.csproj", "{5593825E-F5C9-467F-9125-3E3249CFEEAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Servers.GameServer", "ProjectLighthouse.Servers.GameServer\ProjectLighthouse.Servers.GameServer.csproj", "{0CD7F64B-7827-4AC9-B7D8-CE371D505544}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Servers.Website", "ProjectLighthouse.Servers.Website\ProjectLighthouse.Servers.Website.csproj", "{FA9AEA06-D6B5-4E68-8370-DB9188108635}"
Expand All @@ -22,6 +20,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source Code", "Source Code"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Localization", "ProjectLighthouse.Localization\ProjectLighthouse.Localization.csproj", "{18B76DAC-5DCB-44EA-B74D-0B4554BB161C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Servers.API", "ProjectLighthouse.Servers.API\ProjectLighthouse.Servers.API.csproj", "{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectLighthouse.Servers.Presence", "ProjectLighthouse.Servers.Presence\ProjectLighthouse.Servers.Presence.csproj", "{6F186DE8-7734-4B08-AE1F-6C9CF77520FA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,10 +43,6 @@ Global
{CF65EB5B-5364-4D2A-8639-F147A67F08E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF65EB5B-5364-4D2A-8639-F147A67F08E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF65EB5B-5364-4D2A-8639-F147A67F08E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5593825E-F5C9-467F-9125-3E3249CFEEAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5593825E-F5C9-467F-9125-3E3249CFEEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5593825E-F5C9-467F-9125-3E3249CFEEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5593825E-F5C9-467F-9125-3E3249CFEEAB}.Release|Any CPU.Build.0 = Release|Any CPU
{0CD7F64B-7827-4AC9-B7D8-CE371D505544}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CD7F64B-7827-4AC9-B7D8-CE371D505544}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CD7F64B-7827-4AC9-B7D8-CE371D505544}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -57,16 +55,25 @@ Global
{18B76DAC-5DCB-44EA-B74D-0B4554BB161C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18B76DAC-5DCB-44EA-B74D-0B4554BB161C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18B76DAC-5DCB-44EA-B74D-0B4554BB161C}.Release|Any CPU.Build.0 = Release|Any CPU
{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F}.Release|Any CPU.Build.0 = Release|Any CPU
{6F186DE8-7734-4B08-AE1F-6C9CF77520FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F186DE8-7734-4B08-AE1F-6C9CF77520FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F186DE8-7734-4B08-AE1F-6C9CF77520FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F186DE8-7734-4B08-AE1F-6C9CF77520FA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AFC74569-B289-4ACC-B21C-313A3A62C017} = {D360C08E-EA47-43AC-A566-FDF413442980}
{200EED99-FE3E-45C6-A51E-76ED9819CA2B} = {D360C08E-EA47-43AC-A566-FDF413442980}
{CF65EB5B-5364-4D2A-8639-F147A67F08E7} = {D360C08E-EA47-43AC-A566-FDF413442980}
{5593825E-F5C9-467F-9125-3E3249CFEEAB} = {1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3}
{0CD7F64B-7827-4AC9-B7D8-CE371D505544} = {1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3}
{FA9AEA06-D6B5-4E68-8370-DB9188108635} = {1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3}
{1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3} = {7805B410-9260-4907-A7C6-D739369B2F25}
{C6CFD4AD-47ED-4C86-B0C4-A4216D82E0DC} = {7805B410-9260-4907-A7C6-D739369B2F25}
{18B76DAC-5DCB-44EA-B74D-0B4554BB161C} = {7805B410-9260-4907-A7C6-D739369B2F25}
{7D0D86A0-3C0F-4BED-9629-E0CFBDD1191F} = {1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3}
{6F186DE8-7734-4B08-AE1F-6C9CF77520FA} = {1DE7A758-1F4F-4BA5-BE1C-74F9D0AB9EA3}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion ProjectLighthouse/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
public string WebsiteListenUrl { get; set; } = "http://localhost:10060";
public string GameApiListenUrl { get; set; } = "http://localhost:10061";
public string ApiListenUrl { get; set; } = "http://localhost:10062";

public string PresenceListenUrl { get; set; } = "http://localhost:10072";
public string DbConnectionString { get; set; } = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
public string RedisConnectionString { get; set; } = "redis://localhost:6379";
public string ExternalUrl { get; set; } = "http://localhost:10060";
Expand Down
1 change: 1 addition & 0 deletions ProjectLighthouse/Startup/DebugWarmupLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static void OnApplicationStarted()
ServerType.GameServer => ServerConfiguration.Instance.GameApiListenUrl,
ServerType.Website => ServerConfiguration.Instance.WebsiteListenUrl,
ServerType.Api => ServerConfiguration.Instance.ApiListenUrl,
ServerType.Presence => ServerConfiguration.Instance.PresenceListenUrl,
_ => throw new ArgumentOutOfRangeException(),
};

Expand Down
1 change: 1 addition & 0 deletions ProjectLighthouse/Types/Misc/ServerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public enum ServerType
GameServer = 0,
Website = 1,
Api = 2,
Presence = 3,
}

0 comments on commit 060a4a3

Please sign in to comment.