public function online()
 {
     $this->viewClass = 'Json';
     $JSONAPI = new JSONAPI('mc.moosemanstudios.local', 20059, 'admin', 'D+eVasTv');
     $players_raw = $JSONAPI->call('players.online')[0]['success'];
     // who's online
     $online = $JSONAPI->call('players.online.count')[0]['success'];
     // how many are online
     $max = $JSONAPI->call('players.online.limit')[0]['success'];
     // how many the server can support
     $players = array();
     foreach ($players_raw as $player) {
         $players[] = $player['name'];
     }
     $this->set('players', $players);
     $this->set('online', $online);
     $this->set('max', $max);
     $this->set('_serialize', ['players', 'online', 'max']);
 }
 public function stats($name = null)
 {
     if (!$name) {
         throw new NotFoundException();
     }
     $JSONAPI = new JSONAPI('mc.moosemanstudios.local', 20059, 'admin', 'D+eVasTv');
     $result = $JSONAPI->call('players.name', [$name])[0];
     if ($result['result'] != 'success') {
         throw new BadRequestException();
     }
     $this->set('stats', $result['success']);
     $this->set('_serialize', ['stats']);
 }
Exemplo n.º 3
0
 public function admin_banip($username = null)
 {
     if ($this->Auth->user('role') > 1) {
         $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
         if ($api->call('server.run_command', ['banip ' . $username])) {
             $this->Session->setFlash($username . ' a été ban IP du serveur !', 'toastr_success');
             return $this->redirect($this->referer());
         } else {
             $this->Session->setFlash('Erreur', 'toastr_error');
             return $this->redirect($this->referer());
         }
     } else {
         throw new NotFoundException();
     }
 }
Exemplo n.º 4
0
 public function vote()
 {
     // Si l'utilisateur est connecté
     if ($this->Auth->user()) {
         // On met time dans une variable
         $time = time();
         // On récupère les infos depuis la base de données
         $vote = $this->Vote->find('first', ['conditions' => ['Vote.user_id' => $this->Auth->user('id')], 'order' => ['Vote.created' => 'DESC']]);
         @($next_vote = $vote['Vote']['next_vote']);
         $nb_votes = $this->Vote->find('count', ['conditions' => ['Vote.user_id' => $this->Auth->user('id')]]);
         // Temps avant de revoter en secondes
         $time_to_vote_in_seconds = $this->config['votes_time'] * 60;
         $time_to_vote_in_seconds = $time + $time_to_vote_in_seconds;
         // Temps avant de revoter en minutes
         $time_to_vote_in_minutes = $next_vote - $time;
         $time_to_vote_in_minutes = $time_to_vote_in_minutes / 60;
         $time_to_vote_in_minutes = round($time_to_vote_in_minutes);
         // Si on n'a jamais voté ou si le temps nécessaire avant un nouveau vote s'est écoulé
         if ($nb_votes == 0 or $time >= $next_vote) {
             // On enregistre le nouveau vote
             $this->Vote->create;
             $this->Vote->saveField('user_id', $this->Auth->user('id'));
             $this->Vote->saveField('ip', $_SERVER['REMOTE_ADDR']);
             $this->Vote->saveField('next_vote', $time_to_vote_in_seconds);
             // On l'ajoute dans la table users
             $this->User->id = $this->Auth->user('id');
             $user = $this->User->find('first', array('conditions' => array('id' => $this->User->id)));
             $user_vote = $user['User']['votes'] + 1;
             $this->User->saveField('votes', $user_vote);
             // S'il y a une récompense à octroyer
             if ($this->config['votes_reward'] != 0) {
                 // On récupère les infos de l'utilisateur
                 $user = $this->User->find('first', ['conditions' => ['User.id' => $this->Auth->user('id')]]);
                 $user_tokens = $user['User']['tokens'];
                 // On définit son nouveau nb de tokens
                 $new_user_tokens = $user_tokens + $this->config['votes_reward'];
                 // On sauvegarde
                 $this->User->id = $this->Auth->user('id');
                 $this->User->saveField('tokens', $new_user_tokens);
                 $this->Vote->saveField('reward', $this->config['votes_reward']);
             }
             // S'il y a une/des commande(s) à exécuter
             if (!empty($this->config['votes_command'])) {
                 // JSONAPI
                 $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
                 // On exécute la/les commande(s)
                 $command = str_replace('%player%', $this->Auth->user('username'), $this->config['votes_command']);
                 if (strstr($this->config['votes_command'], '&&&')) {
                     $new_command = explode('&&&', $command);
                     foreach ($new_command as $command) {
                         $command = trim($command);
                         $api->call('server.run_command', [$command]);
                     }
                 } else {
                     $api->call('server.run_command', [$command]);
                 }
             }
             // On redirige vers la page de vote
             $this->Session->setFlash("Merci d'avoir voté !", 'success');
             return $this->redirect(['controller' => 'votes', 'action' => 'index']);
         } else {
             $this->Session->setFlash('Vous avez déjà voté, vous devez encore attendre ' . $time_to_vote_in_minutes . ' minutes', 'error');
             return $this->redirect(['controller' => 'votes', 'action' => 'index']);
         }
         // Si on n'est pas connecté
     } else {
         $this->Session->setFlash('Vous devez être connecté pour accéder à cette page', 'error');
         return $this->redirect(['controller' => 'users', 'action' => 'login']);
     }
 }
