Merge pull request #853 from fourplusone/feature/async_handleMessage

async handle message
pull/871/head
Marcel Klehr 2012-07-12 03:50:37 -07:00
commit ead379cf66
1 changed files with 26 additions and 8 deletions

View File

@ -159,11 +159,7 @@ exports.handleDisconnect = function(client)
*/
exports.handleMessage = function(client, message)
{
_.map(hooks.callAll( "handleMessage", { client: client, message: message }), function ( newmessage ) {
if ( newmessage || newmessage === null ) {
message = newmessage;
}
});
if(message == null)
{
messageLogger.warn("Message is null!");
@ -175,6 +171,23 @@ exports.handleMessage = function(client, message)
return;
}
var handleMessageHook = function(callback){
var dropMessage = false;
// Call handleMessage hook. If a plugin returns null, the message will be dropped. Note that for all messages
// handleMessage will be called, even if the client is not authorized
hooks.aCallAll("handleMessage", { client: client, message: message }, function ( messages ) {
_.each(messages, function(newMessage){
if ( newmessage === null ) {
dropMessage = true;
}
});
// If no plugins explicitly told us to drop the message, its ok to proceed
if(!dropMessage){ callback() };
});
}
var finalHandler = function () {
//Check what type of message we get and delegate to the other methodes
if(message.type == "CLIENT_READY") {
@ -203,11 +216,18 @@ exports.handleMessage = function(client, message)
}
};
if (message && message.padId) {
if (message) {
async.series([
handleMessageHook,
//check permissions
function(callback)
{
if(!message.padId){
// If the message has a padId we assume the client is already known to the server and needs no re-authorization
callback();
return;
}
// Note: message.sessionID is an entirely different kind of
// session from the sessions we use here! Beware! FIXME: Call
// our "sessions" "connections".
@ -231,8 +251,6 @@ exports.handleMessage = function(client, message)
},
finalHandler
]);
} else {
finalHandler();
}
}