Fix client side timestamp problem
Added Support for standalone webchat by reading a json file Fix for jsonfile-interval in code Added working php script with spam prevention, for webchat
This commit is contained in:
parent
912dd0694b
commit
15e7417807
5 changed files with 102 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
|||
function sendChat(message) {
|
||||
function sendChat(me, message) {
|
||||
var ip;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
|
|
@ -13,6 +13,8 @@ function sendChat(message) {
|
|||
dataType: 'json',
|
||||
success: function(response) {
|
||||
//handle response
|
||||
if(response)
|
||||
me.onPlayerChat('', response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ DynMap.prototype = {
|
|||
.keydown(function(event) {
|
||||
if (event.keyCode == '13') {
|
||||
event.preventDefault();
|
||||
sendChat(chatinput.val());
|
||||
sendChat(me, chatinput.val());
|
||||
chatinput.val('');
|
||||
}
|
||||
})
|
||||
|
|
@ -329,6 +329,7 @@ DynMap.prototype = {
|
|||
//var divs = $('div[rel]');
|
||||
//divs.filter(function(i){return parseInt(divs[i].attr('rel')) > timestamp+me.options.messagettl;}).remove();
|
||||
});
|
||||
me.lasttimestamp = update.timestamp;
|
||||
setTimeout(function() { me.update(); }, me.options.updaterate);
|
||||
}, function(status, statusText, request) {
|
||||
me.alertbox
|
||||
|
|
|
|||
32
web/standalone/sendmessage.php
Normal file
32
web/standalone/sendmessage.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
$msginterval = 5; //In seconds - add this to dynmap web config??
|
||||
|
||||
session_start();
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] < time())
|
||||
{
|
||||
$config = json_decode(file_get_contents('dynmap_config.json'), true);
|
||||
$micro = explode(' ', microtime());
|
||||
$timestamp = $micro[1].round($micro[0]*1000);
|
||||
|
||||
$data = json_decode(trim(file_get_contents('php://input')));
|
||||
$data->timestamp = $timestamp;
|
||||
$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())
|
||||
{
|
||||
echo json_encode('You may only chat once every '.$msginterval.' seconds.');
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue