38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.IO;
|
||
|
using System.Text.Json;
|
||
|
using Luski.net.Enums;
|
||
|
using Luski.net.JsonTypes.BaseTypes;
|
||
|
using Luski.net.JsonTypes.WSS;
|
||
|
using WebSocketSharp;
|
||
|
using DataType = Luski.net.Enums.Public.DataType;
|
||
|
|
||
|
namespace Luski.net;
|
||
|
|
||
|
public partial class PublicServer
|
||
|
{
|
||
|
private void DataFromServer(object? sender, MessageEventArgs e)
|
||
|
{
|
||
|
if (e.IsPing) return;
|
||
|
try
|
||
|
{
|
||
|
BetterIncomingWSS? data = JsonSerializer.Deserialize(e.Data, BetterIncomingWSSContext.Default.BetterIncomingWSS);
|
||
|
switch (data?.Type)
|
||
|
{
|
||
|
case DataType.Token:
|
||
|
WSSLogin n = JsonSerializer.Deserialize(e.Data, WSSLoginContext.Default.WSSLogin)!;
|
||
|
File.WriteAllText(Storage.GetStorageDirectory(StorageDirectory.StorageInfo) + "token",
|
||
|
n.SessionToken);
|
||
|
Token = n.Token;
|
||
|
break;
|
||
|
default:
|
||
|
Console.WriteLine("Unknown");
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception exception)
|
||
|
{
|
||
|
Exception(exception);
|
||
|
}
|
||
|
}
|
||
|
}
|