Urban Terror launch check on shutdown.
Added checking if Urban Terror launched while trying to shut down URTrator. If yes - we will show error message and won't quit, until Urban Terror will be dead.
This commit is contained in:
parent
e87d51b1e3
commit
ceaaf67510
@ -11,6 +11,7 @@ package context
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
// stdlib
|
// stdlib
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
// local
|
// local
|
||||||
@ -43,14 +44,19 @@ type Context struct {
|
|||||||
Requester *requester.Requester
|
Requester *requester.Requester
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *Context) Close() {
|
func (ctx *Context) Close() error {
|
||||||
fmt.Println("Closing URTrator...")
|
fmt.Println("Closing URTrator...")
|
||||||
|
|
||||||
|
launched := ctx.Launcher.CheckForLaunchedUrbanTerror()
|
||||||
|
if launched != nil {
|
||||||
|
return errors.New("Urban Terror is launched!")
|
||||||
|
}
|
||||||
ctx.Cache.FlushServers()
|
ctx.Cache.FlushServers()
|
||||||
ctx.Database.Close()
|
ctx.Database.Close()
|
||||||
|
|
||||||
// At last, close main window.
|
// At last, close main window.
|
||||||
gtk.MainQuit()
|
gtk.MainQuit()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx *Context) initializeCache() {
|
func (ctx *Context) initializeCache() {
|
||||||
|
@ -11,6 +11,7 @@ package launcher
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
// stdlib
|
// stdlib
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -19,9 +20,30 @@ import (
|
|||||||
|
|
||||||
// local
|
// local
|
||||||
"github.com/pztrn/urtrator/datamodels"
|
"github.com/pztrn/urtrator/datamodels"
|
||||||
|
|
||||||
|
// Github
|
||||||
|
"github.com/mattn/go-gtk/gtk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Launcher struct {}
|
type Launcher struct {
|
||||||
|
// Flags.
|
||||||
|
// Is Urban Terror launched ATM?
|
||||||
|
launched bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Launcher) CheckForLaunchedUrbanTerror() error {
|
||||||
|
if l.launched {
|
||||||
|
mbox_string := "Game is launched.\n\nCannot quit, because game is launched.\nQuit Urban Terror to exit URTrator!"
|
||||||
|
m := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, mbox_string)
|
||||||
|
m.Response(func() {
|
||||||
|
m.Destroy()
|
||||||
|
})
|
||||||
|
m.Run()
|
||||||
|
return errors.New("User didn't select valid profile, mismatch with server's version.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Launcher) findFreeDisplay() string {
|
func (l *Launcher) findFreeDisplay() string {
|
||||||
current_display_raw := os.Getenv("DISPLAY")
|
current_display_raw := os.Getenv("DISPLAY")
|
||||||
|
@ -319,9 +319,10 @@ func (m *MainWindow) hideOfflineFavoriteServers() {
|
|||||||
|
|
||||||
// Main window initialization.
|
// Main window initialization.
|
||||||
func (m *MainWindow) Initialize() {
|
func (m *MainWindow) Initialize() {
|
||||||
|
gtk.Init(nil)
|
||||||
|
|
||||||
m.initializeStorages()
|
m.initializeStorages()
|
||||||
|
|
||||||
gtk.Init(nil)
|
|
||||||
m.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
m.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
|
||||||
m.window.SetTitle("URTrator")
|
m.window.SetTitle("URTrator")
|
||||||
m.window.Connect("destroy", m.Close)
|
m.window.Connect("destroy", m.Close)
|
||||||
@ -950,7 +951,8 @@ func (m *MainWindow) loadAllServers() {
|
|||||||
fmt.Println("Loading all servers...")
|
fmt.Println("Loading all servers...")
|
||||||
// ToDo: do it without clearing.
|
// ToDo: do it without clearing.
|
||||||
for _, server := range ctx.Cache.Servers {
|
for _, server := range ctx.Cache.Servers {
|
||||||
if m.all_servers_hide_offline.GetActive() && server.Server.Name == "" && server.Server.Players == "" {
|
ping, _ := strconv.Atoi(server.Server.Ping)
|
||||||
|
if m.all_servers_hide_offline.GetActive() && ping > 9999 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
iter := new (gtk.TreeIter)
|
iter := new (gtk.TreeIter)
|
||||||
@ -1076,8 +1078,15 @@ func (m *MainWindow) showShortServerInformation() {
|
|||||||
model.GetValue(iter, 7, srv_address_gval)
|
model.GetValue(iter, 7, srv_address_gval)
|
||||||
srv_address := srv_address_gval.GetString()
|
srv_address := srv_address_gval.GetString()
|
||||||
|
|
||||||
|
var srv_ping_raw string
|
||||||
|
srv_ping_gval := glib.ValueFromNative(srv_ping_raw)
|
||||||
|
model.GetValue(iter, 7, srv_ping_gval)
|
||||||
|
srv_ping := srv_ping_gval.GetString()
|
||||||
|
|
||||||
|
ping, _ := strconv.Atoi(srv_ping)
|
||||||
|
|
||||||
// Getting server information from cache.
|
// Getting server information from cache.
|
||||||
if len(srv_address) > 0 {
|
if len(srv_address) > 0 && ping < 1000 {
|
||||||
server_info := ctx.Cache.Servers[srv_address].Server
|
server_info := ctx.Cache.Servers[srv_address].Server
|
||||||
parsed_general_data := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig)
|
parsed_general_data := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig)
|
||||||
parsed_players_info := ioq3dataparser.ParsePlayersInfoToMap(server_info.PlayersInfo)
|
parsed_players_info := ioq3dataparser.ParsePlayersInfoToMap(server_info.PlayersInfo)
|
||||||
|
Reference in New Issue
Block a user