Exemplo n.º 5
0
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with phpMCWeb. If not, see <http://www.gnu.org/licenses/>.
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body,td,th {
	font-family: "Lucida Console", Monaco, monospace;
	font-size: 11px;
}
</style>
</head>

<body>
<?php 
define("___ACCESS", TRUE);
require "../../includes.php";
require "../../inc/jsonapi.php";
$api = new JSONAPI($jsonapi_ip, $jsonapi_port, $jsonapi_username, $jsonapi_password, $jsonapi_salt);
$data = $api->call("getLatestChats");
$data = array_reverse($data["success"]);
foreach ($data as $message => $value) {
    echo "<div style=\"width: 25%; float: left;\">" . date("H:i", $data[$message]["time"]) . " " . $data[$message]["player"] . ":</div>" . "<div style=\"width: 75%; float: left;\">" . $data[$message]["message"] . "</div>\n";
}
?>
</body>
</html>
 public function admin_send_command()
 {
     if ($this->request->is('ajax')) {
         $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
         $command = trim(str_replace('/', '', $this->request->data['command']));
         if ($this->Auth->user('role') > 1) {
             if (!empty($command) && $api->call('server.run_command', [$command])) {
                 $data['result'] = 'success';
                 $data['message'] = 'Commande envoyée au serveur !';
             } else {
                 $data['result'] = 'error';
                 $data['message'] = 'Erreur';
             }
         } else {
             $data['result'] = 'error';
             $data['message'] = 'Action non autorisée';
         }
         echo json_encode($data);
         exit;
     }
 }
