Skip to content

Commit

Permalink
Load into main menu
Browse files Browse the repository at this point in the history
Temp Disable AutoUpdates
  • Loading branch information
SlejmUr committed Sep 19, 2023
1 parent d05c677 commit d4cacd8
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 126 deletions.
18 changes: 15 additions & 3 deletions PayCheck3ServerApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PayCheckServerLib;
using Newtonsoft.Json;
using PayCheckServerLib;

namespace PayCheck3ServerApp
{
Expand All @@ -7,9 +8,20 @@ internal class Program
static void Main(string[] args)
{
Console.WriteLine("Starting Server(s)!");
ServerManager.UpdateFinished += ServerManager_UpdateFinished;
ServerManager.Pre();
}

private static void ServerManager_UpdateFinished(object? sender, bool e)
{
ServerManager.Start();
Console.ReadLine();
Console.WriteLine("Enter q to quit.");
string stop = "";
while (stop != "q")
{
stop = Console.ReadLine();

Check warning on line 22 in PayCheck3ServerApp/Program.cs

View workflow job for this annotation

GitHub Actions / .NET on windows-latest (Release)

Converting null literal or possible null value to non-nullable type.
};
ServerManager.Stop();
}
}
}
}
6 changes: 6 additions & 0 deletions PayCheckServerLib/Jsons/AttribError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class AttribError

