first version of recorder

This commit is contained in:
Jeena 2015-03-01 19:32:31 +01:00 committed by logsol
parent d36e89bacd
commit 1408b6addd
4 changed files with 1725 additions and 17 deletions

View file

@ -52,7 +52,7 @@ function(Parent, Nc, Parser, Settings) {
y: Math.abs(update.p.y - this.player.doll.body.GetPosition().y)
}
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS
if(true || difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS
&& difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
this.player.doll.updatePositionState(update);
} else {

View file

@ -1,33 +1,63 @@
define([
"Lib/Utilities/NotificationCenter",
"Game/Channel/Channel"
"Game/Channel/Channel",
"Game/Config/Settings",
'fs'
],
function (Nc, Channel) {
function (Nc, Channel, Settings, fs) {
"use strict";
function PipeToServer (process) {
var self = this;
this.channel = null;
this.process = process;
this.recordingFileName = null;
Nc.on(Nc.ns.channel.to.server.controlCommand.send, this.send, this);
process.on('message', function (message, handle) {
process.on('message', this.onProcessMessage.bind(this));
}
PipeToServer.prototype.onProcessMessage = function (message, handle) {
if(message.data.hasOwnProperty('CREATE')) {
self.channel = new Channel(self, message.data.options);
} else if (message.data.hasOwnProperty('KILL')) {
self.channel.destroy();
} else {
self.onMessage(message);
this.channel = new Channel(this, message.data.options);
message.data.options.playingFileName = "Quickstart-1425229312283.log";
if(message.data.options.playingFileName) {
var self = this;
setTimeout(function() {
console.log(message.data.options.playingFileName)
self.play(message.data.options.playingFileName);
}, 2000);
}
if(Settings.CHANNEL_RECORD_SESSION) {
this.recordingFileName = Settings.CHANNEL_RECORDING_PATH + "/" + this.channel.name + "-" + Date.now() + ".log";
if(!fs.existsSync(Settings.CHANNEL_RECORDING_PATH)) {
fs.mkdirSync(Settings.CHANNEL_RECORDING_PATH);
}
}
} else if (message.data.hasOwnProperty('KILL')) {
this.channel.destroy();
} else {
this.onMessage(message);
if(Settings.CHANNEL_RECORD_SESSION && this.channel && this.channel.name) {
var m = JSON.stringify(message);
var timestamp = Date.now();
var line = timestamp + m + "\n";
fs.appendFile(this.recordingFileName, line, function (err) {
if (err) throw err;
});
}
}
};
PipeToServer.prototype.send = function (recipient, data) {
var message = {
@ -50,6 +80,34 @@ function (Nc, Channel) {
}
PipeToServer.prototype.play = function(playingFileName) {
var self = this;
var data = fs.readFileSync(Settings.CHANNEL_RECORDING_PATH + "/" + playingFileName);
var lines = data.toString().split("\n");
var now = Date.now();
var start = 0;
for (var i = 0; i < lines.length; i++) {
// bind message variable
(function() {
var line = lines[i];
if(line.length > 0) {
var time = parseInt(line.substring(0, Date.now().toString().length), 10);
if(i == 0) {
start = time;
}
time -= start;
var jsonString = line.substring(Date.now().toString().length);
var message = JSON.parse(jsonString);
setTimeout(function() {
self.onProcessMessage(message, null);
}, time);
}
})();
};
};
PipeToServer.prototype.destroy = function() {
this.send('coordinator', {destroy:this.channel.name});
this.process.exit(0);

View file

@ -25,6 +25,7 @@ function () {
GRAPHICS_SUBPATH_TILES: 'Tiles/',
MAPS_PATH: 'static/maps/tiled/',
AUDIO_PATH: 'static/sounds/',
CHANNEL_RECORDING_PATH: 'recordings/',
RATIO: 21, //35
// original tile size is 25 but we want it to resize to 20
@ -48,7 +49,7 @@ function () {
RESPAWN_TIME: 5,
HEALTH_DISPLAY_TIME: 2,
CRITICAL_HEALTH_THRESHOLD: 0.3,
RAGDOLL_DESTRUCTION_TIME: 20,
RAGDOLL_DESTRUCTION_TIME: 20000,
VIEWPORT_SPEED_FACTOR: 640,
VIEWPORT_LOOK_AHEAD: 0.1,
@ -80,11 +81,12 @@ function () {
// CHANNEL
CHANNEL_MAX_USERS: 20,
CHANNEL_DESTRUCTION_TIME: 5 * 60,
CHANNEL_DESTRUCTION_TIME: 0.5 * 60,
CHANNEL_END_ROUND_TIME: 4, //10,
CHANNEL_DEFAULT_MAX_USERS: 40,
CHANNEL_DEFAULT_SCORE_LIMIT: 10,
CHANNEL_DEFAULT_LEVELS: ['debug'],
CHANNEL_RECORD_SESSION: false,
// ME STATE
ME_STATE_MAX_DIFFERENCE_METERS: 1,

File diff suppressed because it is too large Load diff