<commit_before>const MAX_MESSAGE_LENGTH = 300;
const TIMEOUT_DEALLOCATE = 15*60*1000;
// Increment this by 1 for each change that breaks compatibility between
// the previous version of the client and the current version of the server.
const BATTLE_ROOM_PROTOCOL_VERSION = 2;

function BattleRoom(roomid, format, p1, p2, parentid, rated) {
	var selfR = this;

	format = ''+(format||'');

	this.type = 'room';
	this.id = roomid;
	this.i = {};
	this.users = {};
	this.format = format;
	//console.log("NEW BATTLE");

	var formatid = toId(format);

	if (rated && Tools.getFormat(formatid).rated) {
		rated = {
			p1: p1.userid,
			p2: p2.userid,
			format: format
		};
	} else {
		rated = false;
	}

	this.rated = rated;
	this.battle = Simulator.create(selfR.id, format, rated, this);
	this.resetTimer = null;
	this.resetUser = '';
	this.destroyTimer = null;

	this.parentid = parentid||'';
	this.p1 = p1 || '';
	this.p2 = p2 || '';

	this.sideTicksLeft = [21, 21];
	if (!rated) this.sideTicksLeft = [28,28];
	this.sideFreeTicks = [0, 0];
	this.maxTicksLeft = 0;

	this.active = false;

	this.log = [];
	this.lastUpdate = 0;
	this.push = function(message) {
		if (typeof message === 'string') {
			this.log.push(message);
		} else {
			this.log = this.log.concat(message);
		}
	};
	this.win = function(winner) {
		if (selfR.rated) {
			var winnerid = toId(winner);
			var rated = selfR.rated;
			selfR.rated = false;
			var p1score = 0.5;

			if (winnerid === rated.p1) {
				p1score = 1;
			} else if (winnerid === rated.p2) {
				p1score = 0;
			}

			var p1 = rated.p1;
			if (Users.getExact(rated.p1)) p1 = Users.getExact(rated.p1).name;
			var p2 = rated.p2;
			if (Users.getExact(rated.p2)) p2 = Users.getExact(rated.p2).name;

			//update.updates.push('[DEBUG] uri: '+config.loginserver+'action.php?act=ladderupdate&serverid='+config.serverid+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2)+'&score='+p1score+'&format='+toId(rated.format)+'&servertoken=[token]');

			if (!rated.p1 || !rated.p2) {
				selfR.push('|chatmsg-raw|ERROR: Ladder not updated: a player does not exist');
			} else {
				var winner = Users.get(winnerid);
				if (winner && !winner.authenticated) {
					winner.emit('console,', {registerAccountMessage: 1});
				}
				var p1rating, p2rating;
				// update rankings
				selfR.push('|chatmsg-raw|Ladder updating...');
				LoginServer.request('ladderupdate', {
					p1: p1,
					p2: p2,
					score: p1score,
					format: toId(rated.format)
				}, function(data, statusCode, error) {
					if (!selfR) {
						console.log('room expired before ladder update was received');
						return;
					}
					if (!data) {<commit_msg>Always show the register message in the battle room<commit_after>const MAX_MESSAGE_LENGTH = 300;
const TIMEOUT_DEALLOCATE = 15*60*1000;
// Increment this by 1 for each change that breaks compatibility between
// the previous version of the client and the current version of the server.
const BATTLE_ROOM_PROTOCOL_VERSION = 2;

function BattleRoom(roomid, format, p1, p2, parentid, rated) {
	var selfR = this;

	format = ''+(format||'');

	this.type = 'room';
	this.id = roomid;
	this.i = {};
	this.users = {};
	this.format = format;
	//console.log("NEW BATTLE");

	var formatid = toId(format);

	if (rated && Tools.getFormat(formatid).rated) {
		rated = {
			p1: p1.userid,
			p2: p2.userid,
			format: format
		};
	} else {
		rated = false;
	}

	this.rated = rated;
	this.battle = Simulator.create(selfR.id, format, rated, this);
	this.resetTimer = null;
	this.resetUser = '';
	this.destroyTimer = null;

	this.parentid = parentid||'';
	this.p1 = p1 || '';
	this.p2 = p2 || '';

	this.sideTicksLeft = [21, 21];
	if (!rated) this.sideTicksLeft = [28,28];
	this.sideFreeTicks = [0, 0];
	this.maxTicksLeft = 0;

	this.active = false;

	this.log = [];
	this.lastUpdate = 0;
	this.push = function(message) {
		if (typeof message === 'string') {
			this.log.push(message);
		} else {
			this.log = this.log.concat(message);
		}
	};
	this.win = function(winner) {
		if (selfR.rated) {
			var winnerid = toId(winner);
			var rated = selfR.rated;
			selfR.rated = false;
			var p1score = 0.5;

			if (winnerid === rated.p1) {
				p1score = 1;
			} else if (winnerid === rated.p2) {
				p1score = 0;
			}

			var p1 = rated.p1;
			if (Users.getExact(rated.p1)) p1 = Users.getExact(rated.p1).name;
			var p2 = rated.p2;
			if (Users.getExact(rated.p2)) p2 = Users.getExact(rated.p2).name;

			//update.updates.push('[DEBUG] uri: '+config.loginserver+'action.php?act=ladderupdate&serverid='+config.serverid+'&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2)+'&score='+p1score+'&format='+toId(rated.format)+'&servertoken=[token]');

			if (!rated.p1 || !rated.p2) {
				selfR.push('|chatmsg-raw|ERROR: Ladder not updated: a player does not exist');
			} else {
				var winner = Users.get(winnerid);
				if (winner && !winner.authenticated) {
					winner.emit('console,', {registerAccountMessage: 1, room: selfR.id});
				}
				var p1rating, p2rating;
				// update rankings
				selfR.push('|chatmsg-raw|Ladder updating...');
				LoginServer.request('ladderupdate', {
					p1: p1,
					p2: p2,
					score: p1score,
					format: toId(rated.format)
				}, function(data, statusCode, error) {
					if (!selfR) {
						console.log('room expired before ladder update was received');
						return;
					}
					if (!data) {
{'fraction_non_alphanumeric': 0.16517690875232774, 'fraction_numerical': 0.02569832402234637, 'mean_word_length': 3.468386023294509, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1383411', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2019, 'n_words': 434}