forked from drrr-like-chat/drrr-like-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
83 lines (62 loc) · 1.84 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
if (file_exists('setting.php')) {
require 'setting.php';
} else {
require 'setting.dist.php';
}
require 'dura.php';
Dura::setup();
if (!isset($_SESSION['room']['id'])) {
// Session not exists.
header('Content-Type: application/xml; charset=UTF-8');
die('<?xml version="1.0" encoding="UTF-8"?><room><error>1</error></room>');
}
$id = $_SESSION['room']['id'];
$roomHandler = new Dura_Model_RoomHandler;
$roomModel = $roomHandler->load($id);
if (!$roomModel) {
// Room not found.
header('Content-Type: application/xml; charset=UTF-8');
die('<?xml version="1.0" encoding="UTF-8"?><room><error>2</error></room>');
}
$file = $roomHandler->getFilePath($id);
$content = md5(file_get_contents($file));
session_write_close();
if (!isset($_GET['fast'])) {
for ($i = 0; $i < DURA_SLEEP_LOOP; $i++) {
if ($content != md5(file_get_contents($file))) {
break;
}
sleep(DURA_SLEEP_TIME);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) // TODO
{
break;
}
}
}
$roomModel = $roomHandler->load($id);
$userId = $_SESSION['user']->getId();
$isLogin = false;
foreach ($roomModel->users as $user) {
if ($userId == (string)$user->id) {
$isLogin = true;
}
}
if (!$isLogin) {
session_name(DURA_SESSION_NAME);
session_start();
unset($_SESSION['room']);
// Room timeout.
header('Content-Type: application/xml; charset=UTF-8');
die('<?xml version="1.0" encoding="UTF-8"?><room><error>3</error></room>');
}
$roomModel->addChild('error', 0);
foreach ($roomModel->talks as $talk) {
if ((string)$talk->uid == 0) {
$name = (string)$talk->name;
$message = (string)$talk->message;
$talk->message = t($message, $name);
}
}
header('Content-Type: application/xml; charset=UTF-8');
die($roomModel->asXML());