<commit_before>//var User = require('./models/schema').User;

var loggedInUsers = {};

var messages = {}; //key = target_user, value = dictionary where key = src, value = array of message tuples (msg, date, self?) including self, msg

var Messagebase = (function Messagebase() {
	var that = Object.create(Messagebase.prototype);

	var io = null;

	that.setIO = function(IO) {
		io = IO;

		//io connection
		io.on('connection', function(socket){
			socket.on('disconnect', function(){
			});

			socket.on('chat message', function(msg, from, to, date) {
				if (Object.keys(messages).indexOf(to) === -1) {
					messages[to] = {};
				}
				if (Object.keys(messages[to]).indexOf(from) === -1) {
					messages[to][from] = [];
				}
				messages[to][from].push([msg, date, false]);
				if (Object.keys(messages).indexOf(from) === -1) {
					messages[from] = {};
				}
				if (Object.keys(messages[from]).indexOf(to) === -1) {
					messages[from][to] = [];
				}
				messages[from][to].push([msg, date, true]);

				io.emit("chat message", msg, from, to, date);
			});
		});
	}

	that.login = function(username) {
		loggedInUsers[username] = true;
		if (io) {
			io.emit("login user", username);
		}
	}

	that.logout =  function(username) {
		loggedInUsers[username] = false;
		if (io) {
			io.emit("logout user", username);
		}<commit_msg>added playerUpdate function to messagebase<commit_after>//var User = require('./models/schema').User;

//var loggedInUsers = {};

//var messages = {}; //key = target_user, value = dictionary where key = src, value = array of message tuples (msg, date, self?) including self, msg


userData = {}; //key = user
//vaue = dictionary

var Messagebase = (function Messagebase() {
	var that = Object.create(Messagebase.prototype);

	var io = null;

	var COORD_SIZE_CAP = 20;

	that.setIO = function(IO) {
		io = IO;

		console.log("msg base set io");

		console.log("is it null? ", io == null);
		console.log("is it undef? ", io == undefined);

		//io connection
		io.on('connection', function(socket){
			console.log("connection established");

			socket.on('disconnect', function(){
			});

			socket.on('session', function(msg){
				console.log("message received: ", msg);
				io.emit("session", "connect world");
			});

			socket.on('playerUpdate', function(data) {
				player = data.address;
				latitude = data.latitude;
				longitude = data.longitude;

				if (!(player in userData)) {
					userData[player] = {'name': 'test', 'team': 'gray', 'coordinates': []};
				}

				if (userData[player]['coordinates'].length > COORD_SIZE_CAP) {
					userData[player]['coordinates'].pop(0);
					userData[player]['coordinates'].push([latitude, longitude]);
				}

				//DEBUG
				io.emit("playerUpdate_confirm", [true, userData]);
			});

			socket.on('chat message', function(msg, from, to, date) {
				if (Object.keys(messages).indexOf(to) === -1) {
					messages[to] = {};
				}
				if (Object.keys(messages[to]).indexOf(from) === -1) {
					messages[to][from] = [];
				}
				messages[to][from].push([msg, date, false]);
				if (Object.keys(messages).indexOf(from) === -1) {
					messages[from] = {};
				}
				if (Object.keys(messages[from]).indexOf(to) === -1) {
					messages[from][to] = [];
				}
				messages[from][to].push([msg, date, true]);

				io.emit("chat message", msg, from, to, date);
			});
		});

		setInterval( () => {
			io.emit("session", "this is a timed message " + (new Date().getTime()));
		}, 1000);
	}

	that.login = function(username) {
		loggedInUsers[username] = true;
		if (io) {
			io.emit("login user", username);
		}
	}

	that.logout =  function(username) {
		loggedInUsers[username] = false;
		if (io) {
			io.emit("logout user", username);
		}
{'fraction_non_alphanumeric': 0.1935309973045822, 'fraction_numerical': 0.004043126684636119, 'mean_word_length': 3.4336917562724016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '472362', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1219, 'n_words': 268}