Page 1 of 1

1.5.1 AS2.0 API onRoomAdded & onRoomListUpdate not worki

Posted: 31 Jan 2007, 01:33
by truantduck
:arrow: I have registered for the two events onRoomAdded and onRoomListUpdate, but I am not reciving any callbacks from the flash as2.0 API when I create a room using the flash as2.0 API call:

Code: Select all

createRoom(Room, -1)
If I don't call createRoom without the 2nd parameter (which is undocumented!?) smartfox throws a NumberFormatException.

:!: Yes, when I explicitly call getRoomList() I can see the new room I just created.

:!: Yes, I can see the server tell me the room is created without errors:

Code: Select all

17:16:39.659 - [ INFO ] > Room [ new_room_name ] created!
:!: No, I do not have any DisabledSysEvents in my config.xml file.

:!: Yes, I am running the latest version of the serevr and the as2.0 API, and I have patched to 1.5.1.

:!: Yes, I have isolated the code, and created a very slim example:

Code: Select all

trace("sfs_room_create.as loaded...");

import it.gotoandplay.smartfoxserver.*


////////////////////////////////// VAR ///////////////////////////////////

var newRoomName; // new room to create
var serverIp		= "127.0.0.1";   // localhost
var port:Number 	= 9339;
var zone:String 	= "testzone";
var username		= "slartibartfast";

///////////////////////////////// SCRIPT /////////////////////////////////

stop();

_global.smartfox = new SmartFoxClient();
smartfox.debug = true;

// register for sfs events...
smartfox.onRoomAdded 		= createRoomCallBack;
smartfox.onCreateRoomError	= createRoomErrorCallBack;
smartfox.onRoomListUpdate	= getRoomListCallBack;
smartfox.onLogin 			= logInCallBack;

// connect to sfs
smartfox.onConnection = gameServerConnectCallBack;
smartfox.connect(serverIp, port);




////////////////////////////////// FUNC //////////////////////////////////

function gameServerConnectCallBack()
{
	trace("gameServerConnectCallBack()");
	
	smartfox.login(zone, username);
	
	listGameRooms();
}

function logInCallBack()
{
	trace("logInCallBack()");
	listGameRooms();
}

function getGameRooms()
{
	trace("getGameRooms()");
	
	smartfox.getRoomList();
	
}

function listGameRooms()
{
	trace("listGameRooms()");
	
	gameListing_lt.removeAll();
	
	for (var i:String in smartfox.roomList)
	{
		var r:Room = smartfox.roomList[i];
		trace("list room " + i + " : " + r.getName());
		gameListing_lt.addItem( r.getName(), i );
	}
}

function createNewRoom()
{
	trace("createNewRoom()");
	
	for (var i:String in smartfox.roomList)
	{
		var r:Room = smartfox.roomList[i];
		trace("scan room names for dupe " + i + " (" + r.getName() + ")");
	
		if (newRoomName == r.getName())
		{
			trace("The room name " + newRoomName + " already exists. Please re-enter a different room name.");
			return;
		}
	}

	var room:Object = new Object();
	room.name = newRoomName;
	room.password = "";

	room.maxUsers = 6;
	room.isGame = true;

	trace("I don't seem to be getting the onRoomAdded server event." );
	trace("Lets trace some data to insure that the event is registered for, and active" );
	trace("smartfox.onRoomAdded = " + smartfox.onRoomAdded);
	trace("typeof(smartfox.onRoomAdded) = " + typeof(smartfox.onRoomAdded) );
	trace("lets call the function now without a responce object to see how it behaves" );
	trace("..." );
	smartfox.onRoomAdded(null);
	trace("..." );
	trace("ok, now lets call smartfox.createRoom() and see what happends..." );

	smartfox.createRoom(room, -1);
}


// callback function after room creation
//
function createRoomCallBack(roomObj:Room)
{
	trace("createRoomCallBack( " + roomObj.getName() + " )");
	
	trace("Lets check the paramater sent, if it's null we will exit, if not.. do other stuff");
	if (roomObj == null)
	{
		trace("hey, you sent me a null paramater. I'm exiting.");
		return;
	}
	else
	{
		trace("param is not null. lets call smartFox.getRoomList() and see if the new room is listed");
		smartfox.getRoomList()
	}
	
	trace("roomObj.getName() = " + roomObj.getName());
}
function createRoomErrorCallBack(errorMsg:String)
{
	trace("createRoomErrorCallBack() ... " + errorMsg);
}

function getRoomListCallBack()
{
	trace("getRoomListCallBack()");
	listGameRooms()
	
}

// EOF
:?: What, if anything, am I doing wrong? Why are the events onRoomAdded and onRoomListUpdate not working for me when it appears other events like onLogin and onConnection are?

:?: Do these events work for anybody else?

:?: Why must I send a second (undocumented) parameter along with smartFox.createRoom() ?

:?: Should I ignore the documentation and work from code examples?

