Not get proximity list update

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

Moderators: Lapo, Bax

Laxika
Posts: 10
Joined: 14 Jun 2010, 12:41

Not get proximity list update

Postby Laxika » 02 Aug 2014, 16:17

Hello guys!

I'm testing the MMOAPI with unity. I'm using 2.8.5 server version and the newest C# API version.

Everything went fine until I tried to test with 2 players online. My problem is that I don't get the PROXIMITY_LIST_UPDATE event for some reason when a new user login.

Here is my client side code:

Code: Select all

using UnityEngine;
using System.Collections;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Requests;
using Sfs2X.Entities.Data;

public class Networking : MonoBehaviour {
   
   public string ServerIP = "127.0.0.1";
   public int ServerPort = 9933;
   
   SmartFox sfs = new SmartFox();

   void Awake() {
      DontDestroyOnLoad(transform.gameObject);
   }

   void Start() {
      sfs.ThreadSafeMode = true;

      sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
      sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
      sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
      sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
      sfs.AddEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, OnProximityUpdate);
   }

   public void Connect() {
      sfs.Connect(ServerIP, ServerPort);
   }
   
   void OnConnection(BaseEvent e)
   {
      if ((bool)e.Params["success"]) {
         Debug.Log("Successfully Connected");

         Login login = Camera.main.GetComponent<Login>();

         sfs.Send(new LoginRequest(login.username, login.password, "Equinox"));
      } else {
         Debug.Log("Connection Failed");
      }
   }

   void OnLogin(BaseEvent e)
   {
      Debug.Log("Logged In: " + e.Params["user"]);

      Application.LoadLevel("world");
   }
   
   void OnLoginError(BaseEvent e)
   {
      Debug.Log("Login error: (" + e.Params["errorCode"] + "): " + e.Params["errorMessage"]);
   }
   
   void OnProximityUpdate(BaseEvent e)
   {
      Debug.Log("Got update!");
      //Debug.Log (e.Params["addedUsers"]);
   }

   void OnExtensionResponse(BaseEvent e)
   {
      string cmd = (string)e.Params["cmd"];
      ISFSObject objIn = (SFSObject)e.Params["params"];
      
      /*if (cmd == "loadmap")
      {
         Debug.Log("Load new map: " + objIn.GetUtfString("map") + " X: " + objIn.GetInt("x") + " Y: " + objIn.GetInt("y"));

         Application.LoadLevel(objIn.GetUtfString("map"));
      }*/
   }
   
   void Update()
   {
      sfs.ProcessEvents ();
   }
   
   void OnApplicationQuit()
   {
      if (sfs.IsConnected)
         sfs.Disconnect();
   }
}


And the code of my server side extension what handle the zone joining:

Code: Select all

package com.equinoxgame.zone.event;

import com.smartfoxserver.v2.SmartFoxServer;
import com.smartfoxserver.v2.api.ISFSApi;
import com.smartfoxserver.v2.api.ISFSMMOApi;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.db.IDBManager;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.Zone;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.variables.SFSUserVariable;
import com.smartfoxserver.v2.entities.variables.UserVariable;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;
import com.smartfoxserver.v2.mmo.Vec3D;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JoinZoneEvent extends BaseServerEventHandler {

    @Override
    public void handleServerEvent(ISFSEvent isfse) throws SFSException {
        ISFSApi api = SmartFoxServer.getInstance().getAPIManager().getSFSApi();
        ISFSMMOApi mmoapi = SmartFoxServer.getInstance().getAPIManager().getMMOApi();

        Room room = getParentExtension().getParentZone().getRoomByName("world");

        try {
            User user = (User) isfse.getParameter(SFSEventParam.USER);
            Zone zone = (Zone) isfse.getParameter(SFSEventParam.ZONE);

            int userId = (int) user.getSession().getProperty("id");

            trace("User (" + userId + ") " + user.getName() + " joined to zone " + zone.getName() + ".");

            IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
            ISFSArray res = dbManager.executeQuery("SELECT * FROM users WHERE id=?", new Object[]{userId});

            ArrayList<UserVariable> list = new ArrayList<>();
            list.add(new SFSUserVariable("id", userId));
            list.add(new SFSUserVariable("x", res.getSFSObject(0).getInt("x")));
            list.add(new SFSUserVariable("y", res.getSFSObject(0).getInt("y")));

            api.setUserVariables(user, list);
            api.joinRoom(user, room);

            mmoapi.setUserPosition(user, new Vec3D(0, 0, 0), room);

            trace("User (" + userId + ") " + user.getName() + ": Set pos to 0/0/0");
            trace("Users in room: " + room.getUserList().size());
        } catch (SQLException ex) {
            Logger.getLogger(JoinZoneEvent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}


This is waht I get on the server logs:

Code: Select all

17:50:46,856 INFO  [main] v2.SmartFoxServer     - Boot sequence starts...
17:50:46,863 INFO  [main] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __    _____ _____ _____ _____
|   __|   __|   __|  |_  |  |  |  | __  |     |     |_   _|
|__   |   __|__   |  |  _|-   -|  | __ -|  |  |  |  | | |
|_____|__|  |_____|  |___|__|__|  |_____|_____|_____| |_|

17:50:47,331 INFO  [main] v2.SmartFoxServer     - License code not found, starti
ng Community Edition license
17:50:47,332 INFO  [main] core.SFSEventManager     - AnonymousService-1 initaliz
ed
17:50:47,343 INFO  [main] impl.DefaultFileReplicator     - Using "C:\Users\Laxik
a\AppData\Local\Temp\vfs_cache" as temporary files store.
17:50:47,391 INFO  [main] v2.SmartFoxServer     - License loaded:

===================================
LICENSE DETAILS
-----------------------------------
Type            : Community Edition
Max users       : 100
===================================

17:50:47,392 INFO  [main] managers.SFSBannedUserStorage     - BanUserStorage ini
tialized
17:50:47,402 INFO  [main] managers.SFSBannedUserManager     - BanUser data loade
d: 0 records.
17:50:47,407 INFO  [main] v2.SmartFoxServer     - Protocol Type is: BINARY
17:50:47,409 INFO  [main] config.SFSConfigurator     - Loading: zones\Equinox.zo
ne.xml
17:50:47,438 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: Equinox
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

17:50:47,632 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: Eq
uinox }, [ MMORoom: world, Id: 0, Group: default, AOI: (100, 100, 100) ]
17:50:47,770 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: --
=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 1, Group: default, isGame: fal
se ]
17:50:47,777 INFO  [main] core.AdminToolService     - AdminTool Service started
17:50:48,654 INFO  [main] http.SFSHttpServer     - Http Server started.
17:50:48,737 INFO  [main] v2.SmartFoxServer     - Listening Sockets: { 127.0.0.1
:9933, (Tcp) } { 127.0.0.1:9933, (Udp) }
17:50:48,739 INFO  [main] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.8.5 ]

