Skip to content

Commit

Permalink
Transition (#30)
Browse files Browse the repository at this point in the history
* transition to MWS

* Now its build
lobby/chat ws send fixed

* using now fixed

* hopefully now good

* now it somehow connects to wss???
i aint say no for this but ok..

* both handling now the new isconnecting

* Fixed for trying to use Debug,  Beta at all time
Fixed Party Controller not reading Namespace
Fixed noupdate would disable Debug
  • Loading branch information
SlejmUr authored Oct 16, 2023
1 parent e685954 commit 8a4375b
Show file tree
Hide file tree
Showing 32 changed files with 646 additions and 706 deletions.
2 changes: 2 additions & 0 deletions DS_Server/DS_Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="L" Version="5.0.0" />
<PackageReference Include="ModdableWebServer" Version="1.1.0.1" />
<PackageReference Include="NetCoreServer" Version="7.0.0" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion DS_Server/MiddleMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public override void OnWsConnecting(HttpRequest request)
request.SetHeader("Upgrade", "websocket");
request.SetHeader("Connection", "Upgrade");
request.SetHeader("Sec-WebSocket-Key", Convert.ToBase64String(WsNonce));
request.SetHeader("Sec-WebSocket-Protocol", "chat, superchat");
request.SetHeader("Sec-WebSocket-Version", "13");
request.SetHeader("MiddleMan", Id.ToString());
request.SetBody();
Expand Down
3 changes: 2 additions & 1 deletion DS_Server/MiddleManStarter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NetCoreServer;
using System.Security.Authentication;
using ModdableWebServer.Helper;

namespace DS_Server
{
Expand All @@ -9,7 +10,7 @@ public class MiddleManStarter
static List<DS_UDPServer> DS_UDPServers = new List<DS_UDPServer>();
public static void Start()
{
var context = new SslContext(SslProtocols.Tls12, PayCheckServerLib.PC3Server.GetCert());
var context = new SslContext(SslProtocols.Tls12, CertHelper.GetCert("cert.pfx","cert"));
Client = new MiddleManClient(context, PayCheckServerLib.Helpers.ConfigHelper.ServerConfig.Hosting.IP, 443);
Client.Connect();
DS_UDPServers.Add(new("127.0.0.1", 6969)); // THIS is a Qos Server
Expand Down
14 changes: 0 additions & 14 deletions PayCheckServerLib/HTTPAttribute.cs

This file was deleted.

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
9 changes: 6 additions & 3 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 @@ -88,7 +89,9 @@ public static PartyPost.Response CreateParty(PartyPostReq partyPost, string name
LeaderId = rsp.LeaderId,
Members = rsp.Members,
UpdatedAt = rsp.UpdatedAt,
version = rsp.Version
version = rsp.Version,
NameSpace = nameSpace,
Attributes = rsp.Attributes
};
PartySaves.Add(code, saved);
Debugger.PrintInfo("New Party made!");
Expand Down Expand Up @@ -134,7 +137,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
4 changes: 3 additions & 1 deletion PayCheckServerLib/PayCheckServerLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="JWT" Version="10.0.3" />
<PackageReference Include="JWT" Version="10.1.1" />
<PackageReference Include="L" Version="5.0.0" />
<PackageReference Include="ModdableWebServer" Version="1.1.0.1" />
<PackageReference Include="NetCoreServer" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>


<ItemGroup>
<Compile Update="Properties/Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
38 changes: 27 additions & 11 deletions PayCheckServerLib/Responses/BasicResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using NetCoreServer;
using ModdableWebServer;
using ModdableWebServer.Attributes;
using ModdableWebServer.Helper;
using NetCoreServer;
using Newtonsoft.Json;
using PayCheckServerLib.Helpers;
using PayCheckServerLib.Jsons;
Expand All @@ -7,8 +10,17 @@ namespace PayCheckServerLib.Responses
{
public class BasicResponse
{
[HTTP("HEAD", "/generate_204")]
public static bool Generate204(HttpRequest _, ServerStruct serverStruct)
{
serverStruct.Response.MakeOkResponse(204);
serverStruct.SendResponse();
return true;
}


[HTTP("GET", "/qosm/public/qos")]
public static bool QOSM_Public_QOS(HttpRequest request, PC3Server.PC3Session session)
public static bool QOSM_Public_QOS(HttpRequest _, ServerStruct serverStruct)
{
ResponseCreator response = new ResponseCreator();
response.SetHeader("Content-Type", "application/json");
Expand All @@ -31,16 +43,17 @@ public static bool QOSM_Public_QOS(HttpRequest request, PC3Server.PC3Session ses
}

response.SetBody(JsonConvert.SerializeObject(rsp, Formatting.Indented));
session.SendResponse(response.GetResponse());
serverStruct.Response = response.GetResponse();
serverStruct.SendResponse();
return true;
}

[HTTP("GET", "/basic/v1/public/misc/time")]
public static bool Time(HttpRequest request, PC3Server.PC3Session session)
public static bool Time(HttpRequest _, ServerStruct serverStruct)
{
if (session.Headers.ContainsKey("cookie"))
if (serverStruct.Headers.ContainsKey("cookie"))
{
var tokens = TokenHelper.ReadFromHeader(session.Headers);
var tokens = TokenHelper.ReadFromHeader(serverStruct.Headers);
Debugger.PrintDebug($"{tokens.AccessToken.UserId}({tokens.AccessToken.Name}) Is still in the server!");
}

Expand All @@ -52,29 +65,32 @@ public static bool Time(HttpRequest request, PC3Server.PC3Session session)
CurrentTime = DateTime.UtcNow.ToString("o")
};
response.SetBody(JsonConvert.SerializeObject(rsp));
session.SendResponse(response.GetResponse());
serverStruct.Response = response.GetResponse();
serverStruct.SendResponse();
return true;
}



[HTTP("GET", "/lobby/v1/messages")]
public static bool LobbyMessages(HttpRequest request, PC3Server.PC3Session session)
public static bool LobbyMessages(HttpRequest _, ServerStruct serverStruct)
{
ResponseCreator response = new ResponseCreator();
response.SetHeader("Content-Type", "application/json");
response.SetBody(File.ReadAllBytes("Files/messages.json"));
session.SendResponse(response.GetResponse());
serverStruct.Response = response.GetResponse();
serverStruct.SendResponse();
return true;
}

[HTTP("GET", "/iam/v3/location/country")]
public static bool Country(HttpRequest request, PC3Server.PC3Session session)
public static bool Country(HttpRequest _, ServerStruct serverStruct)
{
ResponseCreator response = new ResponseCreator();
response.SetHeader("Content-Type", "application/json");
response.SetBody(File.ReadAllBytes("Files/Country.json"));
session.SendResponse(response.GetResponse());
serverStruct.Response = response.GetResponse();
serverStruct.SendResponse();
return true;
}
}
Expand Down
21 changes: 13 additions & 8 deletions PayCheckServerLib/Responses/Challenge.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using NetCoreServer;
using ModdableWebServer;
using ModdableWebServer.Attributes;
using ModdableWebServer.Helper;
using NetCoreServer;
using Newtonsoft.Json;
using PayCheckServerLib.Helpers;
using PayCheckServerLib.Jsons;
Expand All @@ -9,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 @@ -35,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 8a4375b

Please sign in to comment.