<commit_before>// https://codingrange.com/blog/steam-in-home-streaming-discovery-protocol
// https://www.npmjs.com/package/protocol-buffers
// https://github.com/SteamRE/SteamKit/blob/master/Resources/Protobufs/steamclient/steammessages_remoteclient_discovery.proto

var protobuf = require("protocol-buffers"),
    dgram = require("dgram"),
    fs = require("fs"),
    bignum = require("bignum");


var messageTypes = protobuf(fs.readFileSync("steamdiscover.proto"));


var server = dgram.createSocket("udp4");

server.on("message", (m, rinfo) => {
//try {
  var offset = 0;
  console.log(`got message: ${m} from ${rinfo.address}:${rinfo.port}`);
  console.log(m.slice(0,8).toString('hex'));
  offset += 8;

  var headerLength = m.readUInt32LE(offset);
  offset += 4; // 32 bit 

  console.log(`header length: ${headerLength}`);

  var header = m.slice(offset, offset + headerLength);
  console.log(header.toString('hex'));
  var headerContent =  messageTypes.CMsgRemoteClientBroadcastHeader.decode(header);
  console.log(headerContent);

  offset += headerLength;

  var bodyLength = m.readUInt32LE(offset);
  offset += 4; // 32 bit
  
  if (headerContent.msg_type == 1 ) {   /* k)ERemoteClientBroadcastMsgStatus */
    var body_data = m.slice(offset, offset + bodyLength);
    
    var body_content = messageTypes.CMsgRemoteClientBroadcastStatus.decode(body_data);
    console.log(body_content);
    
    var steamid_buffer = (body_content.users[0] || {} ).steamid;
    if (steamid_buffer) {
//      console.log(steamid_buffer.readUIntLE(0,steamid_buffer.length));
      var steamid = bignum.fromBuffer(steamid_buffer, { endian: "little", size: 'auto'} )
      console.log(steamid.toString());
    } 
  }
//  } catch (e) { console.log("Error: " + e + "\n\n");}
});

server.bind(27036);

//messagesTypes["CMsgRemoteClientBroadcastStatus"].decode("");


function broadcastDiscovery(server) {
    
    

}
<commit_msg>remove console.logs<commit_after>// https://codingrange.com/blog/steam-in-home-streaming-discovery-protocol
// https://www.npmjs.com/package/protocol-buffers
// https://github.com/SteamRE/SteamKit/blob/master/Resources/Protobufs/steamclient/steammessages_remoteclient_discovery.proto

var protobuf = require("protocol-buffers"),
    dgram = require("dgram"),
    fs = require("fs"),
    bignum = require("bignum");


var messageTypes = protobuf(fs.readFileSync("steamdiscover.proto"));


var server = dgram.createSocket("udp4");

server.on("message", (m, rinfo) => {
  var offset = 0;
  console.log(`got message from ${rinfo.address}:${rinfo.port}`);
  offset += 8;

  var headerLength = m.readUInt32LE(offset);
  offset += 4; // 32 bit 


  var header = m.slice(offset, offset + headerLength);
  var headerContent =  messageTypes.CMsgRemoteClientBroadcastHeader.decode(header);
  console.log(headerContent);

  offset += headerLength;

  var bodyLength = m.readUInt32LE(offset);
  offset += 4; // 32 bit
  
  if (headerContent.msg_type == 1 ) {   /* k)ERemoteClientBroadcastMsgStatus */
    var body_data = m.slice(offset, offset + bodyLength);
    
    var body_content = messageTypes.CMsgRemoteClientBroadcastStatus.decode(body_data);
    console.log(body_content);
    
    var steamid_buffer = (body_content.users[0] || {} ).steamid;
    if (steamid_buffer) {
      var steamid = bignum.fromBuffer(steamid_buffer, { endian: "little", size: 'auto'} )
      console.log(steamid.toString());
    } 
  }
});

server.bind(27036);



function broadcastDiscovery(server) {
    
    

}

{'fraction_non_alphanumeric': 0.15566980862610683, 'fraction_numerical': 0.01228220508426164, 'mean_word_length': 4.134897360703812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2899861', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1156, 'n_words': 187}