Skip to content

Commit

Permalink
hopefully now good
Browse files Browse the repository at this point in the history
  • Loading branch information
SlejmUr committed Oct 14, 2023
1 parent 486dabf commit 476ece0
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 212 deletions.
33 changes: 21 additions & 12 deletions PayCheckServerLib/Helpers/GSController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -15,7 +18,7 @@ public class GSController
public static Dictionary<string, GameSession> Sessions = new();
public static Dictionary<string, string> 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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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))
{
Expand All @@ -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))
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions PayCheckServerLib/Helpers/PartyController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using ModdableWebServer;
using Newtonsoft.Json;
using PayCheckServerLib.Jsons.PartyStuff;

namespace PayCheckServerLib.Helpers
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion PayCheckServerLib/PayCheckServerLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ItemGroup>
<PackageReference Include="JWT" Version="10.1.1" />
<PackageReference Include="L" Version="5.0.0" />
<PackageReference Include="ModdableWebServer" Version="1.0.0" />
<PackageReference Include="ModdableWebServer" Version="1.1.0" />
<PackageReference Include="NetCoreServer" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
20 changes: 10 additions & 10 deletions PayCheckServerLib/Responses/BasicResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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"))
{
Expand All @@ -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;
}
}
Expand Down
16 changes: 9 additions & 7 deletions PayCheckServerLib/Responses/Challenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataPaging<ChallengesData>>(File.ReadAllText("Files/ChallengeRecords.json")) ?? throw new Exception("ChallengeRecords is null!");
Expand All @@ -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;
}
}
Expand Down
Loading

0 comments on commit 476ece0

Please sign in to comment.