Initial commit

This commit is contained in:
Karolis2011
2019-08-17 22:04:57 +03:00
parent a8fdb0a242
commit 9d08ad0cbe
11 changed files with 639 additions and 0 deletions

352
.gitignore vendored Normal file
View File

@@ -0,0 +1,352 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "ASS.API"]
path = ASS.API
url = https://github.com/Aurorastation/A.S.S.-RPC-protobuffs.git

1
ASS.API Submodule

Submodule ASS.API added at 8ca5a24065

View File

@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc" Version="1.22.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ASS.API\ASS.API.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="defaultConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Attributes\" />
<Folder Include="Extensions\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Logging;
namespace ASS.Server.Helpers
{
class GrpcLoggingWraper : Grpc.Core.Logging.ILogger
{
private ILogger _logger;
public GrpcLoggingWraper(ILogger logger)
{
_logger = logger;
}
public Grpc.Core.Logging.ILogger ForType<T>() => this;
public void Debug(string message) => _logger.LogDebug(message);
public void Debug(string format, params object[] formatArgs) => _logger.LogDebug(format, args: formatArgs);
public void Error(string message) => _logger.LogError(message);
public void Error(string format, params object[] formatArgs) => _logger.LogError(format, args: formatArgs);
public void Error(Exception exception, string message) => _logger.LogError(exception, message);
public void Info(string message) => _logger.LogInformation(message);
public void Info(string format, params object[] formatArgs) => _logger.LogInformation(format, args: formatArgs);
public void Warning(string message) => _logger.LogWarning(message);
public void Warning(string format, params object[] formatArgs) => _logger.LogWarning(format, args: formatArgs);
public void Warning(Exception exception, string message) => _logger.LogWarning(exception, message);
}
}

58
ASS.Server/Program.cs Normal file
View File

@@ -0,0 +1,58 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using ASS.Server.Services;
using ASS.Server.Helpers;
using System.Net.Http;
namespace ASS.Server
{
class Program
{
static void Main(string[] args)
=> new Program().MainAsync(args).GetAwaiter().GetResult();
public async Task MainAsync(string[] args)
{
using (var services = ConfigureServices(args))
{
Grpc.Core.GrpcEnvironment.SetLogger(new GrpcLoggingWraper(services.GetRequiredService<ILogger<GrpcService>>()));
var grpc = services.GetRequiredService<GrpcService>();
grpc.Initialize();
await Task.Delay(-1);
}
}
private ServiceProvider ConfigureServices(string[] args)
{
// Stage 1 services
var services = new ServiceCollection()
.AddSingleton<IConfiguration>(sp =>
new ConfigurationBuilder()
.AddJsonFile("defaultConfig.json", false, false)
.AddJsonFile("config.json", true, false)
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build()
);
var serviceProvider = services.BuildServiceProvider();
// Stage 2 services
services
.AddLogging(c =>
{
c.ClearProviders();
c.AddConsole();
c.AddConfiguration(serviceProvider.GetRequiredService<IConfiguration>().GetSection("Logging"));
})
.AddSingleton(sp => new GrpcService(sp))
.AddSingleton<InstanceService>()
.AddSingleton<HttpClient>();
;
return services.BuildServiceProvider();
}
}
}

View File

