Ejemplo n.º 1
0
if ($mode == 'SendAndRetrieveNew') {
    // retrieve the action parameters used to add a new message
    $name = $_POST['name'];
    $message = $_POST['message'];
    $color = $_POST['color'];
    $id = $_POST['id'];
    // check if we have valid values
    if ($name != '' && $message != '' && $color != '') {
        // post the message to the database
        $chat->postMessage($name, $message, $color);
    }
} elseif ($mode == 'DeleteAndRetrieveNew') {
    // delete all existing messages
    $chat->deleteMessages();
} elseif ($mode == 'RetrieveNew') {
    // get the id of the last message retrieved by the client
    $id = $_POST['id'];
}
// Clear the output
if (ob_get_length()) {
    ob_clean();
}
// Headers are sent to prevent browsers from caching
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: application/json');
// retrieve new messages from the server
echo json_encode($chat->retrieveNewMessages($id));
Ejemplo n.º 2
0
$chat = new Chat();
//Create object of class chat
$id = 0;
//Default value of id
//If request is to send message
if (isset($_POST['json_sendMessage'])) {
    $json_decode = json_decode($_POST['json_sendMessage']);
    $name = $json_decode->name;
    $message = $json_decode->message;
    $id = $json_decode->id;
    if ($name != '' && $message != '') {
        $chat->postMessage($name, $message);
        //Call post message function
    }
} else {
    if (isset($_POST['json_requestNewMessages'])) {
        $chat->CreateTable();
        //Create table if not exist
        $json_decode = json_decode($_POST['json_requestNewMessages']);
        $id = $json_decode->id;
    }
}
if (ob_get_length()) {
    ob_clean();
}
//Clear buffer for previous content
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/xml');
echo $chat->retrieveNewMessages($id);
//Call retrive message function which prints output
Ejemplo n.º 3
0
            } else {
                $ptype = 0;
                $to = 0;
            }
            $message = iconv("Windows-1251", "UTF-8//IGNORE", $message);
            $say = $chat->postMessage($message, $color, $to, $user_id, $channel, $ptype);
            $message = iconv("UTF-8", "Windows-1251//IGNORE", $message);
            if (strpos("{$message}", "Нафаня, ") === 0) {
                $selpech = myquery("select count(*) from game_chat_nakaz where town=0 AND user_id='{$user_id}' and date_zak>'" . time() . "'");
                $userpech = 0;
                if ($selpech != false and mysql_num_rows($selpech) > 0) {
                    $userpech = mysql_result($selpech, 0, 0);
                }
                if ($userpech == 0) {
                    include 'bot/index.php';
                }
            }
        }
    }
}
if (ob_get_length()) {
    ob_clean();
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: text/javascript');
$_SESSION['lastMessageID'] = $id;
echo $json->encode($chat->retrieveNewMessages($user_id, $id, $char['clan_id'], $char['sklon']));