-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatserver.php
More file actions
executable file
·56 lines (41 loc) · 2.09 KB
/
chatserver.php
File metadata and controls
executable file
·56 lines (41 loc) · 2.09 KB
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
#!/usr/bin/php
<?php
// start this script via "./chatserver.php > server.log &"
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
date_default_timezone_set('Europe/Berlin');
include_once dirname(__FILE__).'/config.php';
include_once dirname(__FILE__).'/PhpLiveServer.php';
include_once dirname(__FILE__).'/PhpLiveChat.php';
include_once dirname(__FILE__).'/PhpLiveChatMongo.php';
$server = new PhpLiveServer($serverConfig['port'], $serverConfig['host']);
$server->setAllowedOrigins($serverConfig['allowedOrigins']);
if (!empty($serverConfig['mongo'])) {
$mongo = new Mongo();
$chat = new PhpLiveChatMongo($serverConfig['maxMessages']);
$chat->setDatabase($mongo->chat);
} else {
$chat = new PhpLiveChat($serverConfig['maxMessages']);
}
foreach ($serverConfig['channels'] as $channelName => $channelDescription) {
$chat->addChannel($channelName, $channelDescription);
}
//$chat->addChannel('talk', 'Expertenrunde - heute mit Steve Jobs!');
//$chat->addChannel('offtopic', 'Offtopic - hier kann über alles gequatscht werden.');
$server->addListener('POST /chat/join', array($chat, 'join'));
$server->addListener('POST /chat/get', array($chat, 'get'));
$server->addListener('POST /chat/set', array($chat, 'set'));
$server->addListener('POST /chat/userlist', array($chat, 'getUserList'));
$server->addListener('POST /chat/channellist', array($chat, 'getChannelList'));
$server->addListener('POST /chat/joinChannel', array($chat, 'joinChannel'));
$server->addListener('POST /chat/leaveChannel', array($chat, 'leaveChannel'));
$server->addListener('TIMER /chat/timer', array($chat, 'checkActivity'));
//$server->addListener('TIMER /chat/timer2', array($chat, 'checkActivity'));
$server->addListener('disconnect', array($chat, 'disconnect'));
$server->addListener('unhandledRequest', array($server, 'handleUnhandledRequest'));
$server->addListener('GET /chat/socket', array($server, 'handleWebSocket'));
$server->addListener('GET /', array($chat, 'showIndex'));
$server->startTimer('/chat/timer', 1000);
//$server->startTimer('/chat/timer2', 1000);
$server->listen() or die('listen failed!');