You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
236 lines
6.6 KiB
236 lines
6.6 KiB
var interval;
|
|
var hasStarted = false;
|
|
var hasBeenAlerted = false;
|
|
var id = '';
|
|
var leagueid = '';
|
|
window.onload = ()=>
|
|
{
|
|
startSpinner();
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
const entries = urlParams.entries();
|
|
const params = {};
|
|
for (entry of entries)
|
|
{
|
|
params[entry[0]] = entry[1];
|
|
}
|
|
id = params[id];
|
|
leagueid = params[leagueid]
|
|
}
|
|
function startSpinner()
|
|
{
|
|
var interval = setInterval(() => {
|
|
if(hasStarted)
|
|
{
|
|
document.getElementById('spinner').classList.add('active');
|
|
clearInterval(interval);
|
|
}
|
|
}, 10);
|
|
}
|
|
function stopSpinner()
|
|
{
|
|
document.getElementById('spinner').classList.remove('active')
|
|
}
|
|
async function start()
|
|
{
|
|
if(hasBeenAlerted) hasBeenAlerted = false;
|
|
if(hasStarted) return console.log("Once is enough.")
|
|
hasStarted = true;
|
|
var isUp = await checkStatus();
|
|
if(!isUp) return hasStarted = false;
|
|
console.log(isUp, hasStarted)
|
|
interval = setInterval(() =>
|
|
{
|
|
fetch('https://127.0.0.1:2999/GetLiveclientdataAllgamedata',
|
|
{
|
|
method:"GET",
|
|
mode:"cors",
|
|
headers:
|
|
{
|
|
"Accept": "*/*",
|
|
"Accept-Encoding": "gzip, deflate, br",
|
|
"Access-Control-Allow-Methods": "*",
|
|
"Accept-Language": "pt-PT,pt;q=0.9,en-US;q=0.8,en;q=0.7",
|
|
"Access-Control-Request-Headers": "access-control-allow-methods",
|
|
"Access-Control-Request-Method": "GET",
|
|
"Connection": "keep-alive",
|
|
"Host": "127.0.0.1:2999",
|
|
"Origin": "http://localhost:5000",
|
|
"Referer": "http://localhost:5000/",
|
|
"Sec-Fetch-Dest": "empty",
|
|
"Sec-Fetch-Mode": "cors",
|
|
"Sec-Fetch-Site": "cross-site",
|
|
}
|
|
}).then(handleRes)
|
|
.then(handleData)
|
|
.catch(handleError)
|
|
async function handleRes(res)
|
|
{
|
|
return await res.json()
|
|
}
|
|
function handleError(error)
|
|
{
|
|
return {Error:'There was an error:'+error}
|
|
}
|
|
}, 100);
|
|
}
|
|
|
|
async function checkStatus()
|
|
{
|
|
var x = await fetch('https://127.0.0.1:2999/help',
|
|
{
|
|
method:"GET",
|
|
mode:"cors",
|
|
option:
|
|
{
|
|
timeout:100
|
|
},
|
|
headers:
|
|
{
|
|
"Accept": "*/*",
|
|
"Host": "127.0.0.1:2999",
|
|
"Access-Control-Allow-Methods": "*",
|
|
"Origin": "http://localhost:5000",
|
|
"Referer": "http://localhost:5000/",
|
|
}
|
|
}).then(handleRes)
|
|
.catch(handleError)
|
|
async function handleRes(res)
|
|
{
|
|
return {Error:false};
|
|
}
|
|
function handleError(error)
|
|
{
|
|
return {Error:'There was an error:'+error}
|
|
}
|
|
return x.Error?false:true;
|
|
}
|
|
async function handleData(data)
|
|
{
|
|
if(data.allPlayers.length!=2) return reset('Unqualified match, not enough players.');
|
|
var playerA = data.allPlayers[0].summonerName;
|
|
var playerB = data.allPlayers[1].summonerName;
|
|
//if(data.allPlayers[0].scores.creepScore>=100 || data.allPlayers[1].scores.creepScore>=100) return handleResults(data.allPlayers[0].scores.creepScore==100?playerA:playerB, data)
|
|
if(data.events.Events.length==2) return;
|
|
data.events.Events.forEach(Event =>
|
|
{
|
|
if(Event.EventName =="FirstBlood" || Event.EventName =="FirstBrick") return handleResults(Event, data);
|
|
});
|
|
if(data.allPlayers[0].scores.creepScore>=100 && data.allPlayers[1].scores.creepScore>=100) return handleTie(data)
|
|
}
|
|
function RegisterGame(result,data)
|
|
{
|
|
stopSpinner();
|
|
const PA = data.allPlayers[0]; //Player A
|
|
const PB = data.allPlayers[1]; //Player B
|
|
if(!result.tie)
|
|
{
|
|
result = {
|
|
winCondition:result.EventName,
|
|
winner:result.EventName=='FirstBrick'?result.KillerName:result.Recipient
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result= {
|
|
winCondition:'Tie',
|
|
winner:'Tie'
|
|
}
|
|
}
|
|
|
|
fetch(`${window.location.origin}/api/RegisterGame`,
|
|
{
|
|
method: "POST",
|
|
mode: "cors",
|
|
headers:{
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
'id':id,
|
|
'leagueid':leagueid
|
|
},
|
|
body:JSON.stringify({
|
|
result,
|
|
gameData:
|
|
{
|
|
PlayerA:
|
|
{
|
|
championName:PA.championName,
|
|
summonerName: PA.summonerName,
|
|
isBot: PA.isBot,
|
|
team: PA.team,
|
|
items:PA.items,
|
|
level:PA.level,
|
|
runes:PA.runes,
|
|
skin:PA.skinID,
|
|
skinName:PA.skinName,
|
|
summs:PA.summonerSpells,
|
|
Kills:PA.scores.kills,
|
|
Deaths:PA.scores.deaths,
|
|
CS:PA.scores.creepScore
|
|
},
|
|
PlayerB:
|
|
{
|
|
championName:PB.championName,
|
|
summonerName: PB.summonerName,
|
|
isBot: PB.isBot,
|
|
team: PB.team,
|
|
items:PB.items,
|
|
level:PB.level,
|
|
runes:PB.runes,
|
|
skin:PB.skinID,
|
|
skinName:PB.skinName,
|
|
summs:PB.summonerSpells,
|
|
Kills:PB.scores.kills,
|
|
Deaths:PB.scores.deaths,
|
|
CS:PB.scores.creepScore
|
|
},
|
|
gameTime:data.gameData.gameTime
|
|
},
|
|
fullData:data,
|
|
})
|
|
})
|
|
.then(result => result.json())
|
|
.then(res =>
|
|
{
|
|
if(res.success)
|
|
{
|
|
location.href = '/leagues'
|
|
}
|
|
else alert(res.Error);
|
|
})
|
|
.catch(console.error);
|
|
}
|
|
|
|
function reset(reason)
|
|
{
|
|
if(!hasBeenAlerted) alert(reason);
|
|
hasBeenAlerted=true;
|
|
clearInterval(interval);
|
|
hasStarted=false;
|
|
}
|
|
|
|
function handleResults(result, data)
|
|
{
|
|
//If it gets here there is already a clear winner.
|
|
clearInterval(interval)
|
|
var costumEvent = {
|
|
"EventID": 5000,
|
|
"EventName": "100th creep",
|
|
"EventTime": data.gameData.gameTime,
|
|
"Recipient": '',
|
|
}
|
|
if(result == 'string')
|
|
{
|
|
let cache = result;
|
|
result= costumEvent;
|
|
result.Recipient = cache
|
|
}
|
|
RegisterGame(result, data)
|
|
}
|
|
|
|
function handleTie(data)
|
|
{
|
|
var result = {
|
|
tie:true,
|
|
}
|
|
RegisterGame(result,data)
|
|
} |