Page 1 of 1

Manage double login of same user

Posted: 06 Feb 2012, 02:11
by Hatta
Here I am again with another question.

I'm trying to "recover" a user already logged in SFS from another swf file, but I can not.

Let me explain.
I have two swf file that do exactly the same thing:

Code: Select all

sfs = new SmartFoxClient(true);
sfs.addEventListener(SFSEvent.onConnection, onConnection);
sfs.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate);
sfs.addEventListener(SFSEvent.onJoinRoom, onJoinRoom);		

sfs.connect("localhost", 9339);

private function onConnection(e:SFSEvent){
  trace("onConnection");
  sfs.login("test", "new_user", "");
}

private function onRoomListUpdate(e:SFSEvent):void{
  trace("onRoomListUpdate");
  sfs.joinRoom("room_test", "");
}
		
private function onJoinRoom(e:SFSEvent):void{
  trace("Welcome!!!");
}
I open the first file, everything works and I see Wellcome .
Without closing the first file [/i] I open the second but I can not see Wellcome[/ i], the procedure does not go beyond the event OnConnection .

Rightly, the server locks the second file informing that the user is already logged in:

Code: Select all

User: new_user is already logged in Zone: test
Old user object found
	Old User ID: 4
	Old User IP: 127.0.0.1
	bla bla bla bla

User was found in 1 room(s): room_test
I'm fine but if I wanted to do a prior check to see if new_user is already logged in?

Before the instruction sfs.login ("test", "new_user", ""); [/ i] If user has already logged I proceed with further instructions, otherwise log in.

After connecting to the server, I tried to get a reference to the room_test Room, but, of course, the server replies that the room list is empty.

I need to do this because in the first swf file septum UserVariable I'll have to reread the second swf file and, if so, when switching from one file to another user gets disconnected or out of the room I lose the variables.

Thank you.

Posted: 06 Feb 2012, 09:39
by Bax
Each swf establishes a unique connection to the server, so you can't "move" the user from one swf to another. Also, you can't check on the client side if a user is already logged unless you are logged too.

Re: Manage double login of same user

Posted: 14 Jul 2012, 00:13
by AndyMartin458
I added this to my zone extension where I'm doing a custom login for the user. I don't really know if that's the right error code to use, but this does the trick for making sure someone isn't trying to log in twice with the same user name.

Code: Select all

if(getParentExtension().getParentZone().getUserByName(clientName) != null) {
             SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_ALREADY_LOGGED);
             throw new SFSLoginException("Nice try...", data);
        }