Skip to content

Commit

Permalink
Add a bit of troubleshooting steps for a failed advert attempt.
Browse files Browse the repository at this point in the history
Changes the invalid ss14 uri error to tell the user where to look to resolve it.

The current error for being unable to contact status address looks like its coming from robust itself and not the hub. And gets many people to come to #hosting for something they can fix themselves. This will at least ensure they double-check their config and firewall before asking. Also now the info log will display the attempted advert uri.

Removed a null suppression as it was unnecessary (at least rider said so)
  • Loading branch information
VasilisThePikachu committed Jun 17, 2024
1 parent afd062a commit d96b026
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions SS14.ServerHub/Controllers/ServerListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<IEnumerable<ServerInfo>> Get()

return dbInfos;
}

[EnableCors(CorsPolicies.PolicyHubPublic)]
[HttpGet("info")]
public async Task<IActionResult> GetServerInfo(string url)
Expand All @@ -65,7 +65,7 @@ public async Task<IActionResult> GetServerInfo(string url)

if (dbInfo == null)
return NotFound();

return Ok((RawJson?) dbInfo.InfoData);
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task<IActionResult> Advertise([FromBody] ServerAdvertise advertise)
if (!Uri.TryCreate(advertise.Address, UriKind.Absolute, out var parsedAddress) ||
string.IsNullOrWhiteSpace(parsedAddress.Host) ||
parsedAddress.Scheme is not (Ss14UriHelper.SchemeSs14 or Ss14UriHelper.SchemeSs14s))
return BadRequest("Invalid SS14 URI");
return BadRequest("Invalid SS14 URI. Ensure your hub.server_url starts with ss14:// or ss14s:// and that the address is valid.");

// Ban check.
switch (await CheckAddressBannedAsync(parsedAddress))
Expand All @@ -112,7 +112,7 @@ parsedAddress.Scheme is not (Ss14UriHelper.SchemeSs14 or Ss14UriHelper.SchemeSs1
Debug.Assert(statusJson != null);
Debug.Assert(infoJson != null);

switch (await CheckInfoBannedAsync(parsedAddress, statusJson, infoJson!))
switch (await CheckInfoBannedAsync(parsedAddress, statusJson, infoJson))
{
case BanCheckResult.Banned:
return Unauthorized("Your server has been blocked from advertising on the hub. If you believe this to be in error, please contact us.");
Expand Down Expand Up @@ -149,7 +149,7 @@ parsedAddress.Scheme is not (Ss14UriHelper.SchemeSs14 or Ss14UriHelper.SchemeSs1
StatusData = statusJson,
InferredTags = inferredTags
});

await _dbContext.SaveChangesAsync();
return NoContent();
}
Expand All @@ -176,11 +176,11 @@ parsedAddress.Scheme is not (Ss14UriHelper.SchemeSs14 or Ss14UriHelper.SchemeSs1
{
return (UnprocessableEntity($"/status response data was too large (max: {maxStatusSize} KiB)"), null, null);
}

var statusData = JsonSerializer.Deserialize<ServerStatus>(statusResponse);
if (statusData == null)
throw new InvalidDataException("Status cannot be null");

if (string.IsNullOrWhiteSpace(statusData.Name))
return (UnprocessableEntity("Server name cannot be empty"), null, null);

Expand Down Expand Up @@ -214,8 +214,8 @@ parsedAddress.Scheme is not (Ss14UriHelper.SchemeSs14 or Ss14UriHelper.SchemeSs1
}
catch (Exception e)
{
_logger.LogInformation(e, "Failed to connect to advertising server");
return (UnprocessableEntity("Unable to contact status address"), null, null);
_logger.LogInformation(e, $"Failed to connect to advertising server: {uri}");
return (UnprocessableEntity("Unable to contact status address, ensure your firewall/port forwarding configuration allows traffic from the internet and double check your config."), null, null);
}
}

Expand Down Expand Up @@ -314,4 +314,4 @@ public override void Write(Utf8JsonWriter writer, RawJson value, JsonSerializerO
writer.WriteRawValue(value.Json, skipInputValidation: true);
}
}
}
}

0 comments on commit d96b026

Please sign in to comment.