Exemplo n.º 7
0
 public function read($slug)
 {
     if ($this->Cpage->findBySlug($slug)) {
         // On récupère les données
         $data = $this->Cpage->findBySlug($slug);
         $content = $data['Cpage']['content'];
         $redirect = $data['Cpage']['redirect'];
         // Si c'est une redirection
         if ($redirect == 1) {
             $url = $data['Cpage']['url'];
             return $this->redirect($url);
         } else {
             // JSONAPI
             $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
             // On récupère le groupe du joueur, return NULL si impossible
             if ($api->call('worlds.world.players.player.chat.groups.primary', ['world', $this->Auth->user('username')])[0]['is_success'] == true) {
                 $group = $api->call('worlds.world.players.player.chat.groups.primary', ['world', $this->Auth->user('username')])[0]['success'];
             } else {
                 $group = null;
             }
             // On récupère l'argent que possède le joueur sur le serveur, return NULL si impossible
             if ($api->call('economy.banks.name.balance', [$this->Auth->user('username')])[0]['is_success'] == true) {
                 $balance = $api->call('economy.banks.name.balance', [$this->Auth->user('username')])[0]['success']['balance'];
             } else {
                 $balance = null;
             }
             // On test si l'utilisateur est connecté en jeu
             $online_players = $api->call('players.online.names');
             $player_is_online = in_array($this->Auth->user('username'), "TristanCode");
             // On génère l'url de connexion
             $login = Router::url(['controller' => 'users', 'action' => 'login']);
             // On génère l'ip du serveur
             $ip_port = $this->config['ip_server'] . ':' . $this->config['port_server'];
             // Si ce pattern existe, on le supprime
             $content = preg_replace("/\\[\\[\\{\\{(.*?)\\}\\}\\]\\]/i", "\$1", $content);
             $content = preg_replace("/\\{\\{\\[\\[(.*?)\\]\\]\\}\\}/i", "\$1", $content);
             // Si on n'est connecté ni au site, ni au jeu
             if (!$this->Auth->user() && !$player_is_online) {
                 $content = preg_replace("/\\{\\{(.*?)\\}\\}/i", "<a href='{$login}'>[Vous devez être connecté pour voir ceci]</a>", $content);
                 $content = preg_replace("/\\[\\[(.*?)\\]\\]/i", "<a href='{$login}'>[Vous devez être connecté au site, et au jeu pour voir ceci]</a>", $content);
                 $content = preg_replace("/\\(\\((.*?)\\)\\)/i", "\$1", $content);
             } elseif (!$this->Auth->user() && $player_is_online) {
                 $content = preg_replace("/\\{\\{(.*?)\\}\\}/i", "<a href='{$login}'>[Vous devez être connecté pour voir ceci]</a>", $content);
                 $content = preg_replace("/\\[\\[(.*?)\\]\\]/i", "<a href='{$login}'>[Vous devez être connecté au site, et au jeu pour voir ceci]</a>", $content);
                 $content = preg_replace("/\\(\\((.*?)\\)\\)/i", "\$1", $content);
             } elseif ($this->Auth->user() && !$player_is_online) {
                 $content = preg_replace("/\\{\\{(.*?)\\}\\}/i", "\$1", $content);
                 $content = preg_replace("/\\[\\[(.*?)\\]\\]/i", "<a href='{$login}'>[Vous devez être connecté au site, et au jeu pour voir ceci]</a>", $content);
                 $content = preg_replace("/\\(\\((.*?)\\)\\)/i", "", $content);
             } else {
                 $content = preg_replace("/\\{\\{(.*?)\\}\\}/i", "\$1", $content);
                 $content = preg_replace("/\\[\\[(.*?)\\]\\]/i", "\$1", $content);
                 $content = preg_replace("/\\(\\((.*?)\\)\\)/i", "", $content);
             }
             if ($group != null) {
                 $content = str_replace('%groupe%', $group, $content);
             } else {
                 $content = str_replace('%groupe%', 'inconnu', $content);
             }
             if ($balance != null) {
                 $content = str_replace('%money%', $balance, $content);
             } else {
                 $content = str_replace('%money%', 'inconnu', $content);
             }
             $content = str_replace('%pseudo%', $this->Auth->user('username'), $content);
             $content = str_replace('%email%', $this->Auth->user('email'), $content);
             $content = str_replace('%tokens%', $this->Auth->user('tokens'), $content);
             $content = str_replace('%ip_port%', $ip_port, $content);
             $content = str_replace('%ip%', $this->config['ip_server'], $content);
             $content = str_replace('%port%', $this->config['port_server'], $content);
             $this->set('content', $content);
             $this->set('data', $data);
         }
     } else {
         throw new NotFoundException();
     }
 }
