Beispiel #1
0
        public byte[] GetPacket()
        {
            using (var buffer = new ValveBuffer())
            {
                buffer.WriteLong(-1);                             // non-split packet header
                buffer.WriteByte(Encoding.UTF8.GetBytes("I")[0]); // packet type is always 'I'
                buffer.WriteByte(default_proto_version);

                buffer.WriteString(ServerName);
                buffer.WriteString(MapName);
                buffer.WriteString(GameDirectory);
                buffer.WriteString(GamemodeName);

                buffer.WriteShort((short)Appid);

                buffer.WriteByte(AmountClients);
                buffer.WriteByte(MaxClients);
                buffer.WriteByte(AmountBots);
                buffer.WriteByte((byte)Server);
                buffer.WriteByte((byte)OS);
                buffer.WriteByte((byte)(Passworded ? 1 : 0));
                buffer.WriteByte((byte)(Secure ? 1 : 0));
                buffer.WriteString(GameVersion);

                if (string.IsNullOrEmpty(Tags))
                {
                    // 0x80 - port number is present
                    // 0x10 - server steamid is present
                    // 0x01 - game long appid is present
                    buffer.WriteByte((byte)(0x80 | 0x10 | 0x01));
                    buffer.WriteShort(UDPPort);
                    buffer.WriteLongLong(SteamID);
                    buffer.WriteLongLong(Appid);
                }
                else
                {
                    // 0x80 - port number is present
                    // 0x10 - server steamid is present
                    // 0x20 - tags are present
                    // 0x01 - game long appid is present
                    buffer.WriteByte((byte)(0x80 | 0x10 | 0x20 | 0x01));
                    buffer.WriteShort(UDPPort);
                    buffer.WriteLongLong(SteamID);
                    buffer.WriteString(Tags);
                    buffer.WriteLongLong(Appid);
                }

                return(buffer.ToArray());
            }
        }
Beispiel #2
0
        public byte[] GetPacket()
        {
            using (var buffer = new ValveBuffer())
            {
                buffer.WriteLong(-1);
                buffer.WriteByte(Encoding.UTF8.GetBytes("D")[0]);

                buffer.WriteByte((byte)Players.Count);

                for (int i = 0; i < Players.Count; i++)
                {
                    var player = Players[i];
                    buffer.WriteByte((byte)i);
                    buffer.WriteString(player.Name);
                    buffer.WriteLong(player.Score);
                    buffer.WriteFloat(player.Time);
                }

                return(buffer.ToArray());
            }
        }