This commit is contained in:
cfunder 2022-09-25 20:40:21 -04:00
parent 0c7202e650
commit 1a7c164690
No known key found for this signature in database
GPG Key ID: 15227A6455DDF7EE
4 changed files with 96 additions and 34 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/

View File

@ -1,31 +1,6 @@
# Legal
When including `libmcpilauncher` in your project, you must include these license notices, additionally with the `libmcpilauncher` license notice at the root of the project:
### subprocess license
```
MIT License
Copyright (c) 2018 Christopher Simpkins
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
### Golang Standart Library licenses
```
The Go source code and supporting files in this directory

80
launcher.go Normal file
View File

@ -0,0 +1,80 @@
package launcher
import (
"strings"
"fmt"
"os/exec"
"os"
)
// Fetch the options from an executable_path as a map.
// executable_path must be a string with an executable
// that provides --print-available-feature-flags and its
// functionality.
func GetOptionsMap(executable_path string) map[string]bool {
flags_unformatted, _ := exec.Command(executable_path, "--print-available-feature-flags").Output()
flags_newline_split := strings.Split(string(flags_unformatted), "\n")
//fmt.Println(flags_newline_split)
flags_formatted := map[string]bool{}
for i := 0; i <= len(flags_newline_split)-1; i++ {
flag := flags_newline_split[i]
if strings.HasPrefix(flag, "TRUE") {
flags_formatted[string((flag[5:]))] = true
} else if strings.HasPrefix(flag, "FALSE") {
flags_formatted[string(flag[6:])] = false
}
//fmt.Println(flags_formatted) // Debug
}
//fmt.Println(flags_formatted)
return flags_formatted
}
// Same as GetOptionsMap but returns a slice of option
// names instead of options and their values.
func GetOptionsList (executable_path string) []string {
flags_map := GetOptionsMap(executable_path)
flags_slice := []string{}
for key, _ := range flags_map {
flags_slice = append(flags_slice, key)
}
return flags_slice
}
// Launch the game provided the executable path
// Features must be a slice with strings of enabled features.
func Launch (
executable_path string,
username string,
render_distance string,
debug bool,
features []string,
benchmark bool,
) *exec.Cmd {
var executable_args []string // Arguments slice
// Set the arguments
if debug{
executable_args = append(executable_args, "--debug")
}
if benchmark {
executable_args = append(executable_args, "--benchmark")
}
cmd := exec.Command(executable_path, executable_args...) // Executable init
cmd.Env = os.Environ() // This is required, without this Reborn won't work.
features_string := strings.Join(features, "|") // Python equievelent of .join
cmd.Env = append(cmd.Env, // Append the enviroment variables
"MCPI_USERNAME="+username,
"MCPI_RENDER_DISTANCE="+render_distance,
"MCPI_FEATURE_FLAGS="+features_string,
)
// Return the Cmd object to let the user do anything they want with it
return cmd
}

View File

@ -1,9 +0,0 @@
package libmcpilauncher
import (
subprocess "gopkg.in/go-rillas/subprocess.v1"
)
func GetOptionsMap(excutable_path string) map[string]bool {
}