public partial class AttribSuccess
{
[JsonProperty("createdAt")]
public string createdAt { get; set; } = "0001-01-01T00:00:00Z";

[JsonProperty("deletedAt")]
public string deletedAt { get; set; } = "0001-01-01T00:00:00Z";

[JsonProperty("crossplayEnabled")]
public bool CrossplayEnabled { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion PayCheckServerLib/Jsons/Chats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class actionQueryTopic : ChatBase

public class actionQueryTopicRSP : ChatBase
{
[JsonProperty("params")]
[JsonProperty("result")]
public actionQueryTopicRSPResult Params { get; set; }
}

Expand Down
5 changes: 3 additions & 2 deletions PayCheckServerLib/Jsons/DataPaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ public class DataPaging<T> where T : class
public List<T> Data { get; set; }

[JsonProperty("paging")]
public Paging Paging { get; set; }
public PagingClass Paging { get; set; }
}
public partial class Paging

public class PagingClass
{
[JsonProperty("first")]
public string First { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions PayCheckServerLib/Jsons/EntitlementsJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public class EntitlementsData
public string UpdatedAt { get; set; }

[JsonProperty("features", NullValueHandling = NullValueHandling.Ignore)]
public object[] Features { get; set; }
public List<object> Features { get; set; }

[JsonProperty("useCount", NullValueHandling = NullValueHandling.Ignore)]
public long? UseCount { get; set; }
public long UseCount { get; set; }

[JsonProperty("stackable", NullValueHandling = NullValueHandling.Ignore)]
public bool? Stackable { get; set; }
public bool Stackable { get; set; }
}
}
21 changes: 20 additions & 1 deletion PayCheckServerLib/Responses/Challenge.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NetCoreServer;
using Newtonsoft.Json;
using PayCheckServerLib.Jsons;
using System.Linq;

namespace PayCheckServerLib.Responses
{
Expand All @@ -16,7 +17,7 @@ public static bool ChallengeEligibility(HttpRequest _, PC3Server.PC3Session sess
}

[HTTP("GET", "/challenge/v1/public/namespaces/pd3/users/me/records?limit=2147483647&offset=0")]
public static bool ChallengeRecords(HttpRequest _, PC3Server.PC3Session session)
public static bool ChallengeRecordsAll(HttpRequest _, PC3Server.PC3Session session)
{
var auth = session.Headers["authorization"].Replace("Bearer ", "");
var token = TokenHelper.ReadToken(auth);
Expand All @@ -31,5 +32,23 @@ public static bool ChallengeRecords(HttpRequest _, PC3Server.PC3Session session)
session.SendResponse(creator.GetResponse());
return true;
}

[HTTP("GET", "/challenge/v1/public/namespaces/pd3/users/me/records?limit={limit}&offset={offset}")]
public static bool ChallengeRecordsSplit(HttpRequest _, PC3Server.PC3Session session)
{
var auth = session.Headers["authorization"].Replace("Bearer ", "");
var token = TokenHelper.ReadToken(auth);
ResponseCreator creator = new();
var challenges = JsonConvert.DeserializeObject<DataPaging<ChallengesData>>(File.ReadAllText("Files/ChallengeRecords.json")) ?? throw new Exception("ChallengeRecords is null!");
challenges.Data.Skip(int.Parse(session.HttpParam["offset"])).Take(int.Parse(session.HttpParam["limit"]));
foreach (var item in challenges.Data)
{
item.UserId = token.UserId;
}

creator.SetBody(JsonConvert.SerializeObject(challenges));
session.SendResponse(creator.GetResponse());
return true;
}
}
}
40 changes: 27 additions & 13 deletions PayCheckServerLib/Responses/Entitlements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@ public class Entitlements
[HTTP("GET", "/platform/public/namespaces/pd3/users/{userId}/entitlements?limit={limit}")]
public static bool GetUserEntitlements(HttpRequest _, PC3Server.PC3Session session)
{
var responsecreator = new ResponseCreator();
var entitlements = JsonConvert.DeserializeObject<DataPaging<EntitlementsData>>(File.ReadAllText("./Files/Entitlements.json")) ?? throw new Exception("Entitlements is null!");
var newentitlements = new List<EntitlementsData>();
foreach (var entitlement in entitlements.Data)
try
{
entitlement.UserId = session.HttpParam["userId"];
newentitlements.Add(entitlement);
var responsecreator = new ResponseCreator();
var entitlements = JsonConvert.DeserializeObject<DataPaging<EntitlementsData>>(File.ReadAllText("./Files/Entitlements.json")) ?? throw new Exception("Entitlements is null!");
var newentitlements = new List<EntitlementsData>();
foreach (var entitlement in entitlements.Data)
{
entitlement.UserId = session.HttpParam["userId"];
newentitlements.Add(entitlement);
}
DataPaging<EntitlementsData> payload = new()
{
Data = newentitlements,
Paging = new()
{
First = "",
Last = "",
Next = "",
Previous = "",
}
};
responsecreator.SetBody(JsonConvert.SerializeObject(payload));
session.SendResponse(responsecreator.GetResponse());
return true;
}
DataPaging<EntitlementsData> payload = new()
catch (Exception ex)
{
Data = newentitlements,
Paging = { }
};
responsecreator.SetBody(JsonConvert.SerializeObject(payload));
session.SendResponse(responsecreator.GetResponse());
return true;
Debugger.PrintError(ex.ToString());
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion PayCheckServerLib/Responses/Social.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool PutStatItemsBulk(HttpRequest request, PC3Server.PC3Session se
return true;
}

[HTTP("GET", "/social/v1/public/namespaces/pd3/users/{userId}/statitems?limit=1000&offset=0")]
[HTTP("GET", "/social/v1/public/namespaces/pd3/users/{userId}/statitems?limit={limit}&offset=0")]
public static bool GetUserStatItems(HttpRequest request, PC3Server.PC3Session session)
{
ResponseCreator response = new ResponseCreator();
Expand Down
11 changes: 10 additions & 1 deletion PayCheckServerLib/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ public class ServerManager
{
static GSTATICServer.GSServer STATICServer;
static PD3UDPServer UDPServer;
public static void Start()
/// <summary>
/// Use this to check if update finished (Either Cancelled or Success)
/// </summary>
public static event EventHandler<bool> UpdateFinished;
public static void Pre()
{
Debugger.logger.Info("Lib Info: " + BranchHelper.GetBranch() + " - " + BranchHelper.GetBuildDate() + " " + BranchHelper.GetCommitId());
if (ConfigHelper.ServerConfig.EnableAutoUpdate)
Updater.CheckForJsonUpdates();
UpdateFinished?.Invoke(null, true);
}

public static void Start()
{
if (ConfigHelper.ServerConfig.Hosting.WSS)
PC3Server.Start("127.0.0.1", 443);
if (ConfigHelper.ServerConfig.Hosting.Gstatic)
Expand Down
2 changes: 1 addition & 1 deletion PayCheckServerLib/Servers/PC3Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override void OnWsConnected(HttpRequest request)
Debugger.PrintWarn("The fuck? This User now wants to to join to WS again! " + WS_ID);
}
WSS_Stuff.Add(token.UserId + "_" + WS_ID.ToString().ToLower(), this);
var x = "y{\"jsonrpc\":\"2.0\",\"method\":\"eventConnected\",\"params\":{\"sessionId\":\"9f51a15b940b4c538cc48281950de549\"}}CaEd";
var x = "CaSr{\"jsonrpc\":\"2.0\",\"method\":\"eventConnected\",\"params\":{\"sessionId\":\"9f51a15b940b4c538cc48281950de549\"}}CaEd";
SendBinaryAsync(Encoding.UTF8.GetBytes(x));
}
Debugger.PrintInfo(WSUserId + " joined to " + WS_ID);
Expand Down
23 changes: 14 additions & 9 deletions PayCheckServerLib/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Updater
// that or https://raw.githubusercontent.com/MoolahModding/PayCheck3Files/main
static readonly string FilesUrl = @"https://github.com/MoolahModding/PayCheck3Files/raw/main/";

public static async void CheckForJsonUpdates(bool UIHandleUpdate = false)
public static void CheckForJsonUpdates(bool UIHandleUpdate = false)
{
Dictionary<string, string> LocalFiles = new();
foreach (var file in Directory.GetFiles("./Files"))
Expand All @@ -22,8 +22,9 @@ public static async void CheckForJsonUpdates(bool UIHandleUpdate = false)
{
try
{

HttpClient client = new();
var FilesData = await client.GetStringAsync(FilesUrl + "Hashes.json");
var FilesData = client.GetStringAsync(FilesUrl + "Hashes.json").Result;
Files = JsonConvert.DeserializeObject<Dictionary<string, string>>(FilesData)!;
}
catch
Expand All @@ -36,7 +37,9 @@ public static async void CheckForJsonUpdates(bool UIHandleUpdate = false)
{
Files = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(Path.Join(FilesUrl, "Hashes.json")))!;
}

//Remove 2 Jsons to not cause error!
Files.Remove("UpdatedAtTimes.json");
Files.Remove("WeaponTables.json");
foreach (var KeyPair in Files)
{
try
Expand All @@ -55,35 +58,37 @@ public static async void CheckForJsonUpdates(bool UIHandleUpdate = false)

var inp = Console.ReadLine();

if (inp == null || string.IsNullOrEmpty(inp))
if (string.IsNullOrEmpty(inp))
{
Console.WriteLine("Your input was wrong, skipping");
//Console.WriteLine("Your input was wrong, skipping");
continue;
}

inp = inp.ToLower();
if (inp == "y")
{
Console.WriteLine("Updating started!");
Debugger.PrintInfo("Updating started!");
HttpClient client = new();
var FilesData = await client.GetStringAsync(FilesUrl + KeyPair.Key);
var FilesData = client.GetStringAsync(FilesUrl + KeyPair.Key).Result;
File.WriteAllText(KeyPair.Key, FilesData);
}
else
{
Console.WriteLine("Not want to update, Skipping");
//Debugger.PrintInfo("Not want to update, Skipping");
continue;
}


}
}
}
catch
catch (Exception ex)
{
Debugger.PrintWarn(ex.ToString());
Debugger.PrintWarn("Unable to fetch get file to update", "Updater");
}
}
Debugger.PrintInfo("Update Finished!");
}

public static event EventHandler<string> UpdateWithUI;
Expand Down
2 changes: 1 addition & 1 deletion PayCheckServerLib/WSController/ChatControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Control(byte[] buffer, long offset, long size, PC3Session ses
Method = chatbase.Method,
Params = new()
{
Processed = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()
Processed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()
}
};
var resp = "CaSr" + JsonConvert.SerializeObject(rsp) + "CaEd";
Expand Down
Loading

0 comments on commit d4cacd8

Please sign in to comment.