Dynamically Created Rooms Not Sending Room Update Event

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

dlong
Posts: 26
Joined: 05 May 2009, 02:46
Location: Los Angeles, CA

Dynamically Created Rooms Not Sending Room Update Event

Postby dlong » 14 Oct 2009, 19:42

Here's the code I'm using in my server-side extension to dynamically create rooms. It is more or less the same code from the online java cookbook: http://www.smartfoxserver.com/docs/docP ... okBook.htm

Code: Select all

   private Room CreateRoom(String roomName, int maxUserCount, User user)
   {
      Room newRoom = null;

      // Here we pass the room parameters      
      HashMap<String, String> map = new HashMap<String, String>();
      map.put("name", roomName);
      map.put("pwd", "");
      map.put("maxU", String.valueOf(maxUserCount));
      map.put("maxS", "0");
      map.put("isGame", "true");
      
      try
      {
         newRoom = helper.createRoom(this.currentZone, map, user, true, true);

      }
      catch(ExtensionHelperException ehe)
      {
         this.trace("Could not create room " + roomName + ". Reason: " + ehe.getMessage());
      }
      
      return newRoom;
   }


According to the java docs for extension helper the last two parameters should be:

    sendUpdate - Update the clients about the new room created (true is recommended, otherwise clients will be out of synch with their Room Lists)
    broadcastEvent - Broadcast the event internally.


However, the updates are never sent down to the client so when the user creating the room attempts to join it, that user cannot "find" the room inside the client side room list (using the c# api).

Is this expected behavior? Am I possibly doing something incorrectly?

Any help is appreciated.

DL
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 15 Oct 2009, 08:36

Your code seems correct but it could depend
Is the User already logged in and joined when the Room is created?
Please send us a step by step description.
Lapo
--
gotoAndPlay()
...addicted to flash games
dlong
Posts: 26
Joined: 05 May 2009, 02:46
Location: Los Angeles, CA

Postby dlong » 16 Oct 2009, 01:45

Hi Lapo,

The concept is very similar to the cookbook recipe for logging users in and slotting them into a room, creating them dynamically if necessary.

The basic logic is:
1) Connect to server
2) Login to the zone
3) The zone has an extension that watches for the internal event: InternalEventObject.EVENT_LOGIN
4) When detected, the extension attempts to join the user into the first room it finds that has space in it. If none are available, the extension will create a new room and join the user to that room. Currently, the "room created event" is not being sent out to any other clients in the zone. Where I'm really confused is the helper.createRoom() call though.

Here are the important code snips (more or less):

Code: Select all

   

// This method is used to handle internal server events such as login, join room, etc.
public void handleInternalEvent(InternalEventObject event)
{
if (event.getEventName() == InternalEventObject.EVENT_LOGIN)
{
User newUser = null;
         
// Get the username and password
String username = event.getParam(SFS_EVENT_PARAMETER_KEY_USERNAME);
String password = event.getParam(SFS_EVENT_PARAMETER_KEY_PASSWORD);

// Get the users socket channel
SocketChannel socketChannel = (SocketChannel)event.getObject(SFS_EVENT_PARAMETER_KEY_CHANNEL);

// Attempt to log the user into the SFS system
newUser = helper.canLogin(username, password, socketChannel, currentZone.getName());

// Send login response...
LinkedList<SocketChannel> recipients = new LinkedList<SocketChannel>();
recipients.add(socketChannel);   

sendResponse(responseArray, -1, null, recipients);


if (newUser != null)
{
helper.sendRoomList(socketChannel);

JoinOrCreateRoom(newUser);
               

User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Oct 2009, 08:42

Currently, the "room created event" is not being sent out to any other clients in the zone. Where I'm really confused is the helper.createRoom() call though.


If you set the sendUpdate flag in the createRoom call to true the onRoomAdded event will be fired to all clients. There's no known bugs in this area so it has to work. Please double check your code.

Also we provide a working Java extension example called "PixelGame"
The tutorial is chapter 8.10 of our documentation and you find the sources under javaExtensions/it/gotoandplay/extensions/examples/
Lapo

--

gotoAndPlay()

...addicted to flash games
wjmurdick
Posts: 7
Joined: 18 Jan 2010, 20:23

Postby wjmurdick » 10 Jun 2010, 15:31

This is an old thread, but I wanted to add that I am having the very same problem.

Code: Select all

       
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", aRoomName);
map.put("maxU", Integer.toString(aMaxUsers));
map.put("pwd", aPassword );
map.put("isGame", "false");
map.put("isLimbo", "false");
       
Room lobby = mHelper.createRoom(mZone, map, user, true, true);


And then tracking onRoomAdded, onRoomDeleted, onCreateRoomError, and onRoomListUpdate on the client and none of them are received after this occurs.

Then later, I have this:

Code: Select all

mHelper.joinRoom(user, -1, lobby.getId(), false, "", false, true);


And am tracking onJoinRoom and onJoinRoomError, again with no results on the client. I have looked at the PixelGame example and verified that my code for joining and creating rooms isn't missing anything. The events aren't being received (or sent, unsure).
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 10 Jun 2010, 16:29

The client will receive those events only if he's already logged in and joined in a Room. If he arrives later he will anyways find the new Room in the Room List sent by the server.

In any case the new Room will be there.
Lapo

--

gotoAndPlay()

...addicted to flash games
wjmurdick
Posts: 7
Joined: 18 Jan 2010, 20:23

Postby wjmurdick » 10 Jun 2010, 16:47

Unfortunately that isn't working. The client was already logged in when that room was created, but no room updates were sent. We are having to manually call Zone.sendRoomList() whenever a new room is created in order to get the client properly updated.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 38 guests