-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv_status.php
125 lines (98 loc) · 2.82 KB
/
v_status.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
This script is called by viewer applications from time to time and controls viewer session (can terminate session by returning a "disconnect" variable).
POST Variables:
u=Username
s=Session, usually same as username
r=Room
ct=session time (in milliseconds)
lt=last session time received from this script in (milliseconds)
*/
$room=$_POST[r];
$session=$_POST[s];
$username=$_POST[u];
$message=$_POST[m];
$currentTime=$_POST[ct];
$lastTime=$_POST[lt];
$disconnect=""; //anything else than "" will disconnect with that message
include_once("settings.php");
include_once("incsan.php");
sanV($room);
sanV($session);
//session time management: configure in settings.php
if ($room && $session)
{
//code to keep track of viewer's watch time (in all rooms) and also reset as configured
if ($limitUser)
{
//create folders
$dir="uploads";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0777);
$dir.="/_users";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0777);
//reset counter after some time
$toReset=0;
$counterFile = "$dir/$session";
$resetFile = $counterFile . '.reset';
if (file_exists($resetFile))
{
$lastReset = implode(file($resetFile));
if ($lastReset+$resetTime<time()) $toReset=1;
}else $toReset=1;
//reset counter
if ($toReset)
{
$dfile = fopen($counterFile,"w");
fputs($dfile, "0");
fclose($dfile);
$dfile = fopen($resetFile ,"w");
fputs($dfile, time());
fclose($dfile);
}
//get time
if (file_exists($counterFile))
{
$oldTime = implode(file($counterFile));
$timeUsedU = $oldTime + ($currentTime-$lastTime);
}
//save new time
$dfile = fopen($counterFile,"w");
fputs($dfile, $timeUsedU);
fclose($dfile);
} else $timeUsedU=0;
//code to keep track of total channel use time:
//all usage time ads up (broadcaster + viewers): 10 min broadcast to 2 viewers = 30 min total usage
//this is reset from lb_status.php
if ($limitChannel)
{
//get time
$dir= "uploads";
if (file_exists("$dir/$room/online/$room"))
{
$oldTime = implode(file("$dir/$room/online/$room"));
$timeUsedC = $oldTime + ($currentTime-$lastTime);
}
//save time
$dir="uploads";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0777);
$dir.="/$room";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0777);
$dir.="/online";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0777);
$dfile = fopen($dir."/$room","w");
fputs($dfile, $timeUsedC);
fclose($dfile);
} else $timeUsedC = 0;
}
else
{
$disconnect = "No valid room or session!";
}
//select maximum between user and total channel usage time or current session time if both disabled
$timeUsed = max($timeUsedC, $timeUsedU, $currentTime);
?>timeTotal=<?php echo $maximumSessionTime?>&timeUsed=<?php echo $timeUsed?>&lastTime=<?php echo $currentTime?>&disconnect=<?php echo $disconnect?>&loadstatus=1