-
Notifications
You must be signed in to change notification settings - Fork 4
/
prat.php
executable file
·87 lines (87 loc) · 3.52 KB
/
prat.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
<?php
$start = microtime(true);
error_log("Starting the execution of prat.php at " . date("H:m:i.u d.m.Y", $start));
define("NOUPDATE", 1);
require_once './core.php';
$after_require = microtime(true);
error_log("Core finished, continuing to the main part at: " . date("H:m:i.u d.m.Y", $after_require) . ", ".($after_require - $start) . " seconds later.");
header('Content-Type: text/html; charset=UTF-8');
$ikkevis = false;
if (isset($_GET['write'])) {
if ($_GET['write'] == 'uptime' && r1()) {
$uptime = shell_exec('uptime');
$db->query("INSERT INTO `chat`(`uid`,`message`,`timestamp`) VALUES ('0','$uptime',UNIX_TIMESTAMP())");
}
if ($obj->health == 0) {
$_SESSION['chatwarning'] = [
'string' => feil('En død mann kan vell ikke snakke?'),
'time' => (time()
+ 10)
];
} else {
$s = $db->prepare("SELECT count(*) FROM `forumban` WHERE `uid` = ? AND `bantime` > unix_timestamp() AND
`active` = '1' ORDER BY `bantime` DESC LIMIT 1");
$s->execute([$obj->id]);
if ($s->fetchColumn() == 1) {
/* If banned from the forum, don't post messages to the chat */
$_SESSION['chatwarning'] = [
'string' => '<p style="color:#f00;">Du har ikke tillatelse til å skrive, prøv igjen senere.</p>',
'time' => (time() + 10)
];
} else {
$w = $_GET['write'];
if (strlen($w) <= 1) {
$time = time() + 5;
$_SESSION['chatwarning'] = [
'string' => '<p style="color:#f00;">Du må skrive 2 tegn eller mer for å bruke chatten!</p>',
'time' => $time
];
} else {
$ins = $db->prepare("INSERT INTO `chat` VALUES(NULL,?,?,UNIX_TIMESTAMP())");
$ins->execute([
$obj->id,
$w
]);
header("Content-Type: application/json");
if ($ins->rowCount() == 0) {
echo json_encode(['s' => 0]);
$ikkevis = true;
} else {
echo json_encode(['s' => 1]);
$ikkevis = true;
}
}
}
}
}
if ($ikkevis == false) {
$chat = $db->query("SELECT * FROM `chat` ORDER BY `timestamp` DESC LIMIT 0,20");
if (isset($_SESSION['chatwarning'])) {
if (($_SESSION['chatwarning']['time'] - time()) >= 0) {
echo $_SESSION['chatwarning']['string'];
} else {
unset($_SESSION['chatwarning']);
}
}
while ($r = $chat->fetchObject()) {
$message = smileys(htmlentities($r->message, ENT_NOQUOTES, 'UTF-8'));
$message = wordwrap($message, 200, "<br>\n", true);
$uob = user($r->uid, 1);
if ($r->uid == 0) {
$uob = "Systemet";
} else {
$uob = '<a href="profil.php?id=' . $uob->id . '">' . $uob->user . '</a>';
}
if ($r->id % 2) {
echo
'<div class="chat ct1"><b>[' . date("H:i:s d.m.y",
$r->timestamp) . ']</b> <' . $uob . '>: <span class="chattext">' . $message . '</span></div>';
} else {
echo
'<div class="chat ct2"><b>[' . date("H:i:s d.m.y",
$r->timestamp) . ']</b> <' . $uob . '>: <span class="chattext">' . $message . '</span></div>';
}
}
}
$end = microtime(true);
error_log("Script completed after ". ($end - $start));