|
@@ -1,12 +1,32 @@
|
|
"use strict";
|
|
"use strict";
|
|
// reflector.js
|
|
// reflector.js
|
|
-//
|
|
|
|
-//var parseurl = require( './parse-url' ),
|
|
|
|
- // persistence = require( './persistence' ),
|
|
|
|
|
|
|
|
- var helpers = require( './helpers' );
|
|
|
|
- var fs = require( 'fs' );
|
|
|
|
|
|
+// JoinPath
|
|
|
|
+// Takes multiple arguments, joins them together into one path.
|
|
|
|
+function JoinPath( /* arguments */ ) {
|
|
|
|
+ var result = "";
|
|
|
|
+ if ( arguments.length > 0 ) {
|
|
|
|
+ if ( arguments[ 0 ] ) {
|
|
|
|
+ result = arguments[ 0 ];
|
|
|
|
+ }
|
|
|
|
+ for ( var index = 1; index < arguments.length; index++ ) {
|
|
|
|
+ var newSegment = arguments[ index ];
|
|
|
|
+ if ( newSegment == undefined ) {
|
|
|
|
+ newSegment = "";
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ if ( ( newSegment[ 0 ] == "/" ) && ( result[ result.length - 1 ] == "/" ) ) {
|
|
|
|
+ result = result + newSegment.slice( 1 );
|
|
|
|
+ } else if ( ( newSegment[ 0 ] == "/" ) || ( result[ result.length - 1 ] == "/" ) ) {
|
|
|
|
+ result = result + newSegment;
|
|
|
|
+ } else {
|
|
|
|
+ result = result + "/" + newSegment;
|
|
|
|
+ }
|
|
|
|
+ //result = libpath.join( result, newSegment );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
|
|
function parseSocketUrl( socket ) {
|
|
function parseSocketUrl( socket ) {
|
|
|
|
|
|
@@ -46,7 +66,7 @@ function parseSocketUrl( socket ) {
|
|
//Get the instance ID from the handshake headers for a socket
|
|
//Get the instance ID from the handshake headers for a socket
|
|
function GetNamespace( processedURL ) {
|
|
function GetNamespace( processedURL ) {
|
|
if ( ( processedURL[ 'instance' ] ) && ( processedURL[ 'public_path' ] ) ) {
|
|
if ( ( processedURL[ 'instance' ] ) && ( processedURL[ 'public_path' ] ) ) {
|
|
- return helpers.JoinPath( processedURL[ 'public_path' ], processedURL[ 'application' ], processedURL[ 'instance' ] );
|
|
|
|
|
|
+ return JoinPath( processedURL[ 'public_path' ], processedURL[ 'application' ], processedURL[ 'instance' ] );
|
|
}
|
|
}
|
|
return undefined;
|
|
return undefined;
|
|
}
|
|
}
|
|
@@ -66,9 +86,13 @@ function OnConnection( socket ) {
|
|
var address = socket.conn.request.headers.host;
|
|
var address = socket.conn.request.headers.host;
|
|
var obj = {};
|
|
var obj = {};
|
|
for (var prop in global.instances) {
|
|
for (var prop in global.instances) {
|
|
|
|
+ let user = global.instances[prop].user;
|
|
|
|
+ let loadInfo = global.instances[prop].loadInfo;
|
|
obj[prop] = {
|
|
obj[prop] = {
|
|
- "instance":address + prop,
|
|
|
|
- "clients": Object.keys(global.instances[prop].clients).length
|
|
|
|
|
|
+ "instance":address + '/'+ user + prop,
|
|
|
|
+ "clients": Object.keys(global.instances[prop].clients).length,
|
|
|
|
+ "user": user,
|
|
|
|
+ "loadInfo": loadInfo
|
|
};
|
|
};
|
|
}
|
|
}
|
|
var json = JSON.stringify(obj);
|
|
var json = JSON.stringify(obj);
|
|
@@ -93,12 +117,15 @@ function OnConnection( socket ) {
|
|
|
|
|
|
var loadInfo = resObj.loadInfo //GetLoadForSocket( processedURL );
|
|
var loadInfo = resObj.loadInfo //GetLoadForSocket( processedURL );
|
|
var saveObject = resObj.saveObject //persistence.LoadSaveObject( loadInfo );
|
|
var saveObject = resObj.saveObject //persistence.LoadSaveObject( loadInfo );
|
|
|
|
+ var user = resObj.user;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if it's a new instance, setup record
|
|
//if it's a new instance, setup record
|
|
if( !global.instances[ namespace ] ) {
|
|
if( !global.instances[ namespace ] ) {
|
|
global.instances[ namespace ] = { };
|
|
global.instances[ namespace ] = { };
|
|
|
|
+ global.instances[ namespace ].loadInfo = loadInfo;
|
|
|
|
+ global.instances[ namespace ].user = user;
|
|
global.instances[ namespace ].clients = { };
|
|
global.instances[ namespace ].clients = { };
|
|
global.instances[ namespace ].pendingList = [ ];
|
|
global.instances[ namespace ].pendingList = [ ];
|
|
global.instances[ namespace ].start_time = undefined;
|
|
global.instances[ namespace ].start_time = undefined;
|
|
@@ -400,9 +427,12 @@ function OnConnection( socket ) {
|
|
client.emit ( 'message', clientMessage );
|
|
client.emit ( 'message', clientMessage );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if ( global.instances[ namespace ].pendingList.pending ) {
|
|
|
|
- global.instances[ namespace ].pendingList.push( clientMessage );
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ if (global.instances[namespace]) {
|
|
|
|
+
|
|
|
|
+ if (global.instances[namespace].pendingList.pending) {
|
|
|
|
+ global.instances[namespace].pendingList.push(clientMessage);
|
|
|
|
+ }
|
|
|
|
|
|
// If it's the last client, delete the data and the timer
|
|
// If it's the last client, delete the data and the timer
|
|
if ( Object.keys( global.instances[ namespace ].clients ).length == 0 ) {
|
|
if ( Object.keys( global.instances[ namespace ].clients ).length == 0 ) {
|
|
@@ -412,6 +442,8 @@ function OnConnection( socket ) {
|
|
} else {
|
|
} else {
|
|
// xapi.logClient( undefined, loadInfo[ 'application_path' ], loadInfo[ 'save_name' ], namespace, clientDescriptor.properties || {}, false, false );
|
|
// xapi.logClient( undefined, loadInfo[ 'application_path' ], loadInfo[ 'save_name' ], namespace, clientDescriptor.properties || {}, false, false );
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
} );
|
|
} );
|
|
}
|
|
}
|
|
|
|
|