<?php
passthru('reset');
date_default_timezone_set('Europe/Paris');
ini_set('display_errors', '0');
error_reporting(0);
echo "[\033[32mEffectué\033[0m][\033[36m" . date('d/m H:i:s') . "\033[0m] Lancement des Notifications Push \n";
class Database
{
public static
function Check()
{
try {
$host = "localhost";
$dbname = "yhabbo";
$user = "root";
$pass = "aqwzsx";
$db = new PDO('mysql:host=' . $host . ';dbname=' . $dbname . ';charset=utf8', $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("SET CHARACTER SET utf8");
return $db;
}
catch(PDOException $e) {
echo "[\033[31mErreur\033[0m][\033[36m" . date('d/m H:i:s') . "\033[0m] Connexion à la base de données impossible \n";
}
}
}
if (Database::Check()) {
echo "[\033[32mEffectué\033[0m][\033[36m" . date('d/m H:i:s') . "\033[0m] Notifications Push YourHabbo -> \033[33mEn ligne\033[0m \n";
}
else {
echo "[\033[31mErreur\033[0m][\033[36m" . date('d/m H:i:s') . "\033[0m] Veuillez vérifier votre base de données \n";
}
define('HOST_NAME', "localhost");
define('PORT', "8091");
$null = NULL;
require_once ("class.notifications.php");
$notifications = new Notifications();
$socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socketResource, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($socketResource, 0, PORT);
socket_listen($socketResource);
$clientSocketArray = array(
$socketResource
);
while (true) {
$newSocketArray = $clientSocketArray;
socket_select($newSocketArray, $null, $null, 0, 10);
if (in_array($socketResource, $newSocketArray)) {
$newSocket = socket_accept($socketResource);
$clientSocketArray[] = $newSocket;
$header = socket_read($newSocket, 1024);
$notifications->doHandshake($header, $newSocket, HOST_NAME, PORT);
socket_getpeername($newSocket, $client_ip_address);
$newSocketIndex = array_search($socketResource, $newSocketArray);
unset($newSocketArray[$newSocketIndex]);
}
foreach($newSocketArray as $newSocketArrayResource) {
while (socket_recv($newSocketArrayResource, $socketData, 1024, 0) >= 1) {
$socketMessage = $notifications->unseal($socketData);
$messageObj = json_decode($socketMessage);
if(trim($messageObj->chat_message) AND trim($messageObj->chat_url) AND trim($messageObj->chat_title)) {
$chat_box_message = $notifications->createChatBoxMessage($messageObj->chat_message, $messageObj->chat_url, $messageObj->chat_title);
$notifications->send($chat_box_message);
echo "[\033[35mNotification\033[0m][\033[36m" . date('d/m H:i:s') . "\033[0m] \033[31m$messageObj->chat_message\033[0m \n";
}
break 2;
}
$socketData = @socket_read($newSocketArrayResource, 1024, PHP_NORMAL_READ);
if ($socketData === false) {
socket_getpeername($newSocketArrayResource, $client_ip_address);
$newSocketIndex = array_search($newSocketArrayResource, $clientSocketArray);
unset($clientSocketArray[$newSocketIndex]);
}
}
}
socket_close($socketResource);