Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#### main.js #########################
- var common = require('./common');
- //#### common.js #######################
- var com = {
- 'main': require('./main'),
- 'cache': require('./cache'),
- 'route': require('./route'),
- 'tools': require('./tools'),
- 'Player': require('./models/Player'),
- 'fileserv': new require('node-static').Server('..', { cache: 7200 }),
- 'eventEmitter': require('events').EventEmitter,
- 'url': require('url'),
- 'fs': require('fs'),
- 'mysql': require('mysql'),
- 'db': require('mysql').createClient({
- user: 'root',
- password: '',
- })
- };
- module.exports = com;
- //#### models/Player.js ##################
- var common = require('../common');
- function Player(id) {
- var that = this;
- this.state = 'pending';
- // Ident
- this.id = null;
- this.nickname = null;
- // Variables joueur
- this.vars = null;
- this.private = null;
- this.readonly = null;
- this.public = null;
- // Récupère le fichier décrivant le joueur
- common.fs.readFile('../players/' + id, 'utf8', function(err, data) {
- if (err) {
- that.state = 'failed';
- that.emit('error');
- }
- else {
- that.state = 'ok';
- that.vars = JSON.parse(data);
- that.private = that.vars[0];
- that.readonly = that.vars[1];
- that.public = that.vars[2];
- that.id = id;
- that.nickname = that.vars[1].nickname;
- that.emit('ready', that);
- }
- });
- }
- // DONT WORKS
- Player.prototype = new common.eventEmitter();
- // WORKS
- Player.prototype = new require('events').EventEmitter();
- module.exports = Player;
Add Comment
Please, Sign In to add comment