Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite and TypeScript migration #26

Draft
wants to merge 67 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
87336c6
chore: begin rewrite and TS migration
jonbarrow Apr 22, 2024
d23ca8e
chore: add TODO comment about merging folders in windows folder
jonbarrow Jun 7, 2024
e744130
fix: emit PRUDP packets in session
jonbarrow Jun 8, 2024
b53a6ca
chore: add packet serializing and better type defs/checks
jonbarrow Jun 8, 2024
2a18975
chore(types): update type imports for Packet type def
jonbarrow Jun 8, 2024
662e217
chore(lint): add browser globals to eslint config
jonbarrow Jun 8, 2024
c9a9b98
chore: add browserify command for building
jonbarrow Jun 8, 2024
a5e4303
refactor(rmc): update serialized RMC message data
jonbarrow Jun 8, 2024
336c02d
refactor(prudp): update serialized PRUDPPacket/PRUDPPacketV1 data
jonbarrow Jun 8, 2024
6826034
chore(types): add serialized packet type def
jonbarrow Jun 8, 2024
769b9d2
fix(rmc): rename _error to error on serialized RMC message data
jonbarrow Jun 8, 2024
8a4e758
fix(protocols): assert that RMC parameters exist in method handlers
jonbarrow Jun 8, 2024
4b8b597
chore(rmc): add serialized RMC message type def
jonbarrow Jun 8, 2024
694bc16
refactor: make toJSON methods return serialized types
jonbarrow Jun 8, 2024
6f6ca4a
fix(nex): fix PCAPNGParser import in session.ts
jonbarrow Jun 9, 2024
ccfebcf
refactor: add global settings
jonbarrow Jun 9, 2024
70ae4bc
chore: remove console log in settings.ts
jonbarrow Jun 9, 2024
65ddd7e
chore: update settings types
jonbarrow Jun 9, 2024
a68f1bb
refactor(nex): use new account settings to lookup NEX accounts
jonbarrow Jun 9, 2024
686d9d1
chore(nex): remove debug print in connection.ts
jonbarrow Jun 9, 2024
af544f7
fix(nex): QResult codes are uint32 not int32
jonbarrow Jun 9, 2024
8ecbbb1
fix(nex): fix how error responses find their request messages
jonbarrow Jun 9, 2024
298bf85
chore(nex): add serialized Connection data
jonbarrow Jun 9, 2024
4e70ae2
fix: fix "seconds" type in PCAPNG parser
jonbarrow Jun 9, 2024
225876c
feat: add "time" value to packets
jonbarrow Jun 16, 2024
2655d0f
fix(nex): filter DNS packets by port
jonbarrow Jun 16, 2024
f8bc323
fix(types): add "time" value to SerializedPRUDPPacket
jonbarrow Jun 16, 2024
98d80b2
feat(nex): add stack traces to serialized packets
jonbarrow Jun 17, 2024
a4574fa
refactor(nex): pass Buffer data as array values
jonbarrow Jun 17, 2024
dfd9d40
refactor: add window menu and update Settings
jonbarrow Jun 17, 2024
de8f16f
fix(types): update SerializedPacket Buffer types
jonbarrow Jun 17, 2024
f0b696a
fix: revert Recent Files dialog. Caused issues
jonbarrow Jun 17, 2024
f6ad9ae
fix(nex): fix raw RMC packet serializing
jonbarrow Jun 17, 2024
26b1eb6
feat: add the start of UI
jonbarrow Jun 17, 2024
4ee87dd
refactor: condense protocol method classes into one folder
jonbarrow Jul 15, 2024
05fbd8d
feat: implement all of SecureConnection
jonbarrow Jul 15, 2024
191a1b9
feat: add NintendoLoginData/AccountExtraInfo types
jonbarrow Jul 15, 2024
39f409b
feat: implement all of NAT Traversal
jonbarrow Jul 15, 2024
2293de5
refactor: replace RMCMessage with type import in RMC methods
jonbarrow Jul 15, 2024
f6d3dfd
refactor: strongly type RMCs
jonbarrow Jul 15, 2024
af610ee
fix: fix pSourceKey value check in connection
jonbarrow Jul 15, 2024
a3a8fb5
chore: remove incorrect comments from SecureConnection and NAT Traversal
jonbarrow Jul 15, 2024
92f3d2c
feat: implement all of NotificationEvents
jonbarrow Jul 15, 2024
c26cc68
feat: display packet JSON in UI when selected
jonbarrow Jul 15, 2024
c6ebc8f
feat: start implementing MatchMaking
jonbarrow Jul 15, 2024
8a910e9
feat: add basic search to packet list
jonbarrow Jul 15, 2024
331beca
feat: start implementing MatchMakingExt
jonbarrow Jul 15, 2024
dd0276a
feat: start implementing MatchmakeExtension
jonbarrow Jul 16, 2024
00e5044
chore: update account settings structure in README
jonbarrow Jul 16, 2024
291efad
feat: add MatchmakeExtension::FindOfficialCommunity
jonbarrow Aug 8, 2024
0d5d5ef
feat: add FindOfficialCommunity RMC types
jonbarrow Aug 8, 2024
4be2ccd
fix: add p2p packet filtering checks
jonbarrow Aug 8, 2024
827d3d9
fix: update PIA magic check
jonbarrow Aug 8, 2024
933c66c
chore: improve PRUDP packet filtering
jonbarrow Aug 9, 2024
6b49d49
feat: Add AutoMatchmakeWithSearchCriteria_Postpone
ashquarky Jan 7, 2025
d54ad6e
chore: update PRUDPPacketV1 code styles
jonbarrow Jan 8, 2025
9661560
feat: add Charles dump support and Switch packet support
jonbarrow Jan 8, 2025
80a89d6
feat: complete TicketGranting protocol
jonbarrow Jan 8, 2025
301421c
feat: complete MatchMakingExt protocol
jonbarrow Jan 8, 2025
9ab8acb
chore: remove dangling comma in MatchMakingExt
jonbarrow Jan 8, 2025
26d5954
chore: npm audit fix
jonbarrow Jan 8, 2025
babaf61
feat: complete MatchMaking protocol
jonbarrow Jan 8, 2025
6b1140b
feat: complete MatchmakeExtension protocol
jonbarrow Jan 8, 2025
e55f767
feat: complete MatchmakeReferee protocol
jonbarrow Jan 8, 2025
d6530a0
feat: complete Ranking protocol
jonbarrow Jan 8, 2025
07241a0
chore: update method IDs in MatchmakeReferee protocol
jonbarrow Jan 8, 2025
cb7406c
fix: Account for NEX versions in JoinMatchmakeSessionParam
ashquarky Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/nex/protocols/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import NotificationEventsProtocol from '@/nex/protocols/notification-events';
import MatchMakingProtocol from '@/nex/protocols/match-making';
import MatchMakingExtProtocol from '@/nex/protocols/match-making-ext';
import MatchmakeExtensionProtocol from '@/nex/protocols/matchmake-extension';
import RankingProtocol from '@/nex/protocols/ranking';
import MatchmakeRefereeProtocol from '@/nex/protocols/matchmake-referee';
import type RMCMessage from '@/nex/rmc-message';
import type ServiceProtocol from '@/types/nex/service-protocol';
Expand All @@ -27,6 +28,8 @@ export default function getProtocol(message: RMCMessage): ServiceProtocol | null
return MatchMakingExtProtocol;
case MatchmakeExtensionProtocol.ID:
return MatchmakeExtensionProtocol;
case RankingProtocol.ID:
return RankingProtocol;
case MatchmakeRefereeProtocol.ID:
return MatchmakeRefereeProtocol;
}
Expand Down
198 changes: 198 additions & 0 deletions src/nex/protocols/ranking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import RMCMessage from '@/nex/rmc-message';
import * as Methods from '@/nex/protocols/ranking/methods';
import type Packet from '@/types/nex/packet';

