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){
var $cs=$("#"+fieldID).closest('.flag_selection').find(':checkbox:checked');
if ($cs.length > 8) {
$("#"+fieldID).prop('checked', false);
alert("You cannot select more than 8 flags!");
}
if (fieldID == "flag_blockhunt"){
if ($("#flag_blockhunt").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_quakecraft"){
if ($("#flag_quakecraft").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_skyblock"){
if ($("#flag_skyblock").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_skywars"){
if ($("#flag_skywars").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_spleef"){
if ($("#flag_spleef").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_tntrun"){
if ($("#flag_tntrun").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_vanilla"){
if ($("#flag_vanilla").is(":checked")) {
$("#flag_skywars").attr('checked', false);
$("#flag_skyblock").attr('checked', false);
$("#flag_quakecraft").attr('checked', false);
$("#flag_tntrun").attr('checked', false);
$("#flag_spleef").attr('checked', false);
$("#flag_blockhunt").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);
});