Example #1
0
 public function init()
 {
     define('DBPATH', 'localhost');
     define('DBUSER', 'root');
     define('DBPASS', 'root');
     define('DBNAME', 'bdpinos');
     // session_start();
     global $dbh;
     $dbh = mysql_connect(DBPATH, DBUSER, DBPASS);
     mysql_selectdb(DBNAME, $dbh);
     if ($_GET['action'] == "chatheartbeat") {
         chatHeartbeat();
     }
     if ($_GET['action'] == "sendchat") {
         sendChat();
     }
     if ($_GET['action'] == "closechat") {
         closeChat();
     }
     if ($_GET['action'] == "startchatsession") {
         startChatSession();
     }
     if (!isset($_SESSION['chatHistory'])) {
         $_SESSION['chatHistory'] = array();
     }
     if (!isset($_SESSION['openChatBoxes'])) {
         $_SESSION['openChatBoxes'] = array();
     }
 }
Example #2
0
/**
 * chat handler, keys: show, send | params: message
 * @param string $key
 * @param mixed $params
 * @return mixed
 *
 */
function chatHandler($key, $params)
{
    $var = null;
    switch ($key) {
        case 'show':
            $var = getChatHistory($_SESSION['chat']);
            break;
        case 'send':
            //$username = getUsername();
            $var = sendChat($_SESSION['user'], $params);
            break;
        default:
            break;
    }
    return $var;
}
Example #3
0
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
define('DBPATH', 'localhost');
define('DBUSER', 'root');
define('DBPASS', 'vertrigo');
define('DBNAME', 'chat');
session_start();
global $dbh;
$dbh = mysql_connect(DBPATH, DBUSER, DBPASS);
mysql_selectdb(DBNAME, $dbh);
if ($_GET['action'] == "chatheartbeat") {
    chatHeartbeat();
}
if ($_GET['action'] == "sendchat") {
    sendChat();
}
if ($_GET['action'] == "closechat") {
    closeChat();
}
if ($_GET['action'] == "startchatsession") {
    startChatSession();
}
if (!isset($_SESSION['chatHistory'])) {
    $_SESSION['chatHistory'] = array();
}
if (!isset($_SESSION['openChatBoxes'])) {
    $_SESSION['openChatBoxes'] = array();
}
function chatHeartbeat()
{
Example #4
0
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

*/
session_start();

global $dbh;

if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); } 
if ($_GET['action'] == "sendchat") { sendChat(); } 
if ($_GET['action'] == "closechat") { closeChat(); } 
if ($_GET['action'] == "startchatsession") { startChatSession(); } 

if (!isset($_SESSION['chatHistory'])) {
	$_SESSION['chatHistory'] = array();	
}

if (!isset($_SESSION['openChatBoxes'])) {
	$_SESSION['openChatBoxes'] = array();	
}

function chatHeartbeat() {
	include("../static/site_config.php"); 
	include ("../static/clase_mysql.php");
	$miconexion = new clase_mysql;
Example #5
0
//        this allows us to track which records have been loaded if multiple tabs for the same chat room are open.
$pageId = Filter::text($_GET['pageId']);
$isValidPageId = Filter::isValidTimestamp($pageId);
if (empty($isValidPageId)) {
    $pageId = time();
}
$slug = Filter::text($_GET['slug']);
$project = Project::getProjectFromSlug($slug);
if ($_GET['action'] == "getonlineusers") {
    getOnlineUsers($slug);
}
if ($_GET['action'] == "chatheartbeat") {
    chatHeartbeat($slug, $pageId);
}
if ($_GET['action'] == "sendchat") {
    sendChat($pageId);
}
if ($_GET['action'] == "closechat") {
    closeChat();
}
if ($_GET['action'] == "startchatsession") {
    startChatSession($pageId);
}
if (!isset($_SESSION['chatHistory'])) {
    $_SESSION['chatHistory'] = array();
}
if (!isset($_SESSION['openChatBoxes'])) {
    $_SESSION['openChatBoxes'] = array();
}
function chatHeartbeat($slug, $pageId)
{
function wsOnMessage($clientID, $message, $messageLength, $binary)
{
    // check if message length is 0
    if ($messageLength == 0) {
        wsClose($clientID);
        return;
    }
    // split the message by spaces into an array, and fetch the command
    $message = explode(' ', $message);
    $command = array_shift($message);
    // check which command was received
    if ($command == 'TEXT') {
        // a client has sent chat text to the server
        if (!isUser($clientID)) {
            // the client has not yet sent a JOIN with a valid username, and is trying to send a TEXT
            wsClose($clientID);
            return;
        }
        // put the message back into a string
        $text = implode(' ', $message);
        if ($text == '') {
            // the text is blank
            wsSend($clientID, 'SERVER Message was blank.');
            return;
        }
        // fetch the client's username, and send the chat text to all clients
        // the text is actually also sent back to the client which sent the text, which sort of acts as a confirmation that the text worked
        $username = getUsername($clientID);
        sendChat($username, $text);
    } elseif ($command == 'JOIN') {
        // a client is joining the chat
        if (isUser($clientID)) {
            // the client has already sent a JOIN with a valid username
            wsClose($clientID);
            return;
        }
        // fetch username, and trim any whitespace before and after the username
        $username = trim($message[0]);
        if ($username == '') {
            // the username is blank
            wsClose($clientID);
            return;
        }
        if (strlen($username) > CB_MAX_USERNAME_LENGTH) {
            // username length is more than CB_MAX_USERNAME_LENGTH
            wsSend($clientID, 'SERVER Username length cannot be more than ' . CB_MAX_USERNAME_LENGTH . '.');
            wsClose($clientID);
            return;
        }
        if (isUsername($username)) {
            // username is already being used by another client
            wsSend($clientID, 'SERVER Username already taken.');
            wsClose($clientID);
            return;
        }
        // add the user
        addUser($clientID, $username);
    } elseif ($command == 'QUIT') {
        // a client is leaving the chat
        if (!isUser($clientID)) {
            // the client has not yet sent a JOIN with a valid username, and is trying to send a QUIT
            wsClose($clientID);
            return;
        }
        // remove the user
        removeUser($clientID);
    } else {
        // unknown command received, close connection
        wsClose($clientID);
    }
}
 $action = $_POST['action'];
 if (isset($_POST['roll'])) {
     $to_roll = mysql_real_escape_string($_POST['roll']);
 }
 if ($action == "startChatSession") {
     startChatSession($to_roll, $enroll);
 } else {
     if ($action == "sendChat") {
         $msg = $_POST['msg'];
         $to_user = mysql_real_escape_string($_POST['name']);
         $t = time() - 3;
         $sql = "SELECT NULL FROM stud_data WHERE usr_roll=" . $to_roll . " AND time>=" . $t;
         $result = mysql_query($sql);
         $count = mysql_num_rows($result);
         if ($count == 1) {
             sendChat($to_roll, $to_user, $msg, $enroll, $username);
         } else {
             echo "<root success='no'><user>" . $to_user . "</user></root>";
         }
     } else {
         if ($action == "getChat") {
             getChat($to_roll, $enroll);
         } else {
             if ($action == "setWritingStatus") {
                 setWritingStatus($enroll, "yes");
             } else {
                 if ($action == "checkMyOnlineStatus") {
                     checkMyOnlineStatus($enroll);
                 } else {
                     if ($action == "setOnlineStatus") {
                         $status = mysql_real_escape_string($_POST['status']);