NodeWorld

WorldNetworkGate

La référence est en anglais : elle est générée à partir des commentaires du code, écrits en anglais.

csharp
public sealed class WorldNetworkGate : IFluxNetworkGate

Namespace NodeWorld.SDK.Client.Flux.

The one door between a world and the Internet on the client: web (HttpClient), WebSocket, images and video of the FL# scripts go through it, never the client's own requests (API, avatars). A choice is kept per hostname (Ruby: « par hostname »), for every world, on this device: the domain with its subdomains (the Public Suffix List tells where the domain starts: allowing helicityohno.github.io does not allow github.io), or an IP address. The big video sites are allowed from the start, a list the player edits (« Liste déjà faite modifiable »). A request waits for the player's answer or for the world to leave. An IP of this machine or of the local network written by the world asks with a warning; a name that points there is refused. In the Unity editor everything is allowed (« Tout autorisé dans l'éditeur »). Logs: "[Web]" with the hostname only.

Fields

ShippedVideoSites

csharp
public static readonly IReadOnlyList<string> ShippedVideoSites

The video sites the client ships (Ruby: « Grands sites vidéo »).

Constructors

WorldNetworkGate

csharp
public WorldNetworkGate(string path, bool allowEverything)

A gate kept in that file (tests); allowEverything: the editor's rule.

Properties

Shared

csharp
public static WorldNetworkGate Shared { get; }

The gate of this device (created on the main thread the first time; kept in persistentDataPath).

AllowEverything

csharp
public bool AllowEverything { get; set; }

Everything allowed without a window (the Unity editor).

WorldId

csharp
public string WorldId { get; }

The world now (set by the FL# runtime when a world starts), null between worlds.

Resolve

csharp
public Func<string, CancellationToken, Task<IPAddress[]>> Resolve { get; set; }

The name resolver (tests replace it).

Allowed

csharp
public IReadOnlyList<string> Allowed { get; }

Hostnames allowed for good.

Refused

csharp
public IReadOnlyList<string> Refused { get; }

Hostnames refused for good.

VideoSites

csharp
public IReadOnlyList<string> VideoSites { get; }

The video sites allowed without a window (the shipped list, as the player edited it).

Pending

csharp
public IReadOnlyList<WorldNetworkRequest> Pending { get; }

Requests waiting for the player.

Methods

BeginWorld

csharp
public void BeginWorld(string worldId)

A world starts: its requests will name it.

EndWorld

csharp
public void EndWorld()

The world leaves: "This time" ends, the requests still waiting are dropped (their windows go).

AuthorizeAsync

csharp
public async Task<IPAddress[]> AuthorizeAsync(FluxWebAddress address, CancellationToken cancellationToken)

A web request or WebSocket of the world: waits for the player's choice for its domain (or IP address), then gives the addresses to connect to. Throws FluxNetworkRefusedException when the player refused it, or when its name points to this machine or the local network.

AuthorizeVideoAsync

csharp
public async Task<bool> AuthorizeVideoAsync(string url, CancellationToken cancellationToken)

A video address (any network protocol libVLC reads: http, https, rtmp, rtsp, udp, mms, srt...): true when the world may open it. libVLC and yt-dlp resolve the name themselves, the gate checks it first (a name that points to the local network is refused). The media servers yt-dlp finds next are the resolver's, not the world's: not asked.

IsVideoScheme

csharp
public static bool IsVideoScheme(string scheme)

The network protocols of libVLC a world may use for a video (no local file, screen or capture device).

KeyOf

csharp
public static string KeyOf(FluxWebAddress address)

What a choice is kept for: the domain of a name (with its subdomains) or the IP address, with the port when it is not the standard one.

Covers

csharp
public static bool Covers(string kept, string hostname)

A kept hostname covers this hostname (host with its port when not standard): the same, or a subdomain of it on the same port. A kept public suffix (github.io itself) covers only itself, an IP address only itself.

Forget

csharp
public void Forget(string hostname)

Removes a hostname from the allowed or refused ones: the next request to it asks again.

AddVideoSite

csharp
public bool AddVideoSite(string text)

Adds a video site (a hostname the player types): allowed without a window from now on. False if it is not a hostname.

RemoveVideoSite

csharp
public void RemoveVideoSite(string site)

Removes a video site: a world asks for it again.

NormalizeTyped

csharp
public static string NormalizeTyped(string text)

A hostname as the player types it (https://www.Example.com/x, example.com:8080): its normalized form, null if it is none.

Events

Asked

csharp
public event Action<WorldNetworkRequest> Asked

A world asks a hostname the player has not answered (on the main thread): the window and the notification show it.

Settled

csharp
public event Action<WorldNetworkRequest> Settled

A request was answered or dropped (on the main thread): its window and notification go.

Changed

csharp
public event Action Changed

The lists changed (on the main thread): the settings repaint.

Removed

csharp
public event Action Removed

The player removed a choice or a video site in the settings (on the main thread).