/*jslint node: true */
'use strict';

var Player = require('./lib/server/Player').Player,
	player;

exports.listen = function (app) {
	var io = require('socket.io').listen(app),
		room = io.of('/room');

	room.on('connection', function (user) {
		// Player joins room
		user.emit('identify-player', { id: user.id });
		user.on('identify-player', function (data) {
			// Create player with new data
			player = new Player(data);
			console.log(player.get('all'));
			user.emit('server-message', { text: 'Välkommen ' + player.get('name') + '!' });
		});

		// Player sends message
		user.on('user-message', function (data) {
			// Send the message to all player in room
			room.emit('user-message', { text: data, player: player.get('all') });
		});

		// Player disconnect
		user.on('disconnect', function () {
			room.emit('server-message', { text: player.get('name') + ' har lämnat spelet.' });
		});
	});

	return io;
};

@@ -90,18 +90,24 @@
 %0A%09player
+s = %5B%5D
 ;%0A
-
 %0Aexports
@@ -244,16 +244,31 @@
 user) %7B%0A
+%09%09var player;%0A%0A
 %09%09// Pla
@@ -330,16 +330,47 @@
 r.id %7D);
+%0A%0A%09%09// Browser send player data
 %0A%09%09user.
@@ -477,42 +477,194 @@
 a);%0A
+%0A
 %09%09%09
-console.log(player.get('all'));
+// Remove player from array%0A%09%09%09players = players.filter(function (p) %7B return p.getSocketID !== user.id; %7D);%0A%0A%09%09%09// Add player to array%0A%09%09%09players.push(player);%0A%0A%09%09%09// Welcome player
 %0A%09%09%09
@@ -1051,31 +1051,33 @@
 : player.get
-('name'
+FullName(
 ) + ' har l%C3%A4

Save players in array on server