Use debug package for logging
This commit is contained in:
@@ -99,8 +99,6 @@ export class SqlTeamReservationRepository
|
||||
throw new Error(`Reservation not found for Aime ID ${aimeId}`);
|
||||
}
|
||||
|
||||
console.log(row);
|
||||
|
||||
const insertSql = sql
|
||||
.insert("idz.team_member", {
|
||||
id: row.profile_id,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logger from "debug";
|
||||
import { Transform } from "stream";
|
||||
|
||||
import { checkTeamName } from "./checkTeamName";
|
||||
@@ -49,6 +50,8 @@ import { updateUiReport } from "./updateUiReport";
|
||||
import { updateUserLog } from "./updateUserLog";
|
||||
import { lockProfileExtend } from "./lockProfileExtend";
|
||||
|
||||
const debug = logger("app:idz:decoder");
|
||||
|
||||
export type ReaderFn = ((buf: Buffer) => Request) & {
|
||||
msgCode: number;
|
||||
msgLen: number;
|
||||
@@ -181,8 +184,8 @@ export class Decoder extends Transform {
|
||||
const reqBuf = this.state.slice(0, 0x30 + msgLen);
|
||||
const payloadBuf = reqBuf.slice(0x30);
|
||||
|
||||
console.log("Idz: Req: Raw:", reqBuf.toString("hex"));
|
||||
console.log("Idz: Req: Header:", header);
|
||||
debug(`Raw: ${reqBuf.toString("hex")}`);
|
||||
debug(`Header: ${JSON.stringify(header)}`);
|
||||
|
||||
const reader = readerFns.get(msgCode);
|
||||
|
||||
@@ -194,7 +197,7 @@ export class Decoder extends Transform {
|
||||
|
||||
const payload = reader(payloadBuf);
|
||||
|
||||
console.log("Idz: Req: Payload:", payload);
|
||||
debug(`Payload: ${JSON.stringify(payload)}`);
|
||||
|
||||
return callback(null, payload);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ saveSettings.msgLen = 0x0020;
|
||||
export function saveSettings(buf: Buffer): SaveSettingsRequest {
|
||||
const pack = buf.readUInt32LE(0x000c);
|
||||
|
||||
console.log("Idz: SETTINGS PACK", pack.toString(16));
|
||||
|
||||
return {
|
||||
type: "save_settings_req",
|
||||
aimeId: buf.readUInt32LE(0x0004) as AimeId,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import logger from "debug";
|
||||
import { Transform } from "stream";
|
||||
|
||||
import { _team } from "./_team";
|
||||
@@ -33,6 +34,8 @@ import { updateTeamLeader } from "./updateTeamLeader";
|
||||
import { updateTeamMember } from "./updateTeamMember";
|
||||
import { Response } from "../response";
|
||||
|
||||
const debug = logger("app:idz:encoder");
|
||||
|
||||
function encode(res: Response): Buffer {
|
||||
switch (res.type) {
|
||||
case "check_team_name_res":
|
||||
@@ -147,14 +150,14 @@ export class Encoder extends Transform {
|
||||
}
|
||||
|
||||
_transform(res: Response, encoding, callback) {
|
||||
console.log("Idz: Res: Object:", res);
|
||||
debug(`Object: ${JSON.stringify(res)}`);
|
||||
|
||||
const buf = encode(res);
|
||||
|
||||
console.log("Idz: Res: Encoded:", buf.toString("hex"));
|
||||
debug(`Encoded: ${buf.toString("hex")}`);
|
||||
|
||||
if (buf.readInt16LE(0) === 0) {
|
||||
throw new Error("MESSAGE TYPE CODE YOU FUCKING IDIOT");
|
||||
throw new Error("Missing message type code");
|
||||
}
|
||||
|
||||
return callback(null, buf);
|
||||
|
||||
@@ -59,8 +59,6 @@ export async function createAutoTeam(
|
||||
const [lastAuto, lastTeamId] = peek;
|
||||
const occupancy = await w.teamReservations().occupancyHack(lastTeamId);
|
||||
|
||||
console.log(occupancy);
|
||||
|
||||
if (occupancy < 6) {
|
||||
// Team isn't full, so return this one
|
||||
await w.teamReservations().reserveHack(lastTeamId, aimeId, now);
|
||||
|
||||
@@ -50,8 +50,6 @@ export async function loadTopTen(
|
||||
});
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(courses));
|
||||
|
||||
return {
|
||||
type: "load_top_ten_res",
|
||||
courseCount: courses.length,
|
||||
|
||||
+6
-3
@@ -1,14 +1,17 @@
|
||||
import logger from "debug";
|
||||
import { Socket } from "net";
|
||||
|
||||
import { beginDbSession } from "./db";
|
||||
import { dispatch } from "./handler";
|
||||
import { setup } from "./setup";
|
||||
|
||||
const debug = logger("app:idz:session");
|
||||
|
||||
export default async function idz(socket: Socket) {
|
||||
const txn = await beginDbSession();
|
||||
const { input, output } = setup(socket);
|
||||
|
||||
console.log("Idz: Connection opened");
|
||||
debug("Connection opened");
|
||||
|
||||
try {
|
||||
for await (const req of input) {
|
||||
@@ -17,11 +20,11 @@ export default async function idz(socket: Socket) {
|
||||
|
||||
await txn.commit();
|
||||
} catch (e) {
|
||||
console.log("Idz: Error:", e);
|
||||
debug(`Error:\n${e.toString()}`);
|
||||
await txn.rollback();
|
||||
}
|
||||
|
||||
console.log("Idz: Connection closed\n");
|
||||
debug("Connection closed");
|
||||
|
||||
input.end();
|
||||
}
|
||||
|
||||
+4
-1
@@ -1,11 +1,14 @@
|
||||
import logger from "debug";
|
||||
import { createSocket } from "dgram";
|
||||
|
||||
const debug = logger("app:idz:ping");
|
||||
|
||||
export default function createPing(port: number, host: string) {
|
||||
const socket = createSocket("udp4");
|
||||
|
||||
socket.bind(port, host);
|
||||
socket.on("message", (msg, rinfo) => {
|
||||
console.log(`Idz Ping: Ping from ${rinfo.address}:${rinfo.port}`);
|
||||
debug(`Ping from ${rinfo.address}:${rinfo.port}`);
|
||||
socket.send(msg, rinfo.port, rinfo.address);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user