示例#1
0
文件: index.js 项目: Gifer17/mcnext
             watcher = fs.watch(MCPathes.Events, function(event, filename){
                 console.log('event is: ' + event, console.logLevel.L_Full);
                 if (filename) {
                     console.log('filename provided: ' + filename + " with event: " + event, console.logLevel.L_Low);

                     if ((filename == EventFile) && (event == "rename")){
                         var _data;

                         try {
                             _data = fs.readFileSync(MCPathes.Events + filename);
                         } catch (e){
                             console.err("Can't load Events file: " + MCPathes.Events + filename + "\n" + e);
                         }

                         fs.unlink(MCPathes.Events + filename, function (error) {
                             if (error !== null) {
                                 console.err('exec error: ' + error);
                             }
                         });

                         if (_data){
                             ParseEventsFile(_data);
                         }
                     }
                 } else {
                     console.log('filename not provided', console.logLevel.L_Full);
                 }
             });
示例#2
0
文件: service.js 项目: Gifer17/mcnext
 Service.Read_JSON_File = function(_file, invertSlesh){
     var res = undefined;

     try {
         res = fs.readFileSync(_file);

         if (invertSlesh) res = res.toString().replace(/\\/g, '/');

         var txt = res;
     } catch (e){
         console.err("Can't load JSON file: " + _file + "\n" + e);

         return;
     }

     try {
         res = JSON.parse(res);
     } catch (e){
         console.err("Wrong JSON format or syntax error: " + _file + "\n" + e);

         return;
     }

     console.log("JSON file successfully loaded: " + _file + "\n" + txt);

     return res;
 };
示例#3
0
文件: index.js 项目: Gifer17/mcnext
     _eventsList.forEach(function(element){
         console.log('Parse "events.txt", srt:' + element, console.logLevel.L_Low);

         if (element != ""){
             element = Service.StringToObj(element);

             if (element.cmd){
                 switch (element.cmd){
                     case "stop":
                         StopHTTPServer(DropAllUsers(StopEventsWatcher));
                     break;

                     case "start":
                         START(AlternativePortNumber);
                     break;

                     case "config":
                         ConfigurateStartParams([
                             element.port,
                             element.pass,
                             element.mcport,
                             element.profile
                         ]);
                     break;
                 };
             };
         };
     });
示例#4
0
文件: index.js 项目: Gifer17/mcnext
 function StopHTTPServer(callback){
     if (HTTPServer){
         for (var i = 0; i < __sockets.length; i++) {
             console.log('HTTP socket #' + i + ' destroyed', console.logLevel.L_High);

             __sockets[i].destroy();
         }

         WebRTC.KillWebRTCConnections();

         HTTPServer.on('close', function(){
             console.important("HTTP Server stopped.");

             if (callback) callback();
         });

         WebRTCServer.server.on('close', function(){
             console.important("WebRTCServer Server stopped.");
         });

         if (STUNServer) STUNServer.close();

         HTTPServer.close();
     }
 }
示例#5
0
文件: index.js 项目: Gifer17/mcnext
 function onRequest(request, response) {
     console.DublicateToFile(MCPathes.Profile + "logs/" +
         (new Date()).myFormat('yyyy') + "/" +
         (new Date()).myFormat('mm') + "/" +
         (new Date()).myFormat('dd') + "/node.log");

     if (request.method === 'GET'){
         var pathname = URL.parse(request.url).pathname;

         console.log("Request for " + pathname + " received.", console.logLevel.L_Full);

         Route.GO(FileLoader.handle, pathname, request, response);
     } else
     if (request.method === 'POST'){
         POST_Processing.Parse(request, response);
     };
 }
