RoSearcher icon indicating copy to clipboard operation
RoSearcher copied to clipboard

Idea: multi-threading servers searching

Open lulu5239 opened this issue 3 years ago • 0 comments

When I created my server-side version of RoSearcher, I noticed it was still slow, so I added some threading in it, and it's 5 times faster. So you can see how mine works, I created:

let rechercheThreadsGlobal = 5
let rechercheAdditionGlobal = 10 // 10
function chercherDansJeu(id,jeu,suite,vitesse,precision){
  let rechercheThreads = vitesse || rechercheThreadsGlobal
  let rechercheAddition = precision || rechercheAdditionGlobal
  let ytID = Youtubeurs.filter(y=>y.id==id)[0] && Youtubeurs.findIndex(y=>y.id==id)
  let ytURLs
  let n = 0
  let arriveFin = 0
  let url
  // console.log(ytID)
  let chercherServ;
  chercherServ = function(){
    // console.log(n)
    if(n == NaN || n == "FIN"){return}
    // console.log("Cherche serveur.")
    // console.log(n)
    APIcall("https://www.roblox.com/games/getgameinstancesjson?placeId="+jeu+"&startIndex="+n,{},function(r){
      let trucs = JSON.parse(r.body)
      if(trucs.Collection.length > 0){
        trucs.Collection.forEach(function(t,i){
          let bons = t.CurrentPlayers.filter(u=>ytURLs.find(a=>a==u.Thumbnail.Url)).map(u=>ytURLs.findIndex(a=>a==u.Thumbnail.Url))
          if(bons.length>0){
            // console.log(bons)
            bons.forEach(function(i){
              Youtubeurs[i].surServeur = jeu
              Youtubeurs[i].gameId = t.Guid
            })
          }
        })
        
        let serv = trucs.Collection.filter(s=>s.CurrentPlayers.filter(u=>u.Thumbnail.Url == url)[0])[0]
        if(serv){
          // console.log(serv.CurrentPlayers.map(a=>a.Thumbnail))
          if(suite){
            suite(serv.Guid)
          }else{
            console.log(serv.Guid)
          }
        }
        if(n!="FIN"){
          arriveFin = 0
          chercherServ()
        }
      }else{
        if(arriveFin > rechercheThreads){
          n="FIN"
          if(suite){suite()}
        }else{
          setTimeout(function(){
            n -= rechercheAddition
            arriveFin += 1
            chercherServ()
          },500)
        }
      }
    })
    n += rechercheAddition
  }
  APIcall("https://www.roblox.com/headshot-thumbnail/image?userId="+id+"&width=48&height=48&format=png",{},function(r){
    // console.log(r.headers.location)
    if(ytID){
      Youtubeurs[ytID].imageURL = r.headers.location
      // console.log(Youtubeurs[Youtubeurs.findIndex(y=>y==alid)].imageURL)
    }
    url = r.headers.location
    ytURLs = Youtubeurs.map(y=>y.imageURL)
    let i = 0
    while(i<rechercheThreads){
      i++
      chercherServ()
    }
  })
}

(My API call function is just for making requests.) (And there are strange things because I wanted it to also detect Youtubers on the servers.)

I can make the pull request, but I want to know if it would be a waste of time or not.

lulu5239 avatar Aug 28 '21 14:08 lulu5239