-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
48 lines (38 loc) · 1007 Bytes
/
server.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
<?php
include '../../src/speaker.php';
if(isset($_GET['content']))
{
$chat = json_decode(file_get_contents('chat.json'));
if($chat != null)
array_push($chat, $_GET['content']);
else
$chat = [$_GET['content']];
file_put_contents('chat.json', json_encode($chat));
}
else
{
class Chatroom extends SpeakerEvents
{
private $chat = '';
function __construct()
{
$this->chat = file_get_contents('chat.json');
}
function update()
{
return end(json_decode($this->chat));
}
function check()
{
$newestChat = file_get_contents('chat.json');
if($newestChat == $this->chat)
return false;
$this->chat = $newestChat;
return true;
}
}
$speaker = new Speaker();
$speaker->addListener('', new Chatroom());
$speaker->start();
}
?>