Skip to main content

AuthManager

A internal class in TavernLib, TavernLib.Backend.Auth. Reach it through att-stubs' publicized assemblies or Harmony's AccessTools.

Internal: TavernLib's login server on the auth port (1762 by default). Answers pings, mod lists, set_mods, whitelist applications and joins, registering new players in users.json. Server; not run with /launcherauth.

Constructors​

MemberWhat it is
AuthManager(TavernManager manager)Reads the auth port and starts listening.

Fields​

14 private and internal fields
MemberWhat it is
private readonly AuthLimits _limitsPer-address connection and failure limits.
private TcpListener _listenerThe TCP listener on the auth port.
private readonly TavernManager _managerThe TavernManager that supplies the configs.
private readonly int _portThe auth port the server listens on.
private bool _stoppingSet when the game is quitting, which ends the accept loop.
private const int AccountsPerAddressMost accounts that may be registered from one address when the IP limit is on.
private const int ApplicationsMaxMost whitelist applications kept in all.
private const int ApplicationsPerAddressMost whitelist applications kept from one address.
private static readonly TimeSpan ConnectionTimeoutHow long a connection to the auth port may take before it is closed (5 seconds).
private const ulong FirstUserIdThe first user id handed out (1000000000).
private const int MaxModFieldLongest mod id or version in a set_mods list.
private const int MaxModsMost mods a set_mods list may hold.
private const int MaxPayloadLargest request, in bytes, the auth port reads.
private const int MaxTokenLengthLongest join token accepted for a new account.

Properties​

1 private and internal property
MemberWhat it is
private TavernServer Ports { get; }The server's port settings from tavern_server.json.

Methods​

17 private and internal methods
MemberWhat it is
private string ApplicationRefusal(string username, string ip)Returns why a whitelist application is refused, or null if it can be filed.
private object CheckIfPermitted(UserConfig config, ServerSettings settings, string joinerIp, AuthPayloads.AuthenticateRequest payload)Checks blacklist, password and whitelist in that order; returns the refusal to send, or null if the player may join.
private async Task InterpretTcpStream(TcpClient client)Handles one connection: applies limits, reads the request and routes it by its keys (ping, whitelist application, mods list, set_mods, join).
private async Task ManageAuthRequest(Stream stream, JObject payload, string address)Handles a join request: checks the fields are present, then replies with the result of ResolveJoin.
private async Task ManageSetModsRequest(Stream stream, JObject payload, string ip)Stores the mod list a player's game will load on their account, after checking their token.
private async Task ManageWhitelistApplicationRequest(Stream stream, JObject payload, string joinerIp)Handles a whitelist application and files it in the requests file unless it is refused.
private static ulong NextUserId(UserConfig config)Returns one more than the highest user id in the file, and never below FirstUserId.
private async Task<string> ReadFullPayload(Stream stream, CancellationToken token)Reads from the stream until it holds a complete JSON object, or throws if it never does.
private static Dictionary<string, string> ReadModList(JToken token)Parses a set_mods object into a dictionary, or returns null if any entry is too long or not a string.
private ServerSettings ReadSettings()Reads server_settings.json afresh; returns null if it can't be read.
private bool Register(UserConfig config, ServerSettings settings, AuthPayloads.AuthenticateRequest payload, string ip, out object response)Creates or checks the player's account and returns whether users.json changed; the response is the join result.
private object ResolveJoin(AuthPayloads.AuthenticateRequest payload, string ip)Checks permission and registers the player under the user file's lock; returns the response to send.
private async Task StartAuthCycle()Starts the TCP listener and accepts connections until the game quits.
private void StopListening()Stops the listener; runs when the game quits.
private async Task WriteModsListResponse(Stream stream)Sends the enabled server mods and untracked mods, prefixed with a 4 byte big-endian length.
private async Task WritePongResponse(Stream stream)Answers a ping with the server name, ports, password and whitelist flags, and the mod hash and count.
private async Task WriteResponse(Stream stream, object response)Serializes a response object to JSON and writes it to the stream.

Used in​

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