Sfs.MySelf might null after sucessfull login?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 10 Sep 2019, 08:39

I got NullReferenceException inside handler of SFSEvent.LOGIN when accessing Sfs.MySelf.Name

It happend for the first time when two people tried to login into the server in the same time on same login. Any thoughts?
User avatar
Lapo
Site Admin
Posts: 21065
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sfs.MySelf might null after sucessfull login?

Postby Lapo » 10 Sep 2019, 10:46

Hi,
normally one of the two clients should receive a LOGIN_ERROR event.
Are you sure you're handling both LOGIN and LOGIN_ERROR events correctly?

Can you also please specify the version of the API in use, and the SFS2X version?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Re: Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 10 Sep 2019, 13:15

Hi,

i am sure, that the problem occurs inside LOGIN handler.
Client API: 1.7.12
Server Version: 2.13.6
User avatar
Lapo
Site Admin
Posts: 21065
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sfs.MySelf might null after sucessfull login?

Postby Lapo » 10 Sep 2019, 14:37

Is there any server side warning or error when this happens?
Also what's the setting for the "forceLogout" parameter in the Zone config? Is it on? off?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Re: Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 10 Sep 2019, 15:22

There are actually two kinds of issues.
One i already told you and second one, that appears from time to time, which is

Code: Select all

[SFS - ERROR] [TCPSocketLayer] General error reading data from socket: Unable to read data from the transport connection: interrupted.   at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 size) [0x000e2] in <d8cd0ec6fc774382b0a4c707a194e94c>:0
  at Sfs2X.Core.Sockets.TCPSocketLayer.Read () [0x0003a] in <9bfe5727c1e148feb52fa1397dabf0b5>:0


that happened now. On server, there are only these kinds of messages

Code: Select all

{__lib__}: USER XXX ALREADY EXIST --> DISCONNECTING

and

Code: Select all

com.smartfoxserver.v2.exceptions.SFSExtensionException: Extension Request refused. Sender is not a User: { Id: 88, Type: DEFAULT, Logged: No, IP: MY_IP } com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:93) com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)


What i did was open the application twice and login with the same credentials into both. When you log in and someone else is already log in, he is logged out. So i just do a couple of round until i got these issues.
Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Re: Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 10 Sep 2019, 15:25

Now, i did another round. When i tried to log in simultaneously with tho application on single username, the application stopped responding and i had to kill it
User avatar
Lapo
Site Admin
Posts: 21065
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sfs.MySelf might null after sucessfull login?

Postby Lapo » 11 Sep 2019, 07:13

Those errors you have pasted are expected. It simply means that one client was disconnected because the 2nd user logged in, right after.
The client that gets disconnected should also receive the usual SFSEvent.CONNECTION_LOST.

As regards the two users logging in at the same time with the same user name it is possible that a similar error occurs, because one of the two will necessarily be kicked out, however I can't see the real use case. Does your game require players to start two clients simultaneously and find a way to hit the login event at exactly the same time?

SFS2X provides you with two modes to handle duplicate logins:

1) refuse the 2nd login if a user with the same user name already exists
2) kick the previous user and let the new one log in.

This is regulated by the "forceLogout" parameter in the current Zone

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Re: Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 11 Sep 2019, 07:40

Hi,
it is not about use case, we are trying to find any loopholes before final release.

We are using "2) kick the previous user and let the new one log in.", because we have multi-platform solution, that let user to continue playing on another device.

There are still two questions how to handle things
1. Might Sfs.MySelf be null inside login handler? We presumed, then it can never be null there, so we would have to change our code
2. can be [SFS - ERROR] [TCPSocketLayer] General error reading data from socket detected & handled somehow in the client? If so, how? Right now, when this happens, the application freezes, which is not... behaviour we would like to have.
User avatar
Lapo
Site Admin
Posts: 21065
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sfs.MySelf might null after sucessfull login?

Postby Lapo » 11 Sep 2019, 09:56

1. Might Sfs.MySelf be null inside login handler? We presumed, then it can never be null there, so we would have to change our code

In the case you have described it could happen (two users logging at the same time with the same account)
When you get a disconnection event the MySelf user is removed. So in the case above what might happen is that during the handling of the LOGIN event you're getting disconnected by the other client logging in.

2. can be [SFS - ERROR] [TCPSocketLayer] General error reading data from socket detected & handled somehow in the client? If so, how? Right now, when this happens, the application freezes, which is not... behaviour we would like to have.

I'll have to check with my colleague who knows more about the C# API than I do.
As far as I can remember the socket exception is simply reported in the console when raised by the disconnection.
At the same time you get an SFSEvent.CONNECTION_LOST which is what you should handle.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4479
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Sfs.MySelf might null after sucessfull login?

Postby Bax » 12 Sep 2019, 06:49

Lapo wrote:
2. can be [SFS - ERROR] [TCPSocketLayer] General error reading data from socket detected & handled somehow in the client? If so, how? Right now, when this happens, the application freezes, which is not... behaviour we would like to have.

I'll have to check with my colleague who knows more about the C# API than I do.
As far as I can remember the socket exception is simply reported in the console when raised by the disconnection.
At the same time you get an SFSEvent.CONNECTION_LOST which is what you should handle.


I confirm what lapo said. The error can't be caught in your code, but there's no reason to. In fact that error is just logged, because when it occurs, the client is already disconnected or being disconnected immediately after. So you just need to handle the disconnection event.
Paolo Bax
The SmartFoxServer Team
Jochanan
Posts: 67
Joined: 11 May 2018, 09:12

Re: Sfs.MySelf might null after sucessfull login?

Postby Jochanan » 12 Sep 2019, 16:29

Ok, i will check it out

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 5 guests