From d1f306a2e072ad9cd0596be70d19074fb4c49146 Mon Sep 17 00:00:00 2001 From: Tau Date: Tue, 2 Apr 2019 15:40:55 -0400 Subject: [PATCH] wip mini cleanup dispatch --- src/idz/index.ts | 96 +++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/src/idz/index.ts b/src/idz/index.ts index 866019b..0235678 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -2,7 +2,7 @@ import { Socket } from "net"; import { hostname } from "os"; import setup from "./setup"; -import { objectExpression } from "@babel/types"; +import { Response } from "./response"; export default async function idz(socket: Socket) { const { input, output } = setup(socket); @@ -10,106 +10,108 @@ export default async function idz(socket: Socket) { console.log("Idz: Connection opened"); try { - for await (const msg of input) { - switch (msg.type) { + for await (const req of input) { + let res: Response; + + switch (req.type) { case "account_lock_req": - output.write({ + res = { type: "account_lock_res", field_0018: 1, field_001A: 0xffff, field_001C: new Date(Date.now() + 3600000), - }); + }; break; case "account_unlock_req": - output.write({ + res = { type: "account_unlock_res", status: 1, - }); + }; break; case "create_record_req": - output.write({ + res = { type: "generic_res", status: 1, - }); + }; break; case "create_team_req": - output.write({ + res = { type: "create_team_res", name: "ASS GENTLEMEN", members: [], - }); + }; break; case "get_2on2_req": - output.write({ + res = { type: "get_2on2_res", - }); + }; break; case "get_config_req": - output.write({ + res = { type: "get_config_res", status: 1, - }); + }; break; case "get_config_2_req": - output.write({ + res = { type: "get_config_2_res", status: 1, - }); + }; break; case "get_exist_record_req": - output.write({ + res = { type: "get_exist_record_res", result: true, - }); + }; break; case "get_general_reward_req": // A non-generic response is also accepted, but why bother? - output.write({ + res = { type: "generic_res", status: 1, // not even checked but let's be consistent - }); + }; break; case "get_record_req": - output.write({ + res = { type: "get_record_v2_res", name: "てすと", teamId: 0x11223344, lv: 69, fame: 1234, dpoint: 54321, - }); + }; break; case "get_reward_table_req": - output.write({ + res = { type: "get_reward_table_res", - }); + }; break; case "get_server_list_req": const myHost = hostname(); - output.write({ + res = { type: "get_server_list_res", status: 1, userDb: { @@ -147,20 +149,20 @@ export default async function idz(socket: Socket) { }, newsUrl: `http://${myHost}:10012/news`, reportErrorUrl: `http://${myHost}:10013/error`, - }); + }; break; case "get_stocker_req": - output.write({ + res = { type: "get_stocker_res", status: 1, - }); + }; break; case "get_team_req": - output.write({ + res = { type: "get_team_res", name: "ASS GENTLEMEN", members: [ @@ -170,59 +172,61 @@ export default async function idz(socket: Socket) { monthPoints: 1234, }, ], - }); + }; break; case "update_expedition_req": - if (msg.field_0004 === 0) { - output.write({ + if (req.field_0004 === 0) { + res = { type: "generic_res", status: 0, - }); + }; } else { - output.write({ + res = { type: "update_expedition_res", - }); + }; } break; case "update_provisional_store_rank_req": - output.write({ + res = { type: "update_provisional_store_rank_res", rows: [], - }); + }; break; case "update_record_req": - output.write({ + res = { type: "generic_res", status: 1, - }); + }; break; case "update_story_clear_num_req": - output.write({ + res = { type: "update_story_clear_num_res", - }); + }; break; case "update_topic_req": - output.write({ + res = { type: "update_topic_res", - }); + }; break; default: - const exhaustCheck: never = msg; + const exhaustCheck: never = req; - throw new Error(`Unhandled message ${msg["type"]}`); + throw new Error(`Unhandled message ${req["type"]}`); } + + output.write(res); } } catch (e) { console.log("Idz: Error", e);