latest changes

This commit is contained in:
2023-03-01 15:49:28 +00:00
parent ad303c963e
commit 6f9d3dd345
4 changed files with 85 additions and 42 deletions

View File

@@ -23,12 +23,15 @@ type Config struct {
IPAddress string IPAddress string
ScriptToExecute string ScriptToExecute string
SSHPassword string SSHPassword string
NATEscapeServerPort string NATEscapeGameServerPort string
NATEscapeScreenSharePort string
NATEscapeBarrierPort string NATEscapeBarrierPort string
BackendURL string BackendURL string
BrowserCommand string BrowserCommand string
Rate float64 Rate float64
ScreenName string ScreenName string
InternalGameServerPort string
InternalScreenSharePort string
} }
// Exists reports whether the named file or directory exists. // Exists reports whether the named file or directory exists.
@@ -74,6 +77,8 @@ func SetDefaults() error {
c.Rate = 0.0 c.Rate = 0.0
c.BackendURL = "https://xplane-webrtc.akilan.io" c.BackendURL = "https://xplane-webrtc.akilan.io"
c.ScreenName = "Entire screen" c.ScreenName = "Entire screen"
c.InternalGameServerPort = "8088"
c.InternalScreenSharePort = "8888"
file, _ := json.MarshalIndent(c, "", " ") file, _ := json.MarshalIndent(c, "", " ")
@@ -179,7 +184,7 @@ func (c *Config) WriteConfig() error {
//defaults["IPAddress"] = c.IPAddress //defaults["IPAddress"] = c.IPAddress
//defaults["ScriptToExecute"] = c.ScriptToExecute //defaults["ScriptToExecute"] = c.ScriptToExecute
//defaults["SSHPassword"] = c.SSHPassword //defaults["SSHPassword"] = c.SSHPassword
//defaults["NATEscapeServerPort"] = c.NATEscapeServerPort //defaults["NATEscapeGameServerPort"] = c.NATEscapeGameServerPort
//defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort //defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort
// If the config file exists remove and make a new one // If the config file exists remove and make a new one

View File

@@ -1,6 +1,7 @@
package core package core
import ( import (
"crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@@ -47,7 +48,7 @@ func BroadcastServerToBackend() error {
// Game session url // Game session url
//+ file.ID //+ file.ID
gameSession.Link = respIpv4orIPv6 + ":" + config.NATEscapeServerPort + "/?id=" + room.ID gameSession.Link = respIpv4orIPv6 + ":" + config.NATEscapeGameServerPort + "/?id=" + room.ID
// Rate for the game session // Rate for the game session
gameSession.Rate = config.Rate gameSession.Rate = config.Rate
// Server specs to struct GameSession // Server specs to struct GameSession
@@ -75,6 +76,7 @@ func BroadcastServerToBackend() error {
} }
form.Add("CPU", gameSession.Server.CPU) form.Add("CPU", gameSession.Server.CPU)
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("POST", config.BackendURL+"AddGameSession", strings.NewReader(form.Encode())) req, err := http.NewRequest("POST", config.BackendURL+"AddGameSession", strings.NewReader(form.Encode()))
if err != nil { if err != nil {
return err return err

View File

@@ -8,7 +8,7 @@ import (
// EscapeNAT Func to escape NAT // EscapeNAT Func to escape NAT
// - 1 port for server // - 1 port for server
// - 2 port for barrierKVM // - 2 port for barrierKVM
func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error) { func EscapeNAT(ScreenSharePort, GameplayServerPort string) (ServerPort string, ScreensharePort string, barrierKVMport string, err error) {
// Get free port from P2PRC server node // Get free port from P2PRC server node
serverPort, err := frp.GetFRPServerPort("http://64.227.168.102:8088") serverPort, err := frp.GetFRPServerPort("http://64.227.168.102:8088")
@@ -19,7 +19,22 @@ func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
// port for the remote gameplay server // port for the remote gameplay server
ServerPort, err = frp.StartFRPClientForServer("64.227.168.102", serverPort, Port) ServerPort, err = frp.StartFRPClientForServer("64.227.168.102", serverPort, GameplayServerPort)
if err != nil {
return
}
// Get free port from P2PRC server node
ScreensharePort, err = frp.GetFRPServerPort("http://64.227.168.102:8088")
if err != nil {
return
}
time.Sleep(1 * time.Second)
// port for the screenshare port
ScreensharePort, err = frp.StartFRPClientForServer("64.227.168.102", ScreensharePort, ScreenSharePort)
if err != nil { if err != nil {
return return
} }

73
main.go
View File

@@ -16,7 +16,7 @@ import (
func main() { func main() {
addr := flag.String("addr", "0.0.0.0", "Listen address") addr := flag.String("addr", "0.0.0.0", "Listen address")
port := flag.String("port", "8888", "port for running the server") //port := flag.String("port", "8888", "port for running the server")
tls := flag.Bool("tls", false, "Use TLS") tls := flag.Bool("tls", false, "Use TLS")
setconfig := flag.Bool("setconfig", false, "Generates a config file") setconfig := flag.Bool("setconfig", false, "Generates a config file")
certFile := flag.String("certFile", "files/server.crt", "TLS cert file") certFile := flag.String("certFile", "files/server.crt", "TLS cert file")
@@ -25,9 +25,10 @@ func main() {
roomInfo := flag.Bool("roomInfo", false, "Getting room id of headless server") roomInfo := flag.Bool("roomInfo", false, "Getting room id of headless server")
killServer := flag.Bool("killServer", false, "Kills the laplace") killServer := flag.Bool("killServer", false, "Kills the laplace")
killChromium := flag.Bool("killChromium", false, "Kills all chromuim") killChromium := flag.Bool("killChromium", false, "Kills all chromuim")
BinaryToExcute := flag.String("BinaryToExecute", "", "Providing path (i.e Absolute path) of binary to execute") BinaryToExecute := flag.String("BinaryToExecute", "", "Providing path (i.e Absolute path) of binary to execute")
GameServer := flag.Bool("GameServer", false, "Starts the game server by default") GameServer := flag.Bool("GameServer", false, "Starts the game server by default")
Migrate := flag.Bool("Migrate", false, "Sets up the tables for the Sqlite database") Migrate := flag.Bool("Migrate", false, "Sets up the tables for the Sqlite database")
BothServers := flag.Bool("BothServers", false, "Starts the Gameserver and screenshare. Also ensures the screenshare can broadcast the availability to the game server")
flag.Parse() flag.Parse()
@@ -86,19 +87,20 @@ func main() {
return return
} }
// running implementation to escape NAT
Server, barrireKVM, err := core.EscapeNAT(*port)
if err != nil {
log.Fatalln(err)
}
Config, err := config.ConfigInit() Config, err := config.ConfigInit()
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
// running implementation to escape NAT
GameServerPort, ScreenSharePort, barrireKVM, err := core.EscapeNAT(Config.InternalScreenSharePort, Config.InternalGameServerPort)
if err != nil {
log.Fatalln(err)
}
Config.IPAddress = "64.227.168.102" Config.IPAddress = "64.227.168.102"
Config.NATEscapeServerPort = Server Config.NATEscapeGameServerPort = GameServerPort
Config.NATEscapeScreenSharePort = ScreenSharePort
Config.NATEscapeBarrierPort = barrireKVM Config.NATEscapeBarrierPort = barrireKVM
err = Config.WriteConfig() err = Config.WriteConfig()
@@ -106,6 +108,37 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
// If both server and screenshare have be triggered (first set the according flags to true)
if *BothServers {
*headless = true
*tls = true
*GameServer = true
}
if *GameServer {
go gameserver.Server(Config.InternalGameServerPort)
}
if !*GameServer || *BothServers {
if *tls {
log.Println("Listening on TLS:", *addr+":"+Config.InternalScreenSharePort)
go http.ListenAndServeTLS(*addr+":"+Config.InternalScreenSharePort, *certFile, *keyFile, server)
} else {
log.Println("Listening:", *addr+":"+Config.InternalScreenSharePort)
go http.ListenAndServe(*addr+":"+Config.InternalScreenSharePort, server)
}
}
// If both server selected set the remote Gameserver to local now.
if *BothServers {
Config.BackendURL = "http://" + Config.IPAddress + ":" + Config.NATEscapeGameServerPort + "/"
err = Config.WriteConfig()
if err != nil {
fmt.Println(err)
return
}
}
// Running in headless mode // Running in headless mode
if *headless { if *headless {
// Running starting a browser as a background process // Running starting a browser as a background process
@@ -127,15 +160,15 @@ func main() {
var TaskExecute string var TaskExecute string
if *BinaryToExcute != "" { if *BinaryToExecute != "" {
TaskExecute = *BinaryToExcute TaskExecute = *BinaryToExecute
} else { } else {
// Read binary from config file // Read binary from config file
TaskExecute = Config.ScriptToExecute TaskExecute = Config.ScriptToExecute
} }
// Starting screen share headless // Starting screen share headless
cmd := exec.Command(Config.BrowserCommand, "--no-sandbox", "--auto-select-desktop-capture-source="+Config.ScreenName, "--url", "https://"+*addr+":"+*port+"/?mode=headless", "--ignore-certificate-errors") cmd := exec.Command(Config.BrowserCommand, "--no-sandbox", "--auto-select-desktop-capture-source="+Config.ScreenName, "--url", "https://"+*addr+":"+Config.InternalScreenSharePort+"/?mode=headless", "--ignore-certificate-errors")
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@@ -160,20 +193,8 @@ func main() {
} }
if *GameServer { for {
gameserver.Server(*port)
} else {
if *tls {
log.Println("Listening on TLS:", *addr+":"+*port)
if err := http.ListenAndServeTLS(*addr+":"+*port, *certFile, *keyFile, server); err != nil {
log.Fatalln(err)
}
} else {
log.Println("Listening:", *addr+":"+*port)
if err := http.ListenAndServe(*addr+":"+*port, server); err != nil {
log.Fatalln(err)
}
}
} }
// Start P2PRC server // Start P2PRC server