p.s. onCreateRoomError doesn't appear to be working either.

Posted: 31 Jan 2007, 17:28
by Lapo
Hi,
your code does the right things but in wrong order.
If you take a look at the examples we provide, for example the "Advanced Chat" you will be able to see the right sequence. Also the tutorial explains this in detail.

Another helpful source is found at chapter 5.a of our docs. It's a very simple template of a SFS application with connection, login and join.

Here's the sequence in short:

1- connect --> listen for onConnection
2- login --> listen for onLogin

At this point, if login is successful, the API will automatically call the getRoomList() behind the scenes. So you don't have to

3- wait roomList--> listen for onRoomListUpdate
4- join --> listen for onJoinRoom

now you've successfully joined a room, so you can freely send any other request in the order that you want/need

hope it helps

Posted: 31 Jan 2007, 18:27
by truantduck
I don't have any issues joining rooms. I can create a room and join it just fine, and am doing so in the order you describe. That is not my problem.

My problem is that I am not getting callbacks from the server when a new room is created, or when a room is deleted. Specifically I am registering for the events onRoomAdded, onRoomListUpdate and onCreateRoomError but those events do not appear to be firing. I can demonstrate this in three ways:


:arrow: The above code demonstrates that the onRoomAdded and onRoomListUpdate callbacks do not fire when a new room is created.

:arrow: If you modify the code above and replace the "smartfox.createRoom(room, -1);" with "smartfox.createRoom(room);" It will cause a numberFormatException on the server, and the onCreateRoomError callback does not fire. If this event does not fire in this scenario, when would it?

:arrow: Another way I can demonstrate that onRoomListUpdate is not working is by deleting rooms using your admin panel. In this scenario, my client, does not receive the onRoomListUpdate event.



:idea: If you are suggesting that I must already be in a room to receive these callbacks, the above code can also demonstrate that after creating a room, and joining a room, followed by creating another room, fails to generate either the onRoomAdded or onRoomListUpdate events.

:idea: Also - even if I have made some kind of typo, or misnamed the event, I can tell by watching the sfs as2.0 debug trace data, that it doesn't appear that the server is sending any information to the client at all when a new room is created, or when I delete a room using the admin panel, or when I call createRoom() in the way specified by the documentation, causing the previously mentioned numberFormatException.

:idea: Yes, I can work around this issue by constantly calling getRoomList(), and looking through the list for new or missing rooms, but that is not the issue. The issue is that these 3 events do not appear to be firing using sfs 1.5.1 in conjunction with the as2.0 API.


Thank you for your time. :D

Posted: 31 Jan 2007, 21:19
by Lapo
I don't have any issues joining rooms. I can create a room and join it just fine, and am doing so in the order you describe. That is not my problem.
It is :) It seems you're not yet familiar with how SmartFoxServer works. Instead of coding by trial and error please do check the examples that I recommended. They show you exactly how to do and they will clarify many of the doubts you have.

I believe that you can "demonstrate" that the events are not fired because both the code and your expectations are not correct. (Example: you're expecting the onRoomListUpdate to be fired upon the creation of a new room, but this is not correct. )

Please do invest some time with our tutorials and examples and post your questions here if something is not clear.

Thank you

Posted: 31 Jan 2007, 22:18
by truantduck
Further investigation has revealed a few things:

:arrow: I must be in a room in order to receive updates. But not an isGame="true" room.

As you can see my above code creates a room where isGame="true", and when you do that, smartfox automatically joins it. But that's not good enough to get events like onRoomCreated. This was a major point of confusion for me in reading your response. You were telling me I must be in a room, yet I was in a room... the client said I was in a room. The server told me I was in a room. Yet it was not the right kind of room. Very confusing.

:arrow: onRoomListUpdate appears to only be fired when you explicitly call getRoomList(). It is not called when a room is added or destroyed, as it's name seemed to imply.

:arrow: calling createRoom() with the 2nd undocumented parameter is no longer necessary when used in conjunction with the autoJoin() feature.


So the addition of the autoJoin() call (placed in a very specific place) along with an edit to my config.xml file to create a large lobby room where new users are automatically joined into solved all of my issues. :D


:?: Question: Why must I be in a room to get a list of rooms? That seems like a very strange design to me. Isn't it reasonable that somebody who has just logged into a server, but not joined a room would be interested in a getting a list of rooms, that is updated dynamically when new rooms are added or removed so that person can then decide what room to join?


:!: Nowhere in your documentation regarding onRoomAdded() and onRoomDeleted() does it mention that you must first join a room before these events will work. You should consider adding that information to your documentation.



... Oh, I see you have recently replied... well then, allow me to retort...


Please do invest some time in your documentation so that it is clear and doesn't require mind-reading to use.

Please do invest some time in addressing carefully typed and worded concerns containing specific code examples instead of making quick responses based on incorrect assumptions. Had you ran my code you would have realize there is some strange, undocumented behavior regarding isGame="true" rooms.

Please assume that persons who are looking for help in this forum, by nature, are not yet masters with your product.

Please do invest some time in being courteous. It will pay off for you in the long run.

Posted: 03 Feb 2007, 08:48
by Lapo
truantduck,
our documentation is made up of two main sections.
1- Detailed listing of all config parameters and API features
2- Real application examples with step by step walkthrough

Even if it may sound strange, you can easily skip the first part and immediately start with the second one. In other words you can learn "by examples" starting from a set of basic applications that are extremely easy to understand even if you're absolutely new to the product or to the multiplayer world.

I am talking about the first 3 or 4 tutorials found in the Examples/ folder.
If you take the time to inspect these applications you will be guided through all the basics of the server and client interaction, and you'll get "the feeling" of the SmartFoxServer development flow.

The example code that you posted clearly showed that you didn't go through all those examples, so I was strongly recommending to do it. I guess was polite in doing so... but, in case I wasn't, I apologize. :)

