remote gaming UI with Barrier added
This commit is contained in:
428
main.go
428
main.go
@@ -1,264 +1,268 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Akilan1999/remotegameplay/config"
|
"github.com/Akilan1999/remotegameplay/config"
|
||||||
"github.com/Akilan1999/remotegameplay/core"
|
"github.com/Akilan1999/remotegameplay/core"
|
||||||
gameserver "github.com/Akilan1999/remotegameplay/server"
|
gameserver "github.com/Akilan1999/remotegameplay/server"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
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")
|
||||||
barrier := flag.Bool("barrier", false, "set external port barrier")
|
barrier := flag.Bool("barrier", false, "set external port barrier")
|
||||||
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")
|
||||||
keyFile := flag.String("keyFile", "files/server.key", "TLS key file")
|
keyFile := flag.String("keyFile", "files/server.key", "TLS key file")
|
||||||
headless := flag.Bool("headless", false, "Creating screenshare using headless mode")
|
headless := flag.Bool("headless", false, "Creating screenshare using headless mode")
|
||||||
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")
|
||||||
BinaryToExecute := 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")
|
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()
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
server := core.GetHttp()
|
server := core.GetHttp()
|
||||||
|
|
||||||
if *setconfig {
|
if *setconfig {
|
||||||
err := config.SetDefaults()
|
err := config.SetDefaults()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Config, err := config.ConfigInit()
|
Config, err := config.ConfigInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if barrier flag is provided
|
// if barrier flag is provided
|
||||||
if *barrier {
|
if *barrier {
|
||||||
natBarrier, err := core.EscapeNATBarrier()
|
natBarrier, err := core.EscapeNATBarrier()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Config.NATEscapeBarrierPort = natBarrier
|
Config.NATEscapeBarrierPort = natBarrier
|
||||||
err = Config.WriteConfig()
|
err = Config.WriteConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println(Config.IPAddress + ":" + Config.NATEscapeBarrierPort)
|
fmt.Println(Config.IPAddress + ":" + Config.NATEscapeBarrierPort)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print out room information
|
// Starts infinite loop to FRP server running for escaping NAT
|
||||||
if *roomInfo {
|
for {
|
||||||
room, err := core.ReadRoomsFile()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
PrettyPrint(room)
|
}
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// kills laplace server
|
// Print out room information
|
||||||
if *killServer {
|
if *roomInfo {
|
||||||
cmd := exec.Command("pkill", "remotegameplay")
|
room, err := core.ReadRoomsFile()
|
||||||
if err := cmd.Run(); err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
// kills chromium server
|
|
||||||
if *killChromium {
|
|
||||||
cmd := exec.Command("pkill", "chromium")
|
|
||||||
if err := cmd.Run(); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if *Migrate {
|
PrettyPrint(room)
|
||||||
// Connect to Sqlite
|
return
|
||||||
connect, err := gameserver.Connect()
|
}
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
// Migrate table
|
|
||||||
session, err := gameserver.CreateTables(connect)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
session.Scan(gameserver.GameSession{})
|
|
||||||
|
|
||||||
return
|
// kills laplace server
|
||||||
}
|
if *killServer {
|
||||||
|
cmd := exec.Command("pkill", "remotegameplay")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// kills chromium server
|
||||||
|
if *killChromium {
|
||||||
|
cmd := exec.Command("pkill", "chromium")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// running implementation to escape NAT
|
if *Migrate {
|
||||||
GameServerPort, ScreenSharePort, err := core.EscapeNAT(Config.InternalScreenSharePort, Config.InternalGameServerPort)
|
// Connect to Sqlite
|
||||||
if err != nil {
|
connect, err := gameserver.Connect()
|
||||||
log.Fatalln(err)
|
if err != nil {
|
||||||
}
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
// Migrate table
|
||||||
|
session, err := gameserver.CreateTables(connect)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
session.Scan(gameserver.GameSession{})
|
||||||
|
|
||||||
Config.IPAddress = "64.227.168.102"
|
return
|
||||||
Config.NATEscapeGameServerPort = GameServerPort
|
}
|
||||||
Config.NATEscapeScreenSharePort = ScreenSharePort
|
|
||||||
Config.NATEscapeBarrierPort = ""
|
|
||||||
|
|
||||||
err = Config.WriteConfig()
|
// running implementation to escape NAT
|
||||||
if err != nil {
|
GameServerPort, ScreenSharePort, err := core.EscapeNAT(Config.InternalScreenSharePort, Config.InternalGameServerPort)
|
||||||
log.Fatalln(err)
|
if err != nil {
|
||||||
}
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
// If both server and screenshare have be triggered (first set the according flags to true)
|
Config.IPAddress = "64.227.168.102"
|
||||||
if *BothServers {
|
Config.NATEscapeGameServerPort = GameServerPort
|
||||||
*headless = true
|
Config.NATEscapeScreenSharePort = ScreenSharePort
|
||||||
*tls = true
|
Config.NATEscapeBarrierPort = ""
|
||||||
*GameServer = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if *GameServer {
|
err = Config.WriteConfig()
|
||||||
go gameserver.Server(Config.InternalGameServerPort)
|
if err != nil {
|
||||||
time.Sleep(2 * time.Second)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !*GameServer || *BothServers {
|
// If both server and screenshare have be triggered (first set the according flags to true)
|
||||||
if *tls {
|
if *BothServers {
|
||||||
log.Println("Listening on TLS:", *addr+":"+Config.InternalScreenSharePort)
|
*headless = true
|
||||||
go http.ListenAndServeTLS(*addr+":"+Config.InternalScreenSharePort, *certFile, *keyFile, server)
|
*tls = true
|
||||||
time.Sleep(2 * time.Second)
|
*GameServer = true
|
||||||
} else {
|
}
|
||||||
log.Println("Listening:", *addr+":"+Config.InternalScreenSharePort)
|
|
||||||
go http.ListenAndServe(*addr+":"+Config.InternalScreenSharePort, server)
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If both server selected set the remote Gameserver to local now.
|
if *GameServer {
|
||||||
if *BothServers {
|
go gameserver.Server(Config.InternalGameServerPort)
|
||||||
Config.BackendURL = "http://" + Config.IPAddress + ":" + Config.NATEscapeGameServerPort + "/"
|
time.Sleep(2 * time.Second)
|
||||||
err = Config.WriteConfig()
|
}
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Running in headless mode
|
if !*GameServer || *BothServers {
|
||||||
if *headless {
|
if *tls {
|
||||||
// Running starting a browser as a background process
|
log.Println("Listening on TLS:", *addr+":"+Config.InternalScreenSharePort)
|
||||||
go func() {
|
go http.ListenAndServeTLS(*addr+":"+Config.InternalScreenSharePort, *certFile, *keyFile, server)
|
||||||
Config, err = config.ConfigInit()
|
time.Sleep(2 * time.Second)
|
||||||
if err != nil {
|
} else {
|
||||||
log.Fatalln(err)
|
log.Println("Listening:", *addr+":"+Config.InternalScreenSharePort)
|
||||||
}
|
go http.ListenAndServe(*addr+":"+Config.InternalScreenSharePort, server)
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//// Returns the URl address type
|
// If both server selected set the remote Gameserver to local now.
|
||||||
//Addr := Ip4or6(Config.IPAddress)
|
if *BothServers {
|
||||||
//
|
Config.BackendURL = "http://" + Config.IPAddress + ":" + Config.NATEscapeGameServerPort + "/"
|
||||||
//// If address is provided
|
err = Config.WriteConfig()
|
||||||
//if *addr != "" {
|
if err != nil {
|
||||||
// Addr = *addr
|
fmt.Println(err)
|
||||||
// // Add brackets if the ip address is ipv6
|
return
|
||||||
// Addr = Ip4or6(Addr)
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
var TaskExecute string
|
// Running in headless mode
|
||||||
|
if *headless {
|
||||||
|
// Running starting a browser as a background process
|
||||||
|
go func() {
|
||||||
|
Config, err = config.ConfigInit()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
if *BinaryToExecute != "" {
|
//// Returns the URl address type
|
||||||
TaskExecute = *BinaryToExecute
|
//Addr := Ip4or6(Config.IPAddress)
|
||||||
} else {
|
//
|
||||||
// Read binary from config file
|
//// If address is provided
|
||||||
TaskExecute = Config.ScriptToExecute
|
//if *addr != "" {
|
||||||
}
|
// Addr = *addr
|
||||||
|
// // Add brackets if the ip address is ipv6
|
||||||
|
// Addr = Ip4or6(Addr)
|
||||||
|
//}
|
||||||
|
|
||||||
// Starting screen share headless
|
var TaskExecute string
|
||||||
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 {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes program sleep for 2 seconds to allow chromium browser to open
|
if *BinaryToExecute != "" {
|
||||||
time.Sleep(3 * time.Second)
|
TaskExecute = *BinaryToExecute
|
||||||
|
} else {
|
||||||
|
// Read binary from config file
|
||||||
|
TaskExecute = Config.ScriptToExecute
|
||||||
|
}
|
||||||
|
|
||||||
err = core.BroadcastServerToBackend()
|
// Starting screen share headless
|
||||||
if err != nil {
|
cmd := exec.Command(Config.BrowserCommand, "--no-sandbox", "--auto-select-desktop-capture-source="+Config.ScreenName, "--url", "https://"+*addr+":"+Config.InternalScreenSharePort+"/?mode=headless", "--ignore-certificate-errors")
|
||||||
fmt.Println(err)
|
if err := cmd.Start(); err != nil {
|
||||||
} else {
|
log.Fatalln(err)
|
||||||
fmt.Println("success broadcasting to game server")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Task to be executed
|
// Makes program sleep for 2 seconds to allow chromium browser to open
|
||||||
err = RunTask(TaskExecute)
|
time.Sleep(3 * time.Second)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
}
|
err = core.BroadcastServerToBackend()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("success broadcasting to game server")
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
// Task to be executed
|
||||||
|
err = RunTask(TaskExecute)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start P2PRC server
|
for {
|
||||||
//_, err = abstractions.Start()
|
|
||||||
//if err != nil {
|
}
|
||||||
// return
|
|
||||||
//}
|
// Start P2PRC server
|
||||||
|
//_, err = abstractions.Start()
|
||||||
|
//if err != nil {
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrettyPrint print the contents of the obj (
|
// PrettyPrint print the contents of the obj (
|
||||||
// Reference: https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console
|
// Reference: https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console
|
||||||
func PrettyPrint(data interface{}) {
|
func PrettyPrint(data interface{}) {
|
||||||
var p []byte
|
var p []byte
|
||||||
// var err := error
|
// var err := error
|
||||||
p, err := json.MarshalIndent(data, "", "\t")
|
p, err := json.MarshalIndent(data, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("%s \n", p)
|
fmt.Printf("%s \n", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
||||||
// IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
// IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
||||||
func Ip4or6(s string) string {
|
func Ip4or6(s string) string {
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
switch s[i] {
|
switch s[i] {
|
||||||
case '.':
|
case '.':
|
||||||
return s
|
return s
|
||||||
case ':':
|
case ':':
|
||||||
return "[" + s + "]"
|
return "[" + s + "]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "[" + s + "]"
|
return "[" + s + "]"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunTask(task string) error {
|
func RunTask(task string) error {
|
||||||
// Halts the process
|
// Halts the process
|
||||||
cmd := exec.Command("sh", task)
|
cmd := exec.Command("sh", task)
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,22 +155,31 @@
|
|||||||
<main class="modal__content" id="modal-1-content">
|
<main class="modal__content" id="modal-1-content">
|
||||||
{{ range .BarrierIPS }}
|
{{ range .BarrierIPS }}
|
||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault{{ .MachineName }}">
|
<button
|
||||||
<label class="form-check-label" for="flexRadioDefault{{ .MachineName }}">
|
type="button"
|
||||||
|
class="modal__btn modal__btn-primary"
|
||||||
|
onclick="goToLink({{ .BarrierIP }})"
|
||||||
|
data-micromodal-close
|
||||||
|
>
|
||||||
{{ .BarrierIP }} and {{ .MachineName }}
|
{{ .BarrierIP }} and {{ .MachineName }}
|
||||||
</label>
|
</button>
|
||||||
|
<!-- <input class="form-check-input" type="radio" name="flexRadioDefault" id="flexRadioDefault{{ .MachineName }}">-->
|
||||||
|
<!-- <label class="form-check-label" for="flexRadioDefault{{ .MachineName }}">-->
|
||||||
|
<!-- {{ .BarrierIP }} and {{ .MachineName }}-->
|
||||||
|
<!-- </label>-->
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</main>
|
</main>
|
||||||
<footer class="modal__footer">
|
<footer class="modal__footer">
|
||||||
<button
|
<!-- <button-->
|
||||||
type="button"
|
<!-- type="button"-->
|
||||||
class="modal__btn modal__btn-primary"
|
<!-- class="modal__btn modal__btn-primary"-->
|
||||||
onclick="goToLink()"
|
<!-- onclick="goToLink()"-->
|
||||||
data-micromodal-close
|
<!-- data-micromodal-close-->
|
||||||
>
|
<!-- >-->
|
||||||
Continue
|
<!-- Continue-->
|
||||||
</button>
|
<!-- </button>-->
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="modal__btn"
|
class="modal__btn"
|
||||||
@@ -202,11 +211,13 @@
|
|||||||
// set the link to the current link
|
// set the link to the current link
|
||||||
function setCurrentLink({ currentLink }) {
|
function setCurrentLink({ currentLink }) {
|
||||||
link = currentLink.slice(1, -1); //? get rid of the quotes
|
link = currentLink.slice(1, -1); //? get rid of the quotes
|
||||||
|
// If radio button is selected
|
||||||
|
// redirect based on the link provided
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the link in a new tab
|
// open the link in a new tab
|
||||||
function goToLink() {
|
function goToLink(barrierip) {
|
||||||
window.open(link, "_blank");
|
window.open(link + "&barrierip=" + barrierip, "_blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The function is called on OnClick action
|
// The function is called on OnClick action
|
||||||
|
|||||||
Reference in New Issue
Block a user