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_custom_loot"){
if ($("#flag_custom_loot").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_economy"){
if ($("#flag_economy").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_essentials"){
if ($("#flag_essentials").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
$("#flag_rustplusplus").attr('checked', false);
$("#flag_oxide").attr('checked', false);
}
}
if (fieldID == "flag_factions"){
if ($("#flag_factions").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_fast_crafting"){
if ($("#flag_fast_crafting").is(":checked")) {
$("#flag_instant_craft").attr('checked', false);
}
}
if (fieldID == "flag_groups"){
if ($("#flag_groups").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_instant_craft"){
if ($("#flag_instant_craft").is(":checked")) {
$("#flag_fast_crafting").attr('checked', false);
}
}
if (fieldID == "flag_kits"){
if ($("#flag_kits").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
}
}
if (fieldID == "flag_no_sleepers"){
if ($("#flag_no_sleepers").is(":checked")) {
$("#flag_sleepers").attr('checked', false);
}
}
if (fieldID == "flag_oxide"){
if ($("#flag_oxide").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
$("#flag_rustplusplus").attr('checked', false);
$("#flag_essentials").attr('checked', false);
}
}
if (fieldID == "flag_rustplusplus"){
if ($("#flag_rustplusplus").is(":checked")) {
$("#flag_vanilla").attr('checked', false);
$("#flag_oxide").attr('checked', false);
$("#flag_essentials").attr('checked', false);
}
}
if (fieldID == "flag_sleepers"){
if ($("#flag_sleepers").is(":checked")) {
$("#flag_no_sleepers").attr('checked', false);
}
}
if (fieldID == "flag_vanilla"){
if ($("#flag_vanilla").is(":checked")) {
$("#flag_oxide").attr('checked', false);
$("#flag_rustplusplus").attr('checked', false);
$("#flag_kits").attr('checked', false);
$("#flag_custom_loot").attr('checked', false);
$("#flag_economy").attr('checked', false);
$("#flag_factions").attr('checked', false);
$("#flag_groups").attr('checked', false);
$("#flag_magma").attr('checked', false);
$("#flag_essentials").attr('checked', false);
$("#flag_pluton").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);
});