Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ members = [
"packages/agent_core",
"packages/agent_proto",
"packages/api_client",
"packages/ping_monitor",
]
resolver = "3"

[workspace.package]
version = "0.16.5"
version = "0.17.0"

[workspace.dependencies]
tokio = { version = "1.48", features = ["full"] }
Expand All @@ -35,4 +35,3 @@ strip = "debuginfo"
opt-level = "z"
lto = true
codegen-units = 1

6 changes: 3 additions & 3 deletions packages/agent_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "playit-cli"
version.workspace = true
edition = "2021"
edition = "2024"
authors = ["Patrick Lorio <[email protected]>"]
description = "Making it easy to play games with friends. Makes your server public"
repository = "https://github.com/playit-cloud/playit-agent"
Expand All @@ -28,9 +28,9 @@ serde_yaml = "0.9"
crossterm = "0.28"
dotenv = "0.15.0"

playit-agent-core = { path = "../agent_core", version = "0.20.1" }
playit-agent-core = { path = "../agent_core", version = "0.17.0" }
playit-agent-proto = { path = "../agent_proto", version = "1.3.0" }
playit-api-client = { path = "../api_client", version = "0.1.2" }
playit-api-client = { path = "../api_client", version = "0.2.0" }
# playit-ping-monitor = { path = "../ping_monitor" }

[target.'cfg(windows)'.build-dependencies]
Expand Down
121 changes: 40 additions & 81 deletions packages/agent_cli/src/autorun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Write, net::SocketAddr, sync::Arc, time::Duration};

