diff --git a/companion-agent/cmd/agent/main.go b/companion-agent/cmd/agent/main.go index 29affa4..5892bb8 100644 --- a/companion-agent/cmd/agent/main.go +++ b/companion-agent/cmd/agent/main.go @@ -18,7 +18,7 @@ import ( type Config struct { // NATS connection NATSUrl string `envconfig:"NATS_URL" required:"true"` - NATSToken string `envconfig:"NATS_TOKEN" required:"true"` + NATSToken string `envconfig:"NATS_TOKEN" default:""` // License identification LicenseID string `envconfig:"LICENSE_ID" required:"true"` diff --git a/companion-agent/internal/client/nats.go b/companion-agent/internal/client/nats.go index 5ac048d..a6d3912 100644 --- a/companion-agent/internal/client/nats.go +++ b/companion-agent/internal/client/nats.go @@ -7,13 +7,12 @@ import ( "github.com/nats-io/nats.go" ) -// Connect establishes a connection to NATS with token authentication +// Connect establishes a connection to NATS with optional token authentication // and automatic reconnection handling func Connect(url, token string) (*nats.Conn, error) { opts := []nats.Option{ - nats.Token(token), nats.Name("corrosion-companion"), - nats.MaxReconnects(-1), // Unlimited reconnect attempts + nats.MaxReconnects(-1), nats.ReconnectWait(2 * time.Second), nats.DisconnectErrHandler(func(nc *nats.Conn, err error) { if err != nil { @@ -31,6 +30,11 @@ func Connect(url, token string) (*nats.Conn, error) { }), } + // Only use token auth if a token is provided + if token != "" { + opts = append(opts, nats.Token(token)) + } + nc, err := nats.Connect(url, opts...) if err != nil { return nil, fmt.Errorf("failed to connect to NATS: %w", err) diff --git a/frontend/src/views/admin/ServerView.vue b/frontend/src/views/admin/ServerView.vue index be7ef8a..e819d03 100644 --- a/frontend/src/views/admin/ServerView.vue +++ b/frontend/src/views/admin/ServerView.vue @@ -73,8 +73,6 @@ chmod +x corrosion-companion-linux-amd64 # Start with your license key export LICENSE_ID="${licenseKey.value}" export NATS_URL="nats://nats.corrosionmgmt.com:4222" -export NATS_TOKEN="" -export GAME_SERVER_PATH="/path/to/RustDedicated" ./corrosion-companion-linux-amd64`) const windowsCommands = computed(() => `# Requires PowerShell (not Command Prompt) @@ -84,8 +82,6 @@ Invoke-WebRequest -Uri "https://cdn.corrosionmgmt.com/companion/latest/corrosion # Start with your license key $env:LICENSE_ID="${licenseKey.value}" $env:NATS_URL="nats://nats.corrosionmgmt.com:4222" -$env:NATS_TOKEN="" -$env:GAME_SERVER_PATH="C:\\RustServer\\server\\RustDedicated.exe" .\\corrosion-companion-windows-amd64.exe`) async function copySetupCommands() { @@ -390,8 +386,6 @@ onMounted(async () => {

# Start with your license key

export LICENSE_ID="{{ licenseKey }}"

export NATS_URL="nats://nats.corrosionmgmt.com:4222"

-

export NATS_TOKEN="<your-nats-token>"

-

export GAME_SERVER_PATH="/path/to/RustDedicated"

./corrosion-companion-linux-amd64

@@ -403,8 +397,6 @@ onMounted(async () => {

# Start with your license key

$env:LICENSE_ID="{{ licenseKey }}"

$env:NATS_URL="nats://nats.corrosionmgmt.com:4222"

-

$env:NATS_TOKEN="<your-nats-token>"

-

$env:GAME_SERVER_PATH="C:\RustServer\server\RustDedicated.exe"

.\corrosion-companion-windows-amd64.exe