Guest User

Untitled

a guest
Dec 3rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#### main.js #########################
  2. var common = require('./common');
  3.  
  4.  
  5.  
  6. //#### common.js #######################
  7.  
  8. var com = {
  9.     'main': require('./main'),
  10.    
  11.     'cache': require('./cache'),
  12.     'route': require('./route'),
  13.     'tools': require('./tools'),
  14.    
  15.     'Player': require('./models/Player'),
  16.    
  17.     'fileserv': new require('node-static').Server('..', { cache: 7200 }),
  18.    
  19.     'eventEmitter': require('events').EventEmitter,
  20.     'url': require('url'),
  21.     'fs': require('fs'),
  22.    
  23.     'mysql': require('mysql'),
  24.     'db': require('mysql').createClient({
  25.         user: 'root',
  26.         password: '',
  27.     })
  28. };
  29.  
  30. module.exports = com;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. //#### models/Player.js ##################
  42. var common = require('../common');
  43.  
  44. function Player(id) {
  45.     var that = this;
  46.    
  47.     this.state = 'pending';
  48.    
  49.     // Ident
  50.     this.id = null;
  51.     this.nickname = null;
  52.    
  53.     // Variables joueur
  54.     this.vars = null;
  55.     this.private = null;
  56.     this.readonly = null;
  57.     this.public = null;
  58.    
  59.     // Récupère le fichier décrivant le joueur
  60.     common.fs.readFile('../players/' + id, 'utf8', function(err, data) {
  61.         if (err) {
  62.             that.state = 'failed';
  63.             that.emit('error');
  64.         }
  65.         else {
  66.             that.state = 'ok';
  67.            
  68.             that.vars = JSON.parse(data);
  69.             that.private = that.vars[0];
  70.             that.readonly = that.vars[1];
  71.             that.public = that.vars[2];
  72.            
  73.             that.id = id;
  74.             that.nickname = that.vars[1].nickname;
  75.            
  76.             that.emit('ready', that);
  77.         }
  78.     });
  79. }
  80.  
  81. // DONT WORKS
  82. Player.prototype = new common.eventEmitter();
  83. // WORKS
  84. Player.prototype = new require('events').EventEmitter();
  85.  
  86. module.exports = Player;
Add Comment
Please, Sign In to add comment