コード例 #1
0
        public byte[] ToBytes()
        {
            PacketBuilder builder = new PacketBuilder();

            builder.AddInt32(PACKET_HEADER);
            builder.AddByte((byte)_type);
            builder.AddString(_gameTitle);
            builder.AddVersion(_gameVersion);
            builder.AddIPAddress(_sourceIP);
            builder.AddIPAddress(_destinationIP);
            builder.AddString(_playerName);
            AddInstanceBytes(builder);
            builder.AddInt32(PACKET_FOOTER);
            return(builder.ToBytes());
        }
コード例 #2
0
        private async Task HandleChallengeRequest()
        {
            var random = new Random();

            var token = random.Next();

            var builder = new PacketBuilder();

            builder.AddInt16(0x0001);
            builder.AddByte(0x03);
            builder.AddByte(0x00);
            builder.AddInt32(token);

            var buffer = builder.GetBytes();

            await this.networkClient.SendAsync(buffer, buffer.Length);

            var result = await this.networkClient.ReceiveAsync();

            PacketReader reader = new PacketReader(result);

            reader.ReadInt16();
            reader.ReadByte();
            reader.ReadByte();

            var responseToken = reader.ReadInt32();

            if (responseToken != token)
            {
                throw new InvalidOperationException("Invalid token response from server.");
            }
        }
コード例 #3
0
 /// <summary>
 /// Adds instance bytes to packet builder.
 /// </summary>
 protected override void AddInstanceBytes(PacketBuilder builder)
 {
     builder.AddUInt16((ushort)_commandType);
     builder.AddInt32(_sequence);
     builder.AddByte((byte)_code);
     builder.AddBytes(_data);
 }
コード例 #4
0
 /// <summary>
 /// Adds instance bytes to packet builder.
 /// </summary>
 protected override void AddInstanceBytes(PacketBuilder builder)
 {
     builder.AddUInt16((ushort)_commandType);
     builder.AddInt32(_sequence);
     builder.AddUInt16(_retryAttempt);
     builder.AddUInt32(_timeoutMs);
     builder.AddBytes(_data);
 }
コード例 #5
0
        public void AddInt32_ValidInt32_BigEndianOrderingUsed()
        {
            target.AddInt32(0x01020304);

            var actual = this.target.GetBytes();

            Assert.AreEqual(1, actual[0]);
            Assert.AreEqual(2, actual[1]);
            Assert.AreEqual(3, actual[2]);
            Assert.AreEqual(4, actual[3]);
        }
コード例 #6
0
ファイル: HighScores.cs プロジェクト: jon-hyland/games
        /// <summary>
        /// Serializes high score list to packet bytes.
        /// </summary>
        public byte[] ToBytes()
        {
            PacketBuilder builder = new PacketBuilder();

            lock (this)
            {
                builder.AddUInt16((ushort)_scores.Count);
                foreach (HighScore score in _scores)
                {
                    builder.AddString(score.Initials ?? "");
                    builder.AddInt32(score.Score);
                }
            }
            return(builder.ToBytes());
        }