Main/Common: Use config entry for frontend/backend address

This commit is contained in:
mkwcat 2024-05-08 22:39:14 -04:00
parent a949b5c727
commit 2c137ed7f3
No known key found for this signature in database
GPG Key ID: 7A505679CE9E7AA9
4 changed files with 74 additions and 29 deletions

View File

@ -6,31 +6,43 @@ import (
)
type Config struct {
Username string `xml:"username"`
Password string `xml:"password"`
DatabaseAddress string `xml:"databaseAddress"`
DatabaseName string `xml:"databaseName"`
DefaultAddress string `xml:"address"`
GameSpyAddress *string `xml:"gsAddress,omitempty"`
NASAddress *string `xml:"nasAddress,omitempty"`
NASPort string `xml:"nasPort"`
NASAddressHTTPS *string `xml:"nasAddressHttps,omitempty"`
NASPortHTTPS string `xml:"nasPortHttps"`
EnableHTTPS bool `xml:"enableHttps"`
EnableHTTPSExploitWii *bool `xml:"enableHttpsExploitWii,omitempty"`
EnableHTTPSExploitDS *bool `xml:"enableHttpsExploitDS,omitempty"`
LogLevel *int `xml:"logLevel"`
LogOutput string `xml:"logOutput"`
CertPath string `xml:"certPath"`
KeyPath string `xml:"keyPath"`
CertPathWii string `xml:"certDerPathWii"`
KeyPathWii string `xml:"keyPathWii"`
CertPathDS string `xml:"certDerPathDS"`
WiiCertPathDS string `xml:"wiiCertDerPathDS"`
KeyPathDS string `xml:"keyPathDS"`
APISecret string `xml:"apiSecret"`
AllowDefaultDolphinKeys bool `xml:"allowDefaultDolphinKeys"`
ServerName string `xml:"serverName,omitempty"`
Username string `xml:"username"`
Password string `xml:"password"`
DatabaseAddress string `xml:"databaseAddress"`
DatabaseName string `xml:"databaseName"`
DefaultAddress string `xml:"address"`
GameSpyAddress *string `xml:"gsAddress,omitempty"`
NASAddress *string `xml:"nasAddress,omitempty"`
NASPort string `xml:"nasPort"`
NASAddressHTTPS *string `xml:"nasAddressHttps,omitempty"`
NASPortHTTPS string `xml:"nasPortHttps"`
FrontendAddress string `xml:"frontendAddress"`
FrontendBackendAddress string `xml:"frontendBackendAddress"`
BackendAddress string `xml:"backendAddress"`
BackendFrontendAddress string `xml:"backendFrontendAddress"`
EnableHTTPS bool `xml:"enableHttps"`
EnableHTTPSExploitWii *bool `xml:"enableHttpsExploitWii,omitempty"`
EnableHTTPSExploitDS *bool `xml:"enableHttpsExploitDS,omitempty"`
LogLevel *int `xml:"logLevel"`
LogOutput string `xml:"logOutput"`
CertPath string `xml:"certPath"`
KeyPath string `xml:"keyPath"`
CertPathWii string `xml:"certDerPathWii"`
KeyPathWii string `xml:"keyPathWii"`
CertPathDS string `xml:"certDerPathDS"`
WiiCertPathDS string `xml:"wiiCertDerPathDS"`
KeyPathDS string `xml:"keyPathDS"`
APISecret string `xml:"apiSecret"`
AllowDefaultDolphinKeys bool `xml:"allowDefaultDolphinKeys"`
ServerName string `xml:"serverName,omitempty"`
}
func GetConfig() Config {
@ -83,5 +95,21 @@ func GetConfig() Config {
config.LogOutput = "StdOutAndFile"
}
if config.FrontendAddress == "" {
config.FrontendAddress = "127.0.0.1:29998"
}
if config.BackendAddress == "" {
config.BackendAddress = "127.0.0.1:29999"
}
if config.FrontendBackendAddress == "" {
config.FrontendBackendAddress = config.BackendAddress
}
if config.BackendFrontendAddress == "" {
config.BackendFrontendAddress = config.FrontendAddress
}
return config
}

View File

@ -16,9 +16,11 @@ type RPCFrontendPacket struct {
// ConnectFrontend connects to the frontend RPC server
func ConnectFrontend() {
config := GetConfig()
var err error
for i := 0; rpcFrontend == nil; i++ {
rpcFrontend, err = rpc.Dial("tcp", "localhost:29998")
rpcFrontend, err = rpc.Dial("tcp", config.BackendFrontendAddress)
if err != nil {
if i > 20 {
panic(err)

View File

@ -2,6 +2,18 @@
<!-- The address the GameSpy services will bind to -->
<gsAddress>127.0.0.1</gsAddress>
<!-- The address the frontend RPC server will bind to -->
<frontendAddress>127.0.0.1:29998</frontendAddress>
<!-- The address the frontend can reach the backend from -->
<frontendBackendAddress>127.0.0.1:29999</frontendBackendAddress>
<!-- The address the backend RPC server will bind to -->
<backendAddress>127.0.0.1:29999</backendAddress>
<!-- The address the backend can reach the frontend from -->
<backendFrontendAddress>127.0.0.1:29998</backendFrontendAddress>
<!-- The address the NAS HTTP server will bind to -->
<nasAddress>127.0.0.1</nasAddress>
<nasPort>80</nasPort>

View File

@ -12,6 +12,7 @@ import (
"strings"
"sync"
"syscall"
"time"
"wwfc/api"
"wwfc/common"
"wwfc/gamestats"
@ -77,7 +78,7 @@ func backendMain(noSignal, noReload bool) {
}
rpc.Register(&RPCPacket{})
address := "localhost:29999"
address := config.BackendAddress
l, err := net.Listen("tcp", address)
if err != nil {
@ -328,7 +329,7 @@ func frontendMain(noSignal, noBackend bool) {
// startFrontendServer starts the frontend RPC server.
func startFrontendServer() {
rpc.Register(&RPCFrontendPacket{})
address := "localhost:29998"
address := config.FrontendAddress
l, err := net.Listen("tcp", address)
if err != nil {
@ -389,7 +390,7 @@ func waitForBackend() {
backendReady = make(chan struct{})
for {
client, err := rpc.Dial("tcp", "localhost:29999")
client, err := rpc.Dial("tcp", config.FrontendBackendAddress)
if err == nil {
rpcClient = client
rpcMutex.Unlock()
@ -398,6 +399,8 @@ func waitForBackend() {
return
}
<-time.After(50 * time.Millisecond)
}
}