Skip to content

Commit

Permalink
Party stuff going on
Browse files Browse the repository at this point in the history
  • Loading branch information
SlejmUr committed Sep 19, 2023
1 parent e04bac7 commit 114e3ed
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 24 deletions.
49 changes: 49 additions & 0 deletions PayCheckServerLib/Files/PartySessionConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"PSNBaseURL": "https://s2s.np.playstation.net",
"autoJoin": false,
"clientVersion": "0",
"deployment": "",
"dsSource": "",
"fallbackClaimKeys": [],
"inactiveTimeout": 300,
"inviteTimeout": 60,
"joinability": "INVITE_ONLY",
"maxPlayers": 4,
"minPlayers": 1,
"name": "PartySession",
"nativeSessionSetting": {
"PSNServiceLabel": 0,
"PSNSupportedPlatforms": [],
"SessionTitle": "PAYDAY 3 Party",
"ShouldSync": true,
"XboxServiceConfigID": "00000000-0000-0000-0000-00006056e5d6",
"XboxSessionTemplateName": "Payday3",
"localizedSessionName": {
"defaultLanguage": "en-US",
"localizedText": {
"de-DE": "GRUPPE PAYDAY 3",
"en-US": "PAYDAY 3 Party",
"es-419": "GRUPO PAYDAY 3",
"es-ES": "GRUPO PAYDAY 3",
"fr-FR": "GROUPE PAYDAY 3",
"it-IT": "SQUADRA PAYDAY 3",
"ja-JP": "PAYDAY 3 パーティー",
"ko-KR": "PAYDAY 3 파티",
"pl-PL": "ZESPÓŁ PAYDAY 3",
"pt-BR": "GRUPO PAYDAY 3",
"ru-RU": "КОМАНДА PAYDAY 3",
"tr-TR": "PAYDAY 3 GRUP",
"zh-Hans": "PAYDAY 3 参加者",
"zh-Hant": "PAYDAY 3 隊伍"
}
}
},
"persistent": false,
"preferredClaimKeys": [],
"requestedRegions": [
"eu-central-1"
],
"textChat": true,
"tieTeamsSessionLifetime": false,
"type": "NONE"
}
161 changes: 161 additions & 0 deletions PayCheckServerLib/Helpers/PartyController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using Newtonsoft.Json;
using PayCheckServerLib.Jsons;
using PayCheckServerLib.Jsons.PartyStuff;
using System.Security.Cryptography;

namespace PayCheckServerLib.Helpers
{
public class PartyController
{

public class SavedStuff
{
public Dictionary<string, object> Attributes; //WHY I NEED TO SAVE THIS AAAAAAAAAAAAAAA
public string Code;
public string CreatedBy;
public string Id;
public string LeaderId;
public long version;
public List<PartyPost.Member> Members;
public bool IsActive;
public bool IsFull;
public string SessionType;
public string CreatedAt;
public string UpdatedAt;
}

public static Dictionary<string, SavedStuff> PartySaves = new();

public static PartyPost.Response ParsePartyToRSP(SavedStuff stuff)
{
PartyPost.Response rsp = new();
rsp.Code = stuff.Code;
rsp.Attributes = stuff.Attributes;
rsp.Configuration = JsonConvert.DeserializeObject<PartyPost.Configuration>(File.ReadAllText($"Files/{stuff.SessionType}Configuration.json"));

Check warning on line 34 in PayCheckServerLib/Helpers/PartyController.cs

View workflow job for this annotation

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

Possible null reference assignment.
rsp.Id = stuff.Id;
rsp.IsActive = stuff.IsActive;
rsp.IsFull = stuff.IsFull;
rsp.LeaderId = stuff.LeaderId;
rsp.CreatedBy = stuff.CreatedBy;
rsp.Namespace = "pd3";
rsp.Version = stuff.version;
rsp.CreatedAt = stuff.CreatedAt;
rsp.UpdatedAt = stuff.UpdatedAt;
rsp.Members = stuff.Members;
return rsp;
}


public static PartyPost.Response CreateParty(PartyPostReq partyPost)
{
var code = UserIdHelper.CreateCode();

PartyPost.Response rsp = new();
rsp.Code = code;
rsp.Attributes = partyPost.Attributes;
rsp.Configuration = JsonConvert.DeserializeObject<PartyPost.Configuration>(File.ReadAllText($"Files/{partyPost.ConfigurationName}Configuration.json"));

Check warning on line 56 in PayCheckServerLib/Helpers/PartyController.cs

View workflow job for this annotation

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

Possible null reference assignment.
rsp.Id = UserIdHelper.CreateNewID();
rsp.IsActive = true;
rsp.IsFull = false;
rsp.LeaderId = partyPost.Members[0].ID;
rsp.CreatedBy = partyPost.Members[0].ID;
rsp.Namespace = "pd3";
rsp.Version = 1; //init version 1
rsp.CreatedAt = DateTime.UtcNow.ToString("o");
rsp.UpdatedAt = DateTime.UtcNow.ToString("o");
rsp.Members = new();
foreach (var item in partyPost.Members)
{
rsp.Members.Add(new()
{
Id = item.ID,
PlatformId = item.PlatformId.ToUpper(),
PlatformUserId = item.PlatformUserId,
Status = "JOINED",
StatusV2 = "JOINED",
UpdatedAt = DateTime.UtcNow.ToString("o")
});
}

SavedStuff saved = new()
{
Code = code,
SessionType = partyPost.ConfigurationName,
CreatedAt = rsp.CreatedAt,
CreatedBy = rsp.CreatedBy,
Id = rsp.Id,
IsActive = rsp.IsActive,
IsFull = rsp.IsFull,
LeaderId = rsp.LeaderId,
Members = rsp.Members,
UpdatedAt = rsp.UpdatedAt,
version = rsp.Version
};
PartySaves.Add(code, saved);
Debugger.PrintInfo("New Party made!");
return rsp;
}


public static PartyPost.Response JoinParty(string Code, TokenHelper.Token token)
{
if (!PartySaves.ContainsKey(Code))
{
Debugger.PrintError("NO Code???? WHAT THE FUCK");
throw new Exception("Code is not exist in saved parties????");
}
var stuff = PartySaves[Code];
stuff.UpdatedAt = DateTime.UtcNow.ToString("o");
var user = stuff.Members.Where(x => x.Id == token.UserId).First();
//shinenigans too edit user in members
stuff.Members.Remove(user);
user.Status = "JOINED";
user.StatusV2 = "JOINED";
user.UpdatedAt = DateTime.UtcNow.ToString("o");
stuff.Members.Add(user);
//stuff.version += 1; //does this needed?
return ParsePartyToRSP(stuff);
}



public static PartyPost.Response UpdateParty(string PartyId, dynamic body)
{
var party = PartySaves.Where(x=>x.Value.Id == PartyId).FirstOrDefault().Value;
if (party == null)
{
Debugger.PrintError("NO Code???? WHAT THE FUCK");
throw new Exception("Code is not exist in saved parties????");
}

party.UpdatedAt = DateTime.UtcNow.ToString("o");
party.Attributes = body.attributes;
party.version = body.version + 1;

return ParsePartyToRSP(party);
}

public static void LeftParty(string PartyId, string UserId, PC3Server.PC3Session session)
{
var party = PartySaves.Where(x => x.Value.Id == PartyId).FirstOrDefault().Value;
if (party == null)
{
Debugger.PrintError("NO Code???? WHAT THE FUCK");
throw new Exception("Code is not exist in saved parties????");
}

party.UpdatedAt = DateTime.UtcNow.ToString("o");
party.version += 1;
foreach (var m in party.Members)
{
if (m.Id == UserId)
{
m.Status = "LEFT";
m.StatusV2 = "LEFT";
}
}
//todo send other users update that we left!
//or if we are the leader send this one dead and sent to leave everybody
}
}
}
7 changes: 6 additions & 1 deletion PayCheckServerLib/Helpers/TokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public enum TokenPlatform
{
Unknow,
Steam,
Device
Device,
EOS,
EpicGames,
PS4,
PS5,
XBOX
}

public static Token GetTokenFromPlatform(string platformId, TokenPlatform platformType)
Expand Down
16 changes: 16 additions & 0 deletions PayCheckServerLib/Helpers/UserIdHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public static string CreateNewID()
return md5_str;
}

public static string CreateCode()
{
Random rand = new();
int stringlen = 7;
int randValue;
string str = "";
char letter;
for (int i = 0; i < stringlen; i++)
{
randValue = rand.Next(0, 26);
letter = Convert.ToChar(randValue + 65);
str = str + letter;
}
return str;
}

/// <summary>
/// Creating String from MD5
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions PayCheckServerLib/Jsons/PartyStuff/OnPartyCreated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace PayCheckServerLib.Jsons.PartyStuff
{
public class OnPartyCreated
{
[JsonProperty("CreatedBy")]
public string CreatedBy { get; set; }

[JsonProperty("PartyID")]
public string PartyId { get; set; }

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

[JsonProperty("Code")]
public string Code { get; set; }
}
}
76 changes: 76 additions & 0 deletions PayCheckServerLib/Jsons/PartyStuff/OnPartyUpdated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Newtonsoft.Json;

namespace PayCheckServerLib.Jsons.PartyStuff
{
internal class OnPartyUpdated
{
[JsonProperty("ID")]
public string Id { get; set; }

[JsonProperty("Namespace")]
public string Namespace { get; set; }

[JsonProperty("Members")]
public List<PartyPost.Member> Members { get; set; }

[JsonProperty("Attributes")]
public Dictionary<string, object> Attributes { get; set; }

[JsonProperty("CreatedAt")]
public string CreatedAt { get; set; }

[JsonProperty("CreatedBy")]
public string CreatedBy { get; set; }

[JsonProperty("UpdatedAt")]
public string UpdatedAt { get; set; }

[JsonProperty("Version")]
public long Version { get; set; }

[JsonProperty("Configuration")]
public Configuration Configuration { get; set; }

[JsonProperty("ConfigurationName")]
public string ConfigurationName { get; set; }

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

[JsonProperty("LeaderID")]
public string LeaderId { get; set; }

[JsonProperty("Code")]
public string Code { get; set; }
}

public partial class Configuration
{
[JsonProperty("Name")]
public string Name { get; set; }

[JsonProperty("Joinability")]
public string Joinability { get; set; }

[JsonProperty("MinPlayers")]
public long MinPlayers { get; set; }

[JsonProperty("MaxPlayers")]
public long MaxPlayers { get; set; }

[JsonProperty("ClientVersion")]
public string ClientVersion { get; set; }

[JsonProperty("RequestedRegions")]
public List<string> RequestedRegions { get; set; }

[JsonProperty("Type")]
public string Type { get; set; }

[JsonProperty("InviteTimeout")]
public long InviteTimeout { get; set; }

[JsonProperty("InactiveTimeout")]
public long InactiveTimeout { get; set; }
}
}
2 changes: 1 addition & 1 deletion PayCheckServerLib/Jsons/PartyStuff/PartyPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace PayCheckServerLib.Jsons.PartyStuff
{
public class PartyPost
{
public partial class Basic
public partial class Response
{
[JsonProperty("attributes")]
public Dictionary<string, object> Attributes { get; set; }
Expand Down
19 changes: 8 additions & 11 deletions PayCheckServerLib/Jsons/PartyStuff/PartyPostReq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ namespace PayCheckServerLib.Jsons.PartyStuff
{
public class PartyPostReq
{
public partial class Basic
{
[JsonProperty("members")]
public List<Member> Members { get; set; }
[JsonProperty("members")]
public List<Member> Members { get; set; }

[JsonProperty("attributes")]
public Dictionary<string, object> Attributes { get; set; }
[JsonProperty("attributes")]
public Dictionary<string, object> Attributes { get; set; }

[JsonProperty("configurationName")]
public string ConfigurationName { get; set; }
[JsonProperty("configurationName")]
public string ConfigurationName { get; set; }

[JsonProperty("textChat")]
public bool TextChat { get; set; }
}
[JsonProperty("textChat")]
public bool TextChat { get; set; }

public partial class Member
{
Expand Down
1 change: 1 addition & 0 deletions PayCheckServerLib/PayCheckServerLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ItemGroup>
<None Remove="config.json" />
<None Remove="files\Country.json" />
<None Remove="files\PartySessionConfiguration.json" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 114e3ed

Please sign in to comment.