<?php require 'dbadapter.php'; include_once 'header.php'; if (createBill("bill", 300, 15, 1)) { echo "<p>Bill created</p>"; } if (createDate("trash", 21, 1)) { echo "<p>Date created</p>"; } if (createPurchase("Dish Soap", 21, "2014-10-06", 1, 1)) { echo "<p>Purchase created</p>"; } if (createRoom(50, 1, 1)) { echo "<p>Room created</p>"; } include_once 'footer.php';
function generatePrivateAudiences($roomId, $withToken) { $roomMembers = getRoomMembers($roomId, $withToken); foreach ($roomMembers as $roomMember) { $privateAudienceName = "Private Yoda Audience - " . $roomMember['name']; if (($response = roomExists($privateAudienceName, $withToken)) === true) { passOwnershipRoom($privateAudienceName, $roomMember, $withToken); } else { switch ($response['code']) { case '403': //Room exists and has an other owner! (Good!) break; case '404': //Room does not exist.. $room = createRoom($privateAudienceName, $withToken); createWebhook($room['id'], '.*', 'room_message', $withToken); createWebhook($room['id'], '.*', 'room_enter', $withToken); createWebhook($room['id'], '.*', 'room_exit', $withToken); inviteUser($room['id'], $roomMember['id'], $withToken); passOwnershipRoom($privateAudienceName, $roomMember, $withToken); break; } } } }
function wsOnMessage($clientID, $message, $messageLength, $binary) { global $Server; $client = $Server->wsClients[$clientID]; $ip = long2ip($client[6]); // check if message length is 0 if ($messageLength == 0) { $Server->wsClose($clientID); return; } if ($data = isJSON($message)) { if ($data->type == 'auth') { $data->id; $user = getUserInfo($data->id); if (!$user) { $Server->wsRemoveClient($clientID); $Server->log("!{$clientID}[{$ip}] not in system."); } else { $Server->wsClients[$clientID][15] = $data->room; $Server->wsClients[$clientID][12] = $data->id; $Server->wsClients[$clientID][13] = $user['last_name'] . ' ' . $user['first_name']; $client = $Server->wsClients[$clientID]; foreach (array_keys($Server->wsClients) as $id) { if ($id != $clientID) { contactUpdate($id, $clientID, 'online'); sendMess($id, array('System', "{$client[13]} подключен к чату", '000'), $data->room); } else { sendMess($id, array('System', "Здравствуйте, {$client[13]}", '000')); $color = getHystory($id, $data->room); getUsers($id, $data->room); getRooms($id); } } if ($color) { $Server->wsClients[$clientID][14] = $color; } else { if (++$Server->c_id >= 6) { $Server->c_id = 0; } $Server->wsClients[$clientID][14] = $Server->colors[$Server->c_id]; } $Server->log("{$clientID}[{$ip}] login as {$client[13]} ({$client[12]})."); // $Server->log($Server->wsClients[$clientID]); } } else { if ($data->type == 'createRoom') { createRoom($clientID, $data->id, $data->room); } else { if ($data->type == 'add2Room') { add2Room($clientID, $data->id, $data->room); } else { if ($data->type == 'delRoom') { updateRoom($data->room, false, $data->id, true); getRooms($clientID); foreach (array_keys($Server->wsClients) as $id) { if ($id != $clientID) { getUsers($id, $Server->wsClients[$id][15]); } } } else { if ($data->type == 'renRoom') { updateRoom($data->room, $data->name, $data->id); getRooms($clientID); } } } } } } else { $Server->log("{$clientID}[{$ip}] say:{$message}"); if (!isset($client[12]) || $client[12] == '') { sendMess($clientID, array('System', "НЕАВТОРИЗОВАННАЯ ПОПЫТКА ДОСТУПА!", 'f00')); $Server->log("{$clientID}[{$ip}] unauthorized access."); $Server->wsClose($clientID); } else { //The speaker is the only person in the room. Don't let them feel lonely. /*if ( sizeof($Server->wsClients) == 1 ) sendMess($clientID, array('System', "Чат пуст, дождитесь хотябы одного собеседника", '000')); else{*/ $color = $client[14]; $message = str_replace('<', '<', $message); $message = str_replace('>', '>', $message); $message = str_replace('\'', ''', $message); $send_mes = set_smiles($message); //Send the message to everyone but the person who said it foreach (array_keys($Server->wsClients) as $id) { $time = date('H:i:s'); if ($id != $clientID) { $mes = array($client[13] . '|' . $time, $send_mes, $color); } else { $mes = array('You|' . $time, $send_mes, $color); addHistory($client[12], $message, $color, $client[15]); } sendMess($id, $mes, $client[15]); } //} } } }