mirror of
https://github.com/djhackersdev/minime.git
synced 2026-09-08 02:25:21 -05:00
idz: Implement team member add/remove
This commit is contained in:
@@ -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,
|
||||
|
||||
17
src/idz/decoder/updateTeamMember.ts
Normal file
17
src/idz/decoder/updateTeamMember.ts
Normal file
@@ -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<Team>,
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
10
src/idz/encoder/updateTeamMember.ts
Normal file
10
src/idz/encoder/updateTeamMember.ts
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
37
src/idz/handler/updateTeamMember.ts
Normal file
37
src/idz/handler/updateTeamMember.ts
Normal file
@@ -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<UpdateTeamMemberResponse> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
10
src/idz/request/updateTeamMember.ts
Normal file
10
src/idz/request/updateTeamMember.ts
Normal file
@@ -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<Team>;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
4
src/idz/response/updateTeamMember.ts
Normal file
4
src/idz/response/updateTeamMember.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface UpdateTeamMemberResponse {
|
||||
type: "update_team_member_res";
|
||||
status: number;
|
||||
}
|
||||
Reference in New Issue
Block a user