From e12bcdd386df1a0b2b9dd4e0a45a1030a68b1519 Mon Sep 17 00:00:00 2001 From: pztrn Date: Sun, 9 Oct 2016 01:23:38 +0500 Subject: [PATCH] Fixed favorite server addition and saving. --- cache/cache_servers.go | 6 ++++-- ui/favorite.go | 1 + ui/mainwindow.go | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cache/cache_servers.go b/cache/cache_servers.go index ca18e47..0fbe961 100644 --- a/cache/cache_servers.go +++ b/cache/cache_servers.go @@ -63,6 +63,7 @@ func (c *Cache) FlushServers(data map[string]string) { new_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig new_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo new_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate + new_servers[mapping_item_name].Favorite = s.Server.Favorite } else { cached_servers[mapping_item_name].Ip = s.Server.Ip cached_servers[mapping_item_name].Port = s.Server.Port @@ -76,6 +77,7 @@ func (c *Cache) FlushServers(data map[string]string) { cached_servers[mapping_item_name].ExtendedConfig = s.Server.ExtendedConfig cached_servers[mapping_item_name].PlayersInfo = s.Server.PlayersInfo cached_servers[mapping_item_name].IsPrivate = s.Server.IsPrivate + cached_servers[mapping_item_name].Favorite = s.Server.Favorite } } @@ -84,12 +86,12 @@ func (c *Cache) FlushServers(data map[string]string) { fmt.Println("Adding new servers...") if len(new_servers) > 0 { for _, srv := range new_servers { - tx.NamedExec("INSERT INTO servers (ip, port, name, ping, players, maxplayers, gamemode, map, version, extended_config, players_info, is_private) VALUES (:ip, :port, :name, :ping, :players, :maxplayers, :gamemode, :map, :version, :extended_config, :players_info, :is_private)", srv) + tx.NamedExec("INSERT INTO servers (ip, port, name, ping, players, maxplayers, gamemode, map, version, extended_config, players_info, is_private, favorite) VALUES (:ip, :port, :name, :ping, :players, :maxplayers, :gamemode, :map, :version, :extended_config, :players_info, :is_private, :favorite)", srv) } } fmt.Println("Updating cached servers...") for _, srv := range cached_servers { - _, err := tx.NamedExec("UPDATE servers SET name=:name, players=:players, maxplayers=:maxplayers, gamemode=:gamemode, map=:map, ping=:ping, version=:version, extended_config=:extended_config, players_info=:players_info, is_private=:is_private WHERE ip=:ip AND port=:port", &srv) + _, err := tx.NamedExec("UPDATE servers SET name=:name, players=:players, maxplayers=:maxplayers, gamemode=:gamemode, map=:map, ping=:ping, version=:version, extended_config=:extended_config, favorite=:favorite, password=:password, players_info=:players_info, is_private=:is_private WHERE ip=:ip AND port=:port", &srv) if err != nil { fmt.Println(err.Error()) } diff --git a/ui/favorite.go b/ui/favorite.go index 320250d..da8a95a 100644 --- a/ui/favorite.go +++ b/ui/favorite.go @@ -245,6 +245,7 @@ func (f *FavoriteDialog) saveFavorite() error { ctx.Cache.Servers[key].Server.ExtendedConfig = f.server.ExtendedConfig ctx.Cache.Servers[key].Server.PlayersInfo = f.server.PlayersInfo + ctx.Eventer.LaunchEvent("flushServers", map[string]string{}) ctx.Eventer.LaunchEvent("loadFavoriteServers", map[string]string{}) f.window.Destroy() diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 027be19..8ea0cd3 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -135,7 +135,10 @@ func (m *MainWindow) addToFavorites() { current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) - server_address := m.getIpFromServersList(current_tab) + server_address := "" + if !strings.Contains(current_tab, "Favorites") { + server_address = m.getIpFromServersList(current_tab) + } // Getting server from database. m.favorite_dialog = &FavoriteDialog{}