Accessing "Session" data on client.

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

Moderators: Lapo, Bax

Posts: 1
Joined: 21 Nov 2020, 18:10

Accessing "Session" data on client.

Postby SeanShortreed » 21 Nov 2020, 18:14

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.
User avatar
Site Admin
Posts: 21836
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Accessing "Session" data on client.

Postby Lapo » 23 Nov 2020, 08:25

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
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 8 guests