Ejemplo n.º 1
0
        static Player[] ParsePlayers(byte[] players)
        {
            //TODO: Player doesn't have same info for different game/server types
            var pos      = 5; //skip header
            var cnt      = players[pos++];
            var playerAr = new Player[cnt];

            for (var i = 0; i < cnt; i++)
            {
                if (pos >= players.Length)
                {
                    break;
                }
                // ReSharper disable once UnusedVariable
                var pnum = players[pos++];
                //TODO: index is always zero, why? Defined as "Index of player chunk starting from 0." should be usable below
                var start = pos;
                while (players[pos++] != 0x00)
                {
                }
                var name  = Encoding.UTF8.GetString(players, start, pos - start - 1);
                var score = BitConverter.ToInt32(players, pos);
                pos += 4;
                var duration = (int)BitConverter.ToSingle(players, pos);  //in seconds, dropped float precision
                pos        += 4;
                playerAr[i] = new SourcePlayer(name, score, TimeSpan.FromSeconds(duration));
                //use i instead of pnum
            }

            return(playerAr);
        }
        static Player[] ParsePlayers(IServer server, byte[] players)
        {
            //TODO: Player doesn't have same info for different game/server types
            var pos = 5; //skip header
            var cnt = players[pos++];
            var playerAr = new Player[cnt];
            for (var i = 0; i < cnt; i++) {
                if (pos >= players.Length)
                    break;
                // ReSharper disable once UnusedVariable
                var pnum = players[pos++];
                //TODO: index is always zero, why? Defined as "Index of player chunk starting from 0." should be usable below
                var start = pos;
                while (players[pos++] != 0x00) {}
                var name = Encoding.UTF8.GetString(players, start, pos - start - 1);
                var score = BitConverter.ToInt32(players, pos);
                pos += 4;
                var duration = (int) BitConverter.ToSingle(players, pos); //in seconds, dropped float precision
                pos += 4;
                playerAr[i] = new SourcePlayer(server, name, score, TimeSpan.FromSeconds(duration));
                //use i instead of pnum
            }

            return playerAr;
        }