Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: json session store #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

WIP: json session store #29

wants to merge 2 commits into from

Conversation

knocte
Copy link
Member

@knocte knocte commented Oct 13, 2020

No description provided.

knocte and others added 2 commits October 12, 2020 20:39
It's always better to have a human-readable JSON
file than an unreadable DAT one containing bytes.

You can see what the session file contains, what
it is all about.

Also, it prevents the file from getting corrupted.
Happened to me a few times in the past using
FileSessionStore, had to delete the session file
and reconnect/auth.

And it's just way better in general for storing
data. For example, I currently store a lot of
sessions in a SQL database, and doing it with
bytes would have been a pain.

JSON session file is just better in general.
@@ -160,17 +239,17 @@ public static Session FromBytes(byte[] buffer, ISessionStore store, string sessi

var isAuthExsist = reader.ReadInt32() == 1;
int sessionExpires = 0;
TLUser TLUser = null;
int userId = default;
if (isAuthExsist)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol that typo is not in my commit :P

if (isAuthExsist)
{
sessionExpires = reader.ReadInt32();
TLUser = (TLUser)ObjectUtils.DeserializeObject(reader);
userId = (int)ObjectUtils.DeserializeObject (reader);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userId = reader.ReadInt32();

{
writer.Write(1);
writer.Write(SessionExpires);
ObjectUtils.SerializeObject(TLUser, writer);
ObjectUtils.SerializeObject (UserId, writer);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer.write(UserId);

}
public bool AuthenticatedSuccessfully {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we don't have to save UserId at all because we can just run GetSelfUser and If we're not authenticated we get an error

knocte added a commit that referenced this pull request Oct 13, 2020
This will help implementing session storage in JSON
format. WIP PRs:
- #18
- #29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants