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.
This commit is contained in:
Stanislav Nikitin 2016-10-06 21:34:14 +05:00
parent 5ba0664964
commit 8cfbca284e
3 changed files with 64 additions and 16 deletions

View File

@ -11,13 +11,10 @@ package ioq3dataparser
import ( import (
// stdlib // stdlib
"fmt"
"strings" "strings"
) )
func ParseInfoToMap(data string) map[string]string { func ParseInfoToMap(data string) map[string]string {
fmt.Println(data)
parsed_data := make(map[string]string) parsed_data := make(map[string]string)
srv_config := strings.Split(data, "\\") srv_config := strings.Split(data, "\\")
@ -25,10 +22,27 @@ func ParseInfoToMap(data string) map[string]string {
// Parse server configuration into passed server's datamodel. // Parse server configuration into passed server's datamodel.
for i := 0; i < len(srv_config[1:]); i = i + 2 { for i := 0; i < len(srv_config[1:]); i = i + 2 {
parsed_data[srv_config[i]] = srv_config[i + 1] 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 return parsed_data
} }

View File

@ -197,8 +197,14 @@ 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!
if len(players) == 1 && len(players[0]) > 255 {
server.Players = "0"
} else {
server.Players = strconv.Itoa(len(players)) server.Players = strconv.Itoa(len(players))
//server.PlayersInfo = received_lines[2:] }
server.PlayersInfo = strings.Join(received_lines[2:], "\\")
} }
} }

View File

@ -1079,23 +1079,35 @@ func (m *MainWindow) showShortServerInformation() {
// Getting server information from cache. // Getting server information from cache.
if len(srv_address) > 0 { if len(srv_address) > 0 {
server_info := ctx.Cache.Servers[srv_address].Server 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 // Append to treeview generic info first. After appending it
// will be deleted from map. // will be deleted from map.
iter = new(gtk.TreeIter)
m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, "<markup><span font_weight=\"bold\">GENERAL INFO</span></markup>")
// Server's name. // Server's name.
iter := new(gtk.TreeIter) iter := new(gtk.TreeIter)
m.server_info_store.Append(iter) m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, "Server's name") m.server_info_store.SetValue(iter, 0, "Server's name")
m.server_info_store.SetValue(iter, 1, ctx.Colorizer.Fix(parsed["sv_hostname"])) m.server_info_store.SetValue(iter, 1, ctx.Colorizer.Fix(parsed_general_data["sv_hostname"]))
delete(parsed, "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. // Players.
iter = new(gtk.TreeIter) iter = new(gtk.TreeIter)
m.server_info_store.Append(iter) m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, "Players") m.server_info_store.SetValue(iter, 0, "Players")
m.server_info_store.SetValue(iter, 1, server_info.Players + " of " + parsed["sv_maxclients"]) m.server_info_store.SetValue(iter, 1, server_info.Players + " of " + parsed_general_data["sv_maxclients"])
delete(parsed, "sv_maxclients") delete(parsed_general_data, "sv_maxclients")
// Ping // Ping
iter = new(gtk.TreeIter) iter = new(gtk.TreeIter)
@ -1120,11 +1132,27 @@ func (m *MainWindow) showShortServerInformation() {
m.server_info_store.Append(iter) m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, "Passworded") m.server_info_store.SetValue(iter, 0, "Passworded")
passworded_status := "<markup><span foreground=\"green\">No</span></markup>" passworded_status := "<markup><span foreground=\"green\">No</span></markup>"
if parsed["g_needpass"] == "1" { if parsed_general_data["g_needpass"] == "1" {
passworded_status = "<markup><span foreground=\"red\">Yes</span></markup>" passworded_status = "<markup><span foreground=\"red\">Yes</span></markup>"
} }
m.server_info_store.SetValue(iter, 1, passworded_status) 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, "<markup><span font_weight=\"bold\">PLAYERS</span></markup>")
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. // Just a separator.
iter = new(gtk.TreeIter) iter = new(gtk.TreeIter)
@ -1135,7 +1163,7 @@ func (m *MainWindow) showShortServerInformation() {
m.server_info_store.Append(iter) m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, "<markup><span font_weight=\"bold\">OTHER PARAMETERS</span></markup>") m.server_info_store.SetValue(iter, 0, "<markup><span font_weight=\"bold\">OTHER PARAMETERS</span></markup>")
for key, value := range parsed { for key, value := range parsed_general_data {
iter = new(gtk.TreeIter) iter = new(gtk.TreeIter)
m.server_info_store.Append(iter) m.server_info_store.Append(iter)
m.server_info_store.SetValue(iter, 0, key) m.server_info_store.SetValue(iter, 0, key)