@@ -25,29 +25,30 @@ import (
2525)
2626
2727type ServerSettings struct {
28+ RootPath string `json:"rootPath"`
29+ GameDataPath string `json:"gameDataPath"`
30+ LegacyPHPPath string `json:"legacyPHPPath"`
31+ LegacyPHPCGIPath string `json:"legacyPHPCGIPath"`
32+ LegacyCGIBINPath string `json:"legacyCGIBINPath"`
33+ LegacyHTDOCSPath string `json:"legacyHTDOCSPath"`
34+ UseInfinityServer bool `json:"useInfinityServer"`
35+ InfinityServerURL string `json:"infinityServerURL"`
36+ HandleLegacyRequests bool `json:"handleLegacyRequests"`
37+ ExternalLegacyPort int `json:"externalLegacyPort"`
38+ ProxyPort int `json:"proxyPort"`
39+ ServerHTTPPort int `json:"serverHTTPPort"`
40+ UseMad4FP bool `json:"useMad4FP"`
41+ EnableHttpsProxy bool `json:"enableHttpsProxy"`
2842 AllowCrossDomain bool `json:"allowCrossDomain"`
2943 VerboseLogging bool `json:"verboseLogging"`
30- ProxyPort string `json:"proxyPort"`
31- ServerHTTPPort string `json:"serverHTTPPort"`
32- GameRootPath string `json:"gameRootPath"`
3344 ApiPrefix string `json:"apiPrefix"`
45+ OverridePaths []string `json:"overridePaths"`
46+ LegacyOverridePaths []string `json:"legacyOverridePaths"`
3447 ExternalFilePaths []string `json:"externalFilePaths"`
3548 ExtScriptTypes []string `json:"extScriptTypes"`
3649 ExtIndexTypes []string `json:"extIndexTypes"`
37- ExtMimeTypes map [string ]string `json:"extMimeTypes"`
3850 ExtGzippeddTypes []string `json:"extGzippedTypes"`
39- HandleLegacyRequests bool `json:"handleLegacyRequests"`
40- ExternalLegacyPort string `json:"externalLegacyPort"`
41- LegacyHTDOCSPath string `json:"legacyHTDOCSPath"`
42- RootPath string `json:"rootPath"`
43- LegacyCGIBINPath string `json:"legacyCGIBINPath"`
44- PhpCgiPath string `json:"phpCgiPath"`
45- OverridePaths []string `json:"overridePaths"`
46- LegacyOverridePaths []string `json:"legacyOverridePaths"`
47- UseInfinityServer bool `json:"useInfinityServer"`
48- InfinityServerURL string `json:"infinityServerURL"`
49- UseMad4FP bool `json:"useMad4FP"`
50- EnableHttpsProxy bool `json:"enableHttpsProxy"`
51+ ExtMimeTypes map [string ]string `json:"extMimeTypes"`
5152}
5253
5354// ExtApplicationTypes is a map that holds the content types of different file extensions
@@ -56,7 +57,7 @@ var proxy *goproxy.ProxyHttpServer
5657var cwd string
5758
5859func initServer () {
59- //Get the CWD of this application
60+ // Get the CWD of this application
6061 exe , err := os .Executable ()
6162 if err != nil {
6263 panic (err )
@@ -75,78 +76,85 @@ func initServer() {
7576 panic (err )
7677 }
7778
78- //TODO: Update proxySettings.LegacyHTDOCSPath AND proxySettings.LegacyPHPPath for the default values!
79-
80- //Get all of the paramaters passed in.
81- verboseLogging := flag .Bool ("v" , false , "should every proxy request be logged to stdout" )
82- proxyPort := flag .Int ("proxyPort" , 22500 , "proxy listen port" )
83- serverHTTPPort := flag .Int ("serverHttpPort" , 22501 , "zip server http listen port" )
84- gameRootPath := flag .String ("gameRootPath" , serverSettings .GameRootPath , "This is the path where to find the zips" )
85- rootPath := flag .String ("rootPath" , "D:\\ Flashpoint" , "The path that other relative paths use as a base" )
86- apiPrefix := flag .String ("apiPrefix" , "/fpProxy/api" , "apiPrefix is used to prefix any API call." )
87- useMad4FP := flag .Bool ("UseMad4FP" , false , "flag to turn on/off Mad4FP." )
88- externalLegacyPort := flag .String ("externalLegacyPort" , "22600" , "The port that the external legacy server is running on (if handling legacy is disabled)." )
79+ // Get all of the parameters passed in
80+ // TODO: Figure out a way to (partially?) automate everything that's going on below
81+ // TODO: Improve descriptions
82+ rootPath := flag .String ("rootPath" , serverSettings .RootPath , "The path that other relative paths use as a base" )
83+ gameDataPath := flag .String ("gameRootPath" , serverSettings .GameDataPath , "This is the path where to find the zips" )
84+ legacyPHPPath := flag .String ("legacyPHPPath" , serverSettings .LegacyPHPPath , "This is the path for PHP" )
85+ legacyPHPCGIPath := flag .String ("phpCgiPath" , serverSettings .LegacyPHPCGIPath , "Path to PHP CGI executable" )
86+ legacyCGIBINPath := flag .String ("legacyCGIBINPath" , serverSettings .LegacyCGIBINPath , "This is the path for CGI-BIN" )
8987 legacyHTDOCSPath := flag .String ("legacyHTDOCSPath" , serverSettings .LegacyHTDOCSPath , "This is the path for HTDOCS" )
90- phpCgiPath := flag .String ("phpCgiPath" , serverSettings .PhpCgiPath , "Path to PHP CGI executable" )
91- useInfinityServer := flag .Bool ("useInfinityServer" , false , "Whether to use the infinity server or not" )
88+ useInfinityServer := flag .Bool ("useInfinityServer" , serverSettings .UseInfinityServer , "Whether to use the infinity server or not" )
9289 infinityServerURL := flag .String ("infinityServerURL" , serverSettings .InfinityServerURL , "The URL of the infinity server" )
93- legacyCGIBINPath := flag .String ("legacyCGIBINPath" , serverSettings .LegacyCGIBINPath , "This is the path for CGI-BIN" )
94- handleLegacyRequests := flag .Bool ("handleLegacyRequests" , false , "Whether to handle legacy requests internally (true) or externally (false)" )
95- enableHttpsProxy := flag .Bool ("enableHttpsProxy" , false , "Whether to enable HTTPS proxying or not" )
90+ handleLegacyRequests := flag .Bool ("handleLegacyRequests" , serverSettings .HandleLegacyRequests , "Whether to handle legacy requests internally (true) or externally (false)" )
91+ externalLegacyPort := flag .Int ("externalLegacyPort" , serverSettings .ExternalLegacyPort , "The port that the external legacy server is running on (if handling legacy is disabled)." )
92+ proxyPort := flag .Int ("proxyPort" , serverSettings .ProxyPort , "proxy listen port" )
93+ serverHttpPort := flag .Int ("serverHttpPort" , serverSettings .ServerHTTPPort , "zip server http listen port" )
94+ useMad4FP := flag .Bool ("UseMad4FP" , serverSettings .UseMad4FP , "flag to turn on/off Mad4FP." )
95+ enableHttpsProxy := flag .Bool ("enableHttpsProxy" , serverSettings .EnableHttpsProxy , "Whether to enable HTTPS proxying or not" )
96+ allowCrossDomain := flag .Bool ("allowCrossDomain" , serverSettings .AllowCrossDomain , "Whether to allow cross-domain requests" )
97+ verboseLogging := flag .Bool ("verboseLogging" , serverSettings .VerboseLogging , "should every proxy request be logged to stdout" )
98+ apiPrefix := flag .String ("apiPrefix" , serverSettings .ApiPrefix , "apiPrefix is used to prefix any API call." )
9699
97100 flag .Parse ()
98101
99- //Apply all of the flags to the settings
100- serverSettings .VerboseLogging = * verboseLogging
101- serverSettings .RootPath , err = filepath .Abs (strings .Trim (* rootPath , "\" " ))
102+ // Apply all of the flags to the settings
103+ serverSettings .RootPath , err = filepath .Abs (strings .Trim (* rootPath , string (os .PathSeparator )))
102104 if err != nil {
103- fmt .Printf ("Failed to get absolute game root path" )
104- return
105+ fmt .Println ("Failed to get absolute root path" )
106+ panic ( err )
105107 }
106- serverSettings .EnableHttpsProxy = * enableHttpsProxy
107- serverSettings .ProxyPort = strconv .Itoa (* proxyPort )
108- serverSettings .ServerHTTPPort = strconv .Itoa (* serverHTTPPort )
109- serverSettings .ApiPrefix = * apiPrefix
110- serverSettings .UseMad4FP = * useMad4FP
111- serverSettings .ExternalLegacyPort = * externalLegacyPort
112- serverSettings .LegacyCGIBINPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyCGIBINPath , "\" " )))
108+ serverSettings .GameDataPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* gameDataPath , string (os .PathSeparator ))))
113109 if err != nil {
114- fmt .Printf ("Failed to get absolute cgi-bin path" )
115- return
110+ fmt .Println ("Failed to get absolute game data path" )
111+ panic ( err )
116112 }
117- serverSettings .LegacyHTDOCSPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyHTDOCSPath , " \" " )))
113+ serverSettings .LegacyPHPPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyPHPPath , string ( os . PathSeparator ) )))
118114 if err != nil {
119- fmt .Printf ("Failed to get absolute htdocs path" )
120- return
115+ fmt .Println ("Failed to get absolute PHP path" )
116+ panic ( err )
121117 }
122- serverSettings .GameRootPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* gameRootPath , " \" " )))
118+ serverSettings .LegacyPHPCGIPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyPHPCGIPath , string ( os . PathSeparator ) )))
123119 if err != nil {
124- fmt .Printf ("Failed to get absolute game root path" )
125- return
120+ fmt .Println ("Failed to get absolute PHP CGI path" )
121+ panic ( err )
126122 }
127- serverSettings .PhpCgiPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* phpCgiPath , " \" " )))
123+ serverSettings .LegacyCGIBINPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyCGIBINPath , string ( os . PathSeparator ) )))
128124 if err != nil {
129- fmt .Printf ("Failed to get absolute php cgi path" )
130- return
125+ fmt .Println ("Failed to get absolute cgi-bin path" )
126+ panic (err )
127+ }
128+ serverSettings .LegacyHTDOCSPath , err = filepath .Abs (path .Join (serverSettings .RootPath , strings .Trim (* legacyHTDOCSPath , string (os .PathSeparator ))))
129+ if err != nil {
130+ fmt .Println ("Failed to get absolute htdocs path" )
131+ panic (err )
131132 }
132133 serverSettings .UseInfinityServer = * useInfinityServer
133134 serverSettings .InfinityServerURL = * infinityServerURL
134135 serverSettings .HandleLegacyRequests = * handleLegacyRequests
136+ serverSettings .ExternalLegacyPort = * externalLegacyPort
137+ serverSettings .ProxyPort = * proxyPort
138+ serverSettings .ServerHTTPPort = * serverHttpPort
139+ serverSettings .UseMad4FP = * useMad4FP
140+ serverSettings .EnableHttpsProxy = * enableHttpsProxy
141+ serverSettings .AllowCrossDomain = * allowCrossDomain
142+ serverSettings .VerboseLogging = * verboseLogging
143+ serverSettings .ApiPrefix = * apiPrefix
135144
136145 // Print out all path settings
137- fmt .Printf ("Root Path: %s\n " , serverSettings .RootPath )
138- fmt .Printf ("PHP CGI Path: %s\n " , serverSettings .PhpCgiPath )
139- fmt .Printf ("Legacy HTDOCS Path: %s\n " , serverSettings .LegacyHTDOCSPath )
140- fmt .Printf ("Legacy CGI BIN Path: %s\n " , serverSettings .LegacyCGIBINPath )
141- fmt .Printf ("Games Path: %s\n " , serverSettings .GameRootPath )
142-
143- //Setup the proxy.
146+ fmt .Println ("Root Path:" , serverSettings .RootPath )
147+ fmt .Println ("Game Data Path:" , serverSettings .GameDataPath )
148+ fmt .Println ("Legacy PHP Path:" , serverSettings .LegacyPHPPath )
149+ fmt .Println ("Legacy PHP-CGI Path:" , serverSettings .LegacyPHPCGIPath )
150+ fmt .Println ("Legacy CGI-BIN Path:" , serverSettings .LegacyCGIBINPath )
151+ fmt .Println ("Legacy HTDOCS Path:" , serverSettings .LegacyHTDOCSPath )
152+
153+ // Setup the proxy
144154 proxy = goproxy .NewProxyHttpServer ()
145155 proxy .Verbose = serverSettings .VerboseLogging
146- fmt .Printf ("Proxy Server Started on port %s\n " , serverSettings .ProxyPort )
147- fmt .Printf ("Zip Server Started\n \t HTTP Port: %s\n \t Game Root: %s\n " ,
148- serverSettings .ServerHTTPPort ,
149- serverSettings .GameRootPath )
156+ fmt .Println ("Proxy Server started on port" , strconv .Itoa (serverSettings .ProxyPort ))
157+ fmt .Println ("Zip Server started on port" , strconv .Itoa (serverSettings .ServerHTTPPort ))
150158}
151159
152160func setContentType (r * http.Request , resp * http.Response ) {
@@ -211,7 +219,7 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
211219 Method : r .Method ,
212220 URL : & url.URL {
213221 Scheme : "http" ,
214- Host : "127.0.0.1:" + serverSettings .ServerHTTPPort ,
222+ Host : "127.0.0.1:" + strconv . Itoa ( serverSettings .ServerHTTPPort ) ,
215223 Path : "content/" + r .URL .Host + r .URL .Path ,
216224 RawQuery : r .URL .RawQuery ,
217225 },
@@ -261,15 +269,15 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
261269 proxyResp = resRecorder .Result ()
262270 } else {
263271 // Set the Proxy URL and apply it to the Transpor layer so that the request respects the proxy.
264- proxyURL , _ := url .Parse ("http://127.0.0.1:" + serverSettings .ExternalLegacyPort )
272+ proxyURL , _ := url .Parse ("http://127.0.0.1:" + strconv . Itoa ( serverSettings .ExternalLegacyPort ) )
265273 proxy := http .ProxyURL (proxyURL )
266274 transport := & http.Transport {Proxy : proxy }
267275
268276 // A custom Dialer is required for the "localflash" urls, instead of using the DNS, we use this.
269277 transport .DialContext = func (ctx context.Context , network , addr string ) (net.Conn , error ) {
270278 //Set Dialer timeout and keepalive to 30 seconds and force the address to localhost.
271279 dialer := & net.Dialer {Timeout : 30 * time .Second , KeepAlive : 30 * time .Second }
272- addr = "127.0.0.1:" + serverSettings .ExternalLegacyPort
280+ addr = "127.0.0.1:" + strconv . Itoa ( serverSettings .ExternalLegacyPort )
273281 return dialer .DialContext (ctx , network , addr )
274282 }
275283
@@ -360,14 +368,14 @@ XgVWIMrKj4T7p86bcxq4jdWDYUYpRd/2Og==
360368 go func () {
361369 //TODO: Update these to be modifiable in the properties json.
362370 //TODO: Also update the "fpProxy/api/" to be in the properties json.
363- log .Fatal (http .ListenAndServe ("127.0.0.1:" + serverSettings .ServerHTTPPort ,
371+ log .Fatal (http .ListenAndServe ("127.0.0.1:" + strconv . Itoa ( serverSettings .ServerHTTPPort ) ,
364372 zipfs .EmptyFileServer (
365373 serverSettings .ApiPrefix ,
366374 "" ,
367375 serverSettings .VerboseLogging ,
368376 serverSettings .ExtIndexTypes ,
369- serverSettings .GameRootPath ,
370- serverSettings .PhpCgiPath ,
377+ serverSettings .GameDataPath ,
378+ serverSettings .LegacyPHPCGIPath ,
371379 serverSettings .ExtMimeTypes ,
372380 serverSettings .OverridePaths ,
373381 serverSettings .LegacyHTDOCSPath ,
@@ -376,5 +384,5 @@ XgVWIMrKj4T7p86bcxq4jdWDYUYpRd/2Og==
376384 }()
377385
378386 // Start proxy server
379- log .Fatal (http .ListenAndServe ("127.0.0.1:" + serverSettings .ProxyPort , http .AllowQuerySemicolons (proxy )))
387+ log .Fatal (http .ListenAndServe ("127.0.0.1:" + strconv . Itoa ( serverSettings .ProxyPort ) , http .AllowQuerySemicolons (proxy )))
380388}
0 commit comments