added go code to start laplace server

This commit is contained in:
2021-07-19 23:19:27 +04:00
parent 0913e173df
commit dad6165754
9 changed files with 134 additions and 0 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
config.json config.json
env/
remotegameplay

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/remotegameplay.iml" filepath="$PROJECT_DIR$/.idea/remotegameplay.iml" />
</modules>
</component>
</project>

9
.idea/remotegameplay.iml generated Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/Akilan1999/remotegameplay
go 1.16

87
main.go Normal file
View File

@@ -0,0 +1,87 @@
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
)
func main() {
err := LaplaceConfig()
if err != nil {
fmt.Println(err)
}
_, err = LaplaceServer(23424)
if err != nil {
fmt.Println(err)
}
}
// LaplaceConfig Sets up the laplace configuration
func LaplaceConfig() error {
// Setting up environment variable Laplace
curDir := os.Getenv("PWD")
os.Setenv("LAPLACE", curDir)
cmd := exec.Command("./laplace","-setconfig")
// USE THE FOLLOWING TO DEBUG
//cmdReader, err := cmd.StdoutPipe()
//if err != nil {
// fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err)
// return
//}
//
//// the following is used to print output of the command
//// as it makes progress...
//scanner := bufio.NewScanner(cmdReader)
//go func() {
// for scanner.Scan() {
// fmt.Printf("%s\n", scanner.Text())
// //
// // TODO:
// // send output to server
// }
//}()
//
//if err := cmd.Start(); err != nil {
// return err
//}
if err := cmd.Run(); err != nil {
return err
}
return nil
}
// LaplaceServer Executes the laplace server
func LaplaceServer(port int)(*exec.Cmd, error) {
cmd := exec.Command("./laplace","-tls","-addr","0.0.0.0:" + fmt.Sprint(port))
// USE THE FOLLOWING TO DEBUG
cmdReader, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err)
return nil, err
}
// the following is used to print output of the command
// as it makes progress...
scanner := bufio.NewScanner(cmdReader)
go func() {
for scanner.Scan() {
fmt.Printf("%s\n", scanner.Text())
//
// TODO:
// send output to server
}
}()
if err = cmd.Run(); err != nil {
return nil, err
}
return cmd, nil
}

0
requirements.txt Normal file
View File

11
site.yml Normal file
View File

@@ -0,0 +1,11 @@
---
- hosts: all
tasks:
- name: set config for laplace
ansible.builtin.script: ./laplace -setconfig
- name: run laplace
ansible.builtin.script: ./laplace -tls -addr 0.0.0.0:8888