Page 1 of 1

Accessing "Session" data on client.

Posted: 21 Nov 2020, 18:14
by SeanShortreed
Hi guys. I've just followed the tutorial for the login assistant component. I've replaced the logic to set an "avatar" with a simple double called "money". "money" is the name of the column in the database.

Code: Select all

lac = new LoginAssistantComponent(this);
        // Configure the component
        lac.getConfig().loginTable = "users";
        lac.getConfig().userNameField = "email";
        lac.getConfig().passwordField = "password";
        lac.getConfig().nickNameField = "username";
        lac.getConfig().useCaseSensitiveNameChecks = true;
        lac.getConfig().extraFields = Arrays.asList("money");
        lac.getConfig().postProcessPlugin = new ILoginAssistantPlugin ()
            public void execute(LoginData loginData)
                ISFSObject fields = loginData.extraFields;
                double money = fields.getDouble("money");
                // Store avatar in session object
                loginData.session.setProperty("money", money);

How do I access this value on the client? For reference I am using unity.

Re: Accessing "Session" data on client.

Posted: 23 Nov 2020, 08:25
by Lapo
in the post-process plugin the LoginData parameter contains an SFSObject called clientOutGoingData.
You can populate this with whatever data you want to send to client in the Login response.

From client the SFSEvent.LOGIN event contains a data parameter which is the SFSObject populated on the server side.
Quick example in C#:

Code: Select all

void OnLogin(BaseEvent evt)
    Console.WriteLine("Login success");
    ISFSObject data = (ISFSObject) evt.Params["data"];

    int money = data.GetDouble("money");
    // ... etc ...


hope it helps