diff options
author | BlueRaja <BlueRaja.admin@gmail.com> | 2014-05-08 23:50:48 -0500 |
---|---|---|
committer | BlueRaja <BlueRaja.admin@gmail.com> | 2014-05-08 23:50:48 -0500 |
commit | a639bb2fd0e6128b3c92ce789c04619b273d5f5b (patch) | |
tree | 451a279321fcbcd2e1d14141ba3b42bc3dfe8f9e /ajax/chat.ajax.php | |
parent | 17478de9c4ba215a43e7bc1b5849bb6041d50827 (diff) | |
parent | 598c2a0195fd95cda53d9067e6d6973048446a27 (diff) | |
download | pathery-a639bb2fd0e6128b3c92ce789c04619b273d5f5b.tar.xz |
Merge branch 'master' of git.raylu.net:pathery
Conflicts:
includes/mapoftheday.php
Diffstat (limited to 'ajax/chat.ajax.php')
-rw-r--r-- | ajax/chat.ajax.php | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/ajax/chat.ajax.php b/ajax/chat.ajax.php index 02a11c6..1574bde 100644 --- a/ajax/chat.ajax.php +++ b/ajax/chat.ajax.php @@ -6,6 +6,17 @@ session_start(); // exit;
// }
+
+//ini_set('display_errors',1);
+//ini_set('display_startup_errors',1);
+//error_reporting(-1);
+
+if (isset($_REQUEST['pollChannelList'])) {
+ require_once('../includes/chats.php');
+ echo json_encode(getChannelList());
+ exit;
+}
+
if (isset($_SESSION['chatLastReset'])) $chatLastReset = $_SESSION['chatLastReset'];
else $chatLastReset = 0;
@@ -13,6 +24,20 @@ if (strtotime('now') - $chatLastReset > 6) { $_SESSION['chatSendCount'] = 0;
$_SESSION['chatLastReset'] = strtotime('now');
}
+
+//T:
+if (rand(1,4) == 2 || true) {
+ $r[0]['serverMessage'] = 'true';
+ $r[0]['isJoinLeave'] = 'true';
+ $r[0]['message'] = "Server Test";
+ $r[0]['secondsSince'] = 0;
+ $r[0]['displayName'] = 'SERVER';
+ $r[0]['userID'] = null;
+ //echo json_encode($r);
+ //exit;
+}
+
+
if (isset($_REQUEST['messages'])) {
$_SESSION['chatSendCount']++;
if ($_SESSION['chatSendCount'] > 4) {
@@ -31,6 +56,8 @@ session_write_close(); $userID = $_SESSION['userID'];
$chatLockDown = false;
+$use_psuedo_longpoll = true;
+
// STOP CHAT?
//$chatLockDown = true;
@@ -42,6 +69,9 @@ $chatLockDown = false; require_once('../includes/chats.php');
+//exit;
+
+enterChannel($userID);
$sent = false;
if (isset($_REQUEST['messages'])) {
@@ -110,36 +140,33 @@ if (isset($_REQUEST['messages'])) { if ($_REQUEST['getChatFromID']) {
$getChatID = $_REQUEST['getChatFromID'];
- if ($sent) {
- //Wait .2 seconds
- usleep(200000);
- //echo "yesSent";
+ if ($sent == true AND $use_psuedo_longpoll == true) {
+ // PSUEDO LONG POLLING: - This loops to try to retrieve
+ // the message you just sent, back from the server.
+
for( $i = 1; $i < 3; $i++) {
- //echo "loop";
$data = getChat($getChatID);
if ($data !== false) {
- //$data['debug'][] = "Count times: $i";
- //$data['debug'][] = "Count value:".count($data);
echo prepareChatData($data);
exit;
}
- //Wait .1 seconds
- usleep(100000);
+ //Wait .01 seconds per loop
+ usleep(10000);
}
}
$json = prepareChatData(getChat($getChatID));
echo $json;
}
-exit;
function prepareChatData($data) {
- if ($data) {
- foreach($data as &$user) {
- //$user['message'] = $user['message'].'write-append';
- $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
- }
- return json_encode($data);
+ if (!$data)
+ {
+ return false;
+ }
+ foreach($data as &$user) {
+ //$user['message'] = $user['message'].'write-append';
+ $user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
}
- return $data;
+ return json_encode($data);
}
?>
\ No newline at end of file |