function del(url, message)
{
if (message == undefined)
{
message = "Do you want to delete this server? Attention, this can't be undone !!";
}
if (confirm(message))
{
document.location.href=url;
}
}
function showState2(field, state, notice){
if (state == "good"){
notice = ' Good';
}else if (state == "error"){
notice = ' '+notice+'';
}else if (state == "warning"){
notice = ' '+notice+'';
}else if (state == "good_empty"){
state = 'good';
}
$('#'+field+'_state').val(state);
$('#'+field+'_notice').html(notice);
}
function showState3(field, state, notice, noscroll = false){
if (state == "good"){
notice = '';
}else if (state == "error"){
notice = '
'+notice+'
';
}else if (state == "warning"){
notice = ' '+notice+'
';
}
$('#'+field+'_state').val(state);
$('#'+field+'_notice').html(notice);
if (state == "good"){
$('#'+field+'_notice').hide();
}else{
$('#'+field+'_notice').show();
if (!noscroll){$('html,body').animate({scrollTop:$('#'+field+'_notice').offset().top}, 500);}
}
}
function checkName(str){
$.ajax({
type: 'POST',
url: '/ajax.php',
data: { action: "checkServerName", name: str },
success: function(data){
showState3("name", data.state, data.notice);
},
dataType: 'json',
async: false
});
}
function checkAddress(str, str2, str3){
$.ajax({
type: 'POST',
url: '/ajax.php',
data: { action: "checkServerAddress", address: str, port: str2, port_query: str3 },
success: function(data){
if (data.existingserver > 0){
data.notice = data.notice + '. Click here to claim it.';
}
showState3("address", data.state, data.notice);
},
dataType: 'json',
async: false
});
}
function check_server_add_form(){
checkName($('#name').val());
checkAddress($('#address').val(),$('#port').val());
if ($('#connection_state').val()=="error"){
if (!$('#connection_status').is(":visible")){
$('#connection_notice').html(' You need to click on "Check the connection" button first.
');
$('#connection_status').show();
}
}
if (($('#name_state').val()=="good") && ($('#connection_state').val()=="good") && ($('#address_state').val()=="good")){
document.server_form.submit();
}
}
function check_server_form(){
checkName($('#name').val());
checkAddress($('#address').val(),$('#port').val());
if (($('#name_state').val()=="good") && ($('#address_state').val()=="good")){
document.server_form.submit();
}
}
function checkFlag(fieldID){
if (fieldID == "flag_easy"){
if ($("#flag_easy").is(":checked")) {
$("#flag_normal").attr('checked', false);
$("#flag_bambi").attr('checked', false);
$("#flag_hardcore").attr('checked', false);
$("#flag_hard").attr('checked', false);
}
}
if (fieldID == "flag_hard"){
if ($("#flag_hard").is(":checked")) {
$("#flag_normal").attr('checked', false);
$("#flag_bambi").attr('checked', false);
$("#flag_hardcore").attr('checked', false);
$("#flag_easy").attr('checked', false);
}
}
if (fieldID == "flag_no_sync"){
if ($("#flag_no_sync").is(":checked")) {
$("#flag_sync").attr('checked', false);
}
}
if (fieldID == "flag_normal"){
if ($("#flag_normal").is(":checked")) {
$("#flag_bambi").attr('checked', false);
$("#flag_hardcore").attr('checked', false);
$("#flag_hard").attr('checked', false);
$("#flag_easy").attr('checked', false);
}
}
if (fieldID == "flag_pve"){
if ($("#flag_pve").is(":checked")) {
$("#flag_pvp").attr('checked', false);
}
}
if (fieldID == "flag_pvp"){
if ($("#flag_pvp").is(":checked")) {
$("#flag_pve").attr('checked', false);
}
}
if (fieldID == "flag_secure"){
if ($("#flag_secure").is(":checked")) {
$("#flag_unsecure").attr('checked', false);
}
}
if (fieldID == "flag_sync"){
if ($("#flag_sync").is(":checked")) {
$("#flag_no_sync").attr('checked', false);
}
}
if (fieldID == "flag_unsecure"){
if ($("#flag_unsecure").is(":checked")) {
$("#flag_secure").attr('checked', false);
}
}
}
function external_link(str){
$.ajax({
type: 'POST',
url: '/ajax.php',
data: { action: "externalLink", url: str },
success: function(data){
},
dataType: 'json',
async: true
});
}
function check_group_form(){
if (document.getElementById("name").value.length < 5 ) {
showState3('name', 'error', 'Name too short');
}else{
showState3('name', 'good', '');
}
var $b = $('.ServerBoxes');
if ($b.filter(':checked').length >= 2){
showState3('servers', 'good', '');
if ($('#name_state').val()=="good"){
document.group_form.submit();
}
}else{
showState3('servers', 'error', 'You need to select at least 2 servers!');
}
}
function checkConnection(){
$('#connection_notice').html(' Please wait...
');
$('#connection_status').show();
$.ajax({
type: 'POST',
url: '/ajax.php',
data: { action: "checkServerConnection", address: $('#address').val(), port: $('#port').val(), port_query: $('#port_query').val(), version: $('#version').val() },
success: function(data){
if (data.state == "good"){
notice = ' Connection is good.
';
}else if (data.state == "error"){
notice = ' '+data.notice+'
';
}else if (data.state == "warning"){
notice = ' '+data.notice+'
';
}else if (data.state == "good_empty"){
data.state = 'good';
}
$('#connection_state').val(data.state);
$('#connection_notice').html(notice);
},
complete: function(xhr, textStatus){
if (textStatus != "success"){
notice = ' An error occurred. Try again or contact support.
';
$('#connection_state').val('error');
$('#connection_notice').html(notice);
}
},
dataType: 'json',
async: true
});
}
function getTeamspeakState(server_id, field){
$('#'+field).html('');
$.ajax({
type: 'POST',
url: '/ajax.php',
data: {
action: "getTeamspeakState",
server_id: server_id,
},
success: function(data){
$('#'+field).html(data.results);
},
dataType: 'json',
async: true
});
}
function getDiscordState(discord_id, server_id, field){
$('#'+field).html('');
$.ajax({
type: 'POST',
url: '/ajax.php',
data: {
action: "getDiscordState",
discord_id: discord_id,
server_id: server_id,
},
success: function(data){
$('#'+field).html(data.results);
},
dataType: 'json',
async: true
});
}
$(document).ready(function(){
var clipboard = new ClipboardJS('.clipboard');
});
$(window).on('load', function (e) {
setTimeout(() => {
$('#vote-loading-block').hide();
$('#vote-form-block').show();
}, 500);
});