Server bugs out when using PutClass server side

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

Moderators: Lapo, Bax

TheSilverMonkey
Posts: 7
Joined: 19 Apr 2021, 15:30

Server bugs out when using PutClass server side

Postby TheSilverMonkey » 13 May 2021, 05:15

Running into an odd problem. I've tried this both with OnRoomCreated and OnUserJoinRoom and it happens with both. When a room spins up I'm trying to set variables so they can be server owned and won't disappear if the creating user leaves.

The problem is right after the variables get created the server starts to have odd behavior. The first user is able to join fine, but for subsequent users the ROOM_JOIN never gets called after sending a room join request. The server shows the variables all as they should be, and even shows the subsequent users joining in the logs, but the client games don't know that they have joined a room. Only way to fix is restart the server, also no errors in the log. Classes are using SerializableSFSType.

Things I tried:
- I tested with PutString and dummy data instead of PutClass and server has no issues in that case.
- Tested with a very simple class in PutClass, made no difference and still bugs out but no errors in the log.
- Tried setting the variable on the room itself instead of through getApi() but that didn't make a difference.

Am I doing anything wrong? Or should this get moved into an extension request instead of events? Also thinking about switching to an SFSObject but not sure how to implement hash table or dictionary.

Code: Select all

public class OnUserJoinRoomEventHandler extends BaseServerEventHandler {

    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException {
        trace("Begin onRoomAdd");

        Room eventRoom = (Room)event.getParameter(SFSEventParam.ROOM);

        RoomVariable currentLevelDataVariable = eventRoom.getVariable(VariableNames.VariableName_Room_CurrentLevelData);
        if(currentLevelDataVariable == null){
            ISFSObject currentLevelDataSfso = new SFSObject();
            currentLevelDataSfso.putClass(VariableNames.VariableName_Room_CurrentLevelData, new CurrentLevelData());
            RoomVariable roomVariable = new SFSRoomVariable(VariableNames.VariableName_Room_CurrentLevelData,currentLevelDataSfso);
            ArrayList<RoomVariable> variables = new ArrayList<>();
            variables.add(roomVariable);
            SetRoomVariable(event,null,variables);
        }

        RoomVariable changeSetVariable = eventRoom.getVariable(VariableNames.VariableName_Room_ChangeSet);
        if(changeSetVariable == null){
            ISFSObject changeSetSfso = new SFSObject();
            changeSetSfso.putClass(VariableNames.VariableName_Room_ChangeSet, new ChangeSet(-2));
            RoomVariable roomVariable = new SFSRoomVariable(VariableNames.VariableName_Room_ChangeSet,changeSetSfso);
            ArrayList<RoomVariable> variables = new ArrayList<>();
            variables.add(roomVariable);
            SetRoomVariable(event,null,variables);
        }

        trace("End onRoomAdd");
    }

    public void SetRoomVariable(ISFSEvent event, User user, ArrayList<RoomVariable> variables){
        Room eventRoom = (Room)event.getParameter(SFSEventParam.ROOM);
        Room targetRoom = getParentExtension().getParentZone().getRoomByName(eventRoom.getName());
        getApi().setRoomVariables(user, targetRoom, variables);
    }

}


Code: Select all

public class CurrentLevelData implements SerializableSFSType {
    public Hashtable<String, LevelObjectDataItem> Data = new Hashtable<>();
}

public class LevelObjectDataItem implements SerializableSFSType {
    ...
    public String LevelObjectId;
    public Layers Layer;
    public Position Position;
    public ChangeTypes ChangeType;
    ...
 }
User avatar
Lapo
Site Admin
Posts: 22068
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Server bugs out when using PutClass server side

Postby Lapo » 13 May 2021, 08:47

Hi,
can you tell me the SFS2X version in use and also the Unity API versione?

It seems strange that there are no errors on the server side. Have you, perchance, modified the logging level in the SFS2X config?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
TheSilverMonkey
Posts: 7
Joined: 19 Apr 2021, 15:30

Re: Server bugs out when using PutClass server side

Postby TheSilverMonkey » 13 May 2021, 19:14

Very odd that there are no errors. After turning on debugging still not seeing anything being thrown.

Server: 2.17.0 on windows
Remote admin: 3.2.6

Unity: 2021.1.5f1
SFS Client: 4.2

After some more testing I think .PutClass() may be broken or I am not using it correctly. I tried it from the client side first and it doesn't break the server, but the variable doesn't update on the server. Again no errors in the log.

Below, PutClass does not work, while PutText does.

Code: Select all

        var sfsObject = new SFSObject();
        sfsObject.PutClass(VariableName_Room_ChangeSet, changeSet);     
        var roomVariable = new SFSRoomVariable(VariableName_Room_ChangeSet, sfsObject);

        _sfs.Send(new SetRoomVariablesRequest(new List<RoomVariable>() { roomVariable }));


Code: Select all

        var sfsObject = new SFSObject();
        sfsObject.PutText("EMPTY", ""); 
        var roomVariable = new SFSRoomVariable(VariableName_Room_ChangeSet, sfsObject);

        _sfs.Send(new SetRoomVariablesRequest(new List<RoomVariable>() { roomVariable }));
TheSilverMonkey
Posts: 7
Joined: 19 Apr 2021, 15:30

Re: Server bugs out when using PutClass server side

Postby TheSilverMonkey » 14 May 2021, 04:13

Swapped everything over to SFSObjects and now working as expected with those. Probably an issue with PutClass.
User avatar
Rob
Posts: 50
Joined: 01 Jul 2017, 07:33

Re: Server bugs out when using PutClass server side

Postby Rob » 14 May 2021, 08:25

The docs for putClass says "NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports."
TheSilverMonkey
Posts: 7
Joined: 19 Apr 2021, 15:30

Re: Server bugs out when using PutClass server side

Postby TheSilverMonkey » 14 May 2021, 15:33

This was occurring in a server extension and unity desktop, not using unity web gl.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 35 guests