17:50:48,741 INFO  [main] v2.SmartFoxServer     - SmartFoxServer 2X (2.8.5) READ
Y!
17:51:06,789 INFO  [SocketReader] sessions.DefaultSessionManager     - Session c
reated: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:16884 } on Server port
: 9933 <---> 16884
17:51:06,863 INFO  [pool-1-thread-3] api.SFSApi     - User login: { Zone: Equino
x }, ( User Name: laxi, Id: 0, Priv: 0, Sess: 127.0.0.1:16884 ) , Type: Unity
17:51:06,870 INFO  [pool-1-thread-4] Extensions     - {Zone}: User (1) laxi join
ed to zone Equinox.
17:51:06,880 INFO  [pool-1-thread-4] api.SFSApi     - Room joined: [ MMORoom: wo
rld, Id: 0, Group: default, AOI: (100, 100, 100) ], { Zone: Equinox }, ( User Na
me: laxi, Id: 0, Priv: 0, Sess: 127.0.0.1:16884 ) , asSpect: false
17:51:06,884 INFO  [pool-1-thread-4] Extensions     - {Zone}: User (1) laxi: Set
 pos to 0/0/0
17:51:06,887 INFO  [pool-1-thread-4] Extensions     - {Zone}: Users in room: 1
17:51:13,534 INFO  [SocketReader] sessions.DefaultSessionManager     - Session c
reated: { Id: 2, Type: DEFAULT, Logged: No, IP: 127.0.0.1:16887 } on Server port
: 9933 <---> 16887
17:51:13,593 INFO  [pool-1-thread-1] api.SFSApi     - User login: { Zone: Equino
x }, ( User Name: laxi1, Id: 1, Priv: 0, Sess: 127.0.0.1:16887 ) , Type: Unity
17:51:13,595 INFO  [pool-1-thread-1] Extensions     - {Zone}: User (2) laxi1 joi
ned to zone Equinox.
17:51:13,603 INFO  [pool-1-thread-1] api.SFSApi     - Room joined: [ MMORoom: wo
rld, Id: 0, Group: default, AOI: (100, 100, 100) ], { Zone: Equinox }, ( User Na
me: laxi1, Id: 1, Priv: 0, Sess: 127.0.0.1:16887 ) , asSpect: false
17:51:13,606 INFO  [pool-1-thread-1] Extensions     - {Zone}: User (2) laxi1: Se
t pos to 0/0/0
17:51:13,607 INFO  [pool-1-thread-1] Extensions     - {Zone}: Users in room: 2


And this is my client log:

Code: Select all

Successfully Connected
UnityEngine.Debug:Log(Object)
Networking:OnConnection(BaseEvent) (at Assets/Script/Networking/Networking.cs:36)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Networking:Update() (at Assets/Script/Networking/Networking.cs:79)

Logged In: [User: laxi1, Id: 0, isMe: True]
UnityEngine.Debug:Log(Object)
Networking:OnLogin(BaseEvent) (at Assets/Script/Networking/Networking.cs:48)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:ProcessEvents()
Networking:Update() (at Assets/Script/Networking/Networking.cs:79)


The world rooms MMO Settings are the following:

IsMMORoom: true
Default AoI: 100/100/100
Lower/Higher map limits: clear
User max limbo: 50
Millis between proxim. list updates: 100
Send AoI entry point: true

I red all MMO docs I found but still can't figure this out. :S
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Not get proximity list update

Postby Lapo » 02 Aug 2014, 18:07

Everything went fine until I tried to test with 2 players online. My problem is that I don't get the PROXIMITY_LIST_UPDATE event for some reason when a new user login.

You are not supposed to get the event when a new user logs in.
The event will fire when two users in the same MMORoom fall within each other's Area Of Interest (AOI).

Have you checked the examples we provide? The basic Unity "MMO Demo" is pretty straightforward:
http://docs2x.smartfoxserver.com/ExamplesUnity/mmo-demo
Lapo
--
gotoAndPlay()
...addicted to flash games
Laxika
Posts: 10
Joined: 14 Jun 2010, 12:41

Re: Not get proximity list update

Postby Laxika » 04 Aug 2014, 14:32

Thanks for the reply!

The problem was I guess that initially I used Room.add to add the player. (Later I red your mantra post about the APIs. :)) Or waht is possible that the unity console not refreshed because it was in the background. Fortunately everything works fine now.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 93 guests