Verifica player per EmpireFactions.tk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//RESTful Player Verification API for 'empirefactions.tk' | |
//AUTHOR: mrBackSlash | |
//player verification section | |
//include config | |
require 'config.php'; | |
//get params from request | |
$playername = $link->real_escape_string($_GET['ign']); | |
$playerip = $_GET['ip']; | |
$playercountry = $_GET['country']; | |
//check if store is not closed | |
if($is_store_disabled){ | |
makeJson("false", "Lo store al momento è chiuso, riprovare più tardi!"); | |
} | |
//check if database is OK | |
if($e != 0){ | |
makeJson("false", "Impossibile connettersi al database, errore $e!"); | |
} | |
if(!isset($_GET['ign']) | !isset($_GET['ip']) | $playername == "" | $playerip == ""){ | |
makeJson("false", "Richiesta non valida!"); | |
} | |
//chech if player has joined network | |
$j_ver_stmt = $link->prepare("SELECT `last_name` FROM `ls_players` WHERE `last_name` = ?"); | |
$j_ver_stmt->bind_param("s", $playername_p); | |
$playername_p = $playername; | |
if(!$j_ver_stmt->execute()){ | |
$j_ver_stmt->close(); | |
makeJson("false", "Impossibile connettersi al server di verifica, riprovare più tardi!"); | |
} | |
$j_ver_stmt->store_result(); | |
if($j_ver_stmt->num_rows < 1){ | |
$j_ver_stmt->close(); | |
makeJson("false", "Non sei registrato sul server, per farlo entra su 'empirefactions.tk' e registrati con /register password confermapassword"); | |
} | |
$j_ver_stmt->close(); | |
//check if ip is not banned | |
//ip to varbinary(16) conversion | |
$ip_long = ip2long($playerip); | |
$ip_varbinary = dechex($ip_long); | |
//actual check | |
$ip_ver_stmt = $link->prepare("SELECT `reason`, `actor_id`, `created` FROM `bm_ip_bans` WHERE `ip` = UNHEX(?)"); | |
$ip_ver_stmt->bind_param("s", $ip_varbinary_p); | |
$ip_varbinary_p = $ip_varbinary; | |
if(!$ip_ver_stmt->execute()){ | |
$ip_ver_stmt->close(); | |
makeJson("false", "Impossibile connettersi al server di verifica, riprovare più tardi!"); | |
} | |
$ip_ver_stmt->store_result(); | |
if($ip_ver_stmt->num_rows != 0){ | |
$reason_r = $actor_id_r = $created_r = ""; | |
$ip_ver_stmt->bind_result($reason_r, $actor_id_r, $created_r); | |
//actor id conversion to mc username | |
$ip_ver_stmt->fetch(); | |
$actor_id_r_u = bin2hex($actor_id_r); | |
$aid_conv = $link->query("SELECT `name` FROM `bm_players` WHERE `id` = 0x$actor_id_r_u"); | |
if($aid_conv->num_rows == 0){ | |
$actor_id_ok = "NULL"; | |
}else{ | |
$aid_conv_res = $aid_conv->fetch_array(MYSQLI_ASSOC); | |
$actor_id_ok = $aid_conv_res['name']; | |
} | |
//created conversion to human-readable date | |
$created_ok = date("d-m-Y", $created_r) . " alle ore " .date("H:i:s",$created_r); | |
$messaggio = sprintf("Impossibile accedere allo store, il tuo ip è stato bannato da %s il giorno %s per '%s'.", $actor_id_ok, $created_ok, $reason_r); | |
makeJson("false", $messaggio); | |
} | |
$ip_ver_stmt->close(); | |
//check if player_username is not banned | |
//get id from player | |
$playerconv_stmt = $link->prepare("SELECT `id` FROM `bm_players` WHERE `name` = ?"); | |
$playerconv_stmt->bind_param("s", $playername_p); | |
$playername_p = $playername; | |
if(!$playerconv_stmt->execute()){ | |
$playerconv_stmt->close(); | |
makeJson("false", "Impossibile connettersi al server di verifica, riprovare più tardi!"); | |
} | |
$playerconv_stmt->store_result(); | |
if($playerconv_stmt->num_rows != 0){ | |
$playerid_r = ""; | |
$playerconv_stmt->bind_result($playerid_r); | |
$playerconv_stmt->fetch(); | |
$playerid_r_u = bin2hex($playerid_r); | |
}else{ | |
$playerconv_stmt->close(); | |
makeJson("false", "Errore interno, riprovare più tardi!"); | |
} | |
$playerconv_stmt->close(); | |
//check ban | |
$checkbanplayer = $link->query("SELECT `reason`, `actor_id`, `created` FROM `bm_player_bans` WHERE `player_id` = 0x$playerid_r_u"); | |
if($checkbanplayer->num_rows != 0){ | |
$checkbp_res = $checkbanplayer->fetch_array(MYSQLI_ASSOC); | |
$reason_r = $checkbp_res['reason']; | |
$actor_id_r = bin2hex($checkbp_res['actor_id']); | |
$created_r = $checkbp_res['created']; | |
//actor id conversion to mc username | |
$aid_conv = $link->query("SELECT `name` FROM `bm_players` WHERE `id` = 0x$actor_id_r"); | |
if($aid_conv->num_rows == 0){ | |
$actor_id_ok = "NULL"; | |
} | |
$aid_conv_arr = $aid_conv->fetch_array(MYSQLI_ASSOC); | |
$actor_id_ok = $aid_conv_arr['name']; | |
//created conversion to human-readable date | |
$created_ok = date("d-m-Y", $created_r). " alle ore " . date("H:i:s", $created_r); | |
$messaggio = sprintf("Impossibile accedere allo store, sei stato bannato da %s il giorno %s per '%s'.", $actor_id_ok, $created_ok, $reason_r); | |
makeJson("false", $messaggio); | |
}else{ | |
makeJson("true"); | |
} | |
function makeJson($verified, $message=""){ | |
global $link; | |
$rawjson = '{ | |
"verified":%s, | |
"message":"%s" | |
}'; | |
$link->close(); | |
$re = sprintf($rawjson, $verified, $message); | |
die($re); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment