-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
71 lines (63 loc) · 2.02 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Newtonsoft.Json;
using RestSharp;
using Steamworks;
using System;
using System.Net.Http.Headers;
using System.Reflection.Metadata;
using System.Text;
class GEVOTicket
{
public enum ExitStatus : int
{
Success = 0,
NoTicket = 1,
HttpError = 2
}
class Ticket
{
public HAuthTicket Handle { get; set; } = HAuthTicket.Invalid;
public string Value { get; set; } = "";
}
static Ticket GenerateTicket()
{
byte[] ticket = new byte[1024];
return new Ticket {
Handle = SteamUser.GetAuthSessionTicket(ticket, ticket.Length, out uint length),
Value = BitConverter.ToString(ticket).Replace("-", "")[..((int)length * 2)]
};
}
static void InvalidateTicket(ref Ticket ticket)
{
SteamUser.CancelAuthTicket(ticket.Handle);
ticket.Handle = HAuthTicket.Invalid;
ticket.Value = "";
}
async static public Task<int> Main()
{
RestClient client = new("https://gevostats.com/api");
Environment.SetEnvironmentVariable("SteamAppId", 1816670.ToString());
Environment.SetEnvironmentVariable("SteamGameId", 1816670.ToString());
if(!SteamAPI.Init())
{
Console.WriteLine("Steam API Failed!");
return 100;
}
Ticket ticket = GenerateTicket();
if (ticket.Handle == HAuthTicket.Invalid)
{
Console.WriteLine("Invalid Ticket, Unable to Retrieve User Stats");
return (int) ExitStatus.NoTicket;
}
try
{
var result = await client.PostJsonAsync<Models.Request.SteamSync, Models.Response.SteamSync>("Sync", new Models.Request.SteamSync { ticket = ticket.Value });
}catch(Exception)
{
Console.WriteLine("Error Sending Ticket.");
}
InvalidateTicket(ref ticket);
if(ticket.Handle == HAuthTicket.Invalid)
Console.WriteLine("Successfully Invalidated Ticket.");
return (int) ExitStatus.Success;
}
}