Questions about getCreator()

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

Moderators: Lapo, Bax

User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Questions about getCreator()

Postby mistermind » 24 Aug 2010, 05:08

hey there fellas
I'll probably get to that by the end of this week, so I'm asking in advance just to make sure.

I understand that room.getCreator() will get you the user that originally created that room. But what happens if that user leaves? Does the ownership of that room goes to the next user inside (like a "party leader" thing)?

If not, then I think I misunderstood the owner process of a room creation, so here is a second question (if that is the case):
Is assigning a user as owner only an advice to the server to destroy that room in case no one else is in it?


My real propose behind all this:
I'm trying to create a group chat system, but I want it to work just as a party system in common MMOs. In other words:
player X invites player Y to a group chat.
player X is now the "group chat owner" or "party leader" (only they can invite other players)
player X gets disconnected or leaves.
player Y is now the party leader.

Basically if SFS already has a ownership feature then I probably won't need to deal with room variables and what not =)
SELECT * FROM users WHERE clue > 0
0 rows returned.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 24 Aug 2010, 06:34

Hello,

The user who created the room will still be the creator until that user disconnects or logs out. When that user disconnects, the server will automatically set the room creator to another user in that room if there's any users remaining. However, user won't get notified if a room's creator was changed - you will have to create your own logic to notify the users of this change.

Yea, if the owner of the room is assigned to a user - it should automatically get deleted when all users have left. If you want it to be persistent, set the ownership to a server.

To achieve what you want, catch the "userLeave" internal event via your zone - get the user's previously joined room, compare creator of that room to that user. If that user is the creator, manually assign creator to another user and notify all the other users in that room to change the 'party leader'. You would also store the userId of the 'party leader' as a room variable for any new users (when the join the room).
Smartfox's forum is my daily newspaper.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 25 Aug 2010, 05:30

Thanks for the quick reply and the suggestion BigFIsh.
I didn't want to answer right away before I try everything myself =)

Well turns out that getCreator() doesn't really return the creator of the room, but instead a SocketChannel (sorry, don't know what that is).

I could probably just assign a property or room variable and run a loop throu the current players in that room and assign a "creator" myself, but it would be nice to have the official room creator that is currently assigned by SFS so I can keep the players updated whenever the "userExit" is fired internally.

So my questions are:
- Can I get the user out of the SocketChannel getCreator returns to me?
- If not, is there any sort of internal variable that is recording that assignment and can I access it?


Sorry if it seems like I'm asking the same questions. Its just that I'm not sure if you said that I can actually retrieve the creator (or current owner) from the roomObj.
SELECT * FROM users WHERE clue > 0

0 rows returned.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 25 Aug 2010, 06:11

No worries.

SocketChannel is the physical socket channel (connection object) between the server and the client. Each user will have unique socket channel.

Yup, you can fetch the sfs user object from a socket channel using:

var host = _server.getUserByChannel(room.getCreator()); //AS1

then you compare host.userId with leavingUser.userId - and if they match, you then can perform the steps required.

Nope, I don't think there's any internal variable that keep track of the creator's id. I'm assuming this, as when I changed the owner of a room - none of my users received that change (after analysing the incoming messages)

Storing the hostId via a room variable is the ideal way do achieve what you want. I'm currently doing that.
Smartfox's forum is my daily newspaper.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 25 Aug 2010, 06:17

Interesting in deed =) Thanks for that BigFIsh. Never knew anything about SocketChannel til now hehe.
I actually decided to make a system here myself, but I think I'll get back to use the SocketChannel idea you gave.

Here is what I did:

Code: Select all

if (evtName == "userExit" || evtName == "userLost") {
   var roomObj = evt.room;
   var user = evt.user;
   if (roomObj && roomObj.properties.get("leader")) {
      if (roomObj.properties.get("leader") == user.getUserId()){
         var nextUser = roomObj.getAllUsers()[0];
         roomObj.properties.put("leader", nextUser.getUserId());
      }
   }
}


Pretty simple really. It just changes the property leader from the room to the next guy in the list of users. But I'm assuming its better if I just use SocketChannel so I can use the "official" chat owner instead of the first one from the list (which I assume it does the same thing I just did there lol)
SELECT * FROM users WHERE clue > 0

