diff --git a/src/idz/decoder/index.ts b/src/idz/decoder/index.ts index 31d722e..afaabe1 100644 --- a/src/idz/decoder/index.ts +++ b/src/idz/decoder/index.ts @@ -36,6 +36,7 @@ import { saveTimeAttack1, saveTimeAttack2 } from "./saveTimeAttack"; import { saveTopic } from "./saveTopic"; import { unlockProfile } from "./unlockProfile"; import { updateProvisionalStoreRank } from "./updateProvisionalStoreRank"; +import { updateTeamMember } from "./updateTeamMember"; import { updateStoryClearNum1, updateStoryClearNum2, @@ -100,6 +101,7 @@ const funcList: ReaderFn[] = [ updateResult, updateStoryClearNum1, updateStoryClearNum2, + updateTeamMember, updateTeamPoints, updateUiReport, updateUserLog, diff --git a/src/idz/decoder/updateTeamMember.ts b/src/idz/decoder/updateTeamMember.ts new file mode 100644 index 0000000..04f9e23 --- /dev/null +++ b/src/idz/decoder/updateTeamMember.ts @@ -0,0 +1,17 @@ +import { RequestCode } from "./_defs"; +import { ExtId } from "../model/base"; +import { Team } from "../model/team"; +import { UpdateTeamMemberRequest } from "../request/updateTeamMember"; +import { AimeId } from "../../model"; + +updateTeamMember.msgCode = 0x0073 as RequestCode; +updateTeamMember.msgLen = 0x0010; + +export function updateTeamMember(buf: Buffer): UpdateTeamMemberRequest { + return { + type: "update_team_member_req", + action: buf.readUInt8(0x0004) === 0 ? "add" : "remove", + aimeId: buf.readUInt32LE(0x0008) as AimeId, + teamExtId: buf.readUInt32LE(0x000c) as ExtId, + }; +} diff --git a/src/idz/encoder/index.ts b/src/idz/encoder/index.ts index 0cfaa7f..6dbe659 100644 --- a/src/idz/encoder/index.ts +++ b/src/idz/encoder/index.ts @@ -29,6 +29,7 @@ import { saveTopic } from "./saveTopic"; import { unlockProfile } from "./unlockProfile"; import { updateProvisionalStoreRank } from "./updateProvisionalStoreRank"; import { updateStoryClearNum } from "./updateStoryClearNum"; +import { updateTeamMember } from "./updateTeamMember"; import { Response } from "../response"; function encode(res: Response): Buffer { @@ -120,6 +121,9 @@ function encode(res: Response): Buffer { case "update_story_clear_num_res": return updateStoryClearNum(res); + case "update_team_member_res": + return updateTeamMember(res); + case "save_topic_res": return saveTopic(res); diff --git a/src/idz/encoder/updateTeamMember.ts b/src/idz/encoder/updateTeamMember.ts new file mode 100644 index 0000000..11dd1b3 --- /dev/null +++ b/src/idz/encoder/updateTeamMember.ts @@ -0,0 +1,10 @@ +import { UpdateTeamMemberResponse } from "../response/updateTeamMember"; + +export function updateTeamMember(res: UpdateTeamMemberResponse): Buffer { + const buf = Buffer.alloc(0x0010); + + buf.writeUInt16LE(0x0074, 0x0000); + buf.writeUInt32LE(res.status, 0x0004); + + return buf; +} diff --git a/src/idz/handler/index.ts b/src/idz/handler/index.ts index 82a00d9..130e49a 100644 --- a/src/idz/handler/index.ts +++ b/src/idz/handler/index.ts @@ -35,6 +35,7 @@ import { unlockProfile } from "./unlockProfile"; import { updateProvisionalStoreRank } from "./updateProvisionalStoreRank"; import { updateResult } from "./updateResult"; import { updateStoryClearNum } from "./updateStoryClearNum"; +import { updateTeamMember } from "./updateTeamMember"; import { updateTeamPoints } from "./updateTeamPoints"; import { updateUiReport } from "./updateUiReport"; import { updateUserLog } from "./updateUserLog"; @@ -158,6 +159,9 @@ export async function dispatch( case "update_story_clear_num_req": return updateStoryClearNum(w, req); + case "update_team_member_req": + return updateTeamMember(w, req); + case "update_team_points_req": return updateTeamPoints(w, req); diff --git a/src/idz/handler/updateTeamMember.ts b/src/idz/handler/updateTeamMember.ts new file mode 100644 index 0000000..538f287 --- /dev/null +++ b/src/idz/handler/updateTeamMember.ts @@ -0,0 +1,37 @@ +import { _fixupPrevTeam } from "./_team"; +import { UpdateTeamMemberRequest } from "../request/updateTeamMember"; +import { UpdateTeamMemberResponse } from "../response/updateTeamMember"; +import { Repositories } from "../repo"; + +export async function updateTeamMember( + w: Repositories, + req: UpdateTeamMemberRequest +): Promise { + const now = new Date(); + const profileId = await w.profile().find(req.aimeId); + const teamId = await w.teams().find(req.teamExtId); + + switch (req.action) { + case "add": + const prevTeamId = await w.teamMembers().findTeam(profileId); + + await w.teamMembers().join(teamId, profileId, now); + await _fixupPrevTeam(w, prevTeamId); + + break; + + case "remove": + // TODO store expulsion flag in db + await w.teamMembers().leave(teamId, profileId); + + break; + + default: + throw new Error("???"); + } + + return { + type: "update_team_member_res", + status: 0, + }; +} diff --git a/src/idz/request/index.ts b/src/idz/request/index.ts index 8d319cd..8b5aef2 100644 --- a/src/idz/request/index.ts +++ b/src/idz/request/index.ts @@ -35,6 +35,7 @@ import { UnlockProfileRequest } from "./unlockProfile"; import { UpdateProvisionalStoreRankRequest } from "./updateProvisionalStoreRank"; import { UpdateResultRequest } from "./updateResult"; import { UpdateStoryClearNumRequest } from "./updateStoryClearNum"; +import { UpdateTeamMemberRequest } from "./updateTeamMember"; import { UpdateTeamPointsRequest } from "./updateTeamPoints"; import { UpdateUiReportRequest } from "./updateUiReport"; import { UpdateUserLogRequest } from "./updateUserLog"; @@ -77,6 +78,7 @@ export type Request = | UpdateProvisionalStoreRankRequest | UpdateResultRequest | UpdateStoryClearNumRequest + | UpdateTeamMemberRequest | UpdateTeamPointsRequest | UpdateUiReportRequest | UpdateUserLogRequest; diff --git a/src/idz/request/updateTeamMember.ts b/src/idz/request/updateTeamMember.ts new file mode 100644 index 0000000..6e71d42 --- /dev/null +++ b/src/idz/request/updateTeamMember.ts @@ -0,0 +1,10 @@ +import { ExtId } from "../model/base"; +import { Team } from "../model/team"; +import { AimeId } from "../../model"; + +export interface UpdateTeamMemberRequest { + type: "update_team_member_req"; + action: "add" | "remove"; + aimeId: AimeId; + teamExtId: ExtId; +} diff --git a/src/idz/response/index.ts b/src/idz/response/index.ts index ba65c36..edaad65 100644 --- a/src/idz/response/index.ts +++ b/src/idz/response/index.ts @@ -27,6 +27,7 @@ import { SaveTimeAttackResponse } from "./saveTimeAttack"; import { SaveTopicResponse } from "./saveTopic"; import { UpdateProvisionalStoreRankResponse } from "./updateProvisionalStoreRank"; import { UpdateStoryClearNumResponse } from "./updateStoryClearNum"; +import { UpdateTeamMemberResponse } from "./updateTeamMember"; import { UnlockProfileResponse } from "./unlockProfile"; export type Response = @@ -55,6 +56,7 @@ export type Response = | UnlockProfileResponse | UpdateProvisionalStoreRankResponse | UpdateStoryClearNumResponse + | UpdateTeamMemberResponse | SaveExpeditionResponse | SaveGarageResponse | SaveNewCarResponse diff --git a/src/idz/response/updateTeamMember.ts b/src/idz/response/updateTeamMember.ts new file mode 100644 index 0000000..babaa2e --- /dev/null +++ b/src/idz/response/updateTeamMember.ts @@ -0,0 +1,4 @@ +export interface UpdateTeamMemberResponse { + type: "update_team_member_res"; + status: number; +}