Begin using the tslog module
This commit is contained in:
parent
1578df961c
commit
564206dd8b
2 changed files with 10 additions and 6 deletions
|
|
@ -13,7 +13,7 @@ that the host is able to just send that to the other players
|
||||||
*/
|
*/
|
||||||
import * as db from '../utils/db';
|
import * as db from '../utils/db';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
import { active_games } from '../main';
|
import { active_games, log } from '../main';
|
||||||
import { generate_game_code } from '../utils/gamecode';
|
import { generate_game_code } from '../utils/gamecode';
|
||||||
|
|
||||||
export const HostGame = (socket: Socket, data: HostGame) => {
|
export const HostGame = (socket: Socket, data: HostGame) => {
|
||||||
|
|
@ -29,7 +29,7 @@ export const HostGame = (socket: Socket, data: HostGame) => {
|
||||||
|
|
||||||
active_games[game_code] = game;
|
active_games[game_code] = game;
|
||||||
|
|
||||||
console.log(`${data.username} created a game. (Gamecode: ${game_code})`);
|
log.info(`${data.username} created a game. (Gamecode: ${game_code})`);
|
||||||
|
|
||||||
// Respond to client
|
// Respond to client
|
||||||
socket.emit(`HostInformation`, {
|
socket.emit(`HostInformation`, {
|
||||||
|
|
@ -38,11 +38,11 @@ export const HostGame = (socket: Socket, data: HostGame) => {
|
||||||
players: [data.username]
|
players: [data.username]
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
log.error(err);
|
||||||
// Let client know an error occured
|
// Let client know an error occured
|
||||||
socket.emit(`HostInformation`, {
|
socket.emit(`HostInformation`, {
|
||||||
success: false,
|
success: false,
|
||||||
error: `${err.name}: ${err.message}`
|
error: `${err.name}: ${err.message}`
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { Logger } from "tslog";
|
||||||
import * as sio from "socket.io";
|
import * as sio from "socket.io";
|
||||||
import { writeFileSync } from "fs";
|
import { writeFileSync } from "fs";
|
||||||
import { Vote } from "./events/Vote";
|
import { Vote } from "./events/Vote";
|
||||||
|
|
@ -15,6 +16,9 @@ import { NextPresident } from "./events/special/SpecialElection/NextPresident";
|
||||||
import { ExecutiveConfirmation } from "./events/special/ExecutiveConfirmation";
|
import { ExecutiveConfirmation } from "./events/special/ExecutiveConfirmation";
|
||||||
import { InvestigateAffiliation } from "./events/special/InvestigateLoyalty/InvestigateAffiliation";
|
import { InvestigateAffiliation } from "./events/special/InvestigateLoyalty/InvestigateAffiliation";
|
||||||
|
|
||||||
|
export var log: Logger = new Logger({
|
||||||
|
displayLogLevel: true,
|
||||||
|
});
|
||||||
|
|
||||||
export var active_games: {[key: string]: Game} = {};
|
export var active_games: {[key: string]: Game} = {};
|
||||||
|
|
||||||
|
|
@ -29,7 +33,7 @@ function clean_up() {
|
||||||
console.log(`Writing game: ${code} to disk`);
|
console.log(`Writing game: ${code} to disk`);
|
||||||
writeFileSync(`${db_dir}/${code}`, active_games[code].toJSON());
|
writeFileSync(`${db_dir}/${code}`, active_games[code].toJSON());
|
||||||
};
|
};
|
||||||
console.log(`Finished saving games to disk.`);
|
log.info(`Finished saving games to disk.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen to the signals for the cleanup requirement
|
// Listen to the signals for the cleanup requirement
|
||||||
|
|
@ -39,7 +43,7 @@ process.on('SIGINT', clean_up);
|
||||||
const io = sio.listen(3000);
|
const io = sio.listen(3000);
|
||||||
|
|
||||||
io.on(`connection`, (socket: sio.Socket) => {
|
io.on(`connection`, (socket: sio.Socket) => {
|
||||||
console.log(`Client connected`);
|
log.info(`Client connected`);
|
||||||
|
|
||||||
// Game Management
|
// Game Management
|
||||||
socket.on(`HostGame`, (data: HostGame) => HostGame(socket, data));
|
socket.on(`HostGame`, (data: HostGame) => HostGame(socket, data));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue