SFSEventType.PROXIMITY_LIST_UPDATE

Post here your suggestions for new possible features in SmartFoxServer 2X.

Moderators: Lapo, Bax

Post Reply
YoungDeveloper
Posts: 74
Joined: 02 Mar 2014, 21:38
Location: Latvia

SFSEventType.PROXIMITY_LIST_UPDATE

Post by YoungDeveloper »

Story
It would help greatly if there was an option to extend what data is being sent to client when area of interest is updated.

Current Situation
Now on client side it contains fixed fields.

Code: Select all

_sfs.AddEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, OnProximityListUpdate);

Code: Select all

public MMORoom room;
public List<User> addedUsers;
public List<User> removedUsers;
public List<IMMOItem> addedItems;
public List<IMMOItem> removedItems;


Suggestion
It would be great if on the side server you could subscribe to this server event just like any other and override or populate this data.

SFSEventType.PROXIMITY_LIST_UPDATE


In your custom extension you would subscribe to it as any other server event in your override init()

addEventHandler(SFSEventType.PROXIMITY_LIST_UPDATE, ServerEventHandlerProximityListUpdatec.class);


Note: Adding @Instantiation(SINGLE_INSTANCE) would be a good suggestion on this class

What is solves

- Sending one time data which is not required to store inside each user or mmoitem variable, for example current user movement speed received by udp - storing and updating this value in user variables create quite and overhead and calculations, even if user variable change event is not fired on client.
- Ability on not to rely on user or room variables to send one time data, just like entryPointPosition for each user.
- Ability to rely on custom serialization and custom protocols
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSEventType.PROXIMITY_LIST_UPDATE

Post by Lapo »

It would be great if on the side server you could subscribe to this server event just like any other and override or populate this data.

Normally events are triggered when something happens in the server, like a User logs in, or out.
These events report a change of state, providing some details on what happened. They are not meant to be triggered in the middle of a server operation to allow you to modify outgoing data or behavior.

In other words events notify something that has just happened rather than something that is about to happen.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
YoungDeveloper
Posts: 74
Joined: 02 Mar 2014, 21:38
Location: Latvia

Re: SFSEventType.PROXIMITY_LIST_UPDATE

Post by YoungDeveloper »

Yes correct and this suggests that, when server recalculates and fires that event, you can override the class behavior when data is prepared.

Example #1
Overriding but keeping default behavior

Code: Select all

 
@Instantiation(SINGLE_INSTANCE)
public class ServerEventHandlerMyCustomProximityList extends BaseServerEventHandler {

    @Override
    public ISFSObject handleServerEvent() throws SFSException {
        return super(); // this generates default proximity data
    }
}


Result what client gets:

Code: Select all

public MMORoom room;
public List<User> addedUsers;
public List<User> removedUsers;
public List<IMMOItem> addedItems;
public List<IMMOItem> removedItems;





Example #2
Overriding and appending more data.

Code: Select all

 
@Instantiation(SINGLE_INSTANCE)
public class ServerEventHandlerMyCustomProximityList extends BaseServerEventHandler {

    @Override
    public ISFSObject handleServerEvent() throws SFSException {
       ISFSObject obj = super(); // this generates default proximity data
        obj.putUtfString("someKey", "someData");
        return obj;
    }
}


Result what client gets:

Code: Select all

public MMORoom room;
public List<User> addedUsers;
public List<User> removedUsers;
public List<IMMOItem> addedItems;
public List<IMMOItem> removedItems;
public String someKey;



This implementation makes sense as addedUsers, removedUsers and other fields are not hard-coded on client api, instead you get BaseEvent which you need to get the values from by string key anyway.
Post Reply