diff --git a/PayCheckServerLib/Helpers/GSController.cs b/PayCheckServerLib/Helpers/GSController.cs index a7a451d..982892f 100644 --- a/PayCheckServerLib/Helpers/GSController.cs +++ b/PayCheckServerLib/Helpers/GSController.cs @@ -1,8 +1,11 @@ -using Newtonsoft.Json; +using ModdableWebServer; +using ModdableWebServer.Helper; +using Newtonsoft.Json; using PayCheckServerLib.Jsons.GS; using PayCheckServerLib.Jsons.PartyStuff; using PayCheckServerLib.Responses; using PayCheckServerLib.WSController; +using static PayCheckServerLib.Jsons.GS.OnMatchFound; namespace PayCheckServerLib.Helpers { @@ -15,7 +18,7 @@ public class GSController public static Dictionary Sessions = new(); public static Dictionary Tickets = new(); // Here we making a Full created Match - public static void Make(MatchTickets.TicketReqJson ticketReq, PC3Server.PC3Session session, string NameSpace) + public static void Make(MatchTickets.TicketReqJson ticketReq, ServerStruct serverStruct, string NameSpace) { var party = PartyController.PartySaves.Where(x => x.Value.Id == ticketReq.sessionId).FirstOrDefault().Value; if (party == null) @@ -52,7 +55,7 @@ public static void Make(MatchTickets.TicketReqJson ticketReq, PC3Server.PC3Sessi Version = 1 }; Debugger.PrintDebug("gs!!"); - var team = new Team() + var team = new Jsons.GS.Team() { Parties = new(), UserIDs = new() @@ -97,14 +100,16 @@ public static void Make(MatchTickets.TicketReqJson ticketReq, PC3Server.PC3Sessi }; Debugger.PrintDebug("OnSessionInvited"); // Maybe can be much better this but atleast works - foreach (var vs_ui in session.WSSServer.WSUserIds) + foreach (var key in LobbyControl.LobbyUsers.Keys) { + var splitted = key.Split("_"); + string vs_ui = splitted[1]; foreach (var uid in team.UserIDs) { if (uid == vs_ui) { Debugger.PrintDebug("GS_Session OnSessionInvited sent to " + vs_ui); - LobbyControl.SendToLobby(kv, session.GetWSLobby(vs_ui, NameSpace)); + LobbyControl.SendToLobby(kv, LobbyControl.GetLobbyUser(vs_ui, NameSpace)); } } } @@ -148,7 +153,7 @@ public static GameSession JoinSession(string id, string UserId, string NameSpace return session; } - public static GameSession Patch(PatchGameSessions patchGameSessions, string id, PC3Server.PC3Session pcSession, string NameSpace) + public static GameSession Patch(PatchGameSessions patchGameSessions, string id, ServerStruct serverStruct, string NameSpace) { if (!Sessions.TryGetValue(NameSpace + "_" + id, out var session)) { @@ -157,13 +162,14 @@ public static GameSession Patch(PatchGameSessions patchGameSessions, string id, } //send stuff to middleman var random = new Random(); - var mlist = pcSession.MiddleMans; - int index = random.Next(mlist.Count); - var middleMan = mlist[index]; + int rand = random.Next(0, MiddleManControl.MiddleMans.Count); + var MiddleMan = MiddleManControl.MiddleMans.ElementAt(rand); + //todo get client info string Req = "DSInfoReq-END-" + "eu-central-1," + "624677," + session.Id + "," + NameSpace; Debugger.PrintDebug("Sending to middleman"); - middleMan.Send(Req); + var x = MiddleMan.Value; + WebSocketSender.SendWebSocketText(x, Req); //recieve back here? // PLEASE if you know how to wait better than this, make a PR! while (!DSInfoSentList.Contains(NameSpace + "_" + id)) @@ -228,14 +234,17 @@ public static GameSession Patch(PatchGameSessions patchGameSessions, string id, }; // Maybe can be much better this but atleast works - foreach (var vs_ui in pcSession.WSSServer.WSUserIds) + + foreach (var key in LobbyControl.LobbyUsers.Keys) { + var splitted = key.Split("_"); + string vs_ui = splitted[1]; foreach (var uid in session.Members) { if (uid.Id == vs_ui) { Debugger.PrintDebug("GS_Session OnSessionInvited sent to " + vs_ui); - LobbyControl.SendToLobby(kv, pcSession.GetWSLobby(vs_ui, NameSpace)); + LobbyControl.SendToLobby(kv, LobbyControl.GetLobbyUser(vs_ui, NameSpace)); } } } diff --git a/PayCheckServerLib/Helpers/PartyController.cs b/PayCheckServerLib/Helpers/PartyController.cs index c0a8c4b..4a0ded6 100644 --- a/PayCheckServerLib/Helpers/PartyController.cs +++ b/PayCheckServerLib/Helpers/PartyController.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using ModdableWebServer; +using Newtonsoft.Json; using PayCheckServerLib.Jsons.PartyStuff; namespace PayCheckServerLib.Helpers @@ -134,7 +135,7 @@ public static PartyPost.Response UpdateParty(string PartyId, PartyPatch body) return ParsePartyToRSP(party); } - public static void LeftParty(string PartyId, string UserId, PC3Server.PC3Session session) + public static void LeftParty(string PartyId, string UserId, ServerStruct serverStruct) { var party = PartySaves.Where(x => x.Value.Id == PartyId).FirstOrDefault().Value; if (party == null) diff --git a/PayCheckServerLib/PayCheckServerLib.csproj b/PayCheckServerLib/PayCheckServerLib.csproj index b4b68b6..6e969a2 100644 --- a/PayCheckServerLib/PayCheckServerLib.csproj +++ b/PayCheckServerLib/PayCheckServerLib.csproj @@ -36,7 +36,7 @@ - + diff --git a/PayCheckServerLib/Responses/BasicResponse.cs b/PayCheckServerLib/Responses/BasicResponse.cs index 42b3dc3..ac98f0e 100644 --- a/PayCheckServerLib/Responses/BasicResponse.cs +++ b/PayCheckServerLib/Responses/BasicResponse.cs @@ -11,16 +11,16 @@ namespace PayCheckServerLib.Responses public class BasicResponse { [HTTP("HEAD", "/generate_204")] - public static bool Generate204(HttpRequest request, ServerStruct serverStruct) + public static bool Generate204(HttpRequest _, ServerStruct serverStruct) { serverStruct.Response.MakeOkResponse(204); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/qosm/public/qos")] - public static bool QOSM_Public_QOS(HttpRequest request, ServerStruct serverStruct) + public static bool QOSM_Public_QOS(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new ResponseCreator(); response.SetHeader("Content-Type", "application/json"); @@ -44,12 +44,12 @@ public static bool QOSM_Public_QOS(HttpRequest request, ServerStruct serverStruc response.SetBody(JsonConvert.SerializeObject(rsp, Formatting.Indented)); serverStruct.Response = response.GetResponse(); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/basic/v1/public/misc/time")] - public static bool Time(HttpRequest request, ServerStruct serverStruct) + public static bool Time(HttpRequest _, ServerStruct serverStruct) { if (serverStruct.Headers.ContainsKey("cookie")) { @@ -66,31 +66,31 @@ public static bool Time(HttpRequest request, ServerStruct serverStruct) }; response.SetBody(JsonConvert.SerializeObject(rsp)); serverStruct.Response = response.GetResponse(); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/lobby/v1/messages")] - public static bool LobbyMessages(HttpRequest request, ServerStruct serverStruct) + public static bool LobbyMessages(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new ResponseCreator(); response.SetHeader("Content-Type", "application/json"); response.SetBody(File.ReadAllBytes("Files/messages.json")); serverStruct.Response = response.GetResponse(); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/iam/v3/location/country")] - public static bool Country(HttpRequest request, ServerStruct serverStruct) + public static bool Country(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new ResponseCreator(); response.SetHeader("Content-Type", "application/json"); response.SetBody(File.ReadAllBytes("Files/Country.json")); serverStruct.Response = response.GetResponse(); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Challenge.cs b/PayCheckServerLib/Responses/Challenge.cs index ea7862f..1534589 100644 --- a/PayCheckServerLib/Responses/Challenge.cs +++ b/PayCheckServerLib/Responses/Challenge.cs @@ -12,20 +12,21 @@ namespace PayCheckServerLib.Responses public class Challenge { [HTTP("GET", "/challenge/v1/public/namespaces/{namespace}/users/{userId}/eligibility")] - public static bool ChallengeEligibility(HttpRequest _, PC3Server.PC3Session session) + public static bool ChallengeEligibility(HttpRequest _, ServerStruct serverStruct) { ResponseCreator creator = new(); creator.SetBody("{\n \"isComply\": true\n}"); - session.SendResponse(creator.GetResponse()); + serverStruct.Response = creator.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/challenge/v1/public/namespaces/{namespace}/users/me/records?limit={limit}&offset={offset}")] - public static bool ChallengeRecordsSplit(HttpRequest _, PC3Server.PC3Session session) + public static bool ChallengeRecordsSplit(HttpRequest _, ServerStruct serverStruct) { - var offset = int.Parse(session.HttpParam["offset"]); - var limit = int.Parse(session.HttpParam["limit"]); - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var offset = int.Parse(serverStruct.Parameters["offset"]); + var limit = int.Parse(serverStruct.Parameters["limit"]); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); ResponseCreator creator = new(); var challenges = JsonConvert.DeserializeObject>(File.ReadAllText("Files/ChallengeRecords.json")) ?? throw new Exception("ChallengeRecords is null!"); @@ -38,7 +39,8 @@ public static bool ChallengeRecordsSplit(HttpRequest _, PC3Server.PC3Session ses } creator.SetBody(JsonConvert.SerializeObject(challenges)); - session.SendResponse(creator.GetResponse()); + serverStruct.Response = creator.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/CloudSave.cs b/PayCheckServerLib/Responses/CloudSave.cs index 7bc5107..c414c5d 100644 --- a/PayCheckServerLib/Responses/CloudSave.cs +++ b/PayCheckServerLib/Responses/CloudSave.cs @@ -12,7 +12,7 @@ namespace PayCheckServerLib.Responses public class CloudSave { [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/title-data")] - public static bool TitleData(HttpRequest _, PC3Server.PC3Session session) + public static bool TitleData(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); TitleData title = new() @@ -21,30 +21,32 @@ public static bool TitleData(HttpRequest _, PC3Server.PC3Session session) CreatedAt = "2023-06-23T07:21:11.604Z", UpdatedAt = "2023-06-23T07:21:11.604Z", Key = "title-data", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], Value = new() { { "TitleData", "My Fancy Title Data" } } }; response.SetBody(JsonConvert.SerializeObject(title)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/news-feed")] - public static bool NewsFeed(HttpRequest _, PC3Server.PC3Session session) + public static bool NewsFeed(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); //todo: // make into json C# and replace namespace response.SetBody(File.ReadAllText("./Files/NewsFeed.json")); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/infamy-translation-table")] - public static bool InfamyTranslationTable(HttpRequest _, PC3Server.PC3Session session) + public static bool InfamyTranslationTable(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); //InfamyTranslationTable.Basic; @@ -53,7 +55,7 @@ public static bool InfamyTranslationTable(HttpRequest _, PC3Server.PC3Session se CreatedAt = "2023-06-27T12:18:00.00Z", UpdatedAt = "2023-06-27T12:18:00.00Z", Key = "infamy-translation-table", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], SetBy = "SERVER", Value = new() { @@ -65,12 +67,13 @@ public static bool InfamyTranslationTable(HttpRequest _, PC3Server.PC3Session se var infamylist = JsonConvert.DeserializeObject>(File.ReadAllText("Files/BasicInfamyTable.json")) ?? throw new Exception("BasicInfamyTable is null!"); table.Value.InfamyTranslationTable = infamylist; response.SetBody(JsonConvert.SerializeObject(table)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/cloudsave/v1/namespaces/{namespace}/records/bulk")] - public static bool RecordsBulk(HttpRequest request, PC3Server.PC3Session session) + public static bool RecordsBulk(HttpRequest request, ServerStruct serverStruct) { var req = JsonConvert.DeserializeObject(request.Body) ?? throw new Exception("WeaponsTableREQ is null!"); ResponseCreator response = new(); @@ -110,36 +113,39 @@ public static bool RecordsBulk(HttpRequest request, PC3Server.PC3Session session } response.SetBody(JsonConvert.SerializeObject(weaponsTable)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/meta-events")] - public static bool MetaEvents(HttpRequest _, PC3Server.PC3Session session) + public static bool MetaEvents(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); //todo: // make into json C# and replace namespace response.SetBody(File.ReadAllText("Files/MetaEvents.json")); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/security-firm-rotation")] - public static bool SecurityFirmRotation(HttpRequest _, PC3Server.PC3Session session) + public static bool SecurityFirmRotation(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); //todo: // make into json C# and replace namespace response.SetBody(File.ReadAllText("Files/FirmRotation.json")); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/users/{userId}/records/PlatformBlockedPlayerData")] - public static bool PlatformBlockedPlayerData(HttpRequest _, PC3Server.PC3Session session) + public static bool PlatformBlockedPlayerData(HttpRequest _, ServerStruct serverStruct) { - var userID = session.HttpParam["userId"]; + var userID = serverStruct.Parameters["userId"]; ResponseCreator response = new(404); ErrorMSG errorMSG = new() { @@ -147,22 +153,23 @@ public static bool PlatformBlockedPlayerData(HttpRequest _, PC3Server.PC3Session ErrorMessage = $"unable to get_player_record: player record not found, user ID: {userID}, key: PlatformBlockedPlayerData" }; response.SetBody(JsonConvert.SerializeObject(errorMSG)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/users/{userId}/records/progressionsavegame")] - public static bool ProgressionsavegameGET(HttpRequest _, PC3Server.PC3Session session) + public static bool ProgressionsavegameGET(HttpRequest _, ServerStruct serverStruct) { - var userID = session.HttpParam["userId"]; + var userID = serverStruct.Parameters["userId"]; var response = new ResponseCreator(); - if (SaveHandler.IsUserExist(userID, session.HttpParam["namespace"])) + if (SaveHandler.IsUserExist(userID, serverStruct.Parameters["namespace"])) { Progression.Basic? save = null; try { - save = Progression.Basic.FromJson(SaveHandler.ReadUserSTR(userID, session.HttpParam["namespace"])); + save = Progression.Basic.FromJson(SaveHandler.ReadUserSTR(userID, serverStruct.Parameters["namespace"])); save.ProgressionSaveGame.LastTimeEventCheck = TimeHelper.GetEpochTime(); } catch @@ -178,11 +185,12 @@ public static bool ProgressionsavegameGET(HttpRequest _, PC3Server.PC3Session se Value = save, IsPublic = false, Key = "progressionsavegame", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], SetBy = "CLIENT" }; response.SetBody(JsonConvert.SerializeObject(saveRSP, Progression.Converter.Settings)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } response = new ResponseCreator(404); @@ -192,17 +200,18 @@ public static bool ProgressionsavegameGET(HttpRequest _, PC3Server.PC3Session se ErrorMessage = $"unable to get_player_record: player record not found, user ID: {userID}, key: progressionsavegame" }; response.SetBody(JsonConvert.SerializeObject(error)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/cloudsave/v1/namespaces/{namespace}/users/{userId}/records/progressionsavegame")] - public static bool ProgressionsavegamePOST(HttpRequest request, PC3Server.PC3Session session) + public static bool ProgressionsavegamePOST(HttpRequest request, ServerStruct serverStruct) { - var userID = session.HttpParam["userId"]; - SaveHandler.SaveUser(userID, session.HttpParam["namespace"], request.BodyBytes); + var userID = serverStruct.Parameters["userId"]; + SaveHandler.SaveUser(userID, serverStruct.Parameters["namespace"], request.BodyBytes); if (ConfigHelper.ServerConfig.Saves.SaveRequest) - SaveHandler.SaveUser_Request(userID, session.HttpParam["namespace"], request.Body); + SaveHandler.SaveUser_Request(userID, serverStruct.Parameters["namespace"], request.Body); Progression.Basic? save = null; try @@ -223,12 +232,13 @@ public static bool ProgressionsavegamePOST(HttpRequest request, PC3Server.PC3Ses Value = save, IsPublic = false, Key = "progressionsavegame", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], SetBy = "CLIENT" }; ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(saveRSP, Progression.Converter.Settings)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Currency.cs b/PayCheckServerLib/Responses/Currency.cs index 5e34984..3021fc7 100644 --- a/PayCheckServerLib/Responses/Currency.cs +++ b/PayCheckServerLib/Responses/Currency.cs @@ -11,11 +11,11 @@ namespace PayCheckServerLib.Responses public class Currency { [HTTP("GET", "/platform/public/namespaces/{namespace}/users/{userId}/wallets/{currency}")] - public static bool GetUserCurrency(HttpRequest request, PC3Server.PC3Session session) + public static bool GetUserCurrency(HttpRequest request, ServerStruct serverStruct) { - var userID = session.HttpParam["userId"]; - var currencyType = session.HttpParam["currency"]; - var nspace = session.HttpParam["namespace"]; + var userID = serverStruct.Parameters["userId"]; + var currencyType = serverStruct.Parameters["currency"]; + var nspace = serverStruct.Parameters["namespace"]; var currencySymbol = currencyType == "CRED" ? "CREDITS" : currencyType; // return fake data for now Debugger.PrintDebug(String.Format("{0}_{1}_{2}", nspace, userID, currencyType)); @@ -54,7 +54,8 @@ public static bool GetUserCurrency(HttpRequest request, PC3Server.PC3Session ses WalletStatus = "ACTIVE" }; response.SetBody(JsonConvert.SerializeObject(currencyReponse)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Custom.cs b/PayCheckServerLib/Responses/Custom.cs index d7f7654..c94ee96 100644 --- a/PayCheckServerLib/Responses/Custom.cs +++ b/PayCheckServerLib/Responses/Custom.cs @@ -9,16 +9,17 @@ namespace PayCheckServerLib.Responses public class Custom { [HTTP("POST", "/register?username={username}&platformId={pid}&platformType={ptype}&nspace={nspace}")] - public static bool RegisterUser(HttpRequest request, PC3Server.PC3Session session) + public static bool RegisterUser(HttpRequest _, ServerStruct serverStruct) { - var username = session.HttpParam["username"]; - var platformId = session.HttpParam["pid"]; - var platformType = session.HttpParam["ptype"]; + var username = serverStruct.Parameters["username"]; + var platformId = serverStruct.Parameters["pid"]; + var platformType = serverStruct.Parameters["ptype"]; var platform = (TokenHelper.TokenPlatform)uint.Parse(platformType); - var nspace = session.HttpParam["nspace"]; + var nspace = serverStruct.Parameters["nspace"]; UserController.RegisterUser(platformId, platform, username, nspace); - session.SendResponse(session.Response.MakeOkResponse()); + serverStruct.Response.MakeOkResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/DLCs.cs b/PayCheckServerLib/Responses/DLCs.cs index dbd6b72..a0f579d 100644 --- a/PayCheckServerLib/Responses/DLCs.cs +++ b/PayCheckServerLib/Responses/DLCs.cs @@ -27,25 +27,26 @@ public partial class DLC_Value [HTTP("PUT", "/platform/public/namespaces/{namespace}/users/{UserId}/dlc/steam/sync")] - public static bool PUT_DLC_SteamSync(HttpRequest request, PC3Server.PC3Session session) + public static bool PUT_DLC_SteamSync(HttpRequest _, ServerStruct serverStruct) { //var body = JsonConvert.DeserializeObject(request.Body); ResponseCreator response = new ResponseCreator(204); response.SetHeader("Content-Type", "application/json"); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); ; return true; } [HTTP("GET", "/cloudsave/v1/namespaces/{namespace}/records/dlc-entitlements")] - public static bool GETdlcentitlements(HttpRequest request, PC3Server.PC3Session session) + public static bool GETdlcentitlements(HttpRequest _, ServerStruct serverStruct) { TopLevel dlc = new() { SetBy = "SERVER", CreatedAt = "2023-09-25T12:01:02.096Z", Key = "dlc-entitlements", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], UpdatedAt = "2023-09-25T12:01:02.096Z", Value = new() { @@ -58,7 +59,8 @@ public static bool GETdlcentitlements(HttpRequest request, PC3Server.PC3Session ResponseCreator response = new ResponseCreator(); response.SetHeader("Content-Type", "application/json"); response.SetBody(JsonConvert.SerializeObject(dlc)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Entitlements.cs b/PayCheckServerLib/Responses/Entitlements.cs index 7dbbfd9..7a0e29d 100644 --- a/PayCheckServerLib/Responses/Entitlements.cs +++ b/PayCheckServerLib/Responses/Entitlements.cs @@ -11,7 +11,7 @@ namespace PayCheckServerLib.Responses public class Entitlements { [HTTP("GET", "/platform/public/namespaces/{namespace}/users/{userId}/entitlements?limit={limit}")] - public static bool GetUserEntitlements(HttpRequest _, PC3Server.PC3Session session) + public static bool GetUserEntitlements(HttpRequest _, ServerStruct serverStruct) { try { @@ -20,7 +20,7 @@ public static bool GetUserEntitlements(HttpRequest _, PC3Server.PC3Session sessi var newentitlements = new List(); foreach (var entitlement in entitlements.Data) { - entitlement.UserId = session.HttpParam["userId"]; + entitlement.UserId = serverStruct.Parameters["userId"]; newentitlements.Add(entitlement); } DataPaging payload = new() @@ -35,7 +35,8 @@ public static bool GetUserEntitlements(HttpRequest _, PC3Server.PC3Session sessi } }; responsecreator.SetBody(JsonConvert.SerializeObject(payload)); - session.SendResponse(responsecreator.GetResponse()); + serverStruct.Response = responsecreator.GetResponse(); + serverStruct.SendResponse(); return true; } catch (Exception ex) @@ -46,7 +47,7 @@ public static bool GetUserEntitlements(HttpRequest _, PC3Server.PC3Session sessi } [HTTP("GET", "/platform/public/namespaces/{namespace}/users/{userId}/entitlements?itemId={itemid}&limit={limit}")] - public static bool GetUserEntitlementsByItemId(HttpRequest _, PC3Server.PC3Session session) + public static bool GetUserEntitlementsByItemId(HttpRequest _, ServerStruct serverStruct) { try { @@ -55,9 +56,9 @@ public static bool GetUserEntitlementsByItemId(HttpRequest _, PC3Server.PC3Sessi var newentitlements = new List(); foreach (var entitlement in entitlements.Data) { - if (entitlement.ItemId == session.HttpParam["itemid"]) + if (entitlement.ItemId == serverStruct.Parameters["itemid"]) { - entitlement.UserId = session.HttpParam["userId"]; + entitlement.UserId = serverStruct.Parameters["userId"]; newentitlements.Add(entitlement); } @@ -74,7 +75,8 @@ public static bool GetUserEntitlementsByItemId(HttpRequest _, PC3Server.PC3Sessi } }; responsecreator.SetBody(JsonConvert.SerializeObject(payload)); - session.SendResponse(responsecreator.GetResponse()); + serverStruct.Response = responsecreator.GetResponse(); + serverStruct.SendResponse(); return true; } catch (Exception ex) diff --git a/PayCheckServerLib/Responses/Friends.cs b/PayCheckServerLib/Responses/Friends.cs index dfe50b7..3689336 100644 --- a/PayCheckServerLib/Responses/Friends.cs +++ b/PayCheckServerLib/Responses/Friends.cs @@ -11,9 +11,9 @@ namespace PayCheckServerLib.Responses public class Friends { [HTTP("GET", "/friends/namespaces/{namespace}/me/platforms")] - public static bool MePlatforms(HttpRequest _, PC3Server.PC3Session session) + public static bool MePlatforms(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var MainUser = UserController.GetUser(token.UserId, token.Namespace) ?? throw new Exception("MainUser is null!"); ResponseCreator response = new(); @@ -23,14 +23,15 @@ public static bool MePlatforms(HttpRequest _, PC3Server.PC3Session session) Data = MainUser.Friends }; response.SetBody(JsonConvert.SerializeObject(friends)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/friends/namespaces/{namespace}/users/{userId}/add/bulk")] - public static bool FriendAddBulk(HttpRequest request, PC3Server.PC3Session session) + public static bool FriendAddBulk(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var MainUser = UserController.GetUser(token.UserId, token.Namespace) ?? throw new Exception("MainUser is null!"); var friends = JsonConvert.DeserializeObject(request.Body)!.FriendIds; @@ -66,8 +67,8 @@ public static bool FriendAddBulk(HttpRequest request, PC3Server.PC3Session sessi MainUser.Friends.Add(data); } - ResponseCreator response = new(204); - session.SendResponse(response.GetResponse()); + serverStruct.Response = new ResponseCreator(204).GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/GameSessions.cs b/PayCheckServerLib/Responses/GameSessions.cs index b578f0a..62a2dce 100644 --- a/PayCheckServerLib/Responses/GameSessions.cs +++ b/PayCheckServerLib/Responses/GameSessions.cs @@ -12,16 +12,16 @@ namespace PayCheckServerLib.Responses public class GameSessions { [HTTP("GET", "/session/v1/public/namespaces/{namespace}/gamesessions/{sessionid}")] - public static bool GETGameSessions(HttpRequest _, PC3Server.PC3Session session) + public static bool GETGameSessions(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); - var gs = GSController.GetGameSession(session.HttpParam["sessionid"], session.HttpParam["namespace"]); + var gs = GSController.GetGameSession(serverStruct.Parameters["sessionid"], serverStruct.Parameters["namespace"]); response.SetBody(JsonConvert.SerializeObject(gs)); - session.SendResponse(response.GetResponse()); - + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); if (GSController.MatchFoundSent.Contains(token.UserId)) return true; @@ -60,20 +60,21 @@ public static bool GETGameSessions(HttpRequest _, PC3Server.PC3Session session) { "payload", LobbyControl.Base64Encode(JsonConvert.SerializeObject(onMatchFound)) }, { "sentAt", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") }, }; - LobbyControl.SendToLobby(kv, session.GetWSLobby(token.UserId, token.Namespace)); + LobbyControl.SendToLobby(kv, LobbyControl.GetLobbyUser(token.UserId, token.Namespace)); GSController.MatchFoundSent.Add(token.UserId); Debugger.PrintDebug("MatchFoundSent!"); return true; } [HTTP("PATCH", "/session/v1/public/namespaces/{namespace}/gamesessions/{sessionid}")] - public static bool PATCHGameSessions(HttpRequest _, PC3Server.PC3Session session) + public static bool PATCHGameSessions(HttpRequest _, ServerStruct serverStruct) { Debugger.PrintDebug("PATCH! gamesessions"); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); //response.SetBody(JsonConvert.SerializeObject(gamesessions)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); //OnDSStatusChanged @@ -81,15 +82,16 @@ public static bool PATCHGameSessions(HttpRequest _, PC3Server.PC3Session session } [HTTP("POST", "/session/v1/public/namespaces/{namespace}/gamesessions/{sessionid}/join")] - public static bool JoinToGameSessions(HttpRequest _, PC3Server.PC3Session session) + public static bool JoinToGameSessions(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); - var gs = GSController.JoinSession(session.HttpParam["sessionid"], token.UserId, session.HttpParam["namespace"]); + var gs = GSController.JoinSession(serverStruct.Parameters["sessionid"], token.UserId, serverStruct.Parameters["namespace"]); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); response.SetBody(JsonConvert.SerializeObject(gs)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); //Send OnSessionMembersChanged, OnSessionJoined OnSessionJoined onSessionJoined = new() @@ -105,7 +107,7 @@ public static bool JoinToGameSessions(HttpRequest _, PC3Server.PC3Session sessio { "payload", LobbyControl.Base64Encode(JsonConvert.SerializeObject(onSessionJoined)) }, { "sentAt", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") }, }; - LobbyControl.SendToLobby(kv, session.GetWSLobby(token.UserId, token.Namespace)); + LobbyControl.SendToLobby(kv, LobbyControl.GetLobbyUser(token.UserId, token.Namespace)); OnSessionMembersChanged onSessionMembersChanged = new() @@ -168,12 +170,12 @@ public static bool JoinToGameSessions(HttpRequest _, PC3Server.PC3Session sessio }; //OnMemeberChanged to full team? - LobbyControl.SendToLobby(kv, session.GetWSLobby(token.UserId, token.Namespace)); + LobbyControl.SendToLobby(kv, LobbyControl.GetLobbyUser(token.UserId, token.Namespace)); return true; } [HTTP("DELETE", "/session/v1/public/namespaces/{namespace}/gamesessions/{sessionid}/leave")] - public static bool LeaveGameSessions(HttpRequest _, PC3Server.PC3Session session) + public static bool LeaveGameSessions(HttpRequest _, ServerStruct serverStruct) { return false; } diff --git a/PayCheckServerLib/Responses/IAM.cs b/PayCheckServerLib/Responses/IAM.cs index 448826a..423c680 100644 --- a/PayCheckServerLib/Responses/IAM.cs +++ b/PayCheckServerLib/Responses/IAM.cs @@ -13,7 +13,7 @@ namespace PayCheckServerLib.Responses public class IAM { [HTTP("POST", "/iam/v3/oauth/platforms/steam/token")] - public static bool SteamToken(HttpRequest request, PC3Server.PC3Session session) + public static bool SteamToken(HttpRequest request, ServerStruct serverStruct) { ResponseCreator response = new(); if (ConfigHelper.ServerConfig.InDevFeatures.UsePWInsteadSteamToken) @@ -30,7 +30,8 @@ public static bool SteamToken(HttpRequest request, PC3Server.PC3Session session) to get game to allow email + password auth */ response.SetBody(JsonConvert.SerializeObject(new IAM_SteamError())); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } Debugger.PrintDebug(request.Body); @@ -53,7 +54,7 @@ to get game to allow email + password auth var steamId = UserIdHelper.GetSteamIDFromAUTH(platform_token); Debugger.PrintInfo("User with SteamID try to log in: " + steamId); - var (access_token, refresh_token) = UserController.LoginUser(steamId, TokenHelper.TokenPlatform.Steam, session.Headers["namespace"]); + var (access_token, refresh_token) = UserController.LoginUser(steamId, TokenHelper.TokenPlatform.Steam, serverStruct.Headers["namespace"]); response.SetHeader("Content-Type", "application/json"); response.SetHeader("Connection", "keep-alive"); @@ -72,7 +73,7 @@ to get game to allow email + password auth ExpiresIn = 360000, IsComply = true, Jflgs = 1, - Namespace = session.Headers["namespace"], + Namespace = serverStruct.Headers["namespace"], NamespaceRoles = new() { new NamespaceRole() @@ -92,16 +93,17 @@ to get game to allow email + password auth UserId = access_token.UserId }; response.SetBody(JsonConvert.SerializeObject(LoginToken)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/iam/v3/oauth/platforms/device/token")] - public static bool DeviceToken(HttpRequest request, PC3Server.PC3Session session) + public static bool DeviceToken(HttpRequest request, ServerStruct serverStruct) { var deviceid = request.Body.Split('=')[1]; Debugger.PrintDebug(deviceid); - var (access_token, refresh_token) = UserController.LoginUser(deviceid, TokenHelper.TokenPlatform.Device, session.Headers["namespace"]); + var (access_token, refresh_token) = UserController.LoginUser(deviceid, TokenHelper.TokenPlatform.Device, serverStruct.Headers["namespace"]); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -117,7 +119,7 @@ public static bool DeviceToken(HttpRequest request, PC3Server.PC3Session session ExpiresIn = 360000, IsComply = true, Jflgs = 4, - Namespace = session.Headers["namespace"], + Namespace = serverStruct.Headers["namespace"], NamespaceRoles = new() { new NamespaceRole() @@ -136,13 +138,14 @@ public static bool DeviceToken(HttpRequest request, PC3Server.PC3Session session UserId = access_token.UserId }; response.SetBody(JsonConvert.SerializeObject(token)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/iam/v3/oauth/platforms/live/token")] - public static bool LiveToken(HttpRequest request, PC3Server.PC3Session session) + public static bool LiveToken(HttpRequest request, ServerStruct serverStruct) { var splitted = request.Body.Split("&"); Dictionary bodyTokens = new(); @@ -156,7 +159,7 @@ public static bool LiveToken(HttpRequest request, PC3Server.PC3Session session) Debugger.PrintDebug(platform_token); platform_token = platform_token.Replace("XBL3.0%20x%3D", ""); platform_token = platform_token.Split(";")[0]; - var (access_token, refresh_token) = UserController.LoginUser(platform_token, TokenHelper.TokenPlatform.Live, session.Headers["namespace"]); + var (access_token, refresh_token) = UserController.LoginUser(platform_token, TokenHelper.TokenPlatform.Live, serverStruct.Headers["namespace"]); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -172,7 +175,7 @@ public static bool LiveToken(HttpRequest request, PC3Server.PC3Session session) ExpiresIn = 360000, IsComply = true, Jflgs = 4, - Namespace = session.Headers["namespace"], + Namespace = serverStruct.Headers["namespace"], NamespaceRoles = new() { new NamespaceRole() @@ -191,13 +194,14 @@ public static bool LiveToken(HttpRequest request, PC3Server.PC3Session session) UserId = access_token.UserId }; response.SetBody(JsonConvert.SerializeObject(token)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } // Logging in with email + password, also links steam to nebula account on official servers [HTTP("POST", "/iam/v3/authenticateWithLink")] - public static bool AuthenticateWithLink(HttpRequest request, PC3Server.PC3Session session) + public static bool AuthenticateWithLink(HttpRequest request, ServerStruct serverStruct) { var param = HttpUtility.ParseQueryString(request.Body); // either username or email entered @@ -208,7 +212,7 @@ public static bool AuthenticateWithLink(HttpRequest request, PC3Server.PC3Sessio var client_id = param["client_id"]; // request does not have a device id, client_id will do for now - var (access_token, refresh_token) = UserController.LoginUser(client_id!, TokenHelper.TokenPlatform.Device, session.Headers["namespace"]); + var (access_token, refresh_token) = UserController.LoginUser(client_id!, TokenHelper.TokenPlatform.Device, serverStruct.Headers["namespace"]); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -244,15 +248,16 @@ public static bool AuthenticateWithLink(HttpRequest request, PC3Server.PC3Sessio UserId = access_token.UserId }; response.SetBody(JsonConvert.SerializeObject(token)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/iam/v3/public/users/me")] - public static bool UsersMe(HttpRequest _, PC3Server.PC3Session session) + public static bool UsersMe(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -267,7 +272,7 @@ public static bool UsersMe(HttpRequest _, PC3Server.PC3Session session) EmailAddress = $"{token.Name}@pd3_emu.com", EmailVerified = true, Enabled = true, - Namespace = session.Headers["namespace"], + Namespace = serverStruct.Headers["namespace"], OldEmailAddress = $"{token.Name}@pd3_emu.com", PhoneVerified = true, Permissions = new(), @@ -284,12 +289,13 @@ public static bool UsersMe(HttpRequest _, PC3Server.PC3Session session) Roles = new() { "2251438839e948d783ec0e5281daf05" } }; response.SetBody(JsonConvert.SerializeObject(me)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/iam/v3/public/namespaces/{namespace}/users/bulk/basic")] - public static bool BulkBasic(HttpRequest request, PC3Server.PC3Session session) + public static bool BulkBasic(HttpRequest request, ServerStruct serverStruct) { var req = JsonConvert.DeserializeObject(request.Body) ?? throw new Exception("BulkBasic is null!"); ResponseCreator response = new(); @@ -312,21 +318,22 @@ public static bool BulkBasic(HttpRequest request, PC3Server.PC3Session session) } else { - if (user.Namespace == session.Headers["namespace"]) + if (user.Namespace == serverStruct.Headers["namespace"]) bulk.Data.Add(user.UserData); } } response.SetBody(JsonConvert.SerializeObject(bulk)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/iam/v3/public/namespaces/{namespace}/users?query={uname}&by=displayName&limit=100&offset=0")] - public static bool UsersQuery(HttpRequest _, PC3Server.PC3Session session) + public static bool UsersQuery(HttpRequest _, ServerStruct serverStruct) { //Idk what is this but works - var username = session.HttpParam["uname"]; + var username = serverStruct.Parameters["uname"]; username = username.Split("&")[0].Split("=")[1]; //magix shit end Debugger.PrintDebug("UserName to search: " + username); @@ -347,7 +354,7 @@ public static bool UsersQuery(HttpRequest _, PC3Server.PC3Session session) foreach (var item in UserController.GetUsers()) { - if (item.Namespace != session.HttpParam["namespace"]) + if (item.Namespace != serverStruct.Parameters["namespace"]) continue; if (item.UserData.DisplayName.Contains(username)) @@ -366,12 +373,13 @@ public static bool UsersQuery(HttpRequest _, PC3Server.PC3Session session) } response.SetBody(JsonConvert.SerializeObject(dataSearch)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/iam/v3/public/namespaces/{namespace}/platforms/steam/users?rawPUID=true")] - public static bool GetSteamUsersWithPID(HttpRequest request, PC3Server.PC3Session session) + public static bool GetSteamUsersWithPID(HttpRequest request, ServerStruct serverStruct) { var req = JsonConvert.DeserializeObject(request.Body); ResponseCreator response = new(); @@ -386,10 +394,10 @@ public static bool GetSteamUsersWithPID(HttpRequest request, PC3Server.PC3Sessio foreach (var id in req.platformUserIds) { - //can replace the headers to session.HttpParam["namespace"] and will works too - if (UserController.CheckUser(id, TokenHelper.TokenPlatform.Steam, session.Headers["namespace"])) + //can replace the headers to serverStruct.Parameters["namespace"] and will works too + if (UserController.CheckUser(id, TokenHelper.TokenPlatform.Steam, serverStruct.Headers["namespace"])) { - var user = UserController.GetUser(id, TokenHelper.TokenPlatform.Steam, session.Headers["namespace"]); + var user = UserController.GetUser(id, TokenHelper.TokenPlatform.Steam, serverStruct.Headers["namespace"]); steamUsers.userIdPlatforms.Add(new() { platformId = "steam", @@ -402,7 +410,8 @@ public static bool GetSteamUsersWithPID(HttpRequest request, PC3Server.PC3Sessio } response.SetBody(JsonConvert.SerializeObject(steamUsers)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Items.cs b/PayCheckServerLib/Responses/Items.cs index 6abde06..6783433 100644 --- a/PayCheckServerLib/Responses/Items.cs +++ b/PayCheckServerLib/Responses/Items.cs @@ -11,7 +11,7 @@ namespace PayCheckServerLib.Responses public class Items { [HTTP("GET", "/platform/public/namespaces/{namespace}/items/byCriteria?limit={limit}&includeSubCategoryItem=false")] - public static bool GetItemsByCriteria(HttpRequest _, PC3Server.PC3Session session) + public static bool GetItemsByCriteria(HttpRequest _, ServerStruct serverStruct) { ResponseCreator creator = new(); var items = JsonConvert.DeserializeObject>(File.ReadAllText("./Files/Items.json")); @@ -21,12 +21,13 @@ public static bool GetItemsByCriteria(HttpRequest _, PC3Server.PC3Session sessio item.UpdatedAt = timeMrFreeman; } creator.SetBody(JsonConvert.SerializeObject(items)); - session.SendResponse(creator.GetResponse()); + serverStruct.Response = creator.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/platform/public/namespaces/{namespace}/items/byCriteria?tags={tags}&limit={limit}&includeSubCategoryItem=false")] - public static bool GetItemsByCriteriaByTags(HttpRequest _, PC3Server.PC3Session session) + public static bool GetItemsByCriteriaByTags(HttpRequest _, ServerStruct serverStruct) { ResponseCreator creator = new(); var items = JsonConvert.DeserializeObject>(File.ReadAllText("./Files/Items.json")) ?? throw new Exception("Items is null!"); @@ -37,7 +38,7 @@ public static bool GetItemsByCriteriaByTags(HttpRequest _, PC3Server.PC3Session item.UpdatedAt = timeMrFreeman; if (item.Tags != null) { - if (item.Tags.Contains(session.HttpParam["tags"])) + if (item.Tags.Contains(serverStruct.Parameters["tags"])) { finalitems.Add(item); } @@ -49,7 +50,8 @@ public static bool GetItemsByCriteriaByTags(HttpRequest _, PC3Server.PC3Session Paging = { } }; creator.SetBody(JsonConvert.SerializeObject(tosend)); - session.SendResponse(creator.GetResponse()); + serverStruct.Response = creator.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/LobbyBlocked.cs b/PayCheckServerLib/Responses/LobbyBlocked.cs index 1fb8dd3..45109c3 100644 --- a/PayCheckServerLib/Responses/LobbyBlocked.cs +++ b/PayCheckServerLib/Responses/LobbyBlocked.cs @@ -8,20 +8,22 @@ namespace PayCheckServerLib.Responses public class LobbyBlocked { [HTTP("GET", "/lobby/v1/public/player/namespaces/{namespace}/users/me/blocked-by")] - public static bool Blocked(HttpRequest request, PC3Server.PC3Session session) + public static bool Blocked(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); response.SetBody("{\r\n \"data\": []\r\n}"); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/lobby/v1/public/player/namespaces/{namespace}/users/me/blocked")] - public static bool BlockedBy(HttpRequest request, PC3Server.PC3Session session) + public static bool BlockedBy(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); response.SetBody("{\r\n \"data\": []\r\n}"); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/MatchTickets.cs b/PayCheckServerLib/Responses/MatchTickets.cs index 7eac879..bee556e 100644 --- a/PayCheckServerLib/Responses/MatchTickets.cs +++ b/PayCheckServerLib/Responses/MatchTickets.cs @@ -33,9 +33,9 @@ public class WSS_OnMatchmakingStarted } [HTTP("POST", "/match2/v1/namespaces/{namespace}/match-tickets")] - public static bool Tickets(HttpRequest request, PC3Server.PC3Session session) + public static bool Tickets(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var ticket = JsonConvert.DeserializeObject(request.Body); var ticketId = UserIdHelper.CreateNewID(); @@ -46,7 +46,8 @@ public static bool Tickets(HttpRequest request, PC3Server.PC3Session session) }; ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(ticketRsp)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); Debugger.PrintDebug("OnMatchmakingStarted YEET"); //Store Both and send into Lobby WSS @@ -56,7 +57,7 @@ public static bool Tickets(HttpRequest request, PC3Server.PC3Session session) PartyID = ticket.sessionId, CreatedAt = DateTime.UtcNow.ToString("o"), MatchPool = ticket.matchPool, - Namespace = session.Headers["namespace"] + Namespace = serverStruct.Headers["namespace"] }; Dictionary resp = new() { @@ -68,8 +69,8 @@ public static bool Tickets(HttpRequest request, PC3Server.PC3Session session) { "payload", LobbyControl.Base64Encode(JsonConvert.SerializeObject(onMatchmakingStarted)) }, { "sentAt", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") } }; - LobbyControl.SendToLobby(resp, session.GetWSLobby(token.UserId, token.Namespace)); - GSController.Make(ticket, session, session.Headers["namespace"]); + LobbyControl.SendToLobby(resp, LobbyControl.GetLobbyUser(token.UserId, token.Namespace)); + GSController.Make(ticket, serverStruct, serverStruct.Headers["namespace"]); GSController.Tickets.Add(token.UserId, ticketId); /* * Need to check what happens at this stage. diff --git a/PayCheckServerLib/Responses/Orders.cs b/PayCheckServerLib/Responses/Orders.cs index 23224f3..bfec7f3 100644 --- a/PayCheckServerLib/Responses/Orders.cs +++ b/PayCheckServerLib/Responses/Orders.cs @@ -36,7 +36,7 @@ public static string GenOrderNumber() } [HTTP("POST", "/platform/public/namespaces/{namespace}/users/{userid}/orders")] - public static bool UserOrders(HttpRequest request, PC3Server.PC3Session session) + public static bool UserOrders(HttpRequest request, ServerStruct serverStruct) { //ResponseCreator response = new ResponseCreator(); //OrdersJsonPayload payload = new() { @@ -48,7 +48,7 @@ public static bool UserOrders(HttpRequest request, PC3Server.PC3Session session) var body = JsonConvert.DeserializeObject(request.Body) ?? throw new Exception("UserOrders -> body is null!"); if (!Directory.Exists("Orders")) { Directory.CreateDirectory("Orders"); } - File.WriteAllText($"Orders/{session.HttpParam["namespace"]}_{session.HttpParam["userid"]}_{body.ItemId}", request.Body); + File.WriteAllText($"Orders/{serverStruct.Parameters["namespace"]}_{serverStruct.Parameters["userid"]}_{body.ItemId}", request.Body); ResponseCreator response = new(); var ordernumber = GenOrderNumber(); @@ -56,8 +56,8 @@ public static bool UserOrders(HttpRequest request, PC3Server.PC3Session session) Order order = new() { OrderNo = ordernumber, - Namespace = session.HttpParam["namespace"], - UserId = session.HttpParam["userid"], + Namespace = serverStruct.Parameters["namespace"], + UserId = serverStruct.Parameters["userid"], ItemId = item.ItemId, Sandbox = false, Quantity = body.Quantity, @@ -74,7 +74,7 @@ public static bool UserOrders(HttpRequest request, PC3Server.PC3Session session) CurrencySymbol = body.CurrencyCode, // CASH = Cash, GOLD = CStacks CurrencyType = (body.CurrencyCode == "CASH" || body.CurrencyCode == "GOLD") ? "VIRTUAL" : "REAL", - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], Decimals = 0 }, // will be like this until i can confirm they are the same type ~HW12Dev @@ -97,7 +97,8 @@ public static bool UserOrders(HttpRequest request, PC3Server.PC3Session session) PaymentProvider = "WALLET" }; response.SetBody(JsonConvert.SerializeObject(order)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Parties.cs b/PayCheckServerLib/Responses/Parties.cs index 2c9661d..89a83df 100644 --- a/PayCheckServerLib/Responses/Parties.cs +++ b/PayCheckServerLib/Responses/Parties.cs @@ -14,15 +14,16 @@ namespace PayCheckServerLib.Responses public class Parties { [HTTP("POST", "/session/v1/public/namespaces/{namespace}/party")] - public static bool Party(HttpRequest request, PC3Server.PC3Session session) + public static bool Party(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var body = JsonConvert.DeserializeObject(request.Body); var rsp = PartyController.CreateParty(body, token.Namespace); ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(rsp)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); //send notif to user to party created var wss_sess = LobbyControl.GetLobbyUser(token.UserId, token.Namespace); @@ -63,15 +64,16 @@ public static bool Party(HttpRequest request, PC3Server.PC3Session session) } [HTTP("PATCH", "/session/v1/public/namespaces/{namespace}/parties/{partyid}")] - public static bool PATCH_Parties(HttpRequest request, PC3Server.PC3Session session) + public static bool PATCH_Parties(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var body = JsonConvert.DeserializeObject(request.Body); - PartyPost.Response rsp = PartyController.UpdateParty(session.HttpParam["partyid"], body); + PartyPost.Response rsp = PartyController.UpdateParty(serverStruct.Parameters["partyid"], body); ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(rsp)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); OnPartyUpdated pld = new() { Code = rsp.Code, @@ -95,7 +97,7 @@ public static bool PATCH_Parties(HttpRequest request, PC3Server.PC3Session sessi IsFull = rsp.IsFull, LeaderId = rsp.LeaderId, Members = new(), - Namespace = session.HttpParam["namespace"], + Namespace = serverStruct.Parameters["namespace"], UpdatedAt = rsp.UpdatedAt, Version = rsp.Version }; @@ -123,12 +125,14 @@ public static bool PATCH_Parties(HttpRequest request, PC3Server.PC3Session sessi List ids = new(); rsp.Members.ForEach(m => ids.Add(m.Id)); - foreach (var id in session.WSSServer.WSUserIds) + foreach (var id in LobbyControl.LobbyUsers.Keys) { - if (ids.Contains(id)) + var splitted = id.Split("_"); + + if (ids.Contains(splitted[1])) { - Debugger.PrintDebug(id); - LobbyControl.SendToLobby(resp, LobbyControl.GetLobbyUser(id, token.Namespace)); + Debugger.PrintDebug(splitted[1]); + LobbyControl.SendToLobby(resp, LobbyControl.GetLobbyUser(splitted[1], token.Namespace)); } } @@ -137,16 +141,17 @@ public static bool PATCH_Parties(HttpRequest request, PC3Server.PC3Session sessi [HTTP("DELETE", "/session/v1/public/namespaces/{namespace}/parties/{partyid}/users/me/leave")] - public static bool LeaveParties(HttpRequest request, PC3Server.PC3Session session) + public static bool LeaveParties(HttpRequest request, ServerStruct serverStruct) { //This response sadly KILLING THE GAME (Even without emu) // SBZ PLEASE FIX! - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); ResponseCreator response = new(204); - session.SendResponse(response.GetResponse()); - PartyController.LeftParty(session.HttpParam["partyid"], token.UserId, session); - var party = PartyController.PartySaves.Where(x => x.Value.Id == session.HttpParam["partyid"]).FirstOrDefault().Value; + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); + PartyController.LeftParty(serverStruct.Parameters["partyid"], token.UserId, serverStruct); + var party = PartyController.PartySaves.Where(x => x.Value.Id == serverStruct.Parameters["partyid"]).FirstOrDefault().Value; if (party == null) { Debugger.PrintError("NO Code???? WHAT THE FUCK"); @@ -171,9 +176,9 @@ public static bool LeaveParties(HttpRequest request, PC3Server.PC3Session sessio [HTTP("POST", "/session/v1/public/namespaces/{namespace}/parties/{partyid}/users/me/join")] - public static bool JoinParties(HttpRequest request, PC3Server.PC3Session session) + public static bool JoinParties(HttpRequest request, ServerStruct serverStruct) { - var party = PartyController.PartySaves.Where(x => x.Value.Id == session.HttpParam["partyid"]).FirstOrDefault().Value; + var party = PartyController.PartySaves.Where(x => x.Value.Id == serverStruct.Parameters["partyid"]).FirstOrDefault().Value; if (party == null) { Debugger.PrintError("NO Code???? WHAT THE FUCK"); @@ -182,12 +187,13 @@ public static bool JoinParties(HttpRequest request, PC3Server.PC3Session session var rsp = PartyController.ParsePartyToRSP(party); ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(rsp)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/session/v1/public/namespaces/{namespace}/parties/{partyid}/users/me/reject")] - public static bool RejectParties(HttpRequest request, PC3Server.PC3Session session) + public static bool RejectParties(HttpRequest request, ServerStruct serverStruct) { /* var body = JsonConvert.DeserializeObject(request.Body); @@ -205,7 +211,7 @@ public class UsersMeJoinCode } [HTTP("POST", "/session/v1/public/namespaces/{namespace}/parties/users/me/join/code")] - public static bool JoinPartyByCode(HttpRequest request, PC3Server.PC3Session session) + public static bool JoinPartyByCode(HttpRequest request, ServerStruct serverStruct) { var body = JsonConvert.DeserializeObject(request.Body); @@ -214,7 +220,8 @@ public static bool JoinPartyByCode(HttpRequest request, PC3Server.PC3Session ses var rsp = PartyController.ParsePartyToRSP(saved); ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject(rsp)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); } else { @@ -223,29 +230,31 @@ public static bool JoinPartyByCode(HttpRequest request, PC3Server.PC3Session ses Attributes = new Dictionary() { { "id", body.Code }, - { "namespace", session.HttpParam["namespace"] } + { "namespace", serverStruct.Parameters["namespace"] } }, ErrorCode = 20041, - ErrorMessage = $"No party with ID [{body.Code}] exists in namespace [{session.HttpParam["namespace"]}]", - Message = $"No party with ID [{body.Code}] exists in namespace [{session.HttpParam["namespace"]}]", + ErrorMessage = $"No party with ID [{body.Code}] exists in namespace [{serverStruct.Parameters["namespace"]}]", + Message = $"No party with ID [{body.Code}] exists in namespace [{serverStruct.Parameters["namespace"]}]", Name = "PartyNotFound" }; ResponseCreator response = new(404); response.SetBody(JsonConvert.SerializeObject(error)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); } return true; } [HTTP("POST", "/session/v1/public/namespaces/{namespace}/parties/{partyid}/invite")] - public static bool InviteOtherPlayer(HttpRequest request, PC3Server.PC3Session session) + public static bool InviteOtherPlayer(HttpRequest request, ServerStruct serverStruct) { /* var body = JsonConvert.DeserializeObject(request.Body); ResponseCreator response = new(); response.SetBody(JsonConvert.SerializeObject("")); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); */ return false; } diff --git a/PayCheckServerLib/Responses/Session.cs b/PayCheckServerLib/Responses/Session.cs index c3c748d..8896217 100644 --- a/PayCheckServerLib/Responses/Session.cs +++ b/PayCheckServerLib/Responses/Session.cs @@ -10,9 +10,9 @@ namespace PayCheckServerLib.Responses public class Session { [HTTP("GET", "/session/v1/public/namespaces/{namespace}/users/me/attributes")] - public static bool GETSessionAttributes(HttpRequest _, PC3Server.PC3Session session) + public static bool GETSessionAttributes(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); ResponseCreator response = new(); AttribSuccess success = new() @@ -31,14 +31,15 @@ public static bool GETSessionAttributes(HttpRequest _, PC3Server.PC3Session sess UserId = token.UserId }; response.SetBody(JsonConvert.SerializeObject(success)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("POST", "/session/v1/public/namespaces/{namespace}/users/me/attributes")] - public static bool POSTSessionAttributes(HttpRequest request, PC3Server.PC3Session session) + public static bool POSTSessionAttributes(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var req = JsonConvert.DeserializeObject(request.Body) ?? throw new Exception("POSTSessionAttributes -> req is null!"); ResponseCreator response = new(); @@ -52,12 +53,13 @@ public static bool POSTSessionAttributes(HttpRequest request, PC3Server.PC3Sessi UserId = token.UserId }; response.SetBody(JsonConvert.SerializeObject(success)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/session/v1/public/namespaces/{namespace}/users/me/parties")] - public static bool SessionsParties(HttpRequest _, PC3Server.PC3Session session) + public static bool SessionsParties(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -73,12 +75,13 @@ public static bool SessionsParties(HttpRequest _, PC3Server.PC3Session session) Data = new() }; response.SetBody(JsonConvert.SerializeObject(gamesessions)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/session/v1/public/namespaces/{namespace}/users/me/gamesessions")] - public static bool Sessionsgamesessions(HttpRequest _, PC3Server.PC3Session session) + public static bool Sessionsgamesessions(HttpRequest _, ServerStruct serverStruct) { ResponseCreator response = new(); response.SetHeader("Content-Type", "application/json"); @@ -94,7 +97,8 @@ public static bool Sessionsgamesessions(HttpRequest _, PC3Server.PC3Session sess Data = new() }; response.SetBody(JsonConvert.SerializeObject(gamesessions)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Social.cs b/PayCheckServerLib/Responses/Social.cs index 0ff925f..d530e08 100644 --- a/PayCheckServerLib/Responses/Social.cs +++ b/PayCheckServerLib/Responses/Social.cs @@ -12,22 +12,23 @@ namespace PayCheckServerLib.Responses public class Social { [HTTP("PUT", "/social/v1/public/namespaces/{namespace}/users/{userId}/statitems/value/bulk")] - public static bool PutStatItemsBulk(HttpRequest request, PC3Server.PC3Session session) + public static bool PutStatItemsBulk(HttpRequest request, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var statReq = JsonConvert.DeserializeObject>(request.Body); var rsp = UserStatController.AddStat(statReq, token); ResponseCreator responsecreator = new ResponseCreator(); responsecreator.SetBody(JsonConvert.SerializeObject(rsp)); - session.SendResponse(responsecreator.GetResponse()); + serverStruct.Response = responsecreator.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/social/v1/public/namespaces/{namespace}/users/{userId}/statitems?limit={limit}&offset=0")] - public static bool GetUserStatItems(HttpRequest request, PC3Server.PC3Session session) + public static bool GetUserStatItems(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); var stat = UserStatController.GetStat(token.UserId, token.Namespace); @@ -39,16 +40,17 @@ public static bool GetUserStatItems(HttpRequest request, PC3Server.PC3Session se Paging = { } }; response.SetBody(JsonConvert.SerializeObject(responsedata)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } [HTTP("GET", "/social/v1/public/namespaces/{namespace}/users/{userId}/statitems?statCodes={statcode}&limit=20&offset=0")] - public static bool GetUserStatItemsInfamy(HttpRequest request, PC3Server.PC3Session session) + public static bool GetUserStatItemsInfamy(HttpRequest _, ServerStruct serverStruct) { - var auth = session.Headers["authorization"].Replace("Bearer ", ""); + var auth = serverStruct.Headers["authorization"].Replace("Bearer ", ""); var token = TokenHelper.ReadToken(auth); - var statcode = session.HttpParam["statcode"]; + var statcode = serverStruct.Parameters["statcode"]; ResponseCreator response = new ResponseCreator(); DataPaging responsedata = new() { @@ -66,7 +68,8 @@ public static bool GetUserStatItemsInfamy(HttpRequest request, PC3Server.PC3Sess } response.SetBody(JsonConvert.SerializeObject(responsedata)); - session.SendResponse(response.GetResponse()); + serverStruct.Response = response.GetResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/Telemetry.cs b/PayCheckServerLib/Responses/Telemetry.cs index 1fae1a4..786a14f 100644 --- a/PayCheckServerLib/Responses/Telemetry.cs +++ b/PayCheckServerLib/Responses/Telemetry.cs @@ -8,7 +8,7 @@ namespace PayCheckServerLib.Responses public class Telemetry { [HTTP("POST", "/game-telemetry/v1/protected/events")] - public static bool ProtectedEvents(HttpRequest request, PC3Server.PC3Session session) + public static bool ProtectedEvents(HttpRequest request, ServerStruct serverStruct) { if (!Directory.Exists("Telemetry")) { Directory.CreateDirectory("Telemetry"); } try @@ -19,7 +19,8 @@ public static bool ProtectedEvents(HttpRequest request, PC3Server.PC3Session ses { Debugger.PrintError(String.Format("Exception occurred while writing telemetry: {0}", e.ToString())); } - session.SendResponse(session.Response.MakeOkResponse()); + serverStruct.Response.MakeOkResponse(); + serverStruct.SendResponse(); return true; } } diff --git a/PayCheckServerLib/Responses/VersionResponse.cs b/PayCheckServerLib/Responses/VersionResponse.cs index 3dfbbb3..523dd1a 100644 --- a/PayCheckServerLib/Responses/VersionResponse.cs +++ b/PayCheckServerLib/Responses/VersionResponse.cs @@ -48,7 +48,7 @@ static bool GenericVersionResponse(HttpRequest request, ServerStruct serverStruc response.SetBody(JsonConvert.SerializeObject(version)); serverStruct.Response = response.GetResponse(); - ResponseSender.SendResponse(serverStruct); + serverStruct.SendResponse(); return true; }