From ceaaf675102701d7043a44b79e89157c20c81741 Mon Sep 17 00:00:00 2001 From: pztrn Date: Thu, 6 Oct 2016 22:19:03 +0500 Subject: [PATCH] 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. --- context/context_object.go | 8 +++++++- launcher/launcher_object.go | 24 +++++++++++++++++++++++- ui/mainwindow.go | 15 ++++++++++++--- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/context/context_object.go b/context/context_object.go index eb94d33..a74577f 100644 --- a/context/context_object.go +++ b/context/context_object.go @@ -11,6 +11,7 @@ package context import ( // stdlib + "errors" "fmt" // local @@ -43,14 +44,19 @@ type Context struct { Requester *requester.Requester } -func (ctx *Context) Close() { +func (ctx *Context) Close() error { fmt.Println("Closing URTrator...") + launched := ctx.Launcher.CheckForLaunchedUrbanTerror() + if launched != nil { + return errors.New("Urban Terror is launched!") + } ctx.Cache.FlushServers() ctx.Database.Close() // At last, close main window. gtk.MainQuit() + return nil } func (ctx *Context) initializeCache() { diff --git a/launcher/launcher_object.go b/launcher/launcher_object.go index daa6206..b050739 100644 --- a/launcher/launcher_object.go +++ b/launcher/launcher_object.go @@ -11,6 +11,7 @@ package launcher import ( // stdlib + "errors" "fmt" "os" "os/exec" @@ -19,9 +20,30 @@ import ( // local "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 { current_display_raw := os.Getenv("DISPLAY") diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 715cf6d..a2fbb9c 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -319,9 +319,10 @@ func (m *MainWindow) hideOfflineFavoriteServers() { // Main window initialization. func (m *MainWindow) Initialize() { + gtk.Init(nil) + m.initializeStorages() - gtk.Init(nil) m.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL) m.window.SetTitle("URTrator") m.window.Connect("destroy", m.Close) @@ -950,7 +951,8 @@ func (m *MainWindow) loadAllServers() { fmt.Println("Loading all servers...") // ToDo: do it without clearing. 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 } iter := new (gtk.TreeIter) @@ -1076,8 +1078,15 @@ func (m *MainWindow) showShortServerInformation() { model.GetValue(iter, 7, srv_address_gval) 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. - if len(srv_address) > 0 { + if len(srv_address) > 0 && ping < 1000 { server_info := ctx.Cache.Servers[srv_address].Server parsed_general_data := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig) parsed_players_info := ioq3dataparser.ParsePlayersInfoToMap(server_info.PlayersInfo)