First of all. I don't see why you have that problem. Whenever you get the onRoomVariablesUpdate message you also get the roomObj from where the variables where updated. With proper planning you can still log users in different more than one room.
HOWEVER, sending a public chat will only work for the curently active room. - Lapo.. please revise this as I'm not so sure anymore about it - Couldn't find it in the docs 
Withouth server side code, you could have a lobby where all users are logged in and when they choose a map they join that room also, but never quit the mainLobby room.
This way you could use the lobby to send messages between all users and still use your curent room / map structure.
With server side you could build a simple zoneLevel extension with a method like sendMessage that recieves parameters like (msg)...
and then send it to all the users in the zone like
Code: Select all
function handleRequest (cmd, params, user, fromRoom)
{
if (cmd == "sit") {
// cmd send using str raw format - params[0] is the message
var response = new Array();
response.push("publicMessage");
response.push(user.getName());
response.push(params[0]);
_server.sendResponse (response, - 1, null, getAllUsers() , "str");
}
}
function getAllUsers() {
var zone = _server.getCurrentZone();
var allRooms = zone.getRooms();
var allUsers = new Array();
for (var r in allRooms) {
allUsers.concat(allRooms[r].getAllUsers());
}
return allUsers;
}
Then, on the client side you check if the extension message is "publicMessage" (resObj[0] == "publicMessage"); and use resObj[2] for userName that sent the message and resObj[3] for the message.
Only problem here is that if users are allowed to connect to multiple rooms there will be duplicated entryes in the array returned by the getAllUsers() method and, I don't know how SFS behaves but I suppose that, SFS will send a duplicated message to that users. Meaning if a user is connected in 4 rooms at the same time, he might just recieve the same message 4 times. But i'm not sure as I haven't tested this.
If this happens just remove the duplicates form the allUsers array bassing your decision algorithm on a property like userId.
Ok.. it's late.. hope you make something out of this message
