Servers updating and ping detection fixes.

On servers updating when all data successfully gathered we're now
properly updating rows in Servers and Favorites lists.

Increased "simultaneous ping limit" for now, but anyway it provides
too bad results. Need to find a way to fix it.
This commit is contained in:
Stanislav Nikitin 2016-10-06 17:11:36 +05:00
parent 9ce4ad8945
commit 2efd47c301
3 changed files with 44 additions and 42 deletions

View File

@ -19,6 +19,8 @@ import (
type Server struct { type Server struct {
Server *datamodels.Server Server *datamodels.Server
TreeIter gtk.TreeIter AllServersIter *gtk.TreeIter
IterSet bool FavServersIter *gtk.TreeIter
AllServersIterSet bool
FavServersIterSet bool
} }

View File

@ -33,7 +33,8 @@ type Pooler struct {
func (p *Pooler) Initialize() { func (p *Pooler) Initialize() {
fmt.Println("Initializing requester goroutine pooler...") fmt.Println("Initializing requester goroutine pooler...")
p.maxrequests = runtime.NumCPU() * 4 // ToDo: figure out how to make this work nice.
p.maxrequests = runtime.NumCPU() * 2000
p.pp = "\377\377\377\377" p.pp = "\377\377\377\377"
} }
@ -99,7 +100,6 @@ func (p *Pooler) pingServersExecutor(server *datamodels.Server) error {
conn_ping.Close() conn_ping.Close()
delta := strconv.Itoa(int(time.Since(start_p).Nanoseconds()) / 1000000) delta := strconv.Itoa(int(time.Since(start_p).Nanoseconds()) / 1000000)
fmt.Println(delta)
server.Ping = delta server.Ping = delta
return nil return nil
@ -202,8 +202,5 @@ func (p *Pooler) updateSpecificServer(server *datamodels.Server) error {
// ToDo: Calculate ping. 0 for now. // ToDo: Calculate ping. 0 for now.
server.Ping = "0" server.Ping = "0"
fmt.Println(server)
return nil return nil
} }

View File

@ -14,7 +14,6 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"reflect"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -891,33 +890,31 @@ func (m *MainWindow) launchGame() error {
func (m *MainWindow) loadAllServers() { func (m *MainWindow) loadAllServers() {
fmt.Println("Loading all servers...") fmt.Println("Loading all servers...")
// ToDo: do it without clearing. // ToDo: do it without clearing.
srv_addrs := reflect.ValueOf(ctx.Cache.Servers).MapKeys()
fmt.Println(srv_addrs)
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 == "" { if m.all_servers_hide_offline.GetActive() && server.Server.Name == "" && server.Server.Players == "" {
continue continue
} }
var iter gtk.TreeIter iter := new (gtk.TreeIter)
if !server.IterSet { if !server.AllServersIterSet {
server.TreeIter = iter server.AllServersIter = iter
m.all_servers_store.Append(&iter) m.all_servers_store.Append(iter)
server.IterSet = true server.AllServersIterSet = true
} else { } else {
iter = server.TreeIter iter = server.AllServersIter
} }
if server.Server.Name == "" && server.Server.Players == "" { if server.Server.Name == "" && server.Server.Players == "" {
m.all_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf) m.all_servers_store.Set(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
} else { } else {
m.all_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf) m.all_servers_store.Set(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
} }
server_name := ctx.Colorizer.Fix(server.Server.Name) server_name := ctx.Colorizer.Fix(server.Server.Name)
m.all_servers_store.Set(&iter, 1, server_name) m.all_servers_store.SetValue(iter, 1, server_name)
m.all_servers_store.Set(&iter, 2, m.gamemodes[server.Server.Gamemode]) m.all_servers_store.SetValue(iter, 2, m.gamemodes[server.Server.Gamemode])
m.all_servers_store.Set(&iter, 3, server.Server.Map) m.all_servers_store.SetValue(iter, 3, server.Server.Map)
m.all_servers_store.Set(&iter, 4, server.Server.Players + "/" + server.Server.Maxplayers) m.all_servers_store.SetValue(iter, 4, server.Server.Players + "/" + server.Server.Maxplayers)
m.all_servers_store.Set(&iter, 5, server.Server.Ping) m.all_servers_store.SetValue(iter, 5, server.Server.Ping)
m.all_servers_store.Set(&iter, 6, server.Server.Version) m.all_servers_store.SetValue(iter, 6, server.Server.Version)
m.all_servers_store.Set(&iter, 7, server.Server.Ip + ":" + server.Server.Port) m.all_servers_store.SetValue(iter, 7, server.Server.Ip + ":" + server.Server.Port)
} }
} }
@ -930,27 +927,31 @@ func (m *MainWindow) loadFavoriteServers() {
if m.fav_servers_hide_offline.GetActive() && server.Server.Name == "" && server.Server.Players == "" { if m.fav_servers_hide_offline.GetActive() && server.Server.Name == "" && server.Server.Players == "" {
continue continue
} }
var iter gtk.TreeIter iter := new(gtk.TreeIter)
if !server.IterSet { if !server.FavServersIterSet {
server.TreeIter = iter server.FavServersIter = iter
m.fav_servers_store.Append(&iter) m.fav_servers_store.Append(iter)
server.IterSet = true server.FavServersIterSet = true
} else { } else {
iter = server.TreeIter iter = server.FavServersIter
} }
if m.fav_servers_store.IterIsValid(iter) {
if server.Server.Name == "" && server.Server.Players == "" { if server.Server.Name == "" && server.Server.Players == "" {
m.fav_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf) m.fav_servers_store.Set(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_NO, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
} else { } else {
m.fav_servers_store.Set(&iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf) m.fav_servers_store.Set(iter, 0, gtk.NewImage().RenderIcon(gtk.STOCK_OK, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf)
} }
server_name := ctx.Colorizer.Fix(server.Server.Name) server_name := ctx.Colorizer.Fix(server.Server.Name)
m.fav_servers_store.Set(&iter, 1, server_name) m.fav_servers_store.SetValue(iter, 1, server_name)
m.fav_servers_store.Set(&iter, 2, m.gamemodes[server.Server.Gamemode]) m.fav_servers_store.SetValue(iter, 2, m.gamemodes[server.Server.Gamemode])
m.fav_servers_store.Set(&iter, 3, server.Server.Map) m.fav_servers_store.SetValue(iter, 3, server.Server.Map)
m.fav_servers_store.Set(&iter, 4, server.Server.Players + "/" + server.Server.Maxplayers) m.fav_servers_store.SetValue(iter, 4, server.Server.Players + "/" + server.Server.Maxplayers)
m.fav_servers_store.Set(&iter, 5, server.Server.Ping) m.fav_servers_store.SetValue(iter, 5, server.Server.Ping)
m.fav_servers_store.Set(&iter, 6, server.Server.Version) m.fav_servers_store.SetValue(iter, 6, server.Server.Version)
m.fav_servers_store.Set(&iter, 7, server.Server.Ip + ":" + server.Server.Port) m.fav_servers_store.SetValue(iter, 7, server.Server.Ip + ":" + server.Server.Port)
} else {
fmt.Println("Invalid iter for server: " + server.Server.Ip + ":" + server.Server.Port)
}
} }
} }
@ -992,10 +993,12 @@ func (m *MainWindow) showHide() {
} }
} }
// Show tray menu on right-click on tray icon.
func (m *MainWindow) showTrayMenu(cbx *glib.CallbackContext) { func (m *MainWindow) showTrayMenu(cbx *glib.CallbackContext) {
m.tray_menu.Popup(nil, nil, gtk.StatusIconPositionMenu, m.tray_icon, uint(cbx.Args(0)), uint32(cbx.Args(1))) m.tray_menu.Popup(nil, nil, gtk.StatusIconPositionMenu, m.tray_icon, uint(cbx.Args(0)), uint32(cbx.Args(1)))
} }
// Unlocking interface after game shut down.
func (m *MainWindow) unlockInterface() { func (m *MainWindow) unlockInterface() {
m.launch_button.SetSensitive(true) m.launch_button.SetSensitive(true)
m.statusbar.Push(m.statusbar_context_id, "URTrator is ready.") m.statusbar.Push(m.statusbar_context_id, "URTrator is ready.")