The bottom line is that 90% of the questions you were asking are all answered in the examples that we provide, which walk you through the development process as quickly and clearly as possible.

You can ask any questions on this board, but if you seem to have skipped many of the basic infos that we already provide out of the box, then we will suggest that you first go through the first 2/3 examples and then you tell us all your questions, doubts, criticism, etc...

Just to make sure that we are talking about the same thing, your code shows these problems:

1- you call the listGameRooms() method in the login callback, but this is wrong as you don't have received the list yet.

2- the getRoomList() call is already done behind the scenes by the onLogin event. You don't need to call it in your code. At least not during the login process

3- the listGameRooms() doesn't seem to be listing the game rooms only, because it doesn't check the isGame() property.

4- once the room list event is handled you don't seem to be joining any room. Also it's not clear when the createNewRoom() is ever called.
Maybe there's a button somewhere in your FLA that invokes this method, but from your code we can't say.

5- calling the createRoom with the second parameter is not the correct procedure. You should first join your "lobby" or entrance room (which is 99% of the times a regular room) and then allow creation of new rooms from there. This way you don't have to specify the "undocumented" second parameter you mentioned

6- if point #5 is not what you wanted to do, then I'd recommend creating the room from the server side, using an extension. It will be more secure and you'll have more control. This is a more advanced topic and I think you should first get the basics and then move to more complex features.

I will respond to your other questions in a later post

regards

Posted: 03 Feb 2007, 09:13
by Lapo
I must be in a room in order to receive updates. But not an isGame="true" room.
Correct.
Check this post -> http://forums.smartfoxserver.com/viewto ... =4365#4365
We will update our docs with a better overview of room types and their characteristics. Thanks for your input.

When inside a game room you don't get notifications about new rooms added/removed. This is done for a couple of reasons:
1- save bandwidth
2- allow the developer to decide if they want to receive them or not. If they want to keep receiving those events they just need to keep the user joined in the lobby as well as in the game room. The lobby will continue to receive those events.
onRoomListUpdate appears to only be fired when you explicitly call getRoomList(). It is not called when a room is added or destroyed, as it's name seemed to imply.
Correct.
The getRoomListUpdate() sends you the complete list of rooms. You just need to get it once during the life cycle of your application.
Once you have the global list of rooms all you need is receiving updates on which room has been added or removed. This is done through the onRoomAdded and onRoomDeleted events
Question: Why must I be in a room to get a list of rooms? That seems like a very strange design to me.
You don't.
The room list is sent before you get inside any room.
Isn't it reasonable that somebody who has just logged into a server, but not joined a room would be interested in a getting a list of rooms, that is updated dynamically when new rooms are added or removed so that person can then decide what room to join?
In the case you want a user to check the rooms available and get updates about new rooms added / deleted, you'll need a Limbo room.
This is more of an advanced thing.
It seems you want to do alot of stuff immediately without taking the time to digest how the server model works.
SmartFoxServer is very flexible and it can be used to create an almost infinite number of multiuser applications.

By default we provide a basic set of higher level functionalities and behaviors that allow developers to quickly assemble their applications.
If these default behaviors are not enough you can either override them or implement them from scratch, using a rich server side framework.

Sorry for the digression :)

SmartFoxServer is entirely based on Rooms. Rooms are user containers.
If you check the server architecture documents you will see that a Zone represent an isolated part of the server running a multiuser application.
Inside the Zone you can have any number of rooms, each one with its own characteristics
These rooms are essentially user-containers and they allow to group users that need to interact with each other.

Back to your question, all you need is to create a "Lobby room" that gives access to the other rooms (regular, game, private etc...) in your app
Nowhere in your documentation regarding onRoomAdded() and onRoomDeleted() does it mention that you must first join a room before these events will work. You should consider adding that information to your documentation.
It's shown in all the examples :)
Plus we provide a code template that cleary shows the correct sequence of requests that allow a user to connect->login->join and finally interact with the other users.