New to SmartFox and struggling a bit

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

Moderators: Lapo, Bax

bnolte
Posts: 4
Joined: 15 Sep 2015, 18:43

New to SmartFox and struggling a bit

Postby bnolte » 29 Sep 2015, 12:13

Hello everyone,

As stated in the subject I am new to SmartFox and have been trying to work up a Unity project and cross referencing the tutorials as I go/ need them. To be honest I have not made it very far because of what I am sure is one simple detail I forgot or missed.

Originialy I was trying to convert a game I was working on to a multiplayer game by using SmartFox. The game only consisted of 2 scenes so far. The first scene was the log in scene. This scene connected to a vps with a MySQL database and the scene handled account creation, account login authentication, character selection, and then load in the second scene.

The second scene was the first "hub" city. on load of the scene the selected character information was read and the appropriate character model was instantiated from a prefab.

Once I started attempting to incorporate SmartFox into the project I added the connection to the login scene. Originally I had done a login to the SmartFox server and if that was successful a logout and clear of all event listeners occurred prior to loading the next scene.

The next scene would in turn log back into the SmartFox server, and join the room. The whole point of the login logout login again was to verify the client could connect and log in to SmartFox before loading the game scene. At that point everything was going well. The room was joined an don join the player was instantiated.

This is where I started having issues. I was unable to instantiate remote players to the client despite cross referencing the mmo room and object movement tutorials. When I went back to monitor the Smartfox server zone I noticed that the client was no longer connected to either the room nor the zone. I was sending the uservariables as I had added a debug.log entry on the onuservariableupdae call.

Going back and testing various steps I found the client would disconnect after 1 minute. I clocked this ranging from 1 minute exactly to 1 minute 24 seconds.

At this point I went back and ran the object movement tutorial and it did not have the disconnect issue.

From there I created a new project with a single script. this script connected, logged in, joined a room but again would time out in the 1 minute area.



Does anyone have any thoughts on what I am missing?


thank you
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: New to SmartFox and struggling a bit

Postby Lapo » 29 Sep 2015, 16:25

Hi,
bnolte wrote:Once I started attempting to incorporate SmartFox into the project I added the connection to the login scene. Originally I had done a login to the SmartFox server and if that was successful a logout and clear of all event listeners occurred prior to loading the next scene.

The next scene would in turn log back into the SmartFox server, and join the room. The whole point of the login logout login again was to verify the client could connect and log in to SmartFox before loading the game scene. At that point everything was going well. The room was joined an don join the player was instantiated.

I don't think this is a good strategy. You just need to connect and login once. If it fails you can warn the player in the login screen otherwise just keep the connection and load the levels and whatever else you need to do.
The connect/disconnect thing is absolutely unnecessary. In fact; I would recommend to take a look at our Unity Examples package which provides many demos of increasing difficulty. From a basic "Connector" up to a full scale FPS and "Space War" like action games. By checking those you can better understand how to organize your code and how SmartFox fits in the game. I

It's actually very simple :) Here's the package:
http://smartfoxserver.com/download/sfs2x#p=examples

And here the relative tutorials:
http://docs2x.smartfoxserver.com/Exampl ... troduction

This is where I started having issues. I was unable to instantiate remote players to the client despite cross referencing the mmo room and object movement tutorials. When I went back to monitor the Smartfox server zone I noticed that the client was no longer connected to either the room nor the zone. I was sending the uservariables as I had added a debug.log entry on the onuservariableupdae call.

Could it be that by switching scene you destroyed the scene containing the SmartFox instance?
Once again the examples will help you with a simple way to tackle this issue.


From there I created a new project with a single script. this script connected, logged in, joined a room but again would time out in the 1 minute area.

Well, the server will disconnect idle users after a while.
Maybe you have set the "Idle User time" to 60 seconds or so? You can find the setting in the AdminTool > Zone Configurator, double click the Zone you're working with and there it is.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
bnolte
Posts: 4
Joined: 15 Sep 2015, 18:43

Re: New to SmartFox and struggling a bit

Postby bnolte » 29 Sep 2015, 18:10

Thank you for responding.

I did create a new project to keep things small and clean. this example uses just the connection, login, and room join events all using the on base event to send a debug message. Now in this example it doesn't do anything except connect to everything so I can understand the disconnect there from inactivity. I had checked the zone idle time and it is set to the default 120 seconds. I had actually split screen the client and the admin to clock the disconnect from the time it logged in to the time it logged out so that I could get a semi accurate time frame. Which doesn't match up as there is a difference of 30 seconds to 1 minute.

At some point I had added the login-log out - load scene log in as attempt to verify the user could log in before actually taking the time to load the next scene. To be honest I wasn't sure if this was good, bad, or so trivial it didn't even matter.

