Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
host_records.h
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <cstdint>
9#include <string>
10#include <string_view>
11#include <vector>
12
13namespace app {
14
15 inline constexpr uint16_t DEFAULT_HOST_PORT = 47989;
16
20 enum class PairingState {
22 paired,
23 };
24
28 enum class HostReachability {
29 unknown,
30 online,
31 offline,
32 };
33
37 enum class HostAppListState {
38 idle,
39 loading,
40 ready,
41 failed,
42 };
43
48 std::string name;
49 int id = 0;
50 bool hdrSupported = false;
51 bool hidden = false;
52 bool favorite = false;
53 std::string boxArtCacheKey;
54 bool boxArtCached = false;
55 bool running = false;
56 };
57
61 struct HostRecord {
62 std::string displayName;
63 std::string address;
64 uint16_t port = 0;
65 PairingState pairingState = PairingState::not_paired;
66 HostReachability reachability = HostReachability::unknown;
67 std::string activeAddress;
68 std::string uuid;
69 std::string localAddress;
70 std::string remoteAddress;
71 std::string ipv6Address;
72 std::string manualAddress;
73 std::string macAddress;
74 uint16_t httpsPort = 0;
75 uint32_t runningGameId = 0;
76 std::vector<HostAppRecord> apps;
77 HostAppListState appListState = HostAppListState::idle;
79 uint16_t resolvedHttpPort = 0;
80 uint64_t appListContentHash = 0;
82 };
83
88 std::vector<HostRecord> records;
89 std::vector<std::string> errors;
90 };
91
98 const char *to_string(PairingState pairingState);
99
106 const char *to_string(HostReachability reachability);
107
114 std::string normalize_ipv4_address(std::string_view address);
115
122 bool is_valid_ipv4_address(std::string_view address);
123
130 std::string build_default_host_display_name(std::string_view normalizedAddress);
131
138 uint16_t effective_host_port(uint16_t port);
139
147 bool try_parse_host_port(std::string_view portText, uint16_t *parsedPort);
148
157 bool contains_host_address(const std::vector<HostRecord> &records, std::string_view normalizedAddress, uint16_t port = 0);
158
171 bool host_matches_endpoint(const HostRecord &host, std::string_view normalizedAddress, uint16_t port);
172
180 bool validate_host_record(const HostRecord &record, std::string *errorMessage = nullptr);
181
191 std::string serialize_host_records(const std::vector<HostRecord> &records);
192
199 ParseHostRecordsResult parse_host_records(std::string_view serializedRecords);
200
201} // namespace app
const char * to_string(ScreenId screen)
Return a display label for a screen identifier.
Definition client_state.cpp:1416
bool contains_host_address(const std::vector< HostRecord > &records, std::string_view normalizedAddress, uint16_t port)
Return whether a host list already contains an endpoint.
Definition host_records.cpp:385
bool try_parse_host_port(std::string_view portText, uint16_t *parsedPort)
Parse a user-supplied TCP port string.
Definition host_records.cpp:354
ParseHostRecordsResult parse_host_records(std::string_view serializedRecords)
Parse host records from the stable serialized text format.
Definition host_records.cpp:521
uint16_t effective_host_port(uint16_t port)
Return the effective TCP port for a host record.
Definition host_records.cpp:350
std::string serialize_host_records(const std::vector< HostRecord > &records)
Serialize host records into a stable tab-separated text format.
Definition host_records.cpp:494
bool is_valid_ipv4_address(std::string_view address)
Return whether a string is a valid IPv4 address.
Definition host_records.cpp:342
bool host_matches_endpoint(const HostRecord &host, std::string_view normalizedAddress, uint16_t port)
Return whether a host record matches a specific endpoint.
Definition host_records.cpp:392
std::string normalize_ipv4_address(std::string_view address)
Normalize a user-provided IPv4 address.
Definition host_records.cpp:320
std::string build_default_host_display_name(std::string_view normalizedAddress)
Build a controller-friendly default display name for a host.
Definition host_records.cpp:346
bool validate_host_record(const HostRecord &record, std::string *errorMessage)
Validate a host record before saving or serializing it.
Definition host_records.cpp:410
constexpr uint16_t DEFAULT_HOST_PORT
Default HTTP port used by Moonlight-compatible hosts.
Definition host_records.h:15
PairingState
Pairing state tracked for a saved host record.
Definition host_records.h:20
@ not_paired
The client has not completed pairing with the host.
@ paired
The client is paired and can issue authenticated requests.
HostReachability
Reachability state tracked for a discovered or saved host.
Definition host_records.h:28
@ offline
The host did not respond to the latest reachability check.
@ online
The host responded to the latest reachability check.
@ unknown
Reachability has not been probed yet.
HostAppListState
Fetch state for the per-host app library.
Definition host_records.h:37
@ failed
The latest app-list request failed.
@ loading
An app-list request is currently in progress.
@ ready
A recent app list is available for display.
@ idle
No app-list request is active and no fresh result is pending.
App metadata shown on the per-host apps page.
Definition host_records.h:47
std::string boxArtCacheKey
Cache key used to load box art from local storage.
Definition host_records.h:53
bool favorite
True when the app is pinned as a favorite locally.
Definition host_records.h:52
bool hidden
True when the app should be hidden from the default browse view.
Definition host_records.h:51
bool boxArtCached
True when the referenced box art is already cached on disk.
Definition host_records.h:54
std::string name
Display name reported by the host.
Definition host_records.h:48
bool running
True when the app is currently running on the host.
Definition host_records.h:55
bool hdrSupported
True when the app advertises HDR streaming support.
Definition host_records.h:50
Manual host record shown in the shell.
Definition host_records.h:61
std::string activeAddress
Best currently reachable address for live operations.
Definition host_records.h:67
std::string address
Stored primary IPv4 address for the host.
Definition host_records.h:63
std::string displayName
User-facing host label shown in the shell.
Definition host_records.h:62
std::string remoteAddress
Reported WAN address from the host status response.
Definition host_records.h:70
uint32_t lastAppListRefreshTick
Tick count for the most recent app list refresh.
Definition host_records.h:81
std::string uuid
Host UUID reported by Sunshine or GeForce Experience.
Definition host_records.h:68
PairingState pairingState
Current pairing state for this client.
Definition host_records.h:65
uint16_t resolvedHttpPort
Effective HTTP port confirmed by the latest status query.
Definition host_records.h:79
uint16_t port
Stored HTTP port override where zero means DEFAULT_HOST_PORT.
Definition host_records.h:64
HostAppListState appListState
Fetch state for the cached app list.
Definition host_records.h:77
std::string appListStatusMessage
User-visible status for the most recent app list operation.
Definition host_records.h:78
uint64_t appListContentHash
Stable hash of the last fetched app list contents.
Definition host_records.h:80
std::string macAddress
Reported MAC address for the host.
Definition host_records.h:73
HostReachability reachability
Most recent reachability probe result.
Definition host_records.h:66
std::string localAddress
Reported LAN address from the host status response.
Definition host_records.h:69
uint32_t runningGameId
Currently running app identifier, or zero when idle.
Definition host_records.h:75
uint16_t httpsPort
HTTPS port reported by the host for asset requests.
Definition host_records.h:74
std::string manualAddress
Original manually entered address, when different from address.
Definition host_records.h:72
std::vector< HostAppRecord > apps
Latest fetched app list for the host.
Definition host_records.h:76
std::string ipv6Address
Reported IPv6 address from the host status response.
Definition host_records.h:71
Result of parsing a serialized host record list.
Definition host_records.h:87
std::vector< std::string > errors
Non-fatal line-level parse or validation errors.
Definition host_records.h:89
std::vector< HostRecord > records
Parsed host records accepted from the serialized input.
Definition host_records.h:88