Exemplo n.º 8
0
 public function UpdateState($extra = false)
 {
     global $config;
     if (!$extra and !$this->IsTimeToUpdate() or !$this->Exist()) {
         return;
     }
     $this->online = false;
     $users_list = NULL;
     if (empty($this->address)) {
         getDB()->ask("UPDATE `" . $this->db . "` SET `online`='0',`last_update`=NOW() WHERE `id`='" . $this->id . "'");
         return;
     }
     getDB()->ask("UPDATE `" . $this->db . "` SET `last_update`=NOW() WHERE `id`='" . $this->id . "'");
     switch ($this->method) {
         case 2:
             // RCON Connect
             loadTool('rcon.class.php');
             try {
                 $rcon = new MinecraftRcon();
                 $rcon->Connect($this->address, $this->port, $this->rcon);
                 $str = $rcon->Command('list');
             } catch (MinecraftRconException $e) {
                 if ($e->getMessage() == 'Server offline') {
                     getDB()->ask("UPDATE `" . $this->db . "` SET `online`='0' WHERE `id`='" . $this->id . "'");
                     return;
                 }
             }
             $str = str_replace(array("\r\n", "\n", "\r"), '', $str);
             $names = explode(', ', substr($str, 19));
             if (!empty($names)) {
                 for ($i = 0; $i < sizeof($names); $i++) {
                     trim($names[$i]);
                 }
             }
             if (!$names[0] == '') {
                 $users_list = $names;
             }
             break;
         case 3:
             // json-api
             loadTool('json_api.php', 'bukkit/');
             $salt = sqlConfigGet('json-verification-salt');
             if (!$salt) {
                 $salt = md5(rand(1000000000, 2147483647) . rand(1000000000, 2147483647));
                 sqlConfigSet('json-verification-salt', $salt);
             }
             if (!extension_loaded("cURL")) {
                 vtxtlog('[monitoring.class.php] cURL module is required');
                 return;
             }
             $api = new JSONAPI($this->address, $this->port, $this->s_user, $this->rcon, $salt);
             // ToDo rewrite / delete . curl is custom module
             $apiresult = $api->call(array("getPlayerLimit", "getPlayerCount"), array(NULL, NULL));
             if (!$apiresult) {
                 getDB()->ask("UPDATE `" . $this->db . "` SET `online`='0' WHERE `id`='" . $this->id . "'");
                 return;
             }
             $full_state = array('numpl' => $apiresult["success"][1]["success"], 'maxplayers' => $apiresult["success"][0]["success"]);
             break;
         default:
             // query, simple query
             loadTool('query.function.php');
             $full_state = $this->method == 1 ? mcraftQuery($this->address, $this->port) : mcraftQuery_SE($this->address, $this->port);
             if (empty($full_state) or isset($full_state['too_many'])) {
                 getDB()->ask("UPDATE `" . $this->db . "` " . "SET `online`='" . (isset($full_state['too_many']) ? '1' : '0') . "' " . "WHERE `id`='" . $this->id . "'");
                 $this->online = isset($full_state['too_many']) ? true : false;
                 return;
             } elseif (!empty($full_state['players'])) {
                 $users_list = $full_state['players'];
             }
             break;
     }
     $this->online = true;
     $system_users = '';
     $numpl = !empty($full_state['numpl']) ? $full_state['numpl'] : 0;
     if ($users_list) {
         $numpl = sizeof($users_list);
         if ($numpl == 1) {
             $system_users = $users_list[0];
         } else {
             for ($i = 0; $i < $numpl; $i++) {
                 $system_users .= $i == 0 ? $users_list[$i] : ',' . $users_list[$i];
             }
         }
     }
     $this->slots = !empty($full_state) ? $full_state['maxplayers'] : -1;
     $this->numpl = $numpl;
     if (!empty($full_state)) {
         $sql = "UPDATE `" . $this->db . "` SET `numpl`=:numpl, slots=:slots, players=:players, online='1' " . "WHERE `id`='" . $this->id . "'";
         getDB()->ask($sql, array('numpl' => $this->numpl, 'slots' => $this->slots, 'players' => $system_users));
     } else {
         $sql = "UPDATE `" . $this->db . "` SET `numpl`=:numpl, slots='-1', players=:players, online='1' " . "WHERE `id`='{$this->id}'";
         getDB()->ask($sql, array('numpl' => $this->numpl, 'players' => $system_users));
     }
 }
Exemplo n.º 9
0
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with phpMCWeb. If not, see <http://www.gnu.org/licenses/>.
 */
