Question: How to check for logout by account/username is loggin at other location

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

longnt
Posts: 3
Joined: 16 Oct 2020, 02:02

Question: How to check for logout by account/username is loggin at other location

Postby longnt » 16 Oct 2020, 02:13

Hi, currently I developing a custom login mechanic and got stuck at this step.
I need to show for user why they got disconnected especially when they was log out by the system by other user with same username is logged in to zone.
The disconnect reason referenced by documentation for this case is UNKNOW so I decide to implement a custom login handler

Code: Select all

  public void handleServerEvent(ISFSEvent event) throws SFSException
        {
            String name = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
            User user = getApi().getUserByName(name);

            if (user != null)
            {
                trace("USER ALREADY EXISTING --> DISCONNECTING");
                SFSObject data = new SFSObject();
                data.putUtfString("username", user.getName());
                sendForceDisconnect(data, user);
//                getApi().disconnectUser(user);
            }
            else {
                trace("Welcome new user: " + name);
            }
        }
       
 public void sendForceDisconnect(SFSObject data, User user) {
        trace("Sending force disconnect");
        ArrayList<User> us = new ArrayList<>();
        us.add(user);
        getApi().sendExtensionResponse("force_disconnect", data, us, portalRoom,false);
    }


17:23:02,558 INFO [SFSWorker:Ext:1] Extensions - {Portal}: Welcome new user: 1
17:23:02,563 INFO [SFSWorker:Ext:1] api.SFSApi - User login: { Zone: PortalRoom }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:56960 ) , Type: Unity / .Net
17:23:02,650 INFO [SFSWorker:Sys:2] api.SFSApi - Room joined: [ Room: PortalRoom, Id: 1, Group: default, isGame: false ], { Zone: PortalRoom }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:56960 ) , asSpect: false
17:23:07,552 INFO [SocketReader] sessions.DefaultSessionManager - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 127.0.0.1:56966 } on Server port: 9933 <---> 56966
17:23:07,647 INFO [SFSWorker:Ext:1] Extensions - {Portal}: USER ALREADY EXISTING --> DISCONNECTING
17:23:07,647 INFO [SFSWorker:Ext:1] Extensions - {Portal}: Sending force disconnect
17:23:07,648 INFO [SFSWorker:Ext:1] scala.DefLI - User already logged in. Disconnecting previous instance : ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:56960 )
17:23:07,649 INFO [SFSWorker:Ext:1] sessions.DefaultSessionManager - Session removed: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:56960 }
17:23:07,649 INFO [SFSWorker:Ext:1] api.SFSApi - User disconnected: { Zone: PortalRoom }, ( User Name: 1, Id: 0, Priv: 0, Sess: 127.0.0.1:56960 ) , SessionLen: 5086, Type: Unity / .Net
17:23:09,653 INFO [pool-1-thread-4] api.SFSApi - User login: { Zone: PortalRoom }, ( User Name: 1, Id: 1, Priv: 0, Sess: 127.0.0.1:56966 ) , Type: Unity / .Net
17:23:09,675 INFO [SFSWorker:Sys:2] api.SFSApi - Room joined: [ Room: PortalRoom, Id: 1, Group: default, isGame: false ], { Zone: PortalRoom }, ( User Name: 1, Id: 1, Priv: 0, Sess: 127.0.0.1:56966 ) , asSpect: false


And with this implement I got this log. But the device with user that logged in first not received the "force_disconnect" response from server.
Are there any reliable way to achieve this kind of behaviors? How do the first client know they got disconnect by this type of event?

FYI: I got my own server to validate user loggin but it's just API gate for request response and I decided to user smartfox as mechanic to detect realtime disconnecting events since I use it's for my online game in the apps
User avatar
Lapo
Site Admin
Posts: 21696
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Question: How to check for logout by account/username is loggin at other location

Postby Lapo » 16 Oct 2020, 09:09

Hi,
this is something that has been discussed before.
When a client logs in twice with two devices the 1st session is kicked out immediately, the reason for this is not to delay the new login.
Otherwise you would have to potentially wait a significant amount of time to deliver the message to the other end.

So essentially this is the way we decided to implement it, prioritizing the new login.

Additionally if you're on your computer playing and you decide to move on to your laptop or phone and connect from there, why would you care about the reason of the disconnection on the first device? You probably already shut that down, or if you didn't you're still not paying attention to it as you're now logging in with the new device.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
longnt
Posts: 3
Joined: 16 Oct 2020, 02:02

Re: Question: How to check for logout by account/username is loggin at other location

Postby longnt » 18 Oct 2020, 09:43

Hi,
I understand that the code is prioritizing the new login, it's my expected behavior from the beginning. But I really need to show to the user the specific reason why they disconnected.

It's like when you using account on PC but your friend or anyone using the same app and borrow your phone then the device auto login your account on mobile!
The reason is Unknow make it really difficult to implement this type of situation.

Are there anyway I can do this, I really don't want to make a wacky hacky stuff to work around it :(
User avatar
Lapo
Site Admin
Posts: 21696
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Question: How to check for logout by account/username is loggin at other location

Postby Lapo » 18 Oct 2020, 15:31

Sorry, at the moment there isn't.
Lapo

--

gotoAndPlay()

...addicted to flash games
longnt
Posts: 3
Joined: 16 Oct 2020, 02:02

Re: Question: How to check for logout by account/username is loggin at other location

Postby longnt » 19 Oct 2020, 02:12

K, thanks for the information. Are there any chance that this will be implemented in future version?

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 34 guests