<commit_before>/* global require:false,
	exports:false */
'use strict';
var cl_template = require('./client.js');
var game_template = require('./../Game/checkers.js');
var Clients = [];
var Games = [];

function request(socket, data)
{
	if ( 'undefined' == typeof socket )
	{
		return;
	}

	var res = null;
	if ( 'undefined' == typeof data || 'undefined' == typeof data.cmd )
	{
		res = {
			approved: false,
			data: "Error invaild request"
		};
	}

	else
	{
		var clientContext = Clients[socket];
		switch ( data.cmd )
		{
			//Create Game
			case 'C':
				res = createGame(clientContext);
				break;

			//Leave Game
			case 'L':
				res = leaveGame(clientContext);
				break;

			//Join Game
			case 'J':
				res = joinGame(clientContext);
				break;

			//Set Ready
			case 'R':
				res = setReady(clientContext);
				break;

			//Set Wait
			case 'W':
				res = setWait(clientContext);
				break;

			//Set Name
			case 'N':
				res = setName(clientContext);
				break;

			default:
				res = {
					approved: false,
					data: "Error cannot determine command"
				};
				break;
		}
	}
	socket.emit(res);
}

// Helper for adding clients to the lobby.
// Should be done on connect
exports.AddClient = function(socket)
{
	Clients[socket] = new cl_template.CreateClient(socket);
//	Clients.push(
//		{socket: cl_template.CreateClient(socket)}
//		);

	socket.on('lobby', function(data)
	{
		request(socket, data);
	});
};


exports.GetClients = function()
{
	var returns = [];
	for (var i = 0; i < Clients.length; i++) {
		returns.push(Clients[i]);
	}
	return returns;
};

function createGame(clientContext)
{

}

function leaveGame(clientContext)
{

}

function joinGame(clientContext)
{

}

function setReady(clientContext)
{

}

function setWait(clientContext)
{

}

function setName(clientContext)
{

}<commit_msg>added the beginnings of the functions for the lobby<commit_after>/* global require:false,
	exports:false */
var cl_template = require('./client.js');
var game_template = require('./../Game/checkers.js');
var Clients = [];
var Games = [];

function request(socket, data)
{
	if ( 'undefined' == typeof socket )
	{
		return;
	}

	var res = null;
	if ( 'undefined' == typeof data || 'undefined' == typeof data.cmd )
	{
		res = {
			approved: false,
			data: "Error invaild request"
		};
	}

	else
	{
		var clientContext = Clients[socket];
		switch ( data.cmd )
		{
			//Create Game
			case 'C':
				res = createGame(clientContext);
				break;

			//Leave Game
			case 'L':
				res = leaveGame(clientContext);
				break;

			//Join Game
			case 'J':
				res = joinGame(clientContext);
				break;

			//Set Ready
			case 'R':
				res = setReady(clientContext);
				break;

			//Set Wait
			case 'W':
				res = setWait(clientContext);
				break;

			//Set Name
			case 'N':
				res = setName(clientContext);
				break;

			default:
				res = {
					approved: false,
					data: "Error cannot determine command"
				};
				break;
		}
	}
	socket.emit(res);
}

// Helper for adding clients to the lobby.
// Should be done on connect
exports.AddClient = function(socket)
{
	Clients[socket] = new cl_template.CreateClient(socket);
//	Clients.push(
//		{socket: cl_template.CreateClient(socket)}
//		);

	socket.on('lobby', function(data)
	{
		request(socket, data);
	});
};


exports.GetClients = function()
{
	var returns = [];
	for (var i = 0; i < Clients.length; i++) {
		returns.push(Clients[i]);
	}
	return returns;
};

function createGame(clientContext)
{
	//Check if the player is already in a game
	if (clientContext.isInGame === true)
	{
		return {
			approved: false,
			data: "Cannot create a game if you are in a game"
		};
	}

	//Check if the play has a name 
	if('undefined' == typeof clientContext.name || clientContext.name === null)
	{
		return {
			approved: false,
			data: "Cannot create a game. client name is invaild"
		};
	}

	game_template.CreateGame(clientContext);
}

function leaveGame(clientContext)
{
	if(clientContext.isInGame === false)
	{
		return{
			approved: false,
			data: "Cannot leave a game if you are not in a game"
		};
	}

	if ('undefined' == typeof clientContext.name || clientContext.name === null)
	{
		return {
			approved: false,
			data: "Cannot leave game. client name is invaild"
		};
	}

	//Leave the game
}

function joinGame(clientContext)
{
	if (clientContext.isInGame === true)
	{
		return {
			approved: false,
			data: "Cannot join a game if you are in a game"
		};
	}

	if ('undefined' == typeof clientContext.name || clientContext.name === null)
	{
		return{
			approved: false,
			data: "Cannot join a game if you do not have a name"
		};
	}


}

function setReady(clientContext)
{
	if (clientContext.isInGame === false)
	{
		return{
			approved: false,
			data: "Cannot ready whne you are not in a game"
		};
	}

	if ('undefined' == typeof clientContext.name || clientContext.name === null)
	{
		return {
			approved: false,
			data: "Cannot ready if you do not have a name"
		};
	}


}

function setWait(clientContext)
{

}

function setName(clientContext)
{
	if (clientContext.isInGame === true)
	{
		return {
			approved: false,
			data: "Cannot change your name if you are in a game"
		};
	}

	//Change the name
}
{'fraction_non_alphanumeric': 0.14015808752650857, 'fraction_numerical': 0.000385579332947754, 'mean_word_length': 3.024825446082234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3917181', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1765, 'n_words': 498}