diff --git a/database/database_object.go b/database/database_object.go index 31d92ad..d0da9e5 100644 --- a/database/database_object.go +++ b/database/database_object.go @@ -119,6 +119,9 @@ func (d *Database) UpdateServers(data map[string]*datamodels.Server) { cached_servers[mapping_item_name].Ping = s.Ping cached_servers[mapping_item_name].Map = s.Map cached_servers[mapping_item_name].Gamemode = s.Gamemode + cached_servers[mapping_item_name].Version = s.Version + cached_servers[mapping_item_name].ExtendedConfig = s.ExtendedConfig + cached_servers[mapping_item_name].PlayersInfo = s.PlayersInfo } } diff --git a/database/migrations.go b/database/migrations.go index d8220b3..df70b6c 100644 --- a/database/migrations.go +++ b/database/migrations.go @@ -46,6 +46,7 @@ func migrate_full(db *Database, version int) { if version == 4 {four_to_five(db); version = 5} if version == 5 {five_to_six(db); version = 6 } if version == 6 {six_to_seven(db); version = 7} + if version == 7 {seven_to_eight(db); version = 8} } // Initial database structure. @@ -98,3 +99,11 @@ func six_to_seven(db *Database) { db.Db.MustExec("CREATE TABLE configuration (key VARCHAR(128) NOT NULL, value VARCHAR(1024) NOT NULL)") db.Db.MustExec("UPDATE database SET version=7") } + +// Server's extended information. +func seven_to_eight(db *Database) { + fmt.Println("Upgrading database from 7 to 8...") + db.Db.MustExec("ALTER TABLE servers ADD extended_config VARCHAR(4096) NOT NULL DEFAULT ''") + db.Db.MustExec("ALTER TABLE servers ADD players_info VARCHAR(8192) NOT NULL DEFAULT ''") + db.Db.MustExec("UPDATE database SET version=8") +} diff --git a/datamodels/server.go b/datamodels/server.go index ed272fc..82e36ca 100644 --- a/datamodels/server.go +++ b/datamodels/server.go @@ -34,4 +34,8 @@ type Server struct { Password string `db:"password"` // Profile to use with server. ProfileToUse string `db:"profile_to_use"` + // Extended server's configuration. + ExtendedConfig string `db:"extended_config"` + // Players information. + PlayersInfo string `db:"players_info"` } diff --git a/requester/requester_object.go b/requester/requester_object.go index 98f6100..12a8e0f 100644 --- a/requester/requester_object.go +++ b/requester/requester_object.go @@ -195,7 +195,7 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error { ddl = ddl.Add(time.Second * 2) conn.SetDeadline(ddl) - msg := []byte(r.pp + "getinfo") + msg := []byte(r.pp + "getstatus") conn.Write(msg) // UDP Buffer. @@ -218,10 +218,10 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error { srv_config := strings.Split(received_lines[1], "\\") // Parse server configuration into passed server's datamodel. for i := 0; i < len(srv_config); i = i + 1 { - if srv_config[i] == "modversion" { + if srv_config[i] == "g_modversion" { server.Version = srv_config[i + 1] } - if srv_config[i] == "gametype" { + if srv_config[i] == "g_gametype" { server.Gamemode = srv_config[i + 1] } if srv_config[i] == "sv_maxclients" { @@ -233,14 +233,22 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error { if srv_config[i] == "mapname" { server.Map = srv_config[i + 1] } - if srv_config[i] == "hostname" { + if srv_config[i] == "sv_hostname" { server.Name = srv_config[i + 1] } } + if len(received_lines) >= 2 { + // Here we go, players information. + players := received_lines[2:] + server.Players = strconv.Itoa(len(players)) + } } // ToDo: Calculate ping. 0 for now. server.Ping = "0" + // ToDo: put this info. + server.ExtendedConfig = "" + server.PlayersInfo = "" return nil } diff --git a/ui/favorite.go b/ui/favorite.go index 6db39c5..6ef7c88 100644 --- a/ui/favorite.go +++ b/ui/favorite.go @@ -186,6 +186,16 @@ func (f *FavoriteDialog) saveFavorite() error { return errors.New("No server address specified") } + if len(f.profile.GetActiveText()) == 0 { + mbox_string := "Profile wasn't selected.\n\nPlease, select valid profile for this server.\nIf you haven't add profiles yet - you can do it\nin options on \"Urban Terror\" tab." + m := gtk.NewMessageDialog(f.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, mbox_string) + m.Response(func() { + m.Destroy() + }) + m.Run() + return errors.New("No game profile specified") + } + var port string = "" if strings.Contains(f.server_address.GetText(), ":") { port = strings.Split(f.server_address.GetText(), ":")[1]