/** * Try putting the actor on map in an unused spot on a field that is not blocked. * There's a limited number of attempts, though. If all of them fail, * return { row: -1, column: -1 }. * * @param {String} side * @param {Number} nRows * @param {Number} nColumns * @param {Boolean[][]} mapOfObstacles * @param {Object} placesUsed */ function placeActorOnMap (side, nRows, nColumns, mapOfObstacles, placesUsed) { let key = '(-1,-1)'; let row = -1; let column = -1; // NOTE: There's the maximal number of 100 attempts. for (let n=0; n<100; n+=1) { row = Math.floor(Random.fraction() * nRows); column = Math.floor(Random.fraction() * 4); if (side === DEFENDER) { column = nColumns - 1 - column; } key = `(${row},${column})`; if (!placesUsed[key] && !getMapValue({ row, column }, mapOfObstacles)) { placesUsed[key] = true; return { row, column }; } } return { row: -1, column: -1 }; }
[ ATTACKER, DEFENDER ].forEach(side => { let amountSoFar = 0; while (amountSoFar < perTeamAmount) { const amount = Math.min(perTeamAmount - amountSoFar, Math.floor(20 + Random.fraction() * 60)); actors.push({ side, amount }); amountSoFar += amount; } });
encrypt(message) { let ts; if (isNaN(TimeSync.serverOffset())) { ts = new Date(); } else { ts = new Date(Date.now() + TimeSync.serverOffset()); } const data = new TextEncoder('UTF-8').encode(EJSON.stringify({ _id: message._id, text: message.msg, userId: this.userId, ack: Random.id((Random.fraction() + 1) * 20), ts, })); const enc = this.encryptText(data); return enc; }
_.times(10, function () { let _id = addReminder.call({title: faker.name.jobTitle(), description: faker.name.jobDescriptor(), url: faker.internet.url()}); if(Random.fraction() > 0.5) { setKnowledgeReviewed.call({_id}) } });
// Encrypts messages async encryptText(data) { if (!_.isObject(data)) { data = new TextEncoder('UTF-8').encode(EJSON.stringify({ text: data, ack: Random.id((Random.fraction() + 1) * 20) })); } if (!this.isSupportedRoomType(this.typeOfRoom)) { return data; } const vector = crypto.getRandomValues(new Uint8Array(16)); let result; try { result = await encryptAES(vector, this.groupSessionKey, data); } catch (error) { return console.error('E2E -> Error encrypting message: ', error); } return this.keyID + Base64.encode(joinVectorAndEcryptedData(vector, result)); }
encryptText(data) { if (!_.isObject(data)) { data = new TextEncoder('UTF-8').encode(EJSON.stringify({ text: data, ack: Random.id((Random.fraction() + 1) * 20) })); } const iv = crypto.getRandomValues(new Uint8Array(12)); return OTR.crypto.encrypt({ name: 'AES-GCM', iv, }, this.sessionKey, data).then((cipherText) => { cipherText = new Uint8Array(cipherText); const output = new Uint8Array(iv.length + cipherText.length); output.set(iv, 0); output.set(cipherText, iv.length); return EJSON.stringify(output); }).catch(() => { throw new Meteor.Error('encryption-error', 'Encryption error.'); }); }
return ({ row: i, column: j }) => { return { isBlocked: Random.fraction() < 0.4 * Math.pow(1-2*Math.abs(j-nColumns/2)/nColumns, 2) }; };