Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server (Relay) #254

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bba6aac
Initial setup for dedicated server
worstmilk Jul 7, 2021
b7735e2
Split up commands to seperate shared project
worstmilk Jul 8, 2021
8938f8f
Removed the commands from the client
worstmilk Jul 8, 2021
a4d6d1a
Implement server project
worstmilk Jul 8, 2021
8e26984
Remove server commands to use the shared library
worstmilk Jul 8, 2021
011a91a
Change scripts to include shared library
worstmilk Jul 8, 2021
b2f3d2b
Add a way to synchronize the save file to the server
worstmilk Jul 8, 2021
6d0f832
Add reference to shared library
worstmilk Jul 8, 2021
924892f
Re-enable Upnp port forwarding
worstmilk Jul 8, 2021
58f83c9
Little refactor on the SaveHelper class
worstmilk Jul 8, 2021
e16d053
Add check for world file.
worstmilk Jul 8, 2021
6bfc0b9
Remove external unity and cities dependencies from server.
worstmilk Jul 9, 2021
c32ff3b
Implement Play/Pause
worstmilk Jul 9, 2021
3eadd01
Upgrade server to .NET5.0
worstmilk Jul 9, 2021
0e2327d
Add dependency injection
worstmilk Jul 9, 2021
a06afb7
Add web project
worstmilk Jul 12, 2021
ba5bdfe
Revert commands to original state
worstmilk Jul 15, 2021
8788de1
Change Game packets to 8000x range
worstmilk Jul 15, 2021
7c6c4f8
Implement host election
worstmilk Jul 15, 2021
1c8cfe6
Fix rename ClientDisconectHandler
worstmilk Jul 15, 2021
729c90b
Add Unreliable sending
worstmilk Jul 15, 2021
1a73f00
Change log level without restart
worstmilk Jul 15, 2021
bd99a7c
Fix transactions...
worstmilk Jul 15, 2021
40b079a
Rename commands/handlers
worstmilk Jul 15, 2021
c70c94f
Refactor send to all others
worstmilk Jul 15, 2021
1f43ae7
Replace stopwatch connection timeout with AutoResetEvent
worstmilk Jul 15, 2021
b4818dc
Remote CSM.Proto from install script
worstmilk Jul 15, 2021
6e94cda
Host Elect Command in csproj
worstmilk Jul 15, 2021
db46ce8
Fix speed/pause
worstmilk Jul 15, 2021
dad706b
Remove unused commands
worstmilk Jul 15, 2021
693d8fb
Merge branch 'master' into Worstmilk/DedicatedServer
worstmilk Dec 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions CSM.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
# Visual Studio Version 16
VisualStudioVersion = 16.0.31320.298
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSM", "src\CSM.csproj", "{63933537-DA87-4026-A44C-382298FBB399}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSM.Server", "Server\src\CSM.Server\CSM.Server.csproj", "{2885126B-CB52-4DBB-A7A8-A0E99A5CBD00}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSM.Server.Web", "Server\src\CSM.Server.Web\CSM.Server.Web.csproj", "{C9F42385-7429-4D77-A320-586875AEF73B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{63933537-DA87-4026-A44C-382298FBB399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63933537-DA87-4026-A44C-382298FBB399}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63933537-DA87-4026-A44C-382298FBB399}.Release|Any CPU.Build.0 = Release|Any CPU
{2885126B-CB52-4DBB-A7A8-A0E99A5CBD00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2885126B-CB52-4DBB-A7A8-A0E99A5CBD00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2885126B-CB52-4DBB-A7A8-A0E99A5CBD00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2885126B-CB52-4DBB-A7A8-A0E99A5CBD00}.Release|Any CPU.Build.0 = Release|Any CPU
{C9F42385-7429-4D77-A320-586875AEF73B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9F42385-7429-4D77-A320-586875AEF73B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9F42385-7429-4D77-A320-586875AEF73B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9F42385-7429-4D77-A320-586875AEF73B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 10 additions & 0 deletions Server/src/CSM.Server.Web/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
11 changes: 11 additions & 0 deletions Server/src/CSM.Server.Web/CSM.Server.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CSM.Server\CSM.Server.csproj" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions Server/src/CSM.Server.Web/Data/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace CSM.Server.Web.Data
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
25 changes: 25 additions & 0 deletions Server/src/CSM.Server.Web/Data/WeatherForecastService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Linq;
using System.Threading.Tasks;

namespace CSM.Server.Web.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
var rng = new Random();
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToArray());
}
}
}
42 changes: 42 additions & 0 deletions Server/src/CSM.Server.Web/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@page
@model CSM.Server.Web.Pages.ErrorModel

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/app.css" rel="stylesheet" />
</head>

<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>

</html>
32 changes: 32 additions & 0 deletions Server/src/CSM.Server.Web/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace CSM.Server.Web.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
5 changes: 5 additions & 0 deletions Server/src/CSM.Server.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@page "/"

<h1>Hello, world!</h1>

Welcome to your new app.
35 changes: 35 additions & 0 deletions Server/src/CSM.Server.Web/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@page "/"
@namespace CSM.Server.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSM.Server.Web</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="CSM.Server.Web.styles.css" rel="stylesheet" />
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />

<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

<script src="_framework/blazor.server.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions Server/src/CSM.Server.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CSM.Server;

namespace CSM.Server.Web
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.AddCSMServer()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
28 changes: 28 additions & 0 deletions Server/src/CSM.Server.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:26148",
"sslPort": 44338
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"CSM.Server.Web": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
13 changes: 13 additions & 0 deletions Server/src/CSM.Server.Web/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@inherits LayoutComponentBase

<div class="page">
<div class="main">
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
</div>

<div class="content px-4">
@Body
</div>
</div>
</div>
70 changes: 70 additions & 0 deletions Server/src/CSM.Server.Web/Shared/MainLayout.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

.main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
}

.top-row a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row:not(.auth) {
display: none;
}

.top-row.auth {
justify-content: space-between;
}

.top-row a, .top-row .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.main > div {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
Loading