|
|
@ -19,7 +19,25 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
*/ |
|
|
|
//https://icon-icons.com
|
|
|
|
const Keys = { Enter: 13 }; |
|
|
|
var api_response; |
|
|
|
|
|
|
|
function Steam3to64(steam3) { |
|
|
|
var SID64_1 = "7656" |
|
|
|
var SID64_S = Number(1197960265728); |
|
|
|
var PatternSteam3ID = /^\[([Ug]):([0-9]):([0-9]+)\]$/; |
|
|
|
var Steam3ID = PatternSteam3ID.exec(steam3); |
|
|
|
var S3ID_3 = Number(Steam3ID[3]); |
|
|
|
var SID64_2 = S3ID_3 + SID64_S; |
|
|
|
return SID64_1+SID64_2; |
|
|
|
} |
|
|
|
|
|
|
|
function check_cookie_name(name) { |
|
|
|
var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); |
|
|
|
if (match && match[2] != "None") { return true; } |
|
|
|
else { return false; } |
|
|
|
} |
|
|
|
|
|
|
|
$(async function() { |
|
|
|
$(document).on("keypress", "input", function (e) { |
|
|
@ -77,12 +95,13 @@ let invalid_captcha = ` |
|
|
|
` |
|
|
|
// use templates
|
|
|
|
function generate_server_card_div(data){ |
|
|
|
//////////////////////////////////////////
|
|
|
|
return ` |
|
|
|
<div class="col-auto justify-content-center align-self-center" style="padding: 1rem;"> |
|
|
|
<div class="card text-right" style="width: 15rem; height: 15rem;"> |
|
|
|
<img class="card-img" src="${data.preview}" alt="${data.name}" style="filter: blur(1px); height: 100%;"> |
|
|
|
<div class="card-img-overlay" style="background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.7))"><!--background-color: rgba(0, 0, 0, 0.205);--> |
|
|
|
<a href="steam://connect/${data.address}" class="stretched-link" ${data.status ? "" : "disabled"}></a> |
|
|
|
<a href="#" class="stretched-link" ${data.status ? "" : "disabled"} id="ChoiceServerButton_${data.selfname.replaceAll(".","_")}" data-id="${data.selfname.replaceAll(".","_")}"></a> |
|
|
|
<h4 class="card-title" style="color: whitesmoke;">${data.name}</h4> |
|
|
|
<p class="card-text" style="color: whitesmoke; font-family: tf2build; font-size: 3rem; text-align: center;">${data.player_count}/${data.max_players}</p> |
|
|
|
<h4 class="card-title" style="color: whitesmoke; text-align: right;">${data.human_name}</h4> |
|
|
@ -92,6 +111,169 @@ function generate_server_card_div(data){ |
|
|
|
` |
|
|
|
} |
|
|
|
|
|
|
|
function bind_ServerAboutClose(){ |
|
|
|
$('#Modal_ServerAbout_Close').click(async function (ev) { |
|
|
|
ev.preventDefault(); |
|
|
|
$('#Modal_ServerAbout').modal('hide'); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function bind_ServerAboutReportPlayer_Close(){ |
|
|
|
$('#Modal_ServerAboutReportPlayer_Close').click(async function (ev) { |
|
|
|
ev.preventDefault(); |
|
|
|
$('#Modal_ServerAboutReportPlayer').modal('hide'); |
|
|
|
}); |
|
|
|
|
|
|
|
$("#Modal_ServerAboutReportPlayer_send").click(async function (ev) { |
|
|
|
ev.preventDefault(); |
|
|
|
$("#Modal_ServerAboutReportPlayer_error").html(""); |
|
|
|
if($('#Modal_ServerAboutReportPlayer_reason').val().length < 32){ |
|
|
|
$("#Modal_ServerAboutReportPlayer_error").html("У тебя причина говно, сделай ее более красочной. Опиши подробнее где тебя трогали."); |
|
|
|
} |
|
|
|
//$("#Modal_ServerAboutReportPlayer_error").html("ЛОХ");
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function bind_ServerAboutReportPlayerButton(id){ |
|
|
|
console.log(id); |
|
|
|
$(id).click(async function (ev) { |
|
|
|
ev.preventDefault(); |
|
|
|
$('#Modal_ServerAbout').modal('hide'); |
|
|
|
let data = ev.currentTarget.dataset.id.replaceAll("_",".").split("|", 2); |
|
|
|
console.log(data); |
|
|
|
Modal_Fill_Report(data[0], data[1]); |
|
|
|
$('#Modal_ServerAboutReportPlayer').modal('show'); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function Modal_Fill_Report(srv, player_id){ |
|
|
|
$(`#Modal_ServerAboutReportPlayer_name`).html(api_response.servers[srv].players[player_id].name); |
|
|
|
} |
|
|
|
|
|
|
|
function bind_ServerAboutButton(srv_name){ |
|
|
|
$(`#ChoiceServerButton_${srv_name.replaceAll(".","_")}`).click(async function (ev) { |
|
|
|
ev.preventDefault(); |
|
|
|
let srv = ev.currentTarget.dataset.id.replaceAll("_","."); |
|
|
|
Modal_Fill_Choiced(srv); |
|
|
|
$('#Modal_ServerAbout').modal('show'); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function Modal_Fill_Choiced(srv){ |
|
|
|
$("#Modal_ServerAboutBody").empty(); |
|
|
|
$("#Modal_ServerAbout_Label").html(api_response.servers[srv].name); |
|
|
|
let modal_body = ` |
|
|
|
<div class="row justify-content-center"> |
|
|
|
<div class="col text-center"> |
|
|
|
<!--<img class="w-100 h-50 rounded-5" src="${api_response.servers[srv].preview}" alt="server preview">--> |
|
|
|
<h6>${api_response.servers[srv].description}</h6> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<hr> |
|
|
|
<div class="row justify-content-center" id="Modal_ServerAbout_SelectButtons">`;
|
|
|
|
|
|
|
|
if (api_response.servers[srv].status) { |
|
|
|
modal_body += ` |
|
|
|
<div class="col"> |
|
|
|
<div class="card"> |
|
|
|
<img class="card-img" src="site_content/images/logo/terminal.svg" alt="connect"> |
|
|
|
<div class="card-img-overlay d-flex flex-column"> |
|
|
|
<a href="steam://connect/${api_response.servers[srv].address}" class="stretched-link"></a> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<h5 style="text-align:center">Подключиться</h5> |
|
|
|
</div> |
|
|
|
`;
|
|
|
|
if (api_response.servers[srv].workshop.length != 0) { |
|
|
|
modal_body += ` |
|
|
|
<div class="col"> |
|
|
|
<div class="card"> |
|
|
|
<img class="card-img" src="site_content/images/logo/steam.svg" alt="workshop"> |
|
|
|
<div class="card-img-overlay d-flex flex-column"> |
|
|
|
<a href="${api_response.servers[srv].workshop}" class="stretched-link"></a> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<h5 style="text-align:center">Workshop</h5> |
|
|
|
</div> |
|
|
|
`;} else {
|
|
|
|
modal_body += ` |
|
|
|
<div class="col"> |
|
|
|
<div class="card"> |
|
|
|
<img class="card-img" src="site_content/images/logo/steam.svg" alt="workshop"> |
|
|
|
<div class="card-img-overlay d-flex flex-column"> |
|
|
|
<a href="https://tf2.pblr-nyk.pro/tf/maps/${api_response.servers[srv].map}.bsp.bz2" class="stretched-link"></a> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<h5 style="text-align:center">Скачать карту</h5> |
|
|
|
</div>` |
|
|
|
} |
|
|
|
} else { |
|
|
|
modal_body += `<div class="col"><h5 style="text-align:center">Сервер в отключке...</h5></div>` |
|
|
|
} |
|
|
|
modal_body += "</div><hr>"; |
|
|
|
|
|
|
|
let allow_report = check_cookie_name("steam64"); |
|
|
|
if (api_response.servers[srv].status) { |
|
|
|
if(api_response.servers[srv].player_count > 0) { |
|
|
|
modal_body += ` |
|
|
|
<div class="row justify-content-center" id="Modal_ServerAbout_Players_Current"> |
|
|
|
<div class="col"> |
|
|
|
<h3 style="text-align:center">Сейчас играет ${api_response.servers[srv].player_count}/${api_response.servers[srv].max_players}</h3> |
|
|
|
</div> |
|
|
|
</div>`; |
|
|
|
modal_body += ` |
|
|
|
<div class="row justify-content-center" id="Modal_ServerAbout_Players_list"> |
|
|
|
<div class="col"> |
|
|
|
<table class="table"> |
|
|
|
<thead> |
|
|
|
<tr> |
|
|
|
<th scope="col">Имя игрока</th> |
|
|
|
<th scope="col">Очки</th> |
|
|
|
<th scope="col">Время игры</th> |
|
|
|
${allow_report?'<th scope="col">Репорт</th>':''} |
|
|
|
</tr> |
|
|
|
</thead> |
|
|
|
<tbody>`;
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
let sorted_players = Object.keys(api_response.servers[srv].players).sort((a, b) => { |
|
|
|
return api_response.servers[srv].players[b].score - api_response.servers[srv].players[a].score; |
|
|
|
}); |
|
|
|
for (const player_id in sorted_players) { |
|
|
|
let player = api_response.servers[srv].players[sorted_players[player_id]]; |
|
|
|
modal_body += ` |
|
|
|
<tr> |
|
|
|
<th scope="row"><a href="https://steamcommunity.com/profiles/${Steam3to64(player.steam2)}" target="_blank" class="player-in-list">${player.name}</a></th> |
|
|
|
<td>${player.score ? player.score : 0}</td> |
|
|
|
<td>${player.duration}</td> |
|
|
|
${allow_report?`<td><a href="#" id="Modal_ReportButton_${srv.replaceAll(".","_")}_${player.id}" data-id="${srv.replaceAll(".","_")}|${sorted_players[player_id]}"><img style="height:1rem" src="site_content/images/logo/report.svg" alt="report"></td>`:''} |
|
|
|
</tr> |
|
|
|
`;
|
|
|
|
} |
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
modal_body += `</tbody>
|
|
|
|
</table> |
|
|
|
</div> |
|
|
|
</div>` |
|
|
|
} else { |
|
|
|
modal_body += ` |
|
|
|
<div class="row justify-content-center" id="Modal_ServerAbout_Players_Current"> |
|
|
|
<div class="col"> |
|
|
|
<h3 style="text-align:center">Сейчас никто не играет</h3> |
|
|
|
</div> |
|
|
|
</div>`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$(modal_body).appendTo("#Modal_ServerAboutBody"); |
|
|
|
|
|
|
|
if(allow_report && api_response.servers[srv].status && api_response.servers[srv].player_count > 0) { |
|
|
|
for (const player_id in api_response.servers[srv].players) { |
|
|
|
player = api_response.servers[srv].players[player_id]; |
|
|
|
bind_ServerAboutReportPlayerButton(`#Modal_ReportButton_${srv.replaceAll(".","_")}_${player.id}`); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function CheckApi() { |
|
|
|
let api_request_time = (new Date).getTime(); |
|
|
|
await fetch("https://tf2.pblr-nyk.pro/api", {headers: {'Cache-Control':'no-cache'}}) |
|
|
@ -114,6 +296,7 @@ async function RequestAPI() { |
|
|
|
await fetch("https://tf2.pblr-nyk.pro/api/stats", {headers: {'Cache-Control':'no-cache'}}) |
|
|
|
.then(res => res.json()) |
|
|
|
.then(res => { |
|
|
|
api_response = res; |
|
|
|
FillServices(res); |
|
|
|
// $('#current_players').text(res.servers.statistic.player_now)
|
|
|
|
$("#current_players").html(res.servers.statistic.player_now); |
|
|
@ -139,6 +322,7 @@ async function RequestAPI() { |
|
|
|
for (let sort_id in sorted_servers) { |
|
|
|
let server = sorted_servers[sort_id]; |
|
|
|
if (server == `statistic`) {continue;} |
|
|
|
res.servers[server].selfname = server; |
|
|
|
if(res.servers[server].status == true && res.servers[server].player_count > 0) { |
|
|
|
if(!active) { |
|
|
|
$(servers_active).appendTo("#servers_list_v2"); |
|
|
@ -152,6 +336,7 @@ async function RequestAPI() { |
|
|
|
} |
|
|
|
} |
|
|
|
$(generate_server_card_div(res.servers[server])).appendTo("#servers_list_v2"); |
|
|
|
bind_ServerAboutButton(server); |
|
|
|
} |
|
|
|
|
|
|
|
for (let sort_id in sorted_servers) { |
|
|
@ -162,8 +347,12 @@ async function RequestAPI() { |
|
|
|
dead = true; |
|
|
|
} |
|
|
|
$(generate_server_card_div(res.servers[server])).appendTo("#servers_list_v2"); |
|
|
|
bind_ServerAboutButton(server); |
|
|
|
} |
|
|
|
} |
|
|
|
////////////////
|
|
|
|
bind_ServerAboutClose(); |
|
|
|
bind_ServerAboutReportPlayer_Close(); |
|
|
|
}).catch((err) => { |
|
|
|
console.log(err); |
|
|
|
//FillFooter("", 0, 0);
|
|
|
@ -273,4 +462,5 @@ function FillRules() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|