-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Folleach/features/account-message
Create methods for create and read in game messages
- Loading branch information
Showing
10 changed files
with
206 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Linq; | ||
using FluentAssertions; | ||
using GeometryDashAPI.Server.Dtos; | ||
using NUnit.Framework; | ||
|
||
namespace GeometryDashAPI.Tests; | ||
|
||
[TestFixture] | ||
public class MessageTests | ||
{ | ||
[Test] | ||
public void DecryptMessage() | ||
{ | ||
var message = Message.FromRaw("SGVsbG8sIGl0J3MgbGlicmFyeSB0ZXN0IHRpbWU=", "eBNEUBFbQUFBEUddV0IRX1FGQl5DXxJFUFJfV0FCHRRWWl8WQBJeVFREEkxeRBRfXF9V"); | ||
|
||
message.Should().BeEquivalentTo(new Message() | ||
{ | ||
Subject = "Hello, it's library test time", | ||
Body = "I've just view network packets, don't keep you mind" | ||
}); | ||
} | ||
|
||
[Test] | ||
public void EncryptMessage() | ||
{ | ||
var message = new Message() | ||
{ | ||
Subject = "Hello, it's library test time", | ||
Body = "I've just view network packets, don't keep you mind" | ||
}; | ||
|
||
var parameters = message.BuildQuery(); | ||
|
||
parameters.FirstOrDefault(x => x.Key == "subject").Value.Should().BeEquivalentTo("SGVsbG8sIGl0J3MgbGlicmFyeSB0ZXN0IHRpbWU="); | ||
parameters.FirstOrDefault(x => x.Key == "body").Value.Should().BeEquivalentTo("eBNEUBFbQUFBEUddV0IRX1FGQl5DXxJFUFJfV0FCHRRWWl8WQBJeVFREEkxeRBRfXF9V"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace GeometryDashAPI.Server.Dtos; | ||
|
||
public class Message : IQuery | ||
{ | ||
private static readonly string BodyXorKey = "14251"; | ||
|
||
public string Subject { get; set; } | ||
public string Body { get; set; } | ||
|
||
public static Message FromRaw(string subject, string body) | ||
{ | ||
return new Message() | ||
{ | ||
Subject = DeserializeSubject(subject), | ||
Body = DeserializeBody(body) | ||
}; | ||
} | ||
|
||
public Parameters BuildQuery() | ||
{ | ||
var parameters = new Parameters(); | ||
BuildQuery(parameters); | ||
return parameters; | ||
} | ||
|
||
public void BuildQuery(Parameters parameters) | ||
{ | ||
parameters.Add(new Property("subject", SerializeSubject(Subject))); | ||
parameters.Add(new Property("body", SerializeBody(Body))); | ||
} | ||
|
||
internal static string DeserializeSubject(string raw) => Encoding.UTF8.GetString(Convert.FromBase64String(raw)); | ||
internal static string SerializeSubject(string subject) => Convert.ToBase64String(Encoding.ASCII.GetBytes(subject)); | ||
|
||
internal static string DeserializeBody(string raw) => Crypt.XOR(Encoding.UTF8.GetString(Convert.FromBase64String(raw)), BodyXorKey); | ||
internal static string SerializeBody(string body) => Convert.ToBase64String(Encoding.ASCII.GetBytes(Crypt.XOR(body, BodyXorKey))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using GeometryDashAPI.Attributes; | ||
|
||
namespace GeometryDashAPI.Server.Dtos; | ||
|
||
[Sense(":")] | ||
public class MessageContent : MessagePreview | ||
{ | ||
[GameProperty("5")] | ||
private string body; | ||
|
||
public string Body | ||
{ | ||
get => Message.DeserializeBody(body); | ||
set => Message.SerializeBody(value); | ||
} | ||
|
||
public Message Message => new() | ||
{ | ||
Body = Message.DeserializeBody(body), | ||
Subject = Subject | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using GeometryDashAPI.Attributes; | ||
|
||
namespace GeometryDashAPI.Server.Dtos; | ||
|
||
[Sense(":")] | ||
public class MessagePreview : GameObject | ||
{ | ||
[GameProperty("1")] | ||
public int MessageId { get; set; } | ||
|
||
[GameProperty("2")] | ||
public int SenderAccountId { get; set; } | ||
|
||
[GameProperty("3")] | ||
public int SenderUserId { get; set; } | ||
|
||
[GameProperty("4")] | ||
private string subject; | ||
|
||
public string Subject | ||
{ | ||
get => Message.DeserializeSubject(subject); | ||
set => Message.SerializeSubject(value); | ||
} | ||
|
||
[GameProperty("6")] | ||
public string SenderUserName { get; set; } | ||
|
||
[GameProperty("7")] | ||
public string Time { get; set; } | ||
|
||
[GameProperty("8")] | ||
public bool HasBeenRead { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"Letter '{Subject}' from {SenderUserName}({SenderAccountId})"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace GeometryDashAPI.Server.Enums; | ||
|
||
public enum AllowMessagesFrom | ||
{ | ||
All = 0, | ||
Friends = 1, | ||
None = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using GeometryDashAPI.Attributes; | ||
using GeometryDashAPI.Server.Dtos; | ||
|
||
namespace GeometryDashAPI.Server.Responses; | ||
|
||
[AsStruct] | ||
[Sense("#")] | ||
public class MessagesPageResponse : GameObject | ||
{ | ||
[GameProperty("0")] | ||
[ArraySeparator("|")] | ||
public List<MessagePreview> Messages { get; set; } | ||
|
||
[GameProperty("1")] | ||
public Pagination Page { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace GeometryDashAPI.Server.Responses; | ||
|
||
public class NoneResponse : GameObject | ||
{ | ||
} |