Internal Event :: pubMsg

Availability:

SmartFoxServer PRO 1.4.2, updated in version 1.5.0

Event name:

pubMsg

Description:

This event is fired each time a public message is sent.
By default the server does not create an event on every public message sent. If you want to listen for these type of event you will have to turn them on on your current Zone. Check the examples below for more details. The event handler can be useful to log or analyze the public messages sent by clients in the current Zone.

Version 1.5.0 update:
The difference with the previous 1.4 version is that you can now process the message and decide if it should be sent to the target room by calling the _server.dispatchPublicMessage() method.

The public message transaction is split into two phases:

1 - the "pubMsg" event is notified by the server to the listening extensions
2 - the extension processes the data and dispatches the message to the target room by calling _server.dispatchPublicMessage()

Properties:

name   description type
room   The Room object object
user   The user who sent the message object
msg   The message java.lang.String(*)

(*) A note on data types: the parameters passed by the server events to the running extensions are all Java types.
You can use them transparently in Actionscript or cast them to AS native data types.
» javadoc for -> java.lang.String

Example:

/**
* Extension intialization
* This example can be used as Zone level extension
*/
function init()
{
	/*
		enable "pubMsg" internal events
		by default this event is turned off
	*/
	var zone = _server.getCurrentZone()
	zone.setPubMsgInternalEvent(true)
}

/**
* Handle internal events
* 
* @param	e	the event object
*/
function handleInternalEvent(e)
{
	evtName = e.name
	
	if (evtName == "pubMsg")
	{
		sourceRoom = e.room		// the room object
		senderUser = e.user		// the sender user
		message = e.msg			// the public message
		
		// ... do something cool here ...
		
		// dispatch the message to its recipients
		_server.dispatchPublicMessage(message, sourceRoom, senderUser)
	}
}

See also:

_server.dispatchPublicMessage()