This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
The-Powder-Toy/src/client/AuthUserCommon.cpp
Tamás Bálint Misius 845e195ba5
Emscripten: Sync session with the website one
Also fix a cursed length-related problem with passing strings from JS to C++.
2023-08-22 00:26:33 +02:00

31 lines
850 B
C++

#include "Client.h"
#include "prefs/GlobalPrefs.h"
void Client::LoadAuthUser()
{
auto &prefs = GlobalPrefs::Ref();
authUser.UserID = prefs.Get("User.ID", 0);
authUser.Username = prefs.Get("User.Username", ByteString(""));
authUser.SessionID = prefs.Get("User.SessionID", ByteString(""));
authUser.SessionKey = prefs.Get("User.SessionKey", ByteString(""));
authUser.UserElevation = prefs.Get("User.Elevation", User::ElevationNone);
}
void Client::SaveAuthUser()
{
auto &prefs = GlobalPrefs::Ref();
Prefs::DeferWrite dw(prefs);
if (authUser.UserID)
{
prefs.Set("User.ID", authUser.UserID);
prefs.Set("User.SessionID", authUser.SessionID);
prefs.Set("User.SessionKey", authUser.SessionKey);
prefs.Set("User.Username", authUser.Username);
prefs.Set("User.Elevation", authUser.UserElevation);
}
else
{
prefs.Clear("User");
}
}