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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
<?
session_start();
//For testing purposes send a fake 404.
// if (rand(1,3) == 2) {
// header("HTTP/1.0 404 Not Found");
// exit;
// }
if (strtotime('now') - $_SESSION['chatLastReset'] > 6) {
$_SESSION['chatSendCount'] = 0;
$_SESSION['chatLastReset'] = strtotime('now');
}
if ($_REQUEST['messages']) {
$_SESSION['chatSendCount']++;
if ($_SESSION['chatSendCount'] > 4) {
$r[0]['error'] = 'Spam';
$r[0]['serverMessage'] = 'true';
$r[0]['message'] = "You're talking too fast - or your internet is being too slow. *OR ARE YOU SPAMMING ON PURPOSE?! JERK!*";
$r[0]['secondsSince'] = 0;
$r[0]['displayName'] = 'SERVER';
$r[0]['userID'] = -1;
echo json_encode($r);
exit;
}
}
//Don't lockout requests by holding the session file open!
session_write_close();
$userID = $_SESSION['userID'];
$chatLockDown = false;
// STOP CHAT?
//$chatLockDown = true;
if (true) {
if ($_SESSION['accepted'] !== 1) {
exit;
}
}
require('../includes/chats.php');
$sent = false;
if ($_REQUEST['messages']) {
$date = isMuted($userID);
if ($date !== false) {
$r[0]['error'] = 'Muted';
$r[0]['serverMessage'] = 'true';
$r[0]['message'] = 'You have been muted; You are muted until '.$date." (The current time is: ".date("Y-m-d H:i:s").")";
$r[0]['secondsSince'] = 0;
$r[0]['displayName'] = 'SERVER';
$r[0]['userID'] = -1;
echo json_encode($r);
exit;
}
if ($chatLockDown == true AND $_SESSION['isAdmin'] !== true) {
$r[0]['error'] = 'Lockdown';
$r[0]['serverMessage'] = 'true';
$r[0]['message'] = 'Chat Lockdown has been activated. Messages are not being accepted';
$r[0]['secondsSince'] = 0;
$r[0]['displayName'] = 'SERVER';
$r[0]['userID'] = -1;
echo json_encode($r);
exit;
}
$messages = $_REQUEST['messages'];
$messages = explode("|:|", $messages);
foreach ($messages as $message) {
$message = chatFilter(stripslashes($message));
if ($message[0] == "/") {
$arguements = explode(" ", substr($message, 1));
$command = $arguements[0];
//Admin only commands
if ($_SESSION['isAdmin'] == true) {
if ($command == 'say') {
$insertID = addchat(-1, substr($message, 5));
}
}
//javascript based commands:
if ($command == 'spoiler' OR $command == 'me') {
$insertID = addchat($userID, $message);
}
if ($command == 'help') {
$r[0]['serverMessage'] = 'true';
$r[0]['message'] = "Commands: /help /time /spoiler /me. Surround text with ** for bold * for italics and ~~ for strikethrough. Chat by Pathery.com";
$r[0]['secondsSince'] = 0;
$r[0]['userID'] = -1;
echo json_encode($r);
exit;
}
if ($command == 'time') {
$r[0]['serverMessage'] = 'true';
$r[0]['message'] = "Server Time: ".date('l jS \of F Y h:i:s A');
$r[0]['secondsSince'] = 0;
$r[0]['userID'] = -1;
echo json_encode($r);
exit;
}
} else {
$insertID = addchat($userID, $message);
}
}
$sent = true;
}
if ($_REQUEST['getChatFromID']) {
$getChatID = $_REQUEST['getChatFromID'];
if ($sent) {
//Wait .2 seconds
usleep(200000);
//echo "yesSent";
for( $i = 1; $i < 3; $i++) {
//echo "loop";
$data = getChat($getChatID);
if ($data !== false) {
//$data['debug'][] = "Count times: $i";
//$data['debug'][] = "Count value:".count($data);
echo prepareChatData($data);
exit;
}
//Wait .1 seconds
usleep(100000);
}
}
$json = prepareChatData(getChat($getChatID));
echo $json;
}
exit;
function prepareChatData($data) {
if ($data) {
foreach($data as &$user) {
//$user['message'] = $user['message'].'write-append';
$user['secondsSince'] = strtotime($user['dateSent']) - strtotime("now");
}
return json_encode($data);
}
return $data;
}
function chatFilter($chat) {
//cuss words
$chat = str_ireplace("fuck you", "i am moron", $chat);
$chat = preg_replace("/[f]+\s*[uv]+\s*[h]*\s*[c\(k]+\s*(([i]*\s*[n]*\s*[g])|([e]*\s*[r]*))*/i", "dumb ", $chat); //fucker / fucking
$chat = preg_replace("/[^a-z]fag(g?[oi]t)?/i", " prince", $chat); //faggot
$chat = preg_replace("/^fag(g?[oi]t)?/i", "prince", $chat); //faggot (beginning of line)
$chat = preg_replace("/^suck\s*my.*(cock|dick|penis)/i", "join me in a riveting game of checkers", $chat); //suck my dick
$chat = str_ireplace("damn", "dumb", $chat);
$chat = str_ireplace("bull shit", "cow doodoo of the male variety", $chat);
$chat = str_ireplace("shit", "poo", $chat);
$chat = str_ireplace("sucks ass", "is dumb", $chat);
$chat = str_ireplace("suck ass", "are dumb", $chat);
$chat = str_ireplace("damnit", "do'h", $chat);
$chat = str_ireplace("a bitch", "an engaging conversationalist", $chat);
$chat = str_ireplace("bitch", "engaging conversationalist", $chat);
$chat = str_ireplace("an asshole", "a pleasant person to be around", $chat);
$chat = str_ireplace("asshole", "pleasant person to be around", $chat);
$chat = str_ireplace("cock", "elbow", $chat);
$chat = str_ireplace("dick", "elbow", $chat);
$chat = str_ireplace("penis", "elbow", $chat);
$chat = str_ireplace("vagina", "femur bone", $chat);
$chat = str_ireplace("cunt", "femur bone", $chat);
//$chat = str_ireplace("hell", "the supermarket", $chat);
$chat = str_ireplace("whore", "entrepreneur", $chat);
$chat = str_ireplace("stfu", "be still my beating heart", $chat);
$chat = str_ireplace("omfg", "omg", $chat);
$chat = str_ireplace("4chan", "NEWT GINGRICH", $chat);
$chat = str_ireplace("nigger", "classy gentleman", $chat);
$chat = str_ireplace("pedophile", "Optimus Prime", $chat);
$chat = str_ireplace(" rape", " shake hands with", $chat);
//Easter Eggs
$chat = str_ireplace("i just pwned Snap", "Snap just totally pwned me ^^", $chat);
$chat = str_ireplace("i just pwned Blue", "Blue just epicly pwned me the with chat filter", $chat);
$chat = str_ireplace("language filter", "highly educated team of monkeys employed to filter bad language", $chat);
return $chat;
}
?>
|