Tris Example - Duplicate username

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

blaez
Posts: 3
Joined: 20 Jan 2013, 04:50

Tris Example - Duplicate username

Postby blaez » 21 Jan 2013, 17:07

Hi guys,

I have download Tris example for android and of course the SmartFoxServer2X.
Then I already replace SFS2X_API_Java.jar with the newer version from SmartFoxServer2X.

Everything work fine, but when I try to test about the default validation for duplicate name in a same Zone, it didn't work.
The second user still logged in, but the field for chatting is disabled.

Do i miss something? Is there anything that need to be added to the sample code? Or I should replace another libraries?

Actually my expectation is just showing the error message which is duplicate name, but when I do a little debugging into the code,
it didn't fall into the breakpoint which is on event: SFSEvent.LOGIN_ERROR.

Thanks in advance.
User avatar
Lapo
Site Admin
Posts: 21069
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Tris Example - Duplicate username

Postby Lapo » 23 Jan 2013, 10:01

Everything work fine, but when I try to test about the default validation for duplicate name in a same Zone, it didn't work.
The second user still logged in, but the field for chatting is disabled.

I am not sure what you are trying to do and what is the expected result.
Have you modified the code?
Or are you just testing what happens when two users with the same name attempt to login?

A step by step description would help.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
blaez
Posts: 3
Joined: 20 Jan 2013, 04:50

Re: Tris Example - Duplicate username

Postby blaez » 23 Jan 2013, 11:57

Hi, Lapo.

No, the code still the same, I didn't change anything.
I just test what will happen when two user login with a same name.

I'm using eclipse as the IDE and use 2 virtual devices to do the login test.
Also, the SmartFoxServer2X is already running.

Both virtual devices successfully connected to the server by the default IP and port.
Then came up the login dialog box, where I can put the username.
1st player name: 'a'.
He logged in with that username. I also test by trying send a message and it works fine.

Then I try the 2nd player with a same name: 'a'.
I expect some error message that telling me the username already exist or something like that, but nothing happen.
The login dialog gone from the screen, but I cannot type anything in the chat message text box.

What should I do?
User avatar
Lapo
Site Admin
Posts: 21069
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Tris Example - Duplicate username

Postby Lapo » 23 Jan 2013, 12:54

The problem is simply due to the fact that the game doesn't handle a login error. It should be done in a real-life application but I think it wasn't done here because the example concentrates on how to implement the game logic.

In any case handling a login error is very straightforward:
if you check Tris class, initSmartFox() method you will find all the events that the game is listening to.
You can add a new event handler:

Code: Select all

sfsClient.addEventListener(SFSEvent.LOGIN_ERROR, this);

And then handle the error response from the server.
The API javadoc provide all the details about the SFSEvent parameters passed by each event:
http://docs2x.smartfoxserver.com/api-do ... oc/client/

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
blaez
Posts: 3
Joined: 20 Jan 2013, 04:50

Re: Tris Example - Duplicate username

Postby blaez » 24 Jan 2013, 15:26

Hi, Lapo.
Thank you so much for your help, I thing it make sense now.
It didn't go to SFSEvent.LOGIN_ERROR is because in Tris that event not yet been add to the EventListener.
I will try it soon after I get home.

Thanks :D

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 3 guests