-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoin.php
39 lines (35 loc) · 929 Bytes
/
join.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
<?php
/**
* join.php
* Have the user join a channel.
* The client has to send:
* - user name
* - channel name
*
* @author Paul
*/
require_once 'conn.php';
$ret = null;
if (isset($_POST['name'])) {
$name = $_POST['name'];
if (isset($_POST['channel'])) {
$channel = $_POST['channel'];
$count = $redis->sadd("channels:$name", "channel:$channel");
if ($count > 0) {
// notify all users in the channel that we have joined the channel
$redis->publish("channel:$name", 'CANCEL');
$redis->publish("channel:$channel", json_encode(array(
'name' => 'SERVER',
'message' => "$name has joined channel: $channel"
)));
}
$ret = array('status' => 'OK');
} else {
$ret = array('err' => 'Missing channel field');
}
} else {
$ret = array('err' => 'You do not have a user, use the /me command');
}
header('Content-Type: application/json');
echo json_encode($ret);
?>