<commit_before>const _ = require('underscore');
const socketio = require('socket.io');
const jwt = require('jsonwebtoken');
const raven = require('raven');

const config = require('./nodeconfig.js');
const logger = require('../log.js');
const ZmqSocket = require('./zmqsocket.js');
const Game = require('../game/game.js');
const Socket = require('../socket.js');
const http = require('http');
const https = require('https');
const fs = require('fs');

var ravenClient = new raven.Client(config.sentryDsn);
ravenClient.patchGlobal();

class GameServer {
    constructor() {
        this.games = {};
        this.sockets = {};

        this.protocol = 'https';

        try {
            var privateKey = fs.readFileSync(config.keyPath).toString();
            var certificate = fs.readFileSync(config.certPath).toString();
        } catch(e) {
            this.protocol = 'http';
        }

        this.host = config.host || process.env.HOST;

        this.socket = new ZmqSocket(this.host, this.protocol);
        this.socket.on('onStartGame', this.onStartGame.bind(this));
        this.socket.on('onSpectator', this.onSpectator.bind(this));

        var server = undefined;

        if(!privateKey || !certificate) {
            server = http.createServer();
        } else {
            server = https.createServer({ key: privateKey, cert: certificate });
        }

        server.listen(process.env.PORT || config.socketioPort);

        this.io = socketio(server);
        this.io.set('heartbeat timeout', 30000);
        this.io.use(this.handshake.bind(this));
        this.io.set('origins', 'http://www.throneteki.net:* https://www.throneteki.net:* http://www.theironthrone.net:* https://www.theironthrone.net:* http://localhost:*');
        this.io.on('connection', this.onConnection.bind(this));
    }

    debugDump() {
        var games = _.map(this.games, game => {
            var players = _.map(game.playersAndSpectators, player => {
                return {
                    name: player.name,
                    left: player.left,
                    disconnected: player.disconnected,
                    id: player.id,
                    spectator: game.isSpectator(player)
                };
            });

            return {
                name: game.name,
                players: players,
                id: game.id,<commit_msg>don't try to set origins while developing<commit_after>const _ = require('underscore');
const socketio = require('socket.io');
const jwt = require('jsonwebtoken');
const raven = require('raven');

const config = require('./nodeconfig.js');
const logger = require('../log.js');
const ZmqSocket = require('./zmqsocket.js');
const Game = require('../game/game.js');
const Socket = require('../socket.js');
const http = require('http');
const https = require('https');
const fs = require('fs');

var ravenClient = new raven.Client(config.sentryDsn);
ravenClient.patchGlobal();

class GameServer {
    constructor() {
        this.games = {};
        this.sockets = {};

        this.protocol = 'https';

        try {
            var privateKey = fs.readFileSync(config.keyPath).toString();
            var certificate = fs.readFileSync(config.certPath).toString();
        } catch(e) {
            this.protocol = 'http';
        }

        this.host = config.host || process.env.HOST;

        this.socket = new ZmqSocket(this.host, this.protocol);
        this.socket.on('onStartGame', this.onStartGame.bind(this));
        this.socket.on('onSpectator', this.onSpectator.bind(this));

        var server = undefined;

        if(!privateKey || !certificate) {
            server = http.createServer();
        } else {
            server = https.createServer({ key: privateKey, cert: certificate });
        }

        server.listen(process.env.PORT || config.socketioPort);

        this.io = socketio(server);
        this.io.set('heartbeat timeout', 30000);
        this.io.use(this.handshake.bind(this));
        if(process.env.NODE_ENV === 'production') {
            this.io.set('origins', 'http://www.throneteki.net:* https://www.throneteki.net:* http://www.theironthrone.net:* https://www.theironthrone.net:*');
        }

        this.io.on('connection', this.onConnection.bind(this));
    }

    debugDump() {
        var games = _.map(this.games, game => {
            var players = _.map(game.playersAndSpectators, player => {
                return {
                    name: player.name,
                    left: player.left,
                    disconnected: player.disconnected,
                    id: player.id,
                    spectator: game.isSpectator(player)
                };
            });

            return {
                name: game.name,
                players: players,
                id: game.id,
{'fraction_non_alphanumeric': 0.15014577259475217, 'fraction_numerical': 0.0020824656393169513, 'mean_word_length': 2.16403162055336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 8, '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': '3491182', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1348, 'n_words': 256}