Skip to content

Commit 80cc2db

Browse files
committed
Add settings for root directory
1 parent 3a6f544 commit 80cc2db

3 files changed

Lines changed: 33 additions & 16 deletions

File tree

main.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"os"
1717
"os/exec"
1818
"os/signal"
19+
"path"
1920
"path/filepath"
2021
"strconv"
2122
"strings"
@@ -44,6 +45,7 @@ type ProxySettings struct {
4445
LegacyPHPPath string `json:"legacyPHPPath"`
4546
LegacyUsePHPServer bool `json:"legacyUsePHPServer"`
4647
LegacyHTDOCSPath string `json:"legacyHTDOCSPath"`
48+
RootPath string `json:"rootPath"`
4749
LegacyCGIBINPath string `json:"legacyCGIBINPath"`
4850
PhpCgiPath string `json:"phpCgiPath"`
4951
OverridePaths []string `json:"overridePaths"`
@@ -81,19 +83,25 @@ func init() {
8183
proxyPort := flag.Int("proxyPort", 22500, "proxy listen port")
8284
serverHTTPPort := flag.Int("serverHttpPort", 22501, "zip server http listen port")
8385
serverHTTPSPort := flag.Int("serverHttpsPort", 22502, "zip server https listen port")
84-
gameRootPath := flag.String("gameRootPath", "D:\\Flashpoint 11 Infinity\\Data\\Games", "This is the path where to find the zips")
86+
gameRootPath := flag.String("gameRootPath", "D:\\Flashpoint\\Data\\Games", "This is the path where to find the zips")
87+
rootPath := flag.String("rootPath", "D:\\Flashpoint", "The path that other relative paths use as a base")
8588
apiPrefix := flag.String("apiPrefix", "/fpProxy/api", "apiPrefix is used to prefix any API call.")
8689
useMad4FP := flag.Bool("UseMad4FP", false, "flag to turn on/off Mad4FP.")
8790
legacyGoPort := flag.Int("legacyGoPort", 22601, "port that the legacy GO server listens on")
8891
legacyPHPPort := flag.Int("legacyPHPPort", 22600, "port that the legacy PHP server listens on")
89-
legacyPHPPath := flag.String("legacyPHPPath", "D:\\Flashpoint 11 Infinity\\Legacy", "This is the path for HTDOCS")
92+
legacyPHPPath := flag.String("legacyPHPPath", "D:\\Flashpoint\\Legacy", "This is the path for HTDOCS")
9093
legacyUsePHPServer := flag.Bool("legacyUsePHPServer", true, "This will run the original PHP script in parallel")
91-
legacyHTDOCSPath := flag.String("legacyHTDOCSPath", "D:\\Flashpoint 11 Infinity\\Legacy\\htdocs", "This is the path for HTDOCS")
92-
phpCgiPath := flag.String("phpCgiPath", "D:\\Flashpoint 11 Infinity\\Legacy\\php-cgi.exe", "Path to PHP CGI executable")
94+
legacyHTDOCSPath := flag.String("legacyHTDOCSPath", "D:\\Flashpoint\\Legacy\\htdocs", "This is the path for HTDOCS")
95+
phpCgiPath := flag.String("phpCgiPath", "D:\\Flashpoint\\Legacy\\php-cgi.exe", "Path to PHP CGI executable")
9396
flag.Parse()
9497

9598
//Apply all of the flags to the settings
9699
proxySettings.VerboseLogging = *verboseLogging
100+
proxySettings.RootPath, err = filepath.Abs(strings.Trim(*rootPath, "\""))
101+
if err != nil {
102+
fmt.Printf("Failed to get absolute game root path")
103+
return
104+
}
97105
proxySettings.ProxyPort = strconv.Itoa(*proxyPort)
98106
proxySettings.ServerHTTPPort = strconv.Itoa(*serverHTTPPort)
99107
proxySettings.ServerHTTPSPort = strconv.Itoa(*serverHTTPSPort)
@@ -103,18 +111,27 @@ func init() {
103111
proxySettings.LegacyPHPPort = strconv.Itoa(*legacyPHPPort)
104112
proxySettings.LegacyPHPPath = *legacyPHPPath
105113
proxySettings.LegacyUsePHPServer = *legacyUsePHPServer
106-
proxySettings.LegacyHTDOCSPath = *legacyHTDOCSPath
107-
proxySettings.GameRootPath, err = filepath.Abs(strings.Trim(*gameRootPath, "\""))
114+
proxySettings.LegacyHTDOCSPath, err = filepath.Abs(path.Join(proxySettings.RootPath, strings.Trim(*legacyHTDOCSPath, "\"")))
115+
if err != nil {
116+
fmt.Printf("Failed to get absolute htdocs path")
117+
return
118+
}
119+
proxySettings.GameRootPath, err = filepath.Abs(path.Join(proxySettings.RootPath, strings.Trim(*gameRootPath, "\"")))
108120
if err != nil {
109121
fmt.Printf("Failed to get absolute game root path")
110122
return
111123
}
112-
proxySettings.PhpCgiPath, err = filepath.Abs(strings.Trim(*phpCgiPath, "\""))
124+
proxySettings.PhpCgiPath, err = filepath.Abs(path.Join(proxySettings.RootPath, strings.Trim(*phpCgiPath, "\"")))
113125
if err != nil {
114126
fmt.Printf("Failed to get absolute php cgi path")
115127
return
116128
}
117129

130+
// Print out all path settings
131+
fmt.Printf("Root Path: %s\n", proxySettings.RootPath)
132+
fmt.Printf("PHP CGI Path: %s\n", proxySettings.PhpCgiPath)
133+
fmt.Printf("Legacy HTDOCS Path: %s\n", proxySettings.LegacyHTDOCSPath)
134+
118135
//Setup the proxy.
119136
proxy = goproxy.NewProxyHttpServer()
120137
proxy.Verbose = proxySettings.VerboseLogging
@@ -183,9 +200,7 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
183200
proxyReq.Header = gamezipRequest.Header
184201
proxyResp, err := client.Do(proxyReq)
185202

186-
if proxyResp.StatusCode < 400 {
187-
fmt.Printf("\tServing from Zip...\n")
188-
} else if proxyResp.StatusCode >= 500 {
203+
if proxyResp.StatusCode >= 500 {
189204
fmt.Println("Gamezip Server Error: ", proxyResp.StatusCode)
190205
}
191206

@@ -288,11 +303,12 @@ func main() {
288303
proxySettings.PhpCgiPath,
289304
proxySettings.ExtMimeTypes,
290305
proxySettings.OverridePaths,
306+
proxySettings.LegacyHTDOCSPath,
291307
),
292308
))
293309
}()
294310

295-
/** THIS SOFTWARE DOES NOT CONTROL THE PHP ROUTER LIFECYCLE */
311+
/** DISABLED WHILE NOT FUNCTIONING */
296312
// //Start Legacy server
297313
// go func() {
298314
// if proxySettings.LegacyUsePHPServer {
@@ -302,7 +318,7 @@ func main() {
302318
// }
303319
// }()
304320

305-
//Start PROXY server
321+
//Start proxy server
306322
log.Fatal(http.ListenAndServe("127.0.0.1:"+proxySettings.ProxyPort, http.AllowQuerySemicolons(proxy)))
307323
}
308324

proxySettings.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2-
"legacyHTDOCSPath": "../Legacy/htdocs/",
3-
"legacyCGIBINPath": "../Legacy/cgi-bin/",
4-
"legacyPHPPath": "../Legacy/",
2+
"legacyHTDOCSPath": "Legacy/htdocs/",
3+
"legacyCGIBINPath": "Legacy/cgi-bin/",
4+
"legacyPHPPath": "Legacy/",
5+
"rootPath": "../",
56
"overridePaths": [
67
"../Legacy/middleware_overrides/"
78
],

zipfs

0 commit comments

Comments
 (0)