mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 00:22:40 +01:00
Merge branch 'master' into 801-DMAPIFixes
This commit is contained in:
@@ -8,8 +8,13 @@ namespace Tgstation.Server.Host.Components.Interop
|
||||
sealed class CommCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// The raw JSON decond of the <see cref="CommCommand"/>
|
||||
/// The dictionary of the <see cref="CommCommand"/>
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, string> Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The raw JSON of the <see cref="CommCommand"/>
|
||||
/// </summary>
|
||||
public string RawJson { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -109,10 +109,11 @@ namespace Tgstation.Server.Host.Components.Interop
|
||||
{
|
||||
command = new CommCommand
|
||||
{
|
||||
Parameters = JsonConvert.DeserializeObject<IReadOnlyDictionary<string, string>>(file)
|
||||
Parameters = JsonConvert.DeserializeObject<IReadOnlyDictionary<string, string>>(file),
|
||||
RawJson = file
|
||||
};
|
||||
}
|
||||
catch (JsonSerializationException ex)
|
||||
catch (JsonException ex)
|
||||
{
|
||||
//file not fully written yet
|
||||
logger.LogDebug("Suppressing json convert exception for command file write: {0}", ex);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Byond.TopicSender;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
@@ -286,6 +287,25 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
content = new object();
|
||||
switch (method)
|
||||
{
|
||||
case Constants.DMCommandChat:
|
||||
try
|
||||
{
|
||||
var message = JsonConvert.DeserializeObject<Response>(command.RawJson, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
});
|
||||
if (message.ChannelIds == null)
|
||||
throw new InvalidOperationException("Missing ChannelIds field!");
|
||||
if (message.Message == null)
|
||||
throw new InvalidOperationException("Missing Message field!");
|
||||
await chat.SendMessage(message.Message, message.ChannelIds, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogDebug("Exception while decoding chat message! Exception: {0}", e);
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
case Constants.DMCommandServerPrimed:
|
||||
//currently unused, maybe in the future
|
||||
break;
|
||||
|
||||
@@ -9,7 +9,6 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Tgstation.Server.Api;
|
||||
@@ -121,6 +120,17 @@ namespace Tgstation.Server.Host.Controllers
|
||||
return BadRequest(new ErrorMessage { Message = "path must not be empty!" });
|
||||
|
||||
NormalizeModelPath(model, out var rawPath);
|
||||
|
||||
var localPath = ioManager.ResolvePath(".");
|
||||
NormalizeModelPath(new Api.Models.Instance
|
||||
{
|
||||
Path = localPath
|
||||
}, out var normalizedLocalPath);
|
||||
|
||||
if (rawPath.StartsWith(normalizedLocalPath, StringComparison.Ordinal))
|
||||
return Conflict("Instances cannot be created in the installation directory!");
|
||||
|
||||
|
||||
var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken);
|
||||
bool attached = false;
|
||||
if (await ioManager.FileExists(model.Path, cancellationToken).ConfigureAwait(false) || await dirExistsTask.ConfigureAwait(false))
|
||||
|
||||
@@ -51,6 +51,13 @@ namespace Tgstation.Server.Tests
|
||||
}, cancellationToken)).ConfigureAwait(false);
|
||||
await Assert.ThrowsExceptionAsync<ConflictException>(() => instanceManagerClient.CreateOrAttach(firstTest, cancellationToken)).ConfigureAwait(false);
|
||||
|
||||
//can't create instances in installation directory
|
||||
await Assert.ThrowsExceptionAsync<ConflictException>(() => instanceManagerClient.CreateOrAttach(new Api.Models.Instance
|
||||
{
|
||||
Path = "./A/Local/Path",
|
||||
Name = "NoInstallDirTest"
|
||||
}, cancellationToken)).ConfigureAwait(false);
|
||||
|
||||
//can't move to existent directories
|
||||
await Assert.ThrowsExceptionAsync<ConflictException>(() => instanceManagerClient.Update(new Api.Models.Instance
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user