export default class RankingProtocol {
static ID = 0x70;
static Name = 'Ranking';

static Methods = {
UploadScore: 0x1,
DeleteScore: 0x2,
DeleteAllScores: 0x3,
UploadCommonData: 0x4,
DeleteCommonData: 0x5,
GetCommonData: 0x6,
ChangeAttributes: 0x7,
ChangeAllAttributes: 0x8,
GetRanking: 0x9,
GetApproxOrder: 0xA,
GetStats: 0xB,
GetRankingByPIDList: 0xC,
GetRankingByUniqueIdList: 0xD,
GetCachedTopXRanking: 0xE,
GetCachedTopXRankings: 0xF
};

private static handlers: Record<number, (message: RMCMessage) => any> = {
0x1: RankingProtocol.UploadScore,
0x2: RankingProtocol.DeleteScore,
0x3: RankingProtocol.DeleteAllScores,
0x4: RankingProtocol.UploadCommonData,
0x5: RankingProtocol.DeleteCommonData,
0x6: RankingProtocol.GetCommonData,
0x7: RankingProtocol.ChangeAttributes,
0x8: RankingProtocol.ChangeAllAttributes,
0x9: RankingProtocol.GetRanking,
0xA: RankingProtocol.GetApproxOrder,
0xB: RankingProtocol.GetStats,
0xC: RankingProtocol.GetRankingByPIDList,
0xD: RankingProtocol.GetRankingByUniqueIdList,
0xE: RankingProtocol.GetCachedTopXRanking,
0xF: RankingProtocol.GetCachedTopXRankings
};

static handlePacket(packet: Packet): void {
if (!packet.message) {
// * This will never happen. Only checked to make TypeScript happy
return;
}

const methodID = packet.message.methodID;
const handler = RankingProtocol.handlers[methodID];

if (!handler) {
packet.message.methodName = `UnknownMethod_0x${methodID.toString(16).toUpperCase().padStart(2, '0')}`;
return;
}

const messageDecoder = handler(packet.message);

packet.message.parameters = new messageDecoder(packet.message);
packet.message.methodName = messageDecoder.Name;
}

private static UploadScore(message: RMCMessage): typeof Methods.UploadScore.Request | typeof Methods.UploadScore.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.UploadScore.Request;
} else {
return Methods.UploadScore.Response;
}
}


private static DeleteScore(message: RMCMessage): typeof Methods.DeleteScore.Request | typeof Methods.DeleteScore.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.DeleteScore.Request;
} else {
return Methods.DeleteScore.Response;
}
}


private static DeleteAllScores(message: RMCMessage): typeof Methods.DeleteAllScores.Request | typeof Methods.DeleteAllScores.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.DeleteAllScores.Request;
} else {
return Methods.DeleteAllScores.Response;
}
}


private static UploadCommonData(message: RMCMessage): typeof Methods.UploadCommonData.Request | typeof Methods.UploadCommonData.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.UploadCommonData.Request;
} else {
return Methods.UploadCommonData.Response;
}
}


private static DeleteCommonData(message: RMCMessage): typeof Methods.DeleteCommonData.Request | typeof Methods.DeleteCommonData.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.DeleteCommonData.Request;
} else {
return Methods.DeleteCommonData.Response;
}
}


private static GetCommonData(message: RMCMessage): typeof Methods.GetCommonData.Request | typeof Methods.GetCommonData.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetCommonData.Request;
} else {
return Methods.GetCommonData.Response;
}
}


private static ChangeAttributes(message: RMCMessage): typeof Methods.ChangeAttributes.Request | typeof Methods.ChangeAttributes.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.ChangeAttributes.Request;
} else {
return Methods.ChangeAttributes.Response;
}
}


private static ChangeAllAttributes(message: RMCMessage): typeof Methods.ChangeAllAttributes.Request | typeof Methods.ChangeAllAttributes.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.ChangeAllAttributes.Request;
} else {
return Methods.ChangeAllAttributes.Response;
}
}


private static GetRanking(message: RMCMessage): typeof Methods.GetRanking.Request | typeof Methods.GetRanking.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetRanking.Request;
} else {
return Methods.GetRanking.Response;
}
}


private static GetApproxOrder(message: RMCMessage): typeof Methods.GetApproxOrder.Request | typeof Methods.GetApproxOrder.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetApproxOrder.Request;
} else {
return Methods.GetApproxOrder.Response;
}
}


private static GetStats(message: RMCMessage): typeof Methods.GetStats.Request | typeof Methods.GetStats.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetStats.Request;
} else {
return Methods.GetStats.Response;
}
}


private static GetRankingByPIDList(message: RMCMessage): typeof Methods.GetRankingByPIDList.Request | typeof Methods.GetRankingByPIDList.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetRankingByPIDList.Request;
} else {
return Methods.GetRankingByPIDList.Response;
}
}


private static GetRankingByUniqueIdList(message: RMCMessage): typeof Methods.GetRankingByUniqueIdList.Request | typeof Methods.GetRankingByUniqueIdList.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetRankingByUniqueIdList.Request;
} else {
return Methods.GetRankingByUniqueIdList.Response;
}
}


private static GetCachedTopXRanking(message: RMCMessage): typeof Methods.GetCachedTopXRanking.Request | typeof Methods.GetCachedTopXRanking.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetCachedTopXRanking.Request;
} else {
return Methods.GetCachedTopXRanking.Response;
}
}


private static GetCachedTopXRankings(message: RMCMessage): typeof Methods.GetCachedTopXRankings.Request | typeof Methods.GetCachedTopXRankings.Response {
if (message.type === RMCMessage.REQUEST) {
return Methods.GetCachedTopXRankings.Request;
} else {
return Methods.GetCachedTopXRankings.Response;
}
}
}
38 changes: 38 additions & 0 deletions src/nex/protocols/ranking/methods/change-all-attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import NEXByteStream from '@/nex/byte-stream';
import RankingChangeAttributesParam from '@/nex/protocols/ranking/types/ranking-change-attributes-param';
import UInt64 from '@/nex/types/uint64';
import type RMCMessage from '@/nex/rmc-message';

// TODO - Add strict types for toJSON methods

export class Request {
public static Name = 'ChangeAllAttributes';

private changeParam = new RankingChangeAttributesParam();
private uniqueId = new UInt64();

constructor(message: RMCMessage) {
const stream = new NEXByteStream(message.parametersData!, message.connection.title);

this.changeParam.extractFrom(stream);
this.uniqueId.extractFrom(stream);
}

public toJSON(): any {
return {
changeParam: this.changeParam,
uniqueId: this.uniqueId
};
}
}

// * No response data
export class Response {
public static Name = 'ChangeAllAttributes';

constructor() {}

public toJSON(): any {
return {};
}
}
42 changes: 42 additions & 0 deletions src/nex/protocols/ranking/methods/change-attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import NEXByteStream from '@/nex/byte-stream';
import UInt32 from '@/nex/types/uint32';
import RankingChangeAttributesParam from '@/nex/protocols/ranking/types/ranking-change-attributes-param';
import UInt64 from '@/nex/types/uint64';
import type RMCMessage from '@/nex/rmc-message';

// TODO - Add strict types for toJSON methods

export class Request {
public static Name = 'ChangeAttributes';

private category = new UInt32();
private changeParam = new RankingChangeAttributesParam();
private uniqueId = new UInt64();

constructor(message: RMCMessage) {
const stream = new NEXByteStream(message.parametersData!, message.connection.title);

this.category.extractFrom(stream);
this.changeParam.extractFrom(stream);
this.uniqueId.extractFrom(stream);
}

public toJSON(): any {
return {
category: this.category,
changeParam: this.changeParam,
uniqueId: this.uniqueId
};
}
}

// * No response data
export class Response {
public static Name = 'ChangeAttributes';

constructor() {}

public toJSON(): any {
return {};
}
}
34 changes: 34 additions & 0 deletions src/nex/protocols/ranking/methods/delete-all-scores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import NEXByteStream from '@/nex/byte-stream';
import UInt64 from '@/nex/types/uint64';
import type RMCMessage from '@/nex/rmc-message';

// TODO - Add strict types for toJSON methods

export class Request {
public static Name = 'DeleteAllScores';

private uniqueId = new UInt64();

constructor(message: RMCMessage) {
const stream = new NEXByteStream(message.parametersData!, message.connection.title);

this.uniqueId.extractFrom(stream);
}

public toJSON(): any {
return {
uniqueId: this.uniqueId
};
}
}

// * No response data
export class Response {
public static Name = 'DeleteAllScores';

constructor() {}

public toJSON(): any {
return {};
}
}
34 changes: 34 additions & 0 deletions src/nex/protocols/ranking/methods/delete-common-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import NEXByteStream from '@/nex/byte-stream';
import UInt64 from '@/nex/types/uint64';
import type RMCMessage from '@/nex/rmc-message';

// TODO - Add strict types for toJSON methods

export class Request {
public static Name = 'DeleteCommonData';

private uniqueId = new UInt64();

constructor(message: RMCMessage) {
const stream = new NEXByteStream(message.parametersData!, message.connection.title);

this.uniqueId.extractFrom(stream);
}

public toJSON(): any {
return {
uniqueId: this.uniqueId
};
}
}

// * No response data
export class Response {
public static Name = 'DeleteCommonData';

constructor() {}

public toJSON(): any {
return {};
}
}
Loading