앱: 멀티플레이·계정·리더보드·광고 연결 (Phase 4~7 클라이언트)
- 게스트 자동 발급, 이메일 가입/로그인(게스트 기록 이전), 닉네임 변경, 계정 삭제 - 커스텀 방 만들기/참가, 로비(호스트 규칙), 1:1·FFA 대전, 가비지 게이지·상쇄·삽입, 상대 미니보드 탭 타겟팅, KO 피드, 관전, 리매치 투표, 재접속 - 리그 대기열·매칭·FT3/FT5·결과(TR/배치), 리더보드 4종, 프로필 전적 - AdMob(UMP 동의) 배너·결과 카드·전면(3판당 1회, 첫 판 제외), 기본은 테스트 ID - 서버: 앱 레벨 keepalive(auto-response), KO 후 로비 갱신, 재접속 시 결과 재전송, x-info 헤더 ASCII 인코딩, 계정 삭제 API - 개인정보처리방침·스토어 등록정보 갱신 (온라인·광고 반영) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,7 +73,7 @@ async function routeWs(req, env, url, u, ns, name, path = "/ws") {
|
||||
const stub = ns.get(ns.idFromName(name));
|
||||
const headers = new Headers(req.headers);
|
||||
headers.set("x-uid", u.id);
|
||||
headers.set("x-info", JSON.stringify(await playerInfo(env, u)));
|
||||
headers.set("x-info", encodeURIComponent(JSON.stringify(await playerInfo(env, u)))); // 헤더는 ASCII 만 안전
|
||||
return stub.fetch(new Request(`https://do${path}`, { headers }));
|
||||
}
|
||||
|
||||
@@ -204,6 +204,17 @@ async function handle(req, env) {
|
||||
});
|
||||
}
|
||||
|
||||
// 계정 삭제 (Play 정책: 계정을 만들 수 있으면 앱 안에서 삭제도 가능해야 한다)
|
||||
if (path === "/api/me/delete" && req.method === "POST") {
|
||||
await db.batch([
|
||||
db.prepare("DELETE FROM solo_records WHERE user_id = ?").bind(me.id),
|
||||
db.prepare("DELETE FROM ratings WHERE user_id = ?").bind(me.id),
|
||||
db.prepare("DELETE FROM matches WHERE p1 = ? AND mode = 'custom'").bind(me.id),
|
||||
db.prepare("DELETE FROM users WHERE id = ?").bind(me.id),
|
||||
]);
|
||||
return json({ ok: true });
|
||||
}
|
||||
|
||||
if (path === "/api/nickname" && req.method === "POST") {
|
||||
if (me.is_guest) return err("게스트는 닉네임을 바꿀 수 없습니다. 로그인해 주세요", 403);
|
||||
const b = await body(req);
|
||||
|
||||
@@ -6,10 +6,15 @@ import { MM_HINT_AFTER_MS, leagueFt } from "./rules.js";
|
||||
const SWEEP_MS = 3_000;
|
||||
|
||||
export class MatchmakerDO extends DurableObject {
|
||||
constructor(ctx, env) {
|
||||
super(ctx, env);
|
||||
ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair('{"t":"ping"}', '{"t":"pong"}'));
|
||||
}
|
||||
|
||||
async fetch(req) {
|
||||
if (req.headers.get("Upgrade") !== "websocket") return new Response("websocket only", { status: 426 });
|
||||
const uid = req.headers.get("x-uid");
|
||||
const info = JSON.parse(req.headers.get("x-info") || "{}");
|
||||
const info = JSON.parse(decodeURIComponent(req.headers.get("x-info") || "%7B%7D"));
|
||||
for (const old of this.ctx.getWebSockets(uid)) {
|
||||
try {
|
||||
old.serializeAttachment({ ...old.deserializeAttachment(), gone: true });
|
||||
@@ -65,7 +70,7 @@ export class MatchmakerDO extends DurableObject {
|
||||
}
|
||||
|
||||
async webSocketMessage(ws, data) {
|
||||
if (data === "leave" || String(data).includes('"leave"')) ws.close(1000, "left");
|
||||
if (String(data).includes('"leave"')) ws.close(1000, "left");
|
||||
}
|
||||
|
||||
async webSocketClose() {}
|
||||
|
||||
@@ -31,7 +31,8 @@ export class RoomLogic {
|
||||
this.roundStartAt = 0;
|
||||
this.nextRoundAt = 0;
|
||||
this.matchId = null;
|
||||
this.finished = false; // 리그 경기 종료 후 방 폐기 표시
|
||||
this.finished = false;
|
||||
this.lastEnd = null; // 끊겼다 돌아온 사람에게 다시 보낼 match_end ({uid|"*": msg}) // 리그 경기 종료 후 방 폐기 표시
|
||||
|
||||
this.outbox = []; // {to: uid|null, except?: uid, msg}
|
||||
this.effects = []; // {type, ...}
|
||||
@@ -58,7 +59,7 @@ export class RoomLogic {
|
||||
id: this.id, kind: this.kind, code: this.code, allowed: this.allowed, rules: this.rules,
|
||||
players: [...this.players.values()], order: this.order, host: this.host, phase: this.phase,
|
||||
round: this.round, roundStartAt: this.roundStartAt, nextRoundAt: this.nextRoundAt,
|
||||
matchId: this.matchId, finished: this.finished,
|
||||
matchId: this.matchId, finished: this.finished, lastEnd: this.lastEnd,
|
||||
};
|
||||
}
|
||||
static fromJSON(j, deps = {}) {
|
||||
@@ -66,6 +67,7 @@ export class RoomLogic {
|
||||
Object.assign(r, {
|
||||
rules: j.rules, order: j.order, host: j.host, phase: j.phase, round: j.round,
|
||||
roundStartAt: j.roundStartAt, nextRoundAt: j.nextRoundAt, matchId: j.matchId, finished: j.finished,
|
||||
lastEnd: j.lastEnd ?? null,
|
||||
});
|
||||
for (const p of j.players) r.players.set(p.uid, p);
|
||||
return r;
|
||||
@@ -113,6 +115,10 @@ export class RoomLogic {
|
||||
existing.disconnectedAt = 0;
|
||||
Object.assign(existing, pickInfo(info));
|
||||
this.send(uid, this.syncMsg(uid));
|
||||
if (this.phase === "match_end" && this.lastEnd) {
|
||||
const end = this.lastEnd[uid] ?? this.lastEnd["*"];
|
||||
if (end) this.send(uid, end);
|
||||
}
|
||||
if (existing.pendingGarbage?.length) {
|
||||
for (const g of existing.pendingGarbage) this.send(uid, g);
|
||||
existing.pendingGarbage = [];
|
||||
@@ -375,6 +381,7 @@ export class RoomLogic {
|
||||
this.broadcast({ t: "ko", who: uid, by: p.lastAttacker, place: p.place });
|
||||
const left = this.alive;
|
||||
if (left.length <= 1) this.endRound(left[0] ?? null);
|
||||
else this.broadcast(this.lobbyMsg()); // 생존 인원·KO 표시 갱신
|
||||
}
|
||||
|
||||
endRound(winner) {
|
||||
@@ -416,7 +423,9 @@ export class RoomLogic {
|
||||
// match_end 메시지는 레이팅 반영 후 래퍼가 trDelta 를 붙여 보낸다.
|
||||
} else {
|
||||
this.effects.push({ type: "custom_end", standings, size: this.order.length });
|
||||
this.broadcast({ t: "match_end", result: standings, winner: winnerUid });
|
||||
const msg = { t: "match_end", result: standings, winner: winnerUid };
|
||||
this.lastEnd = { "*": msg };
|
||||
this.broadcast(msg);
|
||||
this.broadcastRematch();
|
||||
}
|
||||
this.broadcast(this.lobbyMsg());
|
||||
@@ -434,6 +443,7 @@ export class RoomLogic {
|
||||
}
|
||||
|
||||
resetWins() {
|
||||
this.lastEnd = null;
|
||||
for (const p of this.players.values()) {
|
||||
p.wins = 0;
|
||||
p.rematch = false;
|
||||
|
||||
@@ -10,6 +10,8 @@ export class GameRoomDO extends DurableObject {
|
||||
constructor(ctx, env) {
|
||||
super(ctx, env);
|
||||
this.logic = null;
|
||||
// 클라이언트 keepalive: DO 를 깨우지 않고 런타임이 바로 응답한다.
|
||||
ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair('{"t":"ping"}', '{"t":"pong"}'));
|
||||
}
|
||||
|
||||
async load() {
|
||||
@@ -50,7 +52,7 @@ export class GameRoomDO extends DurableObject {
|
||||
const l = await this.load();
|
||||
if (!l) return new Response("no such room", { status: 404 });
|
||||
const uid = req.headers.get("x-uid");
|
||||
const info = JSON.parse(req.headers.get("x-info") || "{}");
|
||||
const info = JSON.parse(decodeURIComponent(req.headers.get("x-info") || "%7B%7D"));
|
||||
const pair = new WebSocketPair();
|
||||
const [client, server] = Object.values(pair);
|
||||
// 같은 유저의 이전 소켓은 정리 (재접속)
|
||||
@@ -162,11 +164,14 @@ export class GameRoomDO extends DurableObject {
|
||||
} catch (err) {
|
||||
console.error("league_end failed", err);
|
||||
}
|
||||
l.lastEnd = {};
|
||||
for (const uid of [e.winner, e.loser]) {
|
||||
l.send(uid, {
|
||||
const msg = {
|
||||
t: "match_end", winner: e.winner, score: e.score,
|
||||
trDelta: result?.[uid]?.trDelta ?? null, before: result?.[uid]?.before ?? null, after: result?.[uid]?.after ?? null,
|
||||
});
|
||||
};
|
||||
l.lastEnd[uid] = msg;
|
||||
l.send(uid, msg);
|
||||
}
|
||||
} else if (e.type === "custom_end") {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user