Skip to content
Permalink
Browse files

Fix sideboarding

decode clientToGre again
  • Loading branch information...
Manuel-777 committed Feb 16, 2019
1 parent 2afdcc0 commit 416d56fca0d2385bd5e22d47a17a43b744fb5301
Showing with 75 additions and 34 deletions.
  1. +33 −0 window_background/background.js
  2. +42 −34 window_background/labels.js
@@ -1058,6 +1058,39 @@ function processLogUser(rawString) {
}
}

function decodePayload(json) {
const messages = require('./messages_pb');

const msgType = json.clientToMatchServiceMessageType.split('_')[1],
binaryMsg = new Buffer(json.payload, 'base64');

try {
let msgDeserialiser;
if (msgType === 'ClientToGREMessage' || msgType === 'ClientToGREUIMessage') {
msgDeserialiser = messages.ClientToGREMessage;
} else if (msgType === 'ClientToMatchDoorConnectRequest') {
msgDeserialiser = messages.ClientToMatchDoorConnectRequest;
} else if (msgType === 'AuthenticateRequest') {
msgDeserialiser = messages.AuthenticateRequest;
} else if (msgType === 'CreateMatchGameRoomRequest') {
msgDeserialiser = messages.CreateMatchGameRoomRequest;
} else if (msgType === 'EchoRequest') {
msgDeserialiser = messages.EchoRequest;
} else {
console.warn(`${msgType} - unknown message type`);
return;
}
const msg = msgDeserialiser.deserializeBinary(binaryMsg);
//console.log(json.msgType);
//console.log(msg.toObject());
return msg.toObject();
} catch (e) {
console.log(e.message);
}

return;
}

// Cuts the string "data" between first ocurrences of the two selected words "startStr" and "endStr";
function dataChop(data, startStr, endStr) {
var start = data.indexOf(startStr)+startStr.length;
@@ -517,47 +517,55 @@ function onLabelGreToClient(entry, json) {
function onLabelClientToMatchServiceMessageTypeClientToGREMessage(entry, json) {
if (!json) return;
if (skipMatch) return;
if (!json.Payload) return;
if (!json.Payload.SubmitDeckResp) return;

// Get sideboard changes
let tempMain = {};
let tempSide = {};
json.Payload.SubmitDeckResp.Deck.DeckCards.forEach(function (grpId) {
if (tempMain[grpId] == undefined) {
tempMain[grpId] = 1
}
else {
tempMain[grpId] += 1;
}
});
if (json.Payload.SubmitDeckResp.Deck.SideboardCards !== undefined) {
json.Payload.SubmitDeckResp.Deck.SideboardCards.forEach(function (grpId) {
if (tempSide[grpId] == undefined) {
tempSide[grpId] = 1
if (!json.payload) return;

if (typeof json.payload == "string") {
json.payload = decodePayload(json);
}

if (json.payload.submitdeckresp) {
// Get sideboard changes
let deckResp = json.payload.submitdeckresp;
console.log("SubmitDeckResp", deckResp);

let tempMain = {};
let tempSide = {};
deckResp.deck.deckcardsList.forEach(function (grpId) {
if (tempMain[grpId] == undefined) {
tempMain[grpId] = 1
}
else {
tempSide[grpId] += 1;
tempMain[grpId] += 1;
}
});
}

var newDeck = {};
newDeck.mainDeck = [];
Object.keys(tempMain).forEach(function (key) {
var c = {"id": key, "quantity": tempMain[key]};
newDeck.mainDeck.push(c);
});
if (deckResp.deck.sideboardcardsList !== undefined) {
deckResp.deck.sideboardcardsList.forEach(function (grpId) {
if (tempSide[grpId] == undefined) {
tempSide[grpId] = 1
}
else {
tempSide[grpId] += 1;
}
});
}

newDeck.sideboard = [];
if (json.Payload.SubmitDeckResp.Deck.SideboardCards !== undefined) {
Object.keys(tempSide).forEach(function (key) {
var c = {"id": key, "quantity": tempSide[key]};
newDeck.sideboard.push(c);
var newDeck = {};
newDeck.mainDeck = [];
Object.keys(tempMain).forEach(function (key) {
var c = {"id": key, "quantity": tempMain[key]};
newDeck.mainDeck.push(c);
});

newDeck.sideboard = [];
if (deckResp.deck.sideboardcardsList !== undefined) {
Object.keys(tempSide).forEach(function (key) {
var c = {"id": key, "quantity": tempSide[key]};
newDeck.sideboard.push(c);
});
}
currentDeck = newDeck;
ipc_send("set_deck", currentDeck, windowOverlay);
}
currentDeck = newDeck;
ipc_send("set_deck", currentDeck, windowOverlay);
}

function onLabelInEventGetPlayerCourse(entry, json) {

0 comments on commit 416d56f

Please sign in to comment.
You can’t perform that action at this time.