define("___ACCESS", TRUE);
require "../includes.php";
require "../inc/loadtimer.php";
require "../inc/jsonapi.php";
require "../lang/" . $language . "/items.php";
$player = $_GET["player"];
if ($player !== "") {
    if (!preg_match("/^[A-Za-z0-9_]+\$/", $player)) {
        die($phpmc["ERRORS"]["INJECT_CAUGHT"]);
    } else {
        $api = new JSONAPI($jsonapi_ip, $jsonapi_port, $jsonapi_username, $jsonapi_password, $jsonapi_salt);
        $data = $api->call("getPlayer", array($player));
        if ($data["result"] !== "success") {
            $error = $phpmc["MAIN"]["PLAYER_OFFLINE"];
        }
    }
} else {
    $error = $phpmc["ERRORS"]["NO_PLAYER_SPECIFIED"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../theme/<?php 
echo $theme;
?>
Exemplo n.º 10
0
 public function admin_disk()
 {
     if ($this->Auth->user('role') > 1) {
         $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
         $totalMemory = round($api->call('server.performance.disk.free')['0']['success']);
         $usedMemory = round($api->call('server.performance.disk.used')['0']['success']);
         $pieData = array(array('Espace disponible', $totalMemory), array('Espace utilisé', $usedMemory));
         $chartName = 'disk_chart';
         $pieChart = $this->Highcharts->create($chartName, 'pie');
         $this->Highcharts->setChartParams($chartName, array('renderTo' => 'disk_chart', 'chartWidth' => 650, 'chartHeight' => 600, 'chartMarginTop' => 60, 'chartMarginLeft' => 90, 'chartMarginRight' => 30, 'chartMarginBottom' => 0, 'chartSpacingRight' => 10, 'chartSpacingBottom' => 15, 'chartSpacingLeft' => 0, 'chartAlignTicks' => FALSE, 'chartBackgroundColorLinearGradient' => array(255, 255, 255, 255), 'chartBackgroundColorStops' => array(array(0, 'rgb(255, 255, 255)'), array(1, 'rgb(255, 255, 255)')), 'title' => 'Utilisation de l\'espace disque du serveur (en MB)', 'titleAlign' => 'center', 'titleFloating' => TRUE, 'titleStyleFont' => '18px Metrophobic, Arial, sans-serif', 'titleStyleColor' => '#606060', 'titleX' => 20, 'titleY' => 20, 'legendEnabled' => TRUE, 'legendLayout' => 'horizontal', 'legendAlign' => 'center', 'legendVerticalAlign ' => 'bottom', 'legendItemStyle' => array('color' => '#222'), 'legendBackgroundColorLinearGradient' => array(0, 0, 0, 25), 'legendBackgroundColorStops' => array(array(0, '#FFFFFF'), array(1, '#FFFFFF')), 'tooltipEnabled' => TRUE, 'tooltipBackgroundColorLinearGradient' => array(0, 0, 0, 50), 'tooltipBackgroundColorStops' => array(array(0, 'rgb(217, 217, 217)'), array(1, 'rgb(255, 255, 255)')), 'creditsEnabled' => FALSE));
         $series = $this->Highcharts->addChartSeries();
         $series->addName('En megabytes')->addData($pieData);
         $pieChart->addSeries($series);
         $this->set(compact('chartName'));
     } else {
         throw new NotFoundException();
     }
 }
 public function admin_update_options()
 {
     if ($this->Auth->user('role') > 1) {
         if ($this->request->is('post')) {
             $this->Informations->id = 1;
             if (isset($this->request->data['use_slider'])) {
                 $this->Informations->saveField('use_slider', 1);
             } else {
                 $this->Informations->saveField('use_slider', 0);
             }
             if (isset($this->request->data['use_captcha'])) {
                 $this->Informations->saveField('use_captcha', 1);
             } else {
                 $this->Informations->saveField('use_captcha', 0);
             }
             if (isset($this->request->data['use_store'])) {
                 $this->Informations->saveField('use_store', 1);
             } else {
                 $this->Informations->saveField('use_store', 0);
             }
             if (isset($this->request->data['use_donation_ladder'])) {
                 $this->Informations->saveField('use_donation_ladder', 1);
             } else {
                 $this->Informations->saveField('use_donation_ladder', 0);
             }
             if (isset($this->request->data['use_paypal'])) {
                 $this->Informations->saveField('use_paypal', 1);
             } else {
                 $this->Informations->saveField('use_paypal', 0);
             }
             if (isset($this->request->data['use_economy'])) {
                 $this->Informations->saveField('use_economy', 1);
             } else {
                 $this->Informations->saveField('use_economy', 0);
             }
             if (isset($this->request->data['use_server_money'])) {
                 $this->Informations->saveField('use_server_money', 1);
             } else {
                 $this->Informations->saveField('use_server_money', 0);
             }
             if (isset($this->request->data['use_votes'])) {
                 $this->Informations->saveField('use_votes', 1);
             } else {
                 $this->Informations->saveField('use_votes', 0);
             }
             if (isset($this->request->data['use_votes_ladder'])) {
                 $this->Informations->saveField('use_votes_ladder', 1);
             } else {
                 $this->Informations->saveField('use_votes_ladder', 0);
             }
             if (isset($this->request->data['use_team'])) {
                 $this->Informations->saveField('use_team', 1);
             } else {
                 $this->Informations->saveField('use_team', 0);
             }
             if (isset($this->request->data['use_contact'])) {
                 $this->Informations->saveField('use_contact', 1);
             } else {
                 $this->Informations->saveField('use_contact', 0);
             }
             if (isset($this->request->data['use_rules'])) {
                 $this->Informations->saveField('use_rules', 1);
             } else {
                 $this->Informations->saveField('use_rules', 0);
             }
             if (isset($this->request->data['happy_hour'])) {
                 $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
                 if ($api->call('server.bukkit.version')[0]['result'] == 'success') {
                     $api->call('server.run_command', ['say Happy hour ! Rendez-vous sur le site. ' . $this->config['happy_hour_bonus'] . '% de ' . $this->config['site_money'] . ' offerts ! (http://' . $_SERVER['HTTP_HOST'] . $this->webroot . 'recharger)']);
                 }
                 $this->Informations->saveField('happy_hour', 1);
             } else {
                 $this->Informations->saveField('happy_hour', 0);
             }
             if (isset($this->request->data['maintenance'])) {
                 $this->Informations->saveField('maintenance', 1);
             } else {
                 $this->Informations->saveField('maintenance', 0);
             }
             if (isset($this->request->data['debug'])) {
                 $this->Informations->saveField('debug', 1);
             } else {
                 $this->Informations->saveField('debug', 0);
             }
             if (isset($this->request->data['use_posts_views'])) {
                 $this->Informations->saveField('use_posts_views', 1);
             } else {
                 $this->Informations->saveField('use_posts_views', 0);
             }
             $this->Session->setFlash('Options mises à jour !', 'toastr_success');
             return $this->redirect(['controller' => 'informations', 'action' => 'index', '?' => ['tab' => 'options']]);
         }
     } else {
         throw new NotFoundException();
     }
 }
Exemplo n.º 12
0
 public function buy()
 {
     $id = $this->request->data['Shop']['id'];
     $money = $this->request->data['Shop']['money'];
     $quantity = $this->request->data['Shop']['quantity'];
     // JSONAPI
     $api = new JSONAPI($this->config['jsonapi_ip'], $this->config['jsonapi_port'], $this->config['jsonapi_username'], $this->config['jsonapi_password'], $this->config['jsonapi_salt']);
     // On test si le joueur est en ligne
     $online_players = $api->call('players.online.names');
     $player_is_online = in_array($this->Auth->user('username'), $online_players[0]['success']);
     // Si l'utilisateur est connecté en jeu
     if ($player_is_online) {
         // Si l'utlisateur est co au site
         if ($this->Auth->user()) {
             // Si la quatité est valide
             if ($quantity >= 1 && $quantity <= 250) {
                 // Si l'item existe
                 if ($this->Shop->findById($id)) {
                     // Si la boutique est activée
                     if ($this->config['use_store'] == 1) {
                         // Si l'utilisateur paye avec la monnaie du site
                         if ($money == 'site') {
                             // On recupère les infos de l'utlisateur
                             $user = $this->User->find('first', ['conditions' => ['User.username' => $this->Auth->user('username')]]);
                             // Le nombre de tokens que possède l'utilisateur
                             $user_tokens = $user['User']['tokens'];
                             // On recupère les infos de l'item
                             $item = $this->Shop->find('first', ['conditions' => ['Shop.id' => $id]]);
                             // Cout de l'achat avec la monnaie du site
                             $price = $item['Shop']['price_money_site'];
                             if ($price == -1) {
                                 return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                 exit;
                             } else {
                                 $price = $item['Shop']['price_money_site'] * $quantity;
                             }
                             // Promotion du produit
                             $promo = $item['Shop']['promo'];
                             if ($promo != -1) {
                                 $promo = round($price / 100 * $promo);
                                 $price = $price - $promo;
                             }
                             // Si l'utilisateur a assez
                             if ($user_tokens >= $price) {
                                 // S'il y a un prérequis pour cet achat
                                 if ($item['Shop']['required'] != -1) {
                                     $item_required = $this->Shop->find('first', ['conditions' => ['Shop.id' => $item['Shop']['required']]]);
                                     $item_required_id = $item_required['Shop']['id'];
                                     $item_required_name = $item_required['Shop']['name'];
                                     // Si l'utilisateur n'a pas le prérequis
                                     if (!$this->shopHistory->find('first', ['conditions' => ['user_id' => $this->Auth->user('id'), 'item_id' => $item_required_id]])) {
                                         $this->Session->setFlash('Cet achat a un prérequis vous devez d\'abord acheter <u>' . $item_required_name . '</u>', 'error');
                                         return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                     }
                                 }
                                 // Historique d'achat
                                 $this->shopHistory->create;
                                 $this->shopHistory->saveField('user_id', $this->Auth->user('id'));
                                 $this->shopHistory->saveField('item', $item['Shop']['name']);
                                 $this->shopHistory->saveField('item_id', $item['Shop']['id']);
                                 $this->shopHistory->saveField('price', $price);
                                 $this->shopHistory->saveField('money', $money);
                                 $this->shopHistory->saveField('quantity', $quantity);
                                 // On définit son nv nb de tokens
                                 $new_user_tokens = $user_tokens - $price;
                                 $this->User->id = $this->Auth->user('id');
                                 $this->User->saveField('tokens', $new_user_tokens);
                                 // On execute la/les commande(s)
                                 $command = str_replace('%player%', $this->Auth->user('username'), $item['Shop']['command']);
                                 for ($i = 0; $i < $quantity; $i++) {
                                     if (strstr($item['Shop']['command'], '&&&')) {
                                         $new_command = explode('&&&', $command);
                                         foreach ($new_command as $command) {
                                             $command = trim($command);
                                             $api->call('server.run_command', [$command]);
                                         }
                                     } else {
                                         $api->call('server.run_command', [$command]);
                                     }
                                 }
                                 // On redirige avec un message
                                 $this->Session->setFlash('Achat effectué, vous avez depensé ' . $price . ' ' . $this->config['site_money'] . '', 'success');
                                 return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                             } else {
                                 $this->Session->setFlash('Vous n\'avez pas assez de ' . $this->config['site_money'] . '', 'error');
                                 return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                             }
                         } else {
                             // Si l'utilisation de la monnaie du serveur est activée
                             if ($this->config['use_economy'] == 1 && $this->config['use_server_money'] == 1) {
                                 // On recupère les infos de l'utlisateur
                                 $user = $this->User->find('first', ['conditions' => ['User.username' => $this->Auth->user('username')]]);
                                 // L'argent que possède l'utilisateur sur le serveur
                                 $user_server_money = $api->call('players.name.bank.balance', [$this->Auth->user('username')])[0]['success'];
                                 // On recupère les infos de l'item
                                 $item = $this->Shop->find('first', ['conditions' => ['Shop.id' => $id]]);
                                 // Cout de l'achat avec la monnaie du serveur
                                 $price = $item['Shop']['price_money_server'];
                                 if ($price == -1) {
                                     return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                     exit;
                                 } else {
                                     $price = $item['Shop']['price_money_server'] * $quantity;
                                 }
                                 $promo = $item['Shop']['promo'];
                                 if ($promo != -1) {
                                     $promo = round($price / 100 * $promo);
                                     $price = $price - $promo;
                                 }
                                 // Si l'utilisateur a assez
                                 if ($user_server_money >= $price) {
                                     // S'il y a un prérequis pour cet achat
                                     if ($item['Shop']['required'] != -1) {
                                         $item_required = $this->Shop->find('first', ['conditions' => ['Shop.id' => $item['Shop']['required']]]);
                                         $item_required_id = $item_required['Shop']['id'];
                                         $item_required_name = $item_required['Shop']['name'];
                                         // Si l'utilisateur n'a pas le prérequis
                                         if (!$this->shopHistory->find('first', ['conditions' => ['user_id' => $this->Auth->user('id'), 'item_id' => $item_required_id]])) {
                                             $this->Session->setFlash('Cet achat a un prérequis vous devez d\'abord acheter <u>' . $item_required_name . '</u>', 'error');
                                             return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                         }
                                     }
                                     // Historique d'achat
                                     $this->shopHistory->create;
                                     $this->shopHistory->saveField('user_id', $this->Auth->user('id'));
                                     $this->shopHistory->saveField('item', $item['Shop']['name']);
                                     $this->shopHistory->saveField('item_id', $item['Shop']['id']);
                                     $this->shopHistory->saveField('price', $price);
                                     $this->shopHistory->saveField('money', $money);
                                     $this->shopHistory->saveField('quantity', $quantity);
                                     // On fait payer l'utilisateur sur le serveur
                                     $api->call('players.name.bank.withdraw', [$this->Auth->user('username'), $price]);
                                     // On execute la/les commande(s)
                                     $command = str_replace('%player%', $this->Auth->user('username'), $item['Shop']['command']);
                                     for ($i = 0; $i < $quantity; $i++) {
                                         if (strstr($item['Shop']['command'], '&&&')) {
                                             $new_command = explode('&&&', $command);
                                             foreach ($new_command as $command) {
                                                 $command = trim($command);
                                                 $api->call('server.run_command', [$command]);
                                             }
                                         } else {
                                             $api->call('server.run_command', [$command]);
                                         }
                                     }
                                     // On redirige avec un message
                                     $this->Session->setFlash('Achat effectué, vous avez depensé ' . $price . ' ' . $this->config['money_server'] . '', 'success');
                                     return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                 } else {
                                     $this->Session->setFlash('Vous n\'avez pas assez de ' . $this->config['money_server'] . '', 'error');
                                     return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                                 }
                             } else {
                                 $this->Session->setFlash('Action impossible', 'error');
                                 return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                             }
                         }
                         // Si la boutique n'est pas activé
                     } else {
                         $this->Session->setFlash('Désolé mais la boutique est désactivé, contactez un administrateur', 'error');
                         return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                     }
                 } else {
                     $this->Session->setFlash('Cet article n\'existe pas !', 'error');
                     return $this->redirect(['controller' => 'shops', 'action' => 'index']);
                 }
                 // Si la quantité est invalide
             } else {
                 $this->Session->setFlash('Quantité invalide', 'error');
                 return $this->redirect(['controller' => 'shops', 'action' => 'index']);
             }
             // Si l'utlisateur n'est pas co au site
         } else {
             $this->Session->setFlash('Vous devez être connecté pour accéder à cette page', 'error');
             return $this->redirect(['controller' => 'users', 'action' => 'login', 'admin' => false]);
         }
         // Si l'utlisateur n'est pas co en jeu
     } else {
         $this->Session->setFlash('Vous devez être connecté en jeu pour faire un achat', 'error');
         return $this->redirect(['controller' => 'shops', 'action' => 'index']);
     }
 }
Exemplo n.º 13
0
<?php

require '../sdk/php/JSONAPI.php';
$api = new JSONAPI("localhost", 20059, "admin", "demo", "");
// host/ip, port, username, password, salt
var_dump($api->call("getPlayerLimit"));