use playit_agent_core::{
network::{
origin_lookup::{OriginLookup, OriginResource},
origin_lookup::{OriginLookup, OriginResource, OriginTarget},
tcp::tcp_settings::TcpSettings,
udp::udp_settings::UdpSettings,
},
Expand All @@ -13,7 +13,7 @@ use playit_agent_proto::PortProto;
use playit_api_client::api::*;
// use playit_ping_monitor::PingMonitor;

use crate::{playit_secret::PlayitSecret, ui::UI, CliError, API_BASE};
use crate::{API_BASE, CliError, playit_secret::PlayitSecret, ui::UI};

pub async fn autorun(ui: &mut UI, mut secret: PlayitSecret) -> Result<(), CliError> {
let secret_code = secret.ensure_valid(ui).await?.get_or_setup(ui).await?;
Expand All @@ -35,7 +35,7 @@ pub async fn autorun(ui: &mut UI, mut secret: PlayitSecret) -> Result<(), CliErr

let lookup = Arc::new(OriginLookup::default());
lookup
.update_from_run_data(&api.agents_rundata().await?)
.update_from_run_data(&api.v1_agents_rundata().await?)
.await;

let mut error_count = 0;
Expand Down Expand Up @@ -75,8 +75,8 @@ pub async fn autorun(ui: &mut UI, mut secret: PlayitSecret) -> Result<(), CliErr
loop {
tokio::time::sleep(Duration::from_secs(3)).await;

let account_tunnels_res = api.agents_rundata().await;
let agent_data = match account_tunnels_res {
let account_tunnels_res = api.v1_agents_rundata().await;
let mut agent_data = match account_tunnels_res {
Ok(v) => v,
Err(error) => {
ui.write_error("Failed to load latest tunnels", error).await;
Expand All @@ -94,8 +94,8 @@ pub async fn autorun(ui: &mut UI, mut secret: PlayitSecret) -> Result<(), CliErr
agent_data.tunnels.len()
);

match agent_data.account_status {
AgentAccountStatus::Guest => 'login_link: {
match agent_data.permissions.account_status {
AccountStatus::Guest => 'login_link: {
let now = now_milli();

match &guest_login_link {
Expand All @@ -118,105 +118,64 @@ pub async fn autorun(ui: &mut UI, mut secret: PlayitSecret) -> Result<(), CliErr
}
}
}
AgentAccountStatus::EmailNotVerified => {
AccountStatus::EmailNotVerified => {
writeln!(
msg,
"Email not verified https://playit.gg/account/settings/account/verify-email"
)
.unwrap();
}
AgentAccountStatus::AccountDeleteScheduled => {
writeln!(msg, "Account scheduled for delete: https://playit.gg/account/settings/account/delete-account").unwrap();
}
AgentAccountStatus::Banned => {
writeln!(msg, "Account banned: https://playit.gg/account").unwrap();
}
AgentAccountStatus::HasMessage => {
writeln!(msg, "You have a message: https://playit.gg/account").unwrap();
}
AgentAccountStatus::AgentOverLimit => {
writeln!(msg, "Too many agents: https://playit.gg/account/agents").unwrap();
}
AgentAccountStatus::AgentDisabled => {
writeln!(
msg,
"Account disabled: https://playit.gg/account/agents/{}",
agent_data.agent_id
)
.unwrap();
AccountStatus::Verified => {}
}

agent_data.notices.sort_by_key(|n| n.priority);

for notice in &agent_data.notices {
writeln!(msg, "[{:?}] {}", notice.priority, notice.message).unwrap();
if let Some(link) = &notice.resolve_link {
writeln!(msg, "{link}").unwrap();
}
AgentAccountStatus::Ready => {}
}

writeln!(msg, "\nTUNNELS").unwrap();

if agent_data.tunnels.is_empty() && agent_data.pending.is_empty() {
let agent_id = match agent_data.agent_type {
AgentType::Default => "default".to_string(),
AgentType::Assignable => agent_data.agent_id.to_string(),
AgentType::SelfManaged => agent_data.agent_id.to_string(),
};

writeln!(
msg,
"Add tunnels here: https://playit.gg/account/agents/{}",
agent_id
agent_data.agent_id
)
.unwrap();
} else {
for tunnel in &agent_data.tunnels {
let addr = tunnel
.custom_domain
.as_ref()
.unwrap_or(&tunnel.assigned_domain);
let src = match tunnel.tunnel_type.as_deref() {
Some("minecraft-java") => addr.clone(),
_ => format!("{}:{}", addr, tunnel.port.from),
let Some(origin) = OriginResource::from_agent_tunnel(&tunnel) else {
continue;
};

let dst = format!("{}:{}", tunnel.local_ip, tunnel.local_port);

if let Some(disabled) = tunnel.disabled {
writeln!(msg, "{} => {} (disabled)", src, dst).unwrap();
if disabled == AgentTunnelDisabled::BySystem {
writeln!(
msg,
"\tsee: https://playit.gg/account/tunnels/{}",
tunnel.id
)
.unwrap();
}
} else if let Some(tunnel_type) = &tunnel.tunnel_type {
writeln!(msg, "{} => {} ({})", src, dst, tunnel_type).unwrap();
} else {
writeln!(
msg,
"{} => {} (proto: {:?}, port count: {})",
src,
dst,
tunnel.proto,
tunnel.port.to - tunnel.port.from
)
.unwrap();
if let Some(reason) = &tunnel.disabled_reason {
writeln!(msg, "{} => (disabled {reason})", tunnel.display_address).unwrap();
continue;
}

let dst = match origin.target {
OriginTarget::Https {
ip,
http_port,
https_port,
} => format!("{ip} (http: {http_port}, https: {https_port})"),
OriginTarget::Port { ip, port } => SocketAddr::new(ip, port).to_string(),
};

writeln!(msg, "{} => {}", tunnel.display_address, dst).unwrap();
}

for tunnel in &agent_data.pending {
if tunnel.is_disabled {
writeln!(
msg,
"tunnel pending (disabled): https://playit.gg/account/tunnels/{}",
tunnel.id
)
.unwrap();
} else {
writeln!(
msg,
"tunnel pending: https://playit.gg/account/tunnels/{}",
tunnel.id
)
.unwrap();
}
writeln!(
msg,
"tunnel ({}): https://playit.gg/account/tunnels/{}",
tunnel.status_msg, tunnel.id
)
.unwrap();
}
}

Expand Down
Loading
Loading