@@ -0,0 +1,53 @@
using ASS.API;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace ASS.Server.Services
{
class ByondService : Byond.ByondBase
{
const string BYOND_LATEST_URL = "https://secure.byond.com/download/build/LATEST/";
const string BYOND_DOWNLOAD_URL = "https://secure.byond.com/download/build/";
HttpClient httpclient;
IConfiguration config;
public ByondService(HttpClient _httpClient, IConfiguration configuration)
{
httpclient = _httpClient;
config = configuration.GetSection("BYOND");
}
public static string GetDownloadUrl(string version)
{
var split = version.Split(".");
return GetDownloadUrl(split[0], split[1]);
}
public static string GetDownloadUrl(int major, int minor) => GetDownloadUrl(major.ToString(), minor.ToString());
public static string GetDownloadUrl(ByondVersion version) => GetDownloadUrl(version.Major, version.Minor);
public static string GetDownloadUrl(string major, string minor)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return $"{BYOND_DOWNLOAD_URL}/{major}/{major}.{minor}_byond_linux.zip";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return $"{BYOND_DOWNLOAD_URL}/{major}/{major}.{minor}_byond.zip";
throw new Exception("Unsupported OS");
}
public async Task<IEnumerable<ByondVersion>> GetVersions()
{
var response = await httpclient.SendAsync(new HttpRequestMessage(HttpMethod.Get, BYOND_LATEST_URL));
var content = await response.Content.ReadAsStringAsync();
var regex = new Regex("\\\"([\\d]+)\\.([\\d]+)_byond.zip\\\"");
var matches = regex.Matches(content);
return matches.Select(m => new ByondVersion() { Major = int.Parse(m.Captures[0].Value), Minor = int.Parse(m.Captures[0].Value) });
}
}
}

View File

@@ -0,0 +1,37 @@
using Grpc.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace ASS.Server.Services
{
class GrpcService : Grpc.Core.Server
{
IServiceProvider _sp;
ILogger logger;
IConfiguration config;
public GrpcService(IServiceProvider sp) : this(sp.GetRequiredService<IConfiguration>())
{
_sp = sp;
logger = _sp.GetRequiredService<ILogger<GrpcService>>();
}
public GrpcService(IConfiguration _config) : base()
{
config = _config;
Ports.Add(config["GRPC:Host"], int.Parse(config["GRPC:Port"]), ServerCredentials.Insecure);
}
public void Initialize()
{
Services.Add(API.Instance.BindService(_sp.GetRequiredService<InstanceService>()));
Start();
logger.LogInformation($"gRPC server listening on {config["GRPC:Host"]}:{config["GRPC:Port"]}");
}
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ASS.API;
using Grpc.Core;
namespace ASS.Server.Services
{
class InstanceService : Instance.InstanceBase
{
public async override Task<InstanceStatus> GetStatus(EmptyRequest request, ServerCallContext context)
{
return new InstanceStatus
{
Message = $"YOU:{request.Auth.Token}:WE:{DateTime.Now.ToString()}"
};
}
}
}

View File

@@ -0,0 +1,21 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"GRPC": {
"Port": 5001,
"Host": "0.0.0.0"
},
"Repository": {
"URL": "https://github.com/Aurorastation/Aurora.3.git"
},
"BYOND": {
"Version": {
"Major": 512,
"Minor": 1467
}
},
"WorkDir": "work"
}

31
Aurora server system.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29123.88
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASS.API", "ASS.API\ASS.API.csproj", "{B39676C5-75B4-4838-A380-5C073A0FBB51}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASS.Server", "ASS.Server\ASS.Server.csproj", "{133D55CB-E33B-46AE-A05C-914DEE1D8754}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B39676C5-75B4-4838-A380-5C073A0FBB51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B39676C5-75B4-4838-A380-5C073A0FBB51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B39676C5-75B4-4838-A380-5C073A0FBB51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B39676C5-75B4-4838-A380-5C073A0FBB51}.Release|Any CPU.Build.0 = Release|Any CPU
{133D55CB-E33B-46AE-A05C-914DEE1D8754}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{133D55CB-E33B-46AE-A05C-914DEE1D8754}.Debug|Any CPU.Build.0 = Debug|Any CPU
{133D55CB-E33B-46AE-A05C-914DEE1D8754}.Release|Any CPU.ActiveCfg = Release|Any CPU
{133D55CB-E33B-46AE-A05C-914DEE1D8754}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AF585F8E-FA6F-439D-8654-670643588CF4}
EndGlobalSection
EndGlobal