public PlayerListViewData(HalfLifeDemo.Player player) { Name = player.InfoKeys["name"]; UpdateRate = player.InfoKeys["cl_updaterate"]; Rate = player.InfoKeys["rate"]; String sid = player.InfoKeys["*sid"]; // "*sid" only exists in protocol 48 Half-Life demos. And even then it's common for people to "convert" protocol 47 demos to 48, so it's best to make sure the infokey value exists. if (player.InfoKeys["*hltv"] != null) { SteamId = "HLTV"; } else if (sid != null) { SteamId = Common.CalculateSteamId(sid); if (SteamId == null) { SteamId = "-"; } } else { SteamId = "-"; } }
private void ParseInfoKeyString(Player player, String s) { String[] infoKeyTokens = s.Split('\\'); for (int i = 0; i < infoKeyTokens.Length; i += 2) { if (i + 1 >= infoKeyTokens.Length) { // Must be an odd number of strings - a key without a value - ignore it. break; } String key = infoKeyTokens[i]; String value = infoKeyTokens[i + 1]; // find or create InfoKey object InfoKey infoKey = Common.FirstOrDefault <InfoKey>(player.InfoKeys, ik => ik.Key == key); if (infoKey == null) { infoKey = new InfoKey(); infoKey.Key = key; // add new infokey player.InfoKeys.Add(infoKey); } else { // don't create a new value entry if the previous value is exactly the same if (infoKey.NewestValueValue == value) { continue; } } // create infokey value InfoKeyValue infoKeyValue = new InfoKeyValue(); infoKeyValue.Value = value; infoKeyValue.Timestamp = currentTimestamp; // add new value to infokey values infoKey.Values.Add(infoKeyValue); } // create a Steam ID key if the player isn't a HLTV proxy. InfoKey hltv = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*hltv"); InfoKey sid = Common.FirstOrDefault(player.InfoKeys, ik => ik.Key == "*sid"); if (hltv == null && sid != null) { String steamId = Common.CalculateSteamId(sid.NewestValueValue); if (steamId != null) { AddInfoKey(player, "SteamId", steamId); } } }