📜 ⬆️ ⬇️

Auto reconnect to Battlefield 4 server

At the weekend you need to rest. It is a fact.
But there is a wonderful phrase "Not a day without a line of code."
So this weekend I decided to arrange a brain warm-up :-)

I love the Battlefield series. Well, she likes me!

In Battlelog for Battlefield 3 there were wonderful queues at the server. Pressed and wait.
What was my disappointment when I discovered that in the fourth part you have to sit and press the button to play with friends.
')
The first thing that came to mind was a simple timer:

setInterval(function(){var button=document.getElementById('ugm-reconnect'); if(button != null) button.click();},1000); 

Press the Reconnect button once a second.

But! First of all, this is not correct, because it loads the browser and the processor with “idle” taps when we have already connected to the server.
Secondly, what if DICE will track such clickers?

Having rummaged in DICE'ovskom code, and they have a fairly advanced front-end framework, I found there “native” handlers.
Specifically: there is a launcher object with the registerForEvent () method.
I looked at how they use it themselves, and wrote this simple code like this:

 //     generic launcher.registerForEvent("error.generic", function(event, game, personaId, errorType, errorCode, errorString) { //     " " if(errorType == "ERR_SERVERCONNECT_SERVERFULL") { var button = jQuery("#ugm-reconnect"); if(button.length > 0){ //        setTimeout(function(){ button.click(); },Math.floor((Math.random()*1000)+1000)); } } }); 


Well, in order not to write to the console every time, I made extensions for Chrome and Firefox .

Source: https://habr.com/ru/post/200690/


All Articles