예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        private void AddInfoKey(Player player, String key, String value)
        {
            InfoKey targetInfoKey = Common.FirstOrDefault <InfoKey>(player.InfoKeys, ik => ik.Key == key);

            if (targetInfoKey == null)
            {
                targetInfoKey     = new InfoKey();
                targetInfoKey.Key = key;
                player.InfoKeys.Add(targetInfoKey);
            }

            if (targetInfoKey.NewestValueValue != value)
            {
                InfoKeyValue ikv = new InfoKeyValue();
                ikv.Value     = value;
                ikv.Timestamp = currentTimestamp;
                targetInfoKey.Values.Add(ikv);
            }
        }
예제 #3
0
        private void MessageUpdateUserInfo()
        {
            Byte  slot     = parser.BitBuffer.ReadByte();
            Int32 entityId = parser.BitBuffer.ReadInt32();

            // note the slot+1, usermessages must use 0 for empty slot or something...
            // updateuserinfo starts at 0
            // user messages start at 1
            slot++;

            // find\create player object
            Player newPlayer = Common.FirstOrDefault <Player>(players, p => p.Id == entityId);

            if (newPlayer == null)
            {
                newPlayer = new Player {
                    Id = entityId
                };
                players.Add(newPlayer);
            }

            newPlayer.Slot = slot;

            // create infokey string
            String s = parser.BitBuffer.ReadString();

            if (demo.NetworkProtocol > 43)
            {
                parser.Seek(16);
            }

            if (s.Length == 0)
            {
                // 0 length text = a player just left and another player's slot is being changed
                // don't need to do anything, slots are always updated above
                return;
            }

            // parse infokey string
            ParseInfoKeyString(newPlayer, s.Remove(0, 1)); // trim leading slash
        }
예제 #4
0
 private Player FindPlayer(Byte slot, Int32 entityId)
 {
     return(Common.FirstOrDefault <Player>(players, player => (slot != 255 && slot == player.Slot) || (entityId != -1 && entityId == player.Id)));
 }
예제 #5
0
        /// <summary>
        /// Reads as much useful information as possible from the registry, such as Steam and Half-Life's install paths.
        /// </summary>
        private static void ReadFromRegistry()
        {
            // read SteamExe
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Steam"))
            {
                if (key != null)
                {
                    Settings.SteamExeFullPath = (string)key.GetValue("SteamExe", "");

                    if (Settings.SteamExeFullPath == null)
                    {
                        Settings.SteamExeFullPath = "";
                    }
                    else
                    {
                        Settings.SteamExeFullPath = Common.SanitisePath(Settings.SteamExeFullPath);

                        // this registry value always seems to be lower case. replace steam.exe with Steam.exe
                        Settings.SteamExeFullPath = Settings.SteamExeFullPath.Replace("steam.exe", "Steam.exe");
                    }
                }
            }

            // check if SteamExe is valid (contains Steam.exe)
            if (File.Exists(Settings.SteamExeFullPath))
            {
                // Find an account name by enumerating subfolder names in "SteamApps"
                // use "common" if it exists, otherwise use the first folder that isn't "sourcemods"
                DirectoryInfo steamAppsDirInfo = new DirectoryInfo(Path.GetDirectoryName(Settings.SteamExeFullPath) + "\\SteamApps");
                DirectoryInfo commonDirInfo    = Common.FirstOrDefault(steamAppsDirInfo.GetDirectories(), di => di.Name.ToLower() == "common");

                if (commonDirInfo != null)
                {
                    Settings.SteamAccountFolder = commonDirInfo.Name;
                }
                else
                {
                    foreach (DirectoryInfo dirInfo in steamAppsDirInfo.GetDirectories())
                    {
                        if (dirInfo.Name.ToLower() != "sourcemods")
                        {
                            Settings.SteamAccountFolder = dirInfo.Name;
                            break;
                        }
                    }
                }
            }
            else
            {
                // bad steam exe path, make the user enter it manually
                Settings.SteamExeFullPath = "";
            }

            // read half-life folder path, add hl.exe to it
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Valve\\Half-Life"))
            {
                if (key != null)
                {
                    Settings.HlExeFullPath = (String)key.GetValue("InstallPath");

                    if (Settings.HlExeFullPath == null)
                    {
                        Settings.HlExeFullPath = "";
                    }
                    else
                    {
                        Common.SanitisePath(Settings.HlExeFullPath);
                        Settings.HlExeFullPath += "\\hl.exe";

                        if (!File.Exists(Settings.HlExeFullPath))
                        {
                            // bad hl.exe path, make the user enter it manually
                            Settings.HlExeFullPath = "";
                        }
                    }
                }
            }
        }
예제 #6
0
 public Player FindPlayer(Byte slot)
 {
     return(Common.FirstOrDefault <Player>(players, p => p.Slot == slot));
 }
예제 #7
0
 public Team FindTeam(String name)
 {
     return(Common.FirstOrDefault <Team>(teams, t => t.Name == name));
 }