/**
 * A `Session` object corresponds to the connection between one game
 * client and the game server it is connected to. A new session is
 * initialized for each new connection to the GS; after successful
 * login, the respective {@link Player} object is associated with the
 * session (and vice-versa), linking the model and communications
 * layers.
 *
 * Incoming data is deserialized here, and each resulting message is
 * passed on to the GSJS request handler for processing within a new
 * request context. Any unhandled errors there are processed by the
 * {@link Session#handleAmfReqError|handleAmfReqError} function; lower
 * level problems (e.g. during AMF deserialization) are handled by the
 * {@link http://nodejs.org/docs/latest/api/domain.html|domain} based
 * {@link Session#handleError|handleError} function, as well as
 * networking errors.
 *
 * Since sessions are usually short-lived (client commonly has to
 * reconnect to other GS when the player is changing locations) and
 * the client already contains functionality to reconnect after an
 * intermittent connection loss, they are not persisted across server
 * restarts.
 *
 * `Session` is a Node.js `{@link http://nodejs.org/api/events.html#events_class_events_eventemitter
 * EventEmitter}`, emitting the following events:
 * * `close` when the client connection has been closed (cleanly or
 *   after an error)
 *
 * @param {string} id unique ID for this session (unique per GS)
 * @param {Socket} socket TCP socket connection to the client
 *
 * @constructor
 */
function Session(id, socket) {
	Session.super_.call(this);
	this.id = id;
	this.loggedIn = false;
	this.preLoginBuffer = [];
	this.socket = socket;
	this.ts = new Date().getTime();
	this.maxMsgSize = config.get('net:maxMsgSize');
	this.jsamf = config.get('net:amflib') === 'js';
	// disable Nagle's algorithm (we need all messages delivered as quickly as possible)
	this.socket.setNoDelay(true);
	// set up domain for low-level issue handling (networking and
	// AMF deserialization issues)
	this.dom = domain.create();
	this.dom.add(this.socket);
	this.dom.on('error', this.handleError.bind(this));
	this.setupSocketEventHandlers();
	this.gsjsProcessMessage = gsjsBridge.getMain().processMessage;
	log.info({session: this, addr: socket.remoteAddress, port: socket.remotePort},
		'new session created');
}
Exemple #2
0
suite.add('itemstack_verb', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'itemstack_verb',
		itemstack_tsid: apple.tsid, verb: 'lick'});
});
Exemple #3
0
suite.add('itemstack_verb_menu', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'itemstack_verb_menu',
		itemstack_tsid: trant.tsid});
});
Exemple #4
0
suite.add('groups_chat', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'local_chat', txt: 'test!'});
});
Exemple #5
0
suite.add('relogin_end', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'relogin_end'});
});
Exemple #6
0
suite.add('login_start', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'login_start'});
});
Exemple #7
0
suite.add('move_xy', function () {
	gsjsBridge.getMain().processMessage(pc, {type: 'move_xy', x: 1, y: 1});
});