Many fixes and debug prints removed.
Removed debug prints, as we don't really need them now. Fixed database updating from cache, until now only inserts was working fine, updates failing. All because of forgotten comma :(. Reworked handling of icons in servers lists, now they didn't recreated, but reused from created on application start. Can also save us much memory for long runs. Moved gamemode detector to mainwindow_helpers, where it should be.
This commit is contained in:
parent
1fc5b925f6
commit
e46d203a3c
13
cache/cache_object.go
vendored
13
cache/cache_object.go
vendored
@ -84,17 +84,24 @@ func (c *Cache) FlushServers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Database.Unlock()
|
||||||
tx := Database.Db.MustBegin()
|
tx := Database.Db.MustBegin()
|
||||||
fmt.Println("Adding new servers...")
|
fmt.Println("Adding new servers...")
|
||||||
for _, srv := range new_servers {
|
if len(new_servers) > 0 {
|
||||||
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)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("Updating cached servers...")
|
fmt.Println("Updating cached servers...")
|
||||||
for _, srv := range cached_servers {
|
for _, srv := range cached_servers {
|
||||||
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, players_info=:players_info, is_private=:is_private WHERE ip=:ip AND port=:port", &srv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
Database.Lock()
|
||||||
fmt.Println("Done")
|
fmt.Println("Done")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,10 @@ func (d *Database) Initialize(cfg *configuration.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Database) Lock() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Database) Migrate() {
|
func (d *Database) Migrate() {
|
||||||
// Getting current database version.
|
// Getting current database version.
|
||||||
dbver := 0
|
dbver := 0
|
||||||
@ -91,3 +95,6 @@ func (d *Database) Migrate() {
|
|||||||
migrate_full(d, dbver)
|
migrate_full(d, dbver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Database) Unlock() {
|
||||||
|
runtime.UnlockOSThread()
|
||||||
|
}
|
||||||
|
@ -233,7 +233,6 @@ func (p *Pooler) updateSpecificServer(server *datamodels.Server) error {
|
|||||||
if len(received_lines) >= 2 {
|
if len(received_lines) >= 2 {
|
||||||
// Here we go, players information.
|
// Here we go, players information.
|
||||||
players := received_lines[2:]
|
players := received_lines[2:]
|
||||||
fmt.Println(players, len(players), len(players[0]))
|
|
||||||
// Calculate players!
|
// Calculate players!
|
||||||
if len(players) == 1 && len(players[0]) > 255 {
|
if len(players) == 1 && len(players[0]) > 255 {
|
||||||
server.Players = "0"
|
server.Players = "0"
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/pztrn/urtrator/ioq3dataparser"
|
"github.com/pztrn/urtrator/ioq3dataparser"
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
"github.com/mattn/go-gtk/gdkpixbuf"
|
||||||
"github.com/mattn/go-gtk/glib"
|
"github.com/mattn/go-gtk/glib"
|
||||||
"github.com/mattn/go-gtk/gtk"
|
"github.com/mattn/go-gtk/gtk"
|
||||||
)
|
)
|
||||||
@ -111,6 +112,17 @@ type MainWindow struct {
|
|||||||
// Real columns positions on servers tabs.
|
// Real columns positions on servers tabs.
|
||||||
column_pos map[string]map[string]int
|
column_pos map[string]map[string]int
|
||||||
|
|
||||||
|
// Resources.
|
||||||
|
// Pixbufs.
|
||||||
|
// For unavailable (e.g. offline) server.
|
||||||
|
server_offline_pic *gdkpixbuf.Pixbuf
|
||||||
|
// For online server.
|
||||||
|
server_online_pic *gdkpixbuf.Pixbuf
|
||||||
|
// For private (passworded) server.
|
||||||
|
server_passworded_pic *gdkpixbuf.Pixbuf
|
||||||
|
// For public server
|
||||||
|
server_public_pic *gdkpixbuf.Pixbuf
|
||||||
|
|
||||||
|
|
||||||
// Flags.
|
// Flags.
|
||||||
// Window is hidden?
|
// Window is hidden?
|
||||||
@ -252,16 +264,6 @@ func (m *MainWindow) editFavorite() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MainWindow) getGameModeName(name string) string {
|
|
||||||
val, ok := m.gamemodes[name]
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
return "Unknown or custom"
|
|
||||||
}
|
|
||||||
|
|
||||||
return val
|
|
||||||
}
|
|
||||||
|
|
||||||
// Executes when "Hide offline servers" checkbox changed it's state on
|
// Executes when "Hide offline servers" checkbox changed it's state on
|
||||||
// "Servers" tab.
|
// "Servers" tab.
|
||||||
func (m *MainWindow) hideOfflineAllServers() {
|
func (m *MainWindow) hideOfflineAllServers() {
|
||||||
@ -439,14 +441,14 @@ func (m *MainWindow) loadAllServers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if server.Server.Name == "" && server.Server.Players == "" && server.Server.Maxplayers == "" {
|
if server.Server.Name == "" && server.Server.Players == "" && server.Server.Maxplayers == "" {
|
||||||
m.all_servers_store.SetValue(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.all_servers_store.SetValue(iter, 0, m.server_offline_pic.GPixbuf)
|
||||||
m.all_servers_store.SetValue(iter, m.column_pos["Servers"]["IP"], server.Server.Ip + ":" + server.Server.Port)
|
m.all_servers_store.SetValue(iter, m.column_pos["Servers"]["IP"], server.Server.Ip + ":" + server.Server.Port)
|
||||||
} else {
|
} else {
|
||||||
m.all_servers_store.SetValue(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.all_servers_store.SetValue(iter, 0, m.server_online_pic.GPixbuf)
|
||||||
if server.Server.IsPrivate == "1" {
|
if server.Server.IsPrivate == "1" {
|
||||||
m.all_servers_store.SetValue(iter, 1, gtk.NewImage().RenderIcon(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.all_servers_store.SetValue(iter, 1, m.server_passworded_pic.GPixbuf)
|
||||||
} else {
|
} else {
|
||||||
m.all_servers_store.SetValue(iter, 1, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.all_servers_store.SetValue(iter, 1, m.server_public_pic.GPixbuf)
|
||||||
}
|
}
|
||||||
server_name := ctx.Colorizer.Fix(server.Server.Name)
|
server_name := ctx.Colorizer.Fix(server.Server.Name)
|
||||||
m.all_servers_store.SetValue(iter, m.column_pos["Servers"]["Name"], server_name)
|
m.all_servers_store.SetValue(iter, m.column_pos["Servers"]["Name"], server_name)
|
||||||
@ -493,14 +495,14 @@ func (m *MainWindow) loadFavoriteServers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if server.Server.Name == "" && server.Server.Players == "" {
|
if server.Server.Name == "" && server.Server.Players == "" {
|
||||||
m.fav_servers_store.SetValue(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.fav_servers_store.SetValue(iter, 0, m.server_offline_pic.GPixbuf)
|
||||||
m.fav_servers_store.SetValue(iter, m.column_pos["Favorites"]["IP"], server.Server.Ip + ":" + server.Server.Port)
|
m.fav_servers_store.SetValue(iter, m.column_pos["Favorites"]["IP"], server.Server.Ip + ":" + server.Server.Port)
|
||||||
} else {
|
} else {
|
||||||
m.fav_servers_store.SetValue(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.fav_servers_store.SetValue(iter, 0, m.server_online_pic.GPixbuf)
|
||||||
if server.Server.IsPrivate == "1" {
|
if server.Server.IsPrivate == "1" {
|
||||||
m.fav_servers_store.SetValue(iter, 1, gtk.NewImage().RenderIcon(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.fav_servers_store.SetValue(iter, 1, m.server_passworded_pic.GPixbuf)
|
||||||
} else {
|
} else {
|
||||||
m.fav_servers_store.SetValue(iter, 1, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
|
m.fav_servers_store.SetValue(iter, 1, m.server_public_pic.GPixbuf)
|
||||||
}
|
}
|
||||||
server_name := ctx.Colorizer.Fix(server.Server.Name)
|
server_name := ctx.Colorizer.Fix(server.Server.Name)
|
||||||
m.fav_servers_store.SetValue(iter, m.column_pos["Favorites"]["Name"], server_name)
|
m.fav_servers_store.SetValue(iter, m.column_pos["Favorites"]["Name"], server_name)
|
||||||
@ -673,22 +675,7 @@ func (m *MainWindow) unlockInterface() {
|
|||||||
|
|
||||||
func (m *MainWindow) updateOneServer() {
|
func (m *MainWindow) updateOneServer() {
|
||||||
current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage()))
|
current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage()))
|
||||||
sel := m.all_servers.GetSelection()
|
srv_address := m.getIpFromServersList(current_tab)
|
||||||
model := m.all_servers.GetModel()
|
|
||||||
iter := new(gtk.TreeIter)
|
|
||||||
_ = sel.GetSelected(iter)
|
|
||||||
|
|
||||||
// Getting server address.
|
|
||||||
var srv_addr string
|
|
||||||
srv_address_gval := glib.ValueFromNative(srv_addr)
|
|
||||||
model.GetValue(iter, m.column_pos["Servers"]["IP"], srv_address_gval)
|
|
||||||
if strings.Contains(current_tab, "Favorites") {
|
|
||||||
sel = m.fav_servers.GetSelection()
|
|
||||||
model = m.fav_servers.GetModel()
|
|
||||||
model.GetValue(iter, m.column_pos["Favorites"]["IP"], srv_address_gval)
|
|
||||||
}
|
|
||||||
|
|
||||||
srv_address := srv_address_gval.GetString()
|
|
||||||
|
|
||||||
if len(srv_address) > 0 {
|
if len(srv_address) > 0 {
|
||||||
go ctx.Requester.UpdateOneServer(srv_address)
|
go ctx.Requester.UpdateOneServer(srv_address)
|
||||||
|
@ -9,6 +9,16 @@ import (
|
|||||||
"github.com/mattn/go-gtk/gtk"
|
"github.com/mattn/go-gtk/gtk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (m *MainWindow) getGameModeName(name string) string {
|
||||||
|
val, ok := m.gamemodes[name]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return "Unknown or custom"
|
||||||
|
}
|
||||||
|
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MainWindow) getIpFromServersList(current_tab string) string {
|
func (m *MainWindow) getIpFromServersList(current_tab string) string {
|
||||||
// Getting server's address from list.
|
// Getting server's address from list.
|
||||||
sel := m.all_servers.GetSelection()
|
sel := m.all_servers.GetSelection()
|
||||||
|
@ -324,6 +324,16 @@ func (m *MainWindow) initializeStorages() {
|
|||||||
|
|
||||||
// Window hidden flag.
|
// Window hidden flag.
|
||||||
m.hidden = false
|
m.hidden = false
|
||||||
|
|
||||||
|
// Pixbufs.
|
||||||
|
// Offline server.
|
||||||
|
m.server_offline_pic = gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "")
|
||||||
|
// Online server.
|
||||||
|
m.server_online_pic = gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "")
|
||||||
|
// Passworded server.
|
||||||
|
m.server_passworded_pic = gtk.NewImage().RenderIcon(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR, "")
|
||||||
|
// Public server.
|
||||||
|
m.server_public_pic = gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tabs widget initialization, including all child widgets.
|
// Tabs widget initialization, including all child widgets.
|
||||||
@ -348,7 +358,6 @@ func (m *MainWindow) InitializeTabs() {
|
|||||||
// +2 because we have 2 static columns.
|
// +2 because we have 2 static columns.
|
||||||
all_servers_columns_to_append := make([]*gtk.TreeViewColumn, len(m.column_names) + 2)
|
all_servers_columns_to_append := make([]*gtk.TreeViewColumn, len(m.column_names) + 2)
|
||||||
for pos, name := range m.column_names {
|
for pos, name := range m.column_names {
|
||||||
fmt.Println(pos, name)
|
|
||||||
// Check if we have column position saved. If so - use it.
|
// Check if we have column position saved. If so - use it.
|
||||||
// Otherwise use default position.
|
// Otherwise use default position.
|
||||||
// Should be actual only for first launch.
|
// Should be actual only for first launch.
|
||||||
@ -424,7 +433,6 @@ func (m *MainWindow) InitializeTabs() {
|
|||||||
// +2 because we have 2 static columns.
|
// +2 because we have 2 static columns.
|
||||||
fav_servers_columns_to_append := make([]*gtk.TreeViewColumn, len(m.column_names) + 2)
|
fav_servers_columns_to_append := make([]*gtk.TreeViewColumn, len(m.column_names) + 2)
|
||||||
for pos, name := range m.column_names {
|
for pos, name := range m.column_names {
|
||||||
fmt.Println(pos, name)
|
|
||||||
// Check if we have column position saved. If so - use it.
|
// Check if we have column position saved. If so - use it.
|
||||||
// Otherwise use default position.
|
// Otherwise use default position.
|
||||||
// Should be actual only for first launch.
|
// Should be actual only for first launch.
|
||||||
|
Reference in New Issue
Block a user