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

SeanShortreed
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
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Accessing "Session" data on client.

Postby Lapo » 23 Nov 2020, 08:25

Hi,
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
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 19 guests