forked from HowTommy/mycryptochat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newroom.php
50 lines (39 loc) · 1.4 KB
/
newroom.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
<?php
require 'inc/conf.php';
require 'inc/constants.php';
require 'inc/init.php';
require 'inc/functions.php';
require 'inc/classes.php';
require 'inc/dbmanager.php';
if(array_key_exists($_POST['nbMinutesToLive'], $allowedTimes)) {
$nbMinutesToLive = $_POST['nbMinutesToLive'];
} else {
exit('cheater');
}
$time = $_SERVER['REQUEST_TIME'];
$selfDestroys = isset($_POST['selfDestroys']) && $_POST['selfDestroys'] == 'true';
$isRemovable = isset($_POST['isRemovable']) && $_POST['isRemovable'] == 'true';
$removePassword = $_POST['removePassword'];
$userHash = getHashForIp();
// we generate a random key
$key = randomString(20);
// we create the chat room object
$chatRoom = new ChatRoom();
$chatRoom->id = $key;
$chatRoom->dateCreation = $time;
$chatRoom->dateLastNewMessage = $time;
$chatRoom->dateEnd = $nbMinutesToLive != 0 ? $time + ($nbMinutesToLive * 60) : 0;
$chatRoom->noMoreThanOneVisitor = $selfDestroys;
$chatRoom->isRemovable = $isRemovable;
$chatRoom->removePassword = $removePassword;
$chatRoom->userId = $userHash;
$chatUser = array();
$chatUser['id'] = $userHash;
$chatUser['dateLastSeen'] = $time;
array_push($chatRoom->users, $chatUser);
$dbManager = new DbManager();
// we delete old chatrooms
$dbManager->CleanChatrooms($time);
// we save the chat room in sqlite
$dbManager->CreateChatroom($chatRoom);
header('Location: chatroom.php?id=' . $key);