Initial commit
This commit is contained in:
53
ASS.Server/Services/ByondService.cs
Normal file
53
ASS.Server/Services/ByondService.cs
Normal 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) });
|
||||
}
|
||||
}
|
||||
}
|
37
ASS.Server/Services/GRPCService.cs
Normal file
37
ASS.Server/Services/GRPCService.cs
Normal 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"]}");
|
||||
}
|
||||
}
|
||||
}
|
20
ASS.Server/Services/InstanceService.cs
Normal file
20
ASS.Server/Services/InstanceService.cs
Normal 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()}"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user