<commit_before>var fs = require('fs');

var Observify = require('observify');
var BattleNode = require('battle-node');

function serverModel(config) {

	config.port = config.port || 2302;

	var rcon = new BattleNode(config);

	var model = Observify({
		ip: config.ip,
		port: config.port,
		password: <PASSWORD>,
		players: [],
		connected: true,
		connecting: true,
		tried: -1,
	});

	rcon.on('login', login);
	rcon.on('message', message);

	model.connected(connected);


	function connect() {
		if(model.connected())
			return;

		model.connecting.set(true);
		rcon.login();
	}

	function login(err, success) {
		model.connecting.set(false);

	  if (err || !success)
	  	return model.connected.set(false);

  	return model.connected.set(true);
	}

	function connected(state) {
		// when connected?
		// get players?
		// start schedule?
	}


	return model;
}
<commit_msg>More work on server model<commit_after>var fs = require('fs');

var Observify = require('observify');
var BattleNode = require('battle-node');

function serverModel(config) {

  config.port = config.port || 2302;

  var rcon = new BattleNode(config);

  var model = Observify({
    ip: config.ip,
    port: config.port,
    password: <PASSWORD>,
    players: [],
    connected: true,
    connecting: true,
    tried: -1,
  });

  rcon.on('login', login);
  rcon.on('message', message);
  rcon.on('disconnect', reconnect);

  model.connected(connected);


  function connect() {
    if(model.connected())
      return;

    model.connecting.set(true);
    rcon.login();
  }

  function login(err, success) {
    model.connecting.set(false);

    if (err || !success)
      return model.connected.set(false);

    return model.connected.set(true);
  }

  function connected(state) {
    if(!state) return;

    getPlayers();
    startScheduler();
  }

  function reconnect() {
    model.connected.set(false);
    rcon.login();
  }

  return model;
}

{'fraction_non_alphanumeric': 0.15556711758584807, 'fraction_numerical': 0.005202913631633715, 'mean_word_length': 3.4105504587155964, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3029660', 'n_tokens_mistral': 689, 'n_tokens_neox': 637, 'n_words': 140}