Skip to content

Commit

Permalink
Merge pull request #24 from DaniElectra/fixes-3
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
jonbarrow authored Feb 24, 2024
2 parents ca428ee + bc374ec commit 8dec0a6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class Connection {
return;
}

if (isResponseRMCMessage && !packet.rmcMessage.isSuccess()) {
if (packet.rmcMessage.isResponse() && !packet.rmcMessage.isSuccess()) {
const requestPacket = this.packets.find(p => {
if (
p.rmcMessage.isRequest() &&
Expand Down
4 changes: 2 additions & 2 deletions src/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ class Packet {
* @returns {boolean} True if has flag
*/
isToClient() {
return this.source === 0xA1;
return (this.source & 0xF) === 0x1;
}

/**
*
* @returns {boolean} True if has flag
*/
isToServer() {
return this.source === 0xAF;
return (this.source & 0xF) === 0xF;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/requests/match_making.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class MigrateGatheringOwnershipV1Request {
*/
constructor(stream) {
this.gid = stream.readUInt32LE();
this.lstPotentialNewOwnersID = stream.readNEXStructure(stream.readPID);
this.lstPotentialNewOwnersID = stream.readNEXList(stream.readPID);
}

toJSON() {
Expand Down Expand Up @@ -981,4 +981,4 @@ module.exports = {
UpdateSessionHostRequest,
UpdateGatheringOwnershipRequest,
MigrateGatheringOwnershipRequest
};
};
26 changes: 18 additions & 8 deletions src/protocols/requests/matchmake_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CreateMatchmakeSessionRequest {
this.anyGathering = stream.readNEXAnyDataHolder();
this.strMessage = stream.readNEXString();

if (semver.gte(nexVersion, '3.5.0')) {
if (semver.gte(nexVersion, '3.4.0')) {
this.participationCount = stream.readUInt16LE();
}
}
Expand Down Expand Up @@ -627,14 +627,19 @@ class JoinMatchmakeSessionExRequest {
* @param {Stream} stream NEX data stream
*/
constructor(stream) {
const nexVersion = stream.connection.title.nex_match_making_version || stream.connection.title.nex_version;

this.gid = stream.readUInt32LE();
this.strMessage = stream.readNEXString();
this.dontCareMyBlockList = stream.readBoolean();
this.participationCount = stream.readUInt16LE();

if (semver.gte(nexVersion, '3.4.0')) {
this.participationCount = stream.readUInt16LE();
}
}

toJSON() {
return {
const data = {
gid: {
__typeName: 'uint32',
__typeValue: this.gid
Expand All @@ -646,12 +651,17 @@ class JoinMatchmakeSessionExRequest {
dontCareMyBlockList: {
__typeName: 'boolean',
__typeValue: this.dontCareMyBlockList
},
participationCount: {
__typeName: 'uint16',
__typeValue: this.participationCount
}
};

if (this.participationCount !== undefined) {
data.participationCount = {
__typeName: 'uint16',
__typeValue: this.participationCount
};
}

return data;
}
}

Expand Down Expand Up @@ -767,7 +777,7 @@ class DebugNotifyEventRequest {
__typeValue: this.pid
},
mainType: {
__typeName: 'uui9nt32int8',
__typeName: 'uint32',
__typeValue: this.mainType
},
subType: {
Expand Down
19 changes: 13 additions & 6 deletions src/protocols/types/message_delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ class UserMessage extends NEXTypes.Structure {
* @param {Stream} stream NEX data stream
*/
parse(stream) {
// TODO - Support NEX 4.0+ messages

this.m_uiID = stream.readUInt32LE();
this.m_idRecipient = stream.readUInt32LE();
this.m_uiRecipientType = stream.readUInt32LE();
this.m_uiParentID = stream.readUInt32LE();
this.m_pidSender = stream.readPID();
this.m_receptiontime = stream.readNEXDateTime();
this.m_uiLifeTime = stream.readUInt32LE();
this.m_uiFlags = stream.readUInt32LE();
this.m_strSubject = stream.readNEXString();
this.m_strSender = stream.readNEXString();
this.m_messageRecipient = stream.readNEXStructure(MessageRecipient);
}

toJSON() {
Expand All @@ -67,6 +70,14 @@ class UserMessage extends NEXTypes.Structure {
__typeName: 'uint32',
__typeValue: this.m_uiID
},
m_idRecipient: {
__typeName: 'uint32',
__typeValue: this.m_idRecipient
},
m_uiRecipientType: {
__typeName: 'uint32',
__typeValue: this.m_uiRecipientType
},
m_uiParentID: {
__typeName: 'uint32',
__typeValue: this.m_uiParentID
Expand Down Expand Up @@ -94,10 +105,6 @@ class UserMessage extends NEXTypes.Structure {
m_strSender: {
__typeName: 'String',
__typeValue: this.m_strSender
},
m_messageRecipient: {
__typeName: 'MessageRecipient',
__typeValue: this.m_messageRecipient
}
};
}
Expand Down Expand Up @@ -171,4 +178,4 @@ module.exports = {
MessageRecipient,
TextMessage,
BinaryMessage
};
};

0 comments on commit 8dec0a6

Please sign in to comment.