Is there some event I can send just for the purpose of preventing a disconnect to ensure that the info is being passed to the server. I was thinking sending the update user variable with just a value set to time or something similar. I am not interested in instantiating a player yet just trying to nail this disconnect issue. I have been working in the tutorials up to the MMO room demo and they do not have the disconnect issue which is why I am confused on what I am missing or doing wrong.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: New to SmartFox and struggling a bit

Postby Lapo » 30 Sep 2015, 07:10

The server only disconnects users if they've been idle for longer than what's configured in the Zone's "User Max Idle Time".
Other than that, there's no reason why should get disconnected.

To investigate further this issue you should print out the reason of the disconnection in the CONNECTION_LOST event.

Examples:

Code: Select all

public void OnConnectionLost(BaseEvent evt)
{
   Debug.LogWarn("Connection lost, reason: " + evt.Params["reason"]);
}


Let us know
Lapo

--

gotoAndPlay()

...addicted to flash games
bnolte
Posts: 4
Joined: 15 Sep 2015, 18:43

Re: New to SmartFox and struggling a bit

Postby bnolte » 30 Sep 2015, 17:00

Thanks for the reply. I do have an OnConnection event with listener as well as an on user exit room with listener. Neither of those ever fire off the debug message despite the fact that I can monitor the zone and see that I am still connected to the zone but disconnected from the room.

Continuing to look into this I think I might have found the issue or at least may be working towards the issue. If left long enough then I would actually lost connection and the event would fire. The room however was kicking me well before that time. So it was an idle issue due to mixing code.


in my original code I instantiated the player into the localplayer variable. When I brought in the object movement code the variable was localPlayer. AS both were declared there were detection errors. However as the player was instantiated to localplayer and the fixedupdate was looking for localPlayer !=null the user variables were never sent which may have been causing the idle issue.

Currently I am still losing connection to the room but at least I think I am headed in the right direction again.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: New to SmartFox and struggling a bit

Postby Lapo » 01 Oct 2015, 09:28

bnolte wrote:Thanks for the reply. I do have an OnConnection event with listener as well as an on user exit room with listener. Neither of those ever fire off the debug message despite the fact that I can monitor the zone and see that I am still connected to the zone but disconnected from the room.

Probably there is a misunderstanding.
When we talk about connections we're referring to the network connection. So I am getting confused when you say "disconnected from the Room".
Actually your network connection is still up and running but your user is not joined in a Room.

Now that I understand what you're trying to say I also immediately suspect that you're using an MMORoom, joining it with your client and then you're not setting the initial position, which is necessary because MMORooms base their updates on the client position.

This is all clearly explained in the documentation here:
http://docs2x.smartfoxserver.com/Advanc ... /mmo-rooms

and also in the MMORoom examples:
http://docs2x.smartfoxserver.com/ExamplesUnity/mmo-demo

If you want I can repeat here what is already explained in the docs, but at the end of the day you'd be much better off by simply taking a bit of time and reading those tutorials :)


Continuing to look into this I think I might have found the issue or at least may be working towards the issue. If left long enough then I would actually lost connection and the event would fire. The room however was kicking me well before that time. So it was an idle issue due to mixing code.

You just need to Join the MMORoom and in the ROOM_JOIN handler set your position.
If you don't do it within 1 minute you're kicked out, because otherwise you will float in a sort of "limbo", invisible to everyone else.

Currently I am still losing connection to the room but at least I think I am headed in the right direction again.

If you don't mind let's avoid using the terms connect/disconnect for Rooms, because they are quite confusing.
The network connection is one thing. Room can simply be joined or left.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
bnolte
Posts: 4
Joined: 15 Sep 2015, 18:43

Re: New to SmartFox and struggling a bit

Postby bnolte » 01 Oct 2015, 11:52

Thanks again for helping. I apologize for saying connecting to the room when I should say join the room.

Also you are absolutely correct. I had set the room up as an mmo room while the code I was working through was the object movement tutorial code for a non-mmo room. One I recreated the room as a non-mmo room I did not have the issue of leaving the room. So now I need to figure out where I got my code crossed in that tutorial version.


Once I am comfortable with the object movement I plan on moving into the mmo room tutorials but I thought it would be best to start at example 1 and go through them in order but it seems I got ahead of myself. The current issue I am having will take some time to go over before moving to the mmo tutorial.

I am having an issue where I run a client on 2 different machines and have them log in as 2 different accounts. The issue is when client 1 tries to move his character does not move he will actually move client 2. Client 2 will try to move and it will move client 1 not himself.


Again thank you for your help.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 67 guests