Favorites and database fixes, players info and extended server config.
Adding a favorite server now requires created valid profile. It will not allow to create favorite server without proper profile. Fixed servers updating database, now they put all fields there. Added stubs for players info and extended server config things in database.
This commit is contained in:
parent
dbf5b60ead
commit
c22744765b
@ -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].Ping = s.Ping
|
||||||
cached_servers[mapping_item_name].Map = s.Map
|
cached_servers[mapping_item_name].Map = s.Map
|
||||||
cached_servers[mapping_item_name].Gamemode = s.Gamemode
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ func migrate_full(db *Database, version int) {
|
|||||||
if version == 4 {four_to_five(db); version = 5}
|
if version == 4 {four_to_five(db); version = 5}
|
||||||
if version == 5 {five_to_six(db); version = 6 }
|
if version == 5 {five_to_six(db); version = 6 }
|
||||||
if version == 6 {six_to_seven(db); version = 7}
|
if version == 6 {six_to_seven(db); version = 7}
|
||||||
|
if version == 7 {seven_to_eight(db); version = 8}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial database structure.
|
// 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("CREATE TABLE configuration (key VARCHAR(128) NOT NULL, value VARCHAR(1024) NOT NULL)")
|
||||||
db.Db.MustExec("UPDATE database SET version=7")
|
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")
|
||||||
|
}
|
||||||
|
@ -34,4 +34,8 @@ type Server struct {
|
|||||||
Password string `db:"password"`
|
Password string `db:"password"`
|
||||||
// Profile to use with server.
|
// Profile to use with server.
|
||||||
ProfileToUse string `db:"profile_to_use"`
|
ProfileToUse string `db:"profile_to_use"`
|
||||||
|
// Extended server's configuration.
|
||||||
|
ExtendedConfig string `db:"extended_config"`
|
||||||
|
// Players information.
|
||||||
|
PlayersInfo string `db:"players_info"`
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error {
|
|||||||
ddl = ddl.Add(time.Second * 2)
|
ddl = ddl.Add(time.Second * 2)
|
||||||
conn.SetDeadline(ddl)
|
conn.SetDeadline(ddl)
|
||||||
|
|
||||||
msg := []byte(r.pp + "getinfo")
|
msg := []byte(r.pp + "getstatus")
|
||||||
conn.Write(msg)
|
conn.Write(msg)
|
||||||
|
|
||||||
// UDP Buffer.
|
// UDP Buffer.
|
||||||
@ -218,10 +218,10 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error {
|
|||||||
srv_config := strings.Split(received_lines[1], "\\")
|
srv_config := strings.Split(received_lines[1], "\\")
|
||||||
// Parse server configuration into passed server's datamodel.
|
// Parse server configuration into passed server's datamodel.
|
||||||
for i := 0; i < len(srv_config); i = i + 1 {
|
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]
|
server.Version = srv_config[i + 1]
|
||||||
}
|
}
|
||||||
if srv_config[i] == "gametype" {
|
if srv_config[i] == "g_gametype" {
|
||||||
server.Gamemode = srv_config[i + 1]
|
server.Gamemode = srv_config[i + 1]
|
||||||
}
|
}
|
||||||
if srv_config[i] == "sv_maxclients" {
|
if srv_config[i] == "sv_maxclients" {
|
||||||
@ -233,14 +233,22 @@ func (r *Requester) UpdateServer(server *datamodels.Server) error {
|
|||||||
if srv_config[i] == "mapname" {
|
if srv_config[i] == "mapname" {
|
||||||
server.Map = srv_config[i + 1]
|
server.Map = srv_config[i + 1]
|
||||||
}
|
}
|
||||||
if srv_config[i] == "hostname" {
|
if srv_config[i] == "sv_hostname" {
|
||||||
server.Name = srv_config[i + 1]
|
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.
|
// ToDo: Calculate ping. 0 for now.
|
||||||
server.Ping = "0"
|
server.Ping = "0"
|
||||||
|
// ToDo: put this info.
|
||||||
|
server.ExtendedConfig = ""
|
||||||
|
server.PlayersInfo = ""
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,16 @@ func (f *FavoriteDialog) saveFavorite() error {
|
|||||||
return errors.New("No server address specified")
|
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 = ""
|
var port string = ""
|
||||||
if strings.Contains(f.server_address.GetText(), ":") {
|
if strings.Contains(f.server_address.GetText(), ":") {
|
||||||
port = strings.Split(f.server_address.GetText(), ":")[1]
|
port = strings.Split(f.server_address.GetText(), ":")[1]
|
||||||
|
Reference in New Issue
Block a user