mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-06 13:47:24 -05:00
I used a hack to make the multiple declaration errors go away, so all that remained in jsHint were actual errors, which I've now mostly fixed. All this linting ended up uncovering one actual bug: Uproar's message not showing. It's a very minor bug in a move no one uses, so I'm going to fold it into this commit.
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
/**
|
|
* Verifier process
|
|
* Pokemon Showdown - http://pokemonshowdown.com/
|
|
*
|
|
* This is just an asynchronous implementation of a verifier for a
|
|
* signed key, because Node.js's crypto functions are synchronous,
|
|
* strangely, considering how everything else is asynchronous.
|
|
*
|
|
* I wrote this one day hoping it would help with performance, but
|
|
* I don't think it had any noticeable effect.
|
|
*
|
|
* @license MIT license
|
|
*/
|
|
|
|
// Because I don't want two files, we're going to fork ourselves.
|
|
|
|
if (!process.send) {
|
|
|
|
// This is the parent
|
|
|
|
var guid = 1;
|
|
var callbacks = {};
|
|
var callbackData = {};
|
|
|
|
var child = require('child_process').fork('verifier.js');
|
|
exports.verify = function (data, signature, callback) {
|
|
var localGuid = guid++;
|
|
callbacks[localGuid] = callback;
|
|
callbackData[localGuid] = data;
|
|
child.send({data: data, sig: signature, guid: localGuid});
|
|
};
|
|
child.on('message', function (response) {
|
|
if (callbacks[response.guid]) {
|
|
callbacks[response.guid](response.success, callbackData[response.guid]);
|
|
delete callbacks[response.guid];
|
|
delete callbackData[response.guid];
|
|
}
|
|
});
|
|
|
|
} else {
|
|
|
|
// This is the child
|
|
|
|
global.Config = require('./config/config.js');
|
|
var crypto = require('crypto');
|
|
|
|
var keyalgo = Config.loginserverkeyalgo;
|
|
var pkey = Config.loginserverpublickey;
|
|
|
|
process.on('message', function (message) {
|
|
var verifier = crypto.createVerify(keyalgo);
|
|
verifier.update(message.data);
|
|
var success = false;
|
|
try {
|
|
success = verifier.verify(pkey, message.sig, 'hex');
|
|
} catch (e) {}
|
|
process.send({
|
|
success: success,
|
|
guid: message.guid
|
|
});
|
|
});
|
|
|
|
}
|