From 8cfbca284e0d15c53963d1305efdc30bd36a0590 Mon Sep 17 00:00:00 2001 From: pztrn Date: Thu, 6 Oct 2016 21:34:14 +0500 Subject: [PATCH] Players parsing fixes and short info done. Fixed players parsing in server's response, now we can show 0 players. Showr info (kinda) completed, general server info, players and vars are here. Some work on sorting is in ToDo. --- ioq3dataparser/exported.go | 26 ++++++++++++++++------ requester/pooler.go | 10 +++++++-- ui/mainwindow.go | 44 +++++++++++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/ioq3dataparser/exported.go b/ioq3dataparser/exported.go index a556e61..913b340 100644 --- a/ioq3dataparser/exported.go +++ b/ioq3dataparser/exported.go @@ -11,13 +11,10 @@ package ioq3dataparser import ( // stdlib - "fmt" "strings" ) func ParseInfoToMap(data string) map[string]string { - fmt.Println(data) - parsed_data := make(map[string]string) srv_config := strings.Split(data, "\\") @@ -25,10 +22,27 @@ func ParseInfoToMap(data string) map[string]string { // Parse server configuration into passed server's datamodel. for i := 0; i < len(srv_config[1:]); i = i + 2 { parsed_data[srv_config[i]] = srv_config[i + 1] - fmt.Println(srv_config[i] + " => " + srv_config[i + 1]) } - fmt.Println(parsed_data) - + return parsed_data +} + +func ParsePlayersInfoToMap(data string) map[string]map[string]string { + parsed_data := make(map[string]map[string]string) + + // Structure: frags|ping|nick + raw_data := strings.Split(data, "\\") + for i := range raw_data { + raw_player_data := strings.Split(raw_data[i], " ") + player_data := make(map[string]string) + if len(raw_player_data) > 1 { + nickname := strings.Join(raw_player_data[2:], " ") + player_data["nick"] = string([]byte(nickname)[1:len(nickname)-1]) + player_data["ping"] = raw_player_data[1] + player_data["frags"] = raw_player_data[0] + parsed_data[player_data["nick"]] = player_data + } + } + return parsed_data } diff --git a/requester/pooler.go b/requester/pooler.go index b7779d7..7ec2707 100644 --- a/requester/pooler.go +++ b/requester/pooler.go @@ -197,8 +197,14 @@ func (p *Pooler) updateSpecificServer(server *datamodels.Server) error { if len(received_lines) >= 2 { // Here we go, players information. players := received_lines[2:] - server.Players = strconv.Itoa(len(players)) - //server.PlayersInfo = received_lines[2:] + fmt.Println(players, len(players), len(players[0])) + // Calculate players! + if len(players) == 1 && len(players[0]) > 255 { + server.Players = "0" + } else { + server.Players = strconv.Itoa(len(players)) + } + server.PlayersInfo = strings.Join(received_lines[2:], "\\") } } diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 45273f5..715cf6d 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -1079,23 +1079,35 @@ func (m *MainWindow) showShortServerInformation() { // Getting server information from cache. if len(srv_address) > 0 { server_info := ctx.Cache.Servers[srv_address].Server - parsed := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig) + parsed_general_data := ioq3dataparser.ParseInfoToMap(server_info.ExtendedConfig) + parsed_players_info := ioq3dataparser.ParsePlayersInfoToMap(server_info.PlayersInfo) // Append to treeview generic info first. After appending it // will be deleted from map. + iter = new(gtk.TreeIter) + m.server_info_store.Append(iter) + m.server_info_store.SetValue(iter, 0, "GENERAL INFO") + // Server's name. iter := new(gtk.TreeIter) m.server_info_store.Append(iter) m.server_info_store.SetValue(iter, 0, "Server's name") - m.server_info_store.SetValue(iter, 1, ctx.Colorizer.Fix(parsed["sv_hostname"])) - delete(parsed, "sv_hostname") + m.server_info_store.SetValue(iter, 1, ctx.Colorizer.Fix(parsed_general_data["sv_hostname"])) + delete(parsed_general_data, "sv_hostname") + + // Game version. + iter = new(gtk.TreeIter) + m.server_info_store.Append(iter) + m.server_info_store.SetValue(iter, 0, "Game version") + m.server_info_store.SetValue(iter, 1, parsed_general_data["g_modversion"]) + delete(parsed_general_data, "g_modversion") // Players. iter = new(gtk.TreeIter) m.server_info_store.Append(iter) m.server_info_store.SetValue(iter, 0, "Players") - m.server_info_store.SetValue(iter, 1, server_info.Players + " of " + parsed["sv_maxclients"]) - delete(parsed, "sv_maxclients") + m.server_info_store.SetValue(iter, 1, server_info.Players + " of " + parsed_general_data["sv_maxclients"]) + delete(parsed_general_data, "sv_maxclients") // Ping iter = new(gtk.TreeIter) @@ -1120,11 +1132,27 @@ func (m *MainWindow) showShortServerInformation() { m.server_info_store.Append(iter) m.server_info_store.SetValue(iter, 0, "Passworded") passworded_status := "No" - if parsed["g_needpass"] == "1" { + if parsed_general_data["g_needpass"] == "1" { passworded_status = "Yes" } m.server_info_store.SetValue(iter, 1, passworded_status) - delete(parsed, "g_needpass") + delete(parsed_general_data, "g_needpass") + + // Just a separator. + iter = new(gtk.TreeIter) + m.server_info_store.Append(iter) + + // Players information + iter = new(gtk.TreeIter) + m.server_info_store.Append(iter) + m.server_info_store.SetValue(iter, 0, "PLAYERS") + + for _, value := range parsed_players_info { + iter = new(gtk.TreeIter) + m.server_info_store.Append(iter) + m.server_info_store.SetValue(iter, 0, value["nick"]) + m.server_info_store.SetValue(iter, 1, "(frags: " + value["frags"] + " | ping: " + value["ping"] + ")") + } // Just a separator. iter = new(gtk.TreeIter) @@ -1135,7 +1163,7 @@ func (m *MainWindow) showShortServerInformation() { m.server_info_store.Append(iter) m.server_info_store.SetValue(iter, 0, "OTHER PARAMETERS") - for key, value := range parsed { + for key, value := range parsed_general_data { iter = new(gtk.TreeIter) m.server_info_store.Append(iter) m.server_info_store.SetValue(iter, 0, key)