Skip to content

Commit

Permalink
feat: dynamic server nomad calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira authored and NathanFlurry committed Jul 3, 2024
1 parent 1d50ae6 commit dd0d229
Show file tree
Hide file tree
Showing 75 changed files with 6,969 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .vscode/rivet.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
{
"path": "../lib/bolt",
},
{
"path": "../svc",
}
],
}
8 changes: 7 additions & 1 deletion fern/definition/servers/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ types:
- udp

DockerHostRouting:
properties: {}
properties:
protocol: optional<HostProtocol>

HostProtocol:
enum:
- tcp
- udp
2 changes: 1 addition & 1 deletion infra/tf/modules/secrets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
external = {
source = "hashicorp/external"
version = "2.3.1"
version = "2.3.3"
}
}
}
Expand Down
55 changes: 51 additions & 4 deletions lib/convert/src/impls/ds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ impl ApiTryFrom<models::ServersDockerPortRouting>
(Some(game_guard), None) => Ok(
backend::dynamic_servers::docker_port::Routing::GameGuard((*game_guard).api_into()),
),
(None, Some(_)) => Ok(backend::dynamic_servers::docker_port::Routing::Host(
backend::dynamic_servers::DockerHostRouting {},
(None, Some(host)) => Ok(backend::dynamic_servers::docker_port::Routing::Host(
(*host).api_into(),
)),
(None, None) => bail_with!(SERVERS_NO_PORT_ROUTERS),
_ => bail_with!(SERVERS_MULTIPLE_PORT_ROUTERS),
Expand All @@ -225,10 +225,10 @@ impl ApiTryFrom<backend::dynamic_servers::docker_port::Routing>
host: None,
})
}
backend::dynamic_servers::docker_port::Routing::Host(_) => {
backend::dynamic_servers::docker_port::Routing::Host(host) => {
Ok(models::ServersDockerPortRouting {
game_guard: None,
host: Some(to_value({})?),
host: Some(Box::new(host.api_try_into()?)),
})
}
}
Expand Down Expand Up @@ -268,6 +268,35 @@ impl ApiTryFrom<backend::dynamic_servers::DockerGameGuardRouting>
}
}

impl ApiFrom<models::ServersDockerHostRouting> for backend::dynamic_servers::DockerHostRouting {
fn api_from(
value: models::ServersDockerHostRouting,
) -> backend::dynamic_servers::DockerHostRouting {
backend::dynamic_servers::DockerHostRouting {
protocol: backend::dynamic_servers::HostProtocol::api_from(
value.protocol.unwrap_or_default().into(),
) as i32,
}
}
}

impl ApiTryFrom<backend::dynamic_servers::DockerHostRouting> for models::ServersDockerHostRouting {
type Error = GlobalError;

fn api_try_from(
value: backend::dynamic_servers::DockerHostRouting,
) -> GlobalResult<models::ServersDockerHostRouting> {
Ok(models::ServersDockerHostRouting {
protocol: Some(
unwrap!(backend::dynamic_servers::HostProtocol::from_i32(
value.protocol
))
.api_into(),
),
})
}
}

impl ApiFrom<models::ServersGameGuardProtocol> for backend::dynamic_servers::GameGuardProtocol {
fn api_from(
value: models::ServersGameGuardProtocol,
Expand Down Expand Up @@ -315,3 +344,21 @@ impl ApiFrom<backend::dynamic_servers::GameGuardProtocol> for models::ServersGam
}
}
}

impl ApiFrom<models::ServersHostProtocol> for backend::dynamic_servers::HostProtocol {
fn api_from(value: models::ServersHostProtocol) -> backend::dynamic_servers::HostProtocol {
match value {
models::ServersHostProtocol::Udp => backend::dynamic_servers::HostProtocol::HostUdp,
models::ServersHostProtocol::Tcp => backend::dynamic_servers::HostProtocol::HostTcp,
}
}
}

impl ApiFrom<backend::dynamic_servers::HostProtocol> for models::ServersHostProtocol {
fn api_from(value: backend::dynamic_servers::HostProtocol) -> models::ServersHostProtocol {
match value {
backend::dynamic_servers::HostProtocol::HostUdp => models::ServersHostProtocol::Udp,
backend::dynamic_servers::HostProtocol::HostTcp => models::ServersHostProtocol::Tcp,
}
}
}
247 changes: 246 additions & 1 deletion proto/backend/dynamic_servers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ syntax = "proto3";
package rivet.backend.dynamic_servers;

import "proto/common.proto";
import "proto/backend/captcha.proto";
import "proto/backend/region.proto";

message Server {
rivet.common.Uuid server_id = 1;
Expand Down Expand Up @@ -65,4 +67,247 @@ enum GameGuardProtocol {
UDP = 4;
}

message DockerHostRouting {}
message DockerHostRouting {
HostProtocol protocol = 1;
}

enum HostProtocol {
HOST_TCP = 0;
HOST_UDP = 1;
}





// MARK: Game Config
message GameConfig {
bool host_networking_enabled = 1;
bool root_user_enabled = 2;
}

// MARK: Game Namespace Config
message NamespaceConfig {
uint32 lobby_count_max = 1;
uint32 max_players_per_client = 2;
uint32 max_players_per_client_vpn = 3;
uint32 max_players_per_client_proxy = 4;
uint32 max_players_per_client_tor = 5;
uint32 max_players_per_client_hosting = 6;
}

// MARK: Game Version Config
message VersionConfig {
repeated LobbyGroup lobby_groups = 1;

optional rivet.backend.captcha.CaptchaConfig captcha = 2;
}

message LobbyGroup {
message Region {
rivet.common.Uuid region_id = 1;
string tier_name_id = 2;
IdleLobbies idle_lobbies = 3;
}

message IdleLobbies {
uint32 min_idle_lobbies = 1;
uint32 max_idle_lobbies = 2;
}

message Actions {
optional FindConfig find = 1;
optional JoinConfig join = 2;
optional CreateConfig create = 3;
}

string name_id = 1;

repeated Region regions = 101;
uint32 max_players_normal = 102;
uint32 max_players_direct = 103;
uint32 max_players_party = 104;
bool listable = 105;
bool taggable = 106;
bool allow_dynamic_max_players = 107;

LobbyRuntime runtime = 201;

optional Actions actions = 301;
}

message LobbyRuntime {
enum NetworkMode {
BRIDGE = 0;
HOST = 1;
}

// Should be named "PortProtocol"
enum ProxyProtocol {
HTTP = 0;
HTTPS = 1;
TCP = 3;
TCP_TLS = 4;
UDP = 2;
}

enum ProxyKind {
GAME_GUARD = 0;
NONE = 1;
}

message PortRange {
uint32 min = 1;
uint32 max = 2;
}

message Port {
string label = 1;

// Only applicable to `ProxyProtocol::HTTP` and `ProxyProtocol::HTTP`.
optional uint32 target_port = 2;

// Only applicable to `ProxyProtocol::UDP` and `ProxyProtocol::TCP` when `proxy_kind` is `ProxyKind::GameGuard`.
optional PortRange port_range = 4;

ProxyProtocol proxy_protocol = 3;

ProxyKind proxy_kind = 5;
}

message EnvVar {
string key = 1;
string value = 2;
}

message Docker {
rivet.common.Uuid build_id = 1;
repeated string args = 2;
repeated EnvVar env_vars = 4;
NetworkMode network_mode = 5;
repeated Port ports = 3;
}

oneof runtime {
Docker docker = 201;
};
}

enum IdentityRequirement {
NONE = 0;
GUEST = 1;
REGISTERED = 2;
}

message VerificationConfig {
string url = 1;
map<string, string> headers = 2;
}

message FindConfig {
bool enabled = 1;
IdentityRequirement identity_requirement = 2;
optional VerificationConfig verification = 3;
}

message JoinConfig {
bool enabled = 1;
IdentityRequirement identity_requirement = 2;
optional VerificationConfig verification = 3;
}

message CreateConfig {
bool enabled = 1;
IdentityRequirement identity_requirement = 2;
optional VerificationConfig verification = 3;

bool enable_public = 4;
bool enable_private = 5;

optional uint64 max_lobbies_per_identity = 6;
}

// MARK: Game Version Config Context
// Context required to publish a new version.
message VersionConfigCtx {
repeated LobbyGroupCtx lobby_groups = 1;
}

message LobbyGroupCtx {
LobbyRuntimeCtx runtime = 101;
}

message LobbyRuntimeCtx {
message Docker {
optional rivet.common.Uuid job_template_id = 1 [deprecated = true];
}

oneof runtime {
Docker docker = 1;
};
}

// MARK: Game Version Config Meta
// Metadata about a given configuration generated after publishing.
message VersionConfigMeta {
repeated LobbyGroupMeta lobby_groups = 1;
}

message LobbyGroupMeta {
// The indexes of `LobbyGroupMeta` and `LobbyGroupConfig` returned by `game-version-get` line up, so
// fetching lobby group config via `lobby_group_id` is done via zipping.
rivet.common.Uuid lobby_group_id = 1;

LobbyRuntimeMeta runtime = 101;
}

message LobbyRuntimeMeta {
message Docker {
optional rivet.common.Uuid job_template_id = 1 [deprecated = true];
}

oneof runtime {
Docker docker = 201;
};
}

// MARK: Lobby State
message Lobby {
enum Publicity {
PUBLIC = 0;
PRIVATE = 1;
}

reserved 10;

rivet.common.Uuid lobby_id = 1;
rivet.common.Uuid lobby_group_id = 2;
rivet.common.Uuid region_id = 3;
rivet.common.Uuid token_session_id = 4;
int64 create_ts = 5;
optional int64 ready_ts = 14;
optional int64 stop_ts = 13;
optional rivet.common.Uuid run_id = 6;
bool is_closed = 11;
rivet.common.Uuid namespace_id = 9;
optional rivet.common.Uuid create_ray_id = 12;
optional rivet.common.Uuid creator_user_id = 15;
bool is_custom = 16;
Publicity publicity = 17;

uint32 max_players_normal = 101;
uint32 max_players_direct = 102;
uint32 max_players_party = 103;
}

// MARK: Player State
message Player {
rivet.common.Uuid player_id = 1;
rivet.common.Uuid lobby_id = 2;
int64 create_ts = 3;
optional int64 register_ts = 4;
optional int64 remove_ts = 5;
rivet.common.Uuid token_session_id = 6;
rivet.common.Uuid create_ray_id = 7;
}

Loading

0 comments on commit dd0d229

Please sign in to comment.