Update MoMMILink to use Kestler StatusHost handlers.

This commit is contained in:
Tyler Young
2020-02-09 09:25:48 -05:00
parent f41cff327e
commit f34d447bde
2 changed files with 9 additions and 7 deletions

View File

@@ -13,6 +13,7 @@
</PropertyGroup> </PropertyGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" /> <Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> <PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="YamlDotNet" Version="8.1.0" /> <PackageReference Include="YamlDotNet" Version="8.1.0" />
</ItemGroup> </ItemGroup>

View File

@@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.Chat;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json; using Newtonsoft.Json;
using Robust.Server.Interfaces.ServerStatus; using Robust.Server.Interfaces.ServerStatus;
using Robust.Server.ServerStatus; using Robust.Server.ServerStatus;
@@ -79,9 +80,9 @@ namespace Content.Server
} }
} }
private bool _handleChatPost(HttpMethod method, HttpListenerRequest request, HttpListenerResponse response) private bool _handleChatPost(HttpMethod method, HttpRequest request, HttpResponse response)
{ {
if (method != HttpMethod.Post || request.Url.AbsolutePath != "/ooc") if (method != HttpMethod.Post || request.Path != "/ooc")
{ {
return false; return false;
} }
@@ -89,7 +90,7 @@ namespace Content.Server
var password = _configurationManager.GetCVar<string>("status.mommipassword"); var password = _configurationManager.GetCVar<string>("status.mommipassword");
OOCPostMessage message; OOCPostMessage message;
using (var streamReader = new StreamReader(request.InputStream, EncodingHelpers.UTF8)) using (var streamReader = new StreamReader(request.Body, EncodingHelpers.UTF8))
using (var jsonReader = new JsonTextReader(streamReader)) using (var jsonReader = new JsonTextReader(streamReader))
{ {
var serializer = new JsonSerializer(); var serializer = new JsonSerializer();
@@ -99,26 +100,26 @@ namespace Content.Server
} }
catch (JsonSerializationException) catch (JsonSerializationException)
{ {
response.Respond(method, "400 Bad Request", HttpStatusCode.BadRequest, "text/plain"); response.StatusCode = (int) HttpStatusCode.BadRequest;
return true; return true;
} }
} }
if (message == null) if (message == null)
{ {
response.Respond(method, "400 Bad Request", HttpStatusCode.BadRequest, "text/plain"); response.StatusCode = (int) HttpStatusCode.BadRequest;
return true; return true;
} }
if (message.Password != password) if (message.Password != password)
{ {
response.Respond(method, "Incorrect password", HttpStatusCode.Forbidden, "text/plain"); response.StatusCode = (int) HttpStatusCode.Forbidden;
return true; return true;
} }
_taskManager.RunOnMainThread(() => _chatManager.SendHookOOC(message.Sender, message.Contents)); _taskManager.RunOnMainThread(() => _chatManager.SendHookOOC(message.Sender, message.Contents));
response.Respond(method, "Message received", HttpStatusCode.OK, "text/plain"); response.StatusCode = (int) HttpStatusCode.OK;
return false; return false;
} }