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 committed Jun 18, 2024
1 parent 8fb3c75 commit c8de313
Show file tree
Hide file tree
Showing 24 changed files with 4,287 additions and 8 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",
}
],
}
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
239 changes: 239 additions & 0 deletions 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 @@ -66,3 +68,240 @@ enum GameGuardProtocol {
}

message DockerHostRouting {}






// 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;
}

23 changes: 22 additions & 1 deletion svc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion svc/api/dynamic-servers/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl Ctx {
util::timestamp::now(),
util::timestamp::now(),
(),
Vec::new(),
);

Ctx { op_ctx }
Expand Down
27 changes: 25 additions & 2 deletions svc/pkg/ds/ops/server-create/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,34 @@ license = "Apache-2.0"

[dependencies]
chirp-client = { path = "../../../../../lib/chirp/client" }
chirp-worker = { path = "../../../../../lib/chirp/worker" }
rivet-operation = { path = "../../../../../lib/operation/core" }
nomad-client = "0.0.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4.0"
uuid = { version = "1", features = ["v4", "serde"] }
http = "0.2"
bit-vec = "0.6"
cjson = "0.1"
nomad-util = { path = "../../../../../lib/nomad-util" }
strum = { version = "0.24", features = ["derive"] }
sha2 = "0.10"
hex = "0.4"
rivet-util = { path = "../../../../../lib/util/core" }
heck = "0.3"
s3-util = { path = "../../../../../lib/s3-util" }
util-build = { package = "rivet-util-build", path = "../../../build/util" }
regex = "1.10"

mm-lobby-list-for-user-id = { path = "../../../mm/ops/lobby-list-for-user-id" }
build-get = { path = "../../../build/ops/get" }
user-identity-get = { path = "../../../user-identity/ops/get" }
upload-get = { path = "../../../upload/ops/get" }
region-get = { path = "../../../region/ops/get" }
ip-info = { path = "../../../ip/ops/info" }
tier-list = { path = "../../../tier/ops/list" }

[dependencies.nomad_client_new]
[dependencies.nomad_client]
package = "nomad_client"
git = "https://github.com/rivet-gg/nomad-client"
rev = "abb66bf0c30c7ff5b0c695dae952481c33e538b5" # pragma: allowlist secret
Expand Down
Loading

0 comments on commit c8de313

Please sign in to comment.