Skip to main content

ServerListingController

A class in TavernLib, TavernLib.Backend.Server.

Sends the server to the Community Servers listing every 3 seconds from a background loop, backing off after failures, and removes it when the game quits. Server; TavernManager makes one when community_listed is on at start.

Constructors​

MemberWhat it is
ServerListingController(TavernManager manager)Sets up the HTTP client, starts the heartbeat loop, and closes the listing when the game quits.

Fields​

5 private and internal fields
MemberWhat it is
private readonly HttpClient _apiClientHTTP client used to post to and delete from the community server listing.
private bool _closedSet once the listing is closing, which ends the heartbeat loop.
private TavernManager _managerThe TavernManager that supplies the server and port configs.
private static readonly TimeSpan IntervalTime between listing heartbeats when they succeed (3 seconds).
private const double LongestWaitSecondsLongest wait, in seconds, between heartbeats after repeated failures.

Methods​

MemberWhat it is
void CloseListing()Sends the listing a remove request with the listing token and stops the loop. Waits up to two seconds for it.
async Task OpenListing()Sends one heartbeat now, the same as Ping.
async Task Ping()Sends one heartbeat now. Throws HttpRequestException with the listing's answer if it isn't accepted.
bool StartClosingListing()The Application.wantsToQuit handler: closes the listing and returns true so the quit goes on.
3 private and internal methods
MemberWhat it is
private async Task HeartbeatAsync()Loop that posts the listing, logs only when the answer changes, and waits longer after each failure.
private static StringContent JsonBody(object payload)Wraps an object as a JSON request body without going through the game's own HTTP helpers.
private async Task<string> Post()Posts the current listing payload; returns null on success, otherwise a short description of what went wrong.

Used in​

Members of other types that take, return or hold a ServerListingController: