summaryrefslogtreecommitdiffstats
path: root/ajax/chat.ajax.php
blob: 55f771827f341828d80124e59c1ce64bab970142 (plain)
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
<?
session_start();
session_write_close();
//Just doing this as evidence that $_SESSION as read-only is still available.
$userID = $_SESSION['userID'];

$chatLockDown = false;
// STOP CHAT?
//$chatLockDown = true;

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]['ID'] = -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));
				}
			}
			//Anyone commands:
			if ($command == 'help') {
				$r[0]['serverMessage'] = 'true';
				$r[0]['message'] = "Commands: /help  THE END.";
				$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_replace("fuck you", "i am moron", $chat);
   $chat = str_replace("fuck", "dumb", $chat);
	
   $chat = str_replace("asshole", "dumb", $chat);
   $chat = str_replace("damnit", "dumb", $chat);
   $chat = str_replace("damn", "dumb", $chat);
   $chat = str_replace("cunt", "dumb", $chat);
   $chat = str_replace("shit", "dumb", $chat);
   $chat = str_replace("bitch", "dumb", $chat);
   $chat = str_replace("sucks ass", "is dumb", $chat);
   $chat = str_replace("suck ass", "is dumb", $chat);
   $chat = str_replace("stfu", "shutup", $chat);
   $chat = str_replace("omfg", "omg", $chat);
   $chat = str_replace("fuk", "dumb", $chat);
 return $chat;
}




?>