<commit_before>exports.BattleServer = {
	Settings : {
		"silently resolve rule exceptions" : true // Whether, if a client sends a party, etc. which breaks some of the set rules, BattleServer should just attempt to align the data with the rules, or whether it should send a warning message back to the client
	},
	clients : [],
	battles : [],
	receive : function (message, from) {
		switch (message.action) {
			case "connect":
				var newcomer = from, others = [];
				newcomer.user = message.user;
				newcomer.invitations = {};
				exports.BattleServer.clients.forEach(function (client) {
					others.push({
						user : client.user,
						ip : client.ip
					});
					exports.BattleServer.send({
						action : "users",
						user : {
							user : newcomer.user,
							ip : newcomer.ip
						}
					}, client);
				});
				exports.BattleServer.clients.push(newcomer);
				exports.BattleServer.send({
					action : "users",
					users : others
				}, newcomer);
				break;
			case "disconnect":
				var index = exports.BattleServer.clients.indexOf(from);
				if (index >= 0)
					exports.BattleServer.clients.splice(index, 1);
				index = -1;
				exports.BattleServer.battles.forEach(function (battle, i) {
					if (battle.clientA.client === from) {
						index = i;
						return;
					} else if (battle.clientB.client === from) {
						index = i;
						return;
					}
				});
				if (index >= 0)
					exports.BattleServer.battles.splice(index, 1);
				exports.BattleServer.clients.forEach(function (client) {
					exports.BattleServer.send({
						action : "disconnect",
						who : {
							user : from.user,
							ip : from.ip
						},
					}, client);
				});
				break;
			case "invite":
				if (exports.BattleServer.battleForClient(from) === null) {
					if (exports.BattleServer.validateForRules(from, message.trainer, message.settings.rules, message.reference)) {
						exports.BattleServer.clients.forEach(function (client) {
							if (client !== from && (!message.hasOwnProperty("who") || (client.ip === message.who.ip && client.user === message.who.user)) && !from.invitations.hasOwnProperty(client.user + ":" + client.ip)) {
								exports.BattleServer.send({
									action : "invitation",
									from : {
										user : from.user,
										ip : from.ip
									}
								}, client);
								from.invitations[client.user + ":" + client.ip] = {
									trainer : message.trainer,
									settings : message.settings
								};
							}
						});
					}
				}
				break;
			case "accept":
				if (exports.BattleServer.battleForClient(from) === null) {
					var clientB = from, clientA = null;
					exports.BattleServer.clients.forEach(function (client) {
						if (client !== from && client.ip === message.who.ip && client.user === message.who.user) {
							clientA = client;
							return;
						}
					});
					if (clientA !== null && exports.BattleServer.battleForClient(clientA) === null && clientA.invitations.hasOwnProperty(clientB.user + ":" + clientB.ip)) {
						var storage = clientA.invitations[clientB.user + ":" + clientB.ip];
						if (exports.BattleServer.validateForRules(from, message.trainer, storage.settings.rules, message.reference)) {
							var battle = {
								clientA : {
									client : clientA,
									trainer : storage.trainer
								},
								clientB : {
									client : clientB,
									trainer : message.trainer
								},
								seed : Math.random() * Math.pow(2, 32),
								settings : storage.settings
							};
							exports.BattleServer.battles.push(battle);
							var clientAInfo = {
								user : battle.clientA.client.user,
								ip : battle.clientA.client.ip,
								trainer : battle.clientA.trainer
							}, clientBInfo = {
								user : battle.clientB.client.user,
								ip : battle.clientB.client.ip,
								trainer : battle.clientB.trainer
							};
							exports.BattleServer.send({
								action : "begin",
								team : 0,
								self : clientAInfo,
								other : clientBInfo,
								seed : Battle.seed,
								settings : Battle.settings
							}, clientA);
							exports.BattleServer.send({
								action : "begin",
								team : 1,
								self : clientBInfo,
								other : clientAInfo,
								seed : Battle.seed,
								settings : Battle.settings
							}, clientB);
						}
					}
				}
				break;<commit_msg>More changes to correct BattleServer<commit_after>exports.BattleServer = {
	Settings : {
		"silently resolve rule exceptions" : true // Whether, if a client sends a party, etc. which breaks some of the set rules, BattleServer should just attempt to align the data with the rules, or whether it should send a warning message back to the client
	},
	clients : [],
	battles : [],
	receive : function (message, from) {
		switch (message.action) {
			case "connect":
				var newcomer = from, others = [];
				newcomer.user = message.user;
				newcomer.invitations = {};
				exports.BattleServer.clients.forEach(function (client) {
					others.push({
						user : client.user,
						ip : client.ip
					});
					exports.BattleServer.send({
						action : "users",
						user : {
							user : newcomer.user,
							ip : newcomer.ip
						}
					}, client);
				});
				exports.BattleServer.clients.push(newcomer);
				exports.BattleServer.send({
					action : "users",
					users : others
				}, newcomer);
				break;
			case "disconnect":
				var index = exports.BattleServer.clients.indexOf(from);
				if (index >= 0)
					exports.BattleServer.clients.splice(index, 1);
				index = -1;
				exports.BattleServer.battles.forEach(function (battle, i) {
					if (battle.clientA.client === from) {
						index = i;
						return;
					} else if (battle.clientB.client === from) {
						index = i;
						return;
					}
				});
				if (index >= 0)
					exports.BattleServer.battles.splice(index, 1);
				exports.BattleServer.clients.forEach(function (client) {
					exports.BattleServer.send({
						action : "disconnect",
						who : {
							user : from.user,
							ip : from.ip
						},
					}, client);
				});
				break;
			case "invite":
				if (exports.BattleServer.battleForClient(from) === null) {
					if (exports.BattleServer.validateForRules(from, message.trainer, message.settings.rules, message.reference)) {
						exports.BattleServer.clients.forEach(function (client) {
							if (client !== from && (!message.hasOwnProperty("who") || (client.ip === message.who.ip && client.user === message.who.user)) && !from.invitations.hasOwnProperty(client.user + ":" + client.ip)) {
								exports.BattleServer.send({
									action : "invitation",
									from : {
										user : from.user,
										ip : from.ip
									}
								}, client);
								from.invitations[client.user + ":" + client.ip] = {
									trainer : message.trainer,
									settings : message.settings
								};
							}
						});
					}
				}
				break;
			case "accept":
				if (exports.BattleServer.battleForClient(from) === null) {
					var clientB = from, clientA = null;
					exports.BattleServer.clients.forEach(function (client) {
						if (client !== from && client.ip === message.who.ip && client.user === message.who.user) {
							clientA = client;
							return;
						}
					});
					if (clientA !== null && exports.BattleServer.battleForClient(clientA) === null && clientA.invitations.hasOwnProperty(clientB.user + ":" + clientB.ip)) {
						var storage = clientA.invitations[clientB.user + ":" + clientB.ip];
						if (exports.BattleServer.validateForRules(from, message.trainer, storage.settings.rules, message.reference)) {
							var battle = {
								clientA : {
									client : clientA,
									trainer : storage.trainer
								},
								clientB : {
									client : clientB,
									trainer : message.trainer
								},
								seed : Math.random() * Math.pow(2, 32),
								settings : storage.settings
							};
							exports.BattleServer.battles.push(battle);
							var clientAInfo = {
								user : battle.clientA.client.user,
								ip : battle.clientA.client.ip,
								trainer : battle.clientA.trainer
							}, clientBInfo = {
								user : battle.clientB.client.user,
								ip : battle.clientB.client.ip,
								trainer : battle.clientB.trainer
							};
							exports.BattleServer.send({
								action : "begin",
								team : 0,
								self : clientAInfo,
								other : clientBInfo,
								seed : battle.seed,
								settings : battle.settings
							}, clientA);
							exports.BattleServer.send({
								action : "begin",
								team : 1,
								self : clientBInfo,
								other : clientAInfo,
								seed : battle.seed,
								settings : battle.settings
							}, clientB);
						}
					}
				}
				break;
{'fraction_non_alphanumeric': 0.13253428604356343, 'fraction_numerical': 0.002304944105105451, 'mean_word_length': 2.2057628370890283, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 7, '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': '924683', 'n_tokens_mistral': 3900, 'n_tokens_neox': 2620, 'n_words': 543}