mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
Additional async rewrite
This commit is contained in:
parent
efe12a00aa
commit
29ce0b82d0
24 changed files with 654 additions and 470 deletions
22
lib/ProtocolResolver.js
Normal file
22
lib/ProtocolResolver.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
const Path = require('path'),
|
||||
fs = require('fs'),
|
||||
Core = require('../protocols/core');
|
||||
|
||||
class ProtocolResolver {
|
||||
constructor() {
|
||||
this.protocolDir = Path.normalize(__dirname+'/../protocols');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Core
|
||||
*/
|
||||
create(protocolId) {
|
||||
protocolId = Path.basename(protocolId);
|
||||
const path = this.protocolDir+'/'+protocolId;
|
||||
if(!fs.existsSync(path+'.js')) throw Error('Protocol definition file missing: '+type);
|
||||
const protocol = require(path);
|
||||
return new protocol();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProtocolResolver;
|
||||
Loading…
Add table
Add a link
Reference in a new issue