0 rows returned.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 27 Aug 2010, 18:05

Humm another find here:
Turns out that getCreator() always retrieve the original creator of the room. It doesn't pass the host to the next player. At first it is useful, but since there is no setCreator, you can't rely on it to pass it over and over as people leave the room. example:
- Player X is the room creator.
- Player X leave the room.
- server fires getCreator as Player X. (so far so good)
- Player Y leaves room.
- server fires getCreator: still Player X.

I guess its best if I just use internal room variables to keep track of a virtual host rather then rely on the getCreator then hehe.
SELECT * FROM users WHERE clue > 0

0 rows returned.
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 27 Aug 2010, 20:30

but since there is no setCreator, you can't rely on it to pass it over and over as people leave the room


What do you mean?

There's a room.setCreator(userObject.getChannel());

but yea, like you said - there's no need to change the room's creator. The server would automatically set a new one when the original creator has disconnected.
Smartfox's forum is my daily newspaper.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 27 Aug 2010, 20:50

Humm sorry I have no idea why I didn't see "setCreator" in the docs lol.

But yea, the use of internal variables seems more reliable. I made it so when the server fires userExist or userLost internal event from a room, the host propertie goes to the next one in the user list, and when the host type /setHost Player X, the extension sets that property to the selected user. Its also better this way so I don't need to worry about possible internal unexpected changing behaviors.

But yea, about getCreator, I tested it by tracing it when the "owner" leaves the room, and it just stay as the original creator.
I made the test by having 3 players in a group chat created by Player X.
Player X left, trace on internal event userExist/userLost indicated that Player X was still the owner. Just to make sure I made Player Y also leave the room, leaving only Player Z there. The trace still indicated that Player X was the owner.

I made a second test but this time I killed Player X connection leaving Player Y and Z in the room. The getCreator trace this time showed nothing.

Either way, the problem is solved now =) Just trying to understand how this method work (or rather if there is something wrong with it) out of curiosity.
SELECT * FROM users WHERE clue > 0

0 rows returned.
XaeroDegreaz
Posts: 26
Joined: 23 Nov 2007, 03:47

Postby XaeroDegreaz » 04 Sep 2010, 01:53

:?

I must be missing something. I have the newest version of SFS and I don't have a getCreator method.

I wasn looking for it for a similar functionality as the OP

Edit:
Woops, after some more research I see that it's a Java method. Is there something like this for the AS3 client side? I can't seem to find it.
XaeroDegreaz
Posts: 26
Joined: 23 Nov 2007, 03:47

Postby XaeroDegreaz » 04 Sep 2010, 05:24

Nevermind, I took care of my problem server side.
This is for a Java server side, room based extension.

Without doing any looping, here is how I accomplished my task:

Code: Select all

@Override
public void init() {
    helper = ExtensionHelper.instance();
    zone = helper.getZone( this.getOwnerZone() );
    room = zone.getRoomByName(__roomName);
    instance = this;
    admin = helper.getUserByChannel( room.getCreator() );

    trace("Game admin is: "+admin.getName());
}

public void handleInternalEvent(InternalEventObject ieo) {
    User user;

    if( ieo.getEventName().equals("userLost") || ieo.getEventName().equals("userExit") ) {
        user = (User) ieo.getObject("user");
        trace("Departing "+user.getName());

        //# Check if we need to send a admin change message to a new user so that games can still
        //# Be started if the original admin leaves.
        if( user.getName().equals( admin.getName() ) ) {
            //# We use a try/catch here because it's possible that there are no more users in the game.
            try{
                trace("Setting "+room.getUserByPlayerIndex(0).getName()+" as the new admin of the game.");
                admin = room.getUserByPlayerIndex(0);
         
                //# TODO send extension message to the new admin to enable the "start" button
            }catch(Exception e) {
                trace("No new admin could be set. Users in room: "+room.getUserCount());
            }
        }
      
    }
}


Where does mine differ from the OP's approach?

The admin property is a direct member of my class. Also, when polling for the next user to assign the admin spot, I use getUserByPlayerIndex(0) instead of enumerating the whole room user's array.

In essence we did it pretty much the same way, I guess :)

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 23 guests