diff --git a/README.md b/README.md index ffc6634..ac3694f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Planning: * Game updating (not from official servers yet, sorry). * Pickup/matchmaking interfaces. * All kinds of notifications. +* Extended profile editor, so every profile could have own configuration +files, etc. +* Clipboard monitoring. * ...maybe more :) # Installation diff --git a/launcher/launcher_object.go b/launcher/launcher_object.go index 0917f6a..daa6206 100644 --- a/launcher/launcher_object.go +++ b/launcher/launcher_object.go @@ -12,34 +12,72 @@ package launcher import ( // stdlib "fmt" + "os" "os/exec" + "strconv" + "strings" + + // local + "github.com/pztrn/urtrator/datamodels" ) type Launcher struct {} +func (l *Launcher) findFreeDisplay() string { + current_display_raw := os.Getenv("DISPLAY") + current_display, _ := strconv.Atoi(strings.Split(current_display_raw, ":")[1]) + current_display += 1 + return strconv.Itoa(current_display) +} + func (l *Launcher) Initialize() { fmt.Println("Initializing game launcher...") } -func (l *Launcher) Launch(binary string, params string, server string, password string, second_x bool, callback func()) { +func (l *Launcher) Launch(profile *datamodels.Profile, server string, password string, callback func()) { // ToDo: only one instance of Urban Terror should be launched, so button // should be disabled. fmt.Println("Launching Urban Terror...") done := make(chan bool, 1) + // Create launch string. - var launch_string string = params + " +connect " + server - if len(password) > 0 { - launch_string += " +password " + password + var launch_bin string = "" + launch_bin, err := exec.LookPath(profile.Binary) + if err != nil { + fmt.Println(err.Error()) } - fmt.Println("Final command: " + launch_string) + + var launch_params []string + if len(server) > 0 { + launch_params = append(launch_params, "+connect", server) + } + if len(password) > 0 { + launch_params = append(launch_params, "+password", password) + } + if len(profile.Additional_params) > 0 { + additional_params := strings.Split(profile.Additional_params, " ") + launch_params = append(launch_params, additional_params...) + } + if profile.Second_x_session == "1" { + fmt.Println(launch_params) + launch_params = append([]string{launch_bin}, launch_params...) + display := l.findFreeDisplay() + launch_bin, err = exec.LookPath("xinit") + if err != nil { + fmt.Println(err.Error()) + } + launch_params = append(launch_params, "--", ":" + display) + } + fmt.Println(launch_params) go func() { go func() { - cmd := exec.Command(binary, launch_string) - err := cmd.Run() - if err != nil { - fmt.Println("Launch error: " + err.Error()) + cmd := exec.Command(launch_bin, launch_params...) + out, err1 := cmd.Output() + if err1 != nil { + fmt.Println("Launch error: " + err1.Error()) } + fmt.Println(string(out)) done <- true }() diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 7e4a47f..56007b9 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -468,7 +468,7 @@ func (m *MainWindow) launchGame() error { m.statusbar.Push(m.statusbar_context_id, "Launching Urban Terror...") m.launch_button.SetSensitive(false) // ToDo: handling server passwords. - ctx.Launcher.Launch(profile[0].Binary, profile[0].Additional_params, srv_address, "", m.unlockInterface) + ctx.Launcher.Launch(&profile[0], srv_address, "", m.unlockInterface) return nil }