示例#6
0
StatsModel.prototype.computeGroups = function (data, ticks, hasDistance) {
    var stats = {}

    stats.distance = {}
    stats.distance.data = [];
    stats.distance.ticks = ticks;
    stats.activity = [];

    hasDistance = hasDistance || false;

    for(var i in data) {
      try {
        if (data[i].length > 1) {
          // We're taking the pseudo median date for the series
          var createdAt = data[i][Math.round(data[i].length / 2)].createdAt;
        } else {
          var createdAt = data[i][0].createdAt;
        }
        stats.distance.data.push({
          createdAt :createdAt,
          content : Math.round(this.sum(hasDistance ? data[i] : this.getDistance(data[i]))) || 0
        });
      } catch (e) {
        console.log(data[i], e);
        debugger;
      }
    }
    /*
    if (!sorted) {
      stats.distance.data.sort(function (a, b) {
        if (a.createdAt > b.createdAt)
          return 1;
        else if (a.createdAt < b.createdAt)
          return -1;
        return 0;
      })
    }*/

    stats.summary = this.getSummary(stats.distance.data);

    return stats
},
示例#7
0
 exports.handle = function(sourceWWW, pathWWW, req, res){
 	if (req.method !== 'GET') {
		res.writeHead(404, {
			'Content-Type': 'text/plain'
		});
		
		res.end('invalid method:' + req.method);
	} else {
        console.log('Load file: ' + sourceWWW, console.logLevel.L_Full);

        sourceWWW = sourceWWW.replace(/\\/g, '/');
        pathWWW   = pathWWW.replace(/\\/g, '/');

        if (sourceWWW[sourceWWW.length - 1] != "/"){
            sourceWWW += "/";
        }

        if ((sourceWWW[sourceWWW.length - 1] != "/") && (sourceWWW[sourceWWW.length - 1] != "/")){
            sourceWWW += "/";
        }

        if (pathWWW != "/" || pathWWW != "/") sourceWWW += pathWWW;

        if ((sourceWWW[sourceWWW.length - 1] == "/") ||  (sourceWWW[sourceWWW.length - 1] == "/")){
            sourceWWW += 'index.html';
        }

        fs.stat(sourceWWW, function(err){
            if (err){
                var _ip = req.connection.remoteAddress;

                res.writeHead(404, {'Content-Type' : 'text/plain'});
                res.end('Error 404 :-(\n\nPath: "' + pathWWW + '" not found!');

                console.err(_ip + ' File: "' + sourceWWW + '" not found (on "stat" cmd). ' + err);
            } else {
                var readStream = fs.createReadStream(sourceWWW);
                var acceptEncoding = req.headers['accept-encoding'];

                if (!acceptEncoding) {
                    acceptEncoding = '';
                }

                res.setHeader('Content-Type', mime.lookup(sourceWWW));

                readStream.on('open', function () {
                    if (MCServer.GZIP && acceptEncoding.match(/\bdeflate\b/)) {
                        res.setHeader('content-encoding', 'deflate');

                        readStream.pipe(zlib.createDeflate()).pipe(res);
                    } else if (MCServer.GZIP && acceptEncoding.match(/\bgzip\b/)) {
                        res.setHeader('content-encoding', 'gzip');

                        readStream.pipe(zlib.createGzip()).pipe(res);
                    } else {
                        readStream.pipe(res);
                    }
                });

                readStream.on("end", function(){
                    console.log("End of file read" + sourceWWW, console.logLevel.L_Full);
                });

                readStream.on('error', function() {
                    console.err("Can't load path: " + sourceWWW);
                });

                res.on('close', function(){
                    readStream.destroy();
                });
            }
        })
	}
 };
示例#8
0
 readStream.on("end", function(){
     console.log("End of file read" + sourceWWW, console.logLevel.L_Full);
 });
示例#9
0
 }).catch(function (e) {
   console.log(e, e.stack);
   reject(e.stack)
 })
示例#10
0
文件: service.js 项目: Gifer17/mcnext
 Service.PrintObjectItems = function(_obj){
   for (var i in _obj){
       console.log(i + ": " + ((typeof(_obj[i]) === 'object') ? JSON.stringify(_obj[i]) : _obj[i]));
   }
 };
示例#11
0
文件: index.js 项目: Gifer17/mcnext
 watcher.on('close', function(){
     console.log('Watcher stopped');
 });
示例#12
0
文件: index.js 项目: Gifer17/mcnext
         socket.on('close', function () {
             console.log('HTTP socket closed', console.logLevel.L_Extended);

             __sockets.splice(__sockets.indexOf(socket), 1);
         });