2011-03-10 07:11:43 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
2011-03-16 01:17:58 +01:00
|
|
|
|
|
|
|
$config = json_decode(file_get_contents('dynmap_config.json'), true);
|
|
|
|
$msginterval = $config['webchat-interval'];
|
|
|
|
|
2011-03-10 07:11:43 +01:00
|
|
|
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] < time())
|
|
|
|
{
|
|
|
|
$micro = explode(' ', microtime());
|
|
|
|
$timestamp = $micro[1].round($micro[0]*1000);
|
|
|
|
|
|
|
|
$data = json_decode(trim(file_get_contents('php://input')));
|
|
|
|
$data->timestamp = $timestamp;
|
2011-12-29 07:19:03 +01:00
|
|
|
$data->ip = $_SERVER['REMOTE_ADDR'];
|
2011-03-10 07:11:43 +01:00
|
|
|
$old_messages = json_decode(file_get_contents('dynmap_webchat.json'), true);
|
|
|
|
if(!empty($old_messages))
|
|
|
|
{
|
|
|
|
foreach($old_messages as $message)
|
|
|
|
{
|
|
|
|
if(($timestamp - $config['updaterate'] - 10000) < $message['timestamp'])
|
|
|
|
$new_messages[] = $message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$new_messages[] = $data;
|
|
|
|
file_put_contents('dynmap_webchat.json', json_encode($new_messages));
|
|
|
|
$_SESSION['lastchat'] = time()+$msginterval;
|
|
|
|
}
|
|
|
|
elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] > time())
|
|
|
|
{
|
2011-04-14 03:23:24 +02:00
|
|
|
header('HTTP/1.1 403 Forbidden');
|
2011-03-10 07:11:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|