Merge remote-tracking branch 'origin/main' into feat/weather-saju

# Conflicts:
#	shared/api/client/@tanstack/react-query.gen.ts
#	shared/api/client/index.ts
#	shared/api/client/sdk.gen.ts
This commit is contained in:
minaChoi committed 2026-10-28 17:17:57 +09:00
commit c61d488794
17 files changed
+469 -126

No files matched your search

+31
View File
@@ -1,3 +1,6 @@
import hashlib
import hmac
import time
import uuid
from dataclasses import dataclass
from datetime import date, timedelta
@@ -10,6 +13,7 @@ from common.database.model.models import User
from common.enums import ErrorType
from common.logger import LOG
from common.utils.kma_time import now_kst
from config.settings import settings
from crud.level_crud import LevelCRUD
# 계정 레벨: 모은 각 총량으로 정한다 (쓰는 기능이 생겨도 레벨은 안 내려간다). 사용자 결정 10/28
@@ -24,9 +28,14 @@ ACTIONS: dict[str, tuple[int, int, str]] = {
"talk": (20, 20, "동네 이야기 글쓰기"),
"checkin": (10, 10, "저녁 체크인"),
"share": (10, 10, "공유하기"),
"game": (2, 20, "날씨게임 라운드 깨기"),
"streak": (50, 50, "7일 연속 출석"),
}
STREAK_DAYS = 7
# 날씨게임 점수는 폰에서 계산해 조작될 수 있다. 하루 한도로 막고, 판 시작부터 라운드당 이만큼은 지나야 받는다
GAME_ROUND_MIN_SEC = 15
GAME_MAX_SEC = 3 * 60 * 60
GAME_MAX_ROUND = 100
STREAK_LOOKBACK = 60
# 레벨로 열리는 것: 새로 생기는 것만 잠근다 (지금 있는 기능·캐릭터·색·기분은 그대로)
@@ -52,6 +61,20 @@ def is_unlocked(points: int, key: str) -> bool:
return level_of(points) >= unlock_level(key)
def game_token(user_id: uuid.UUID, ts: int) -> str:
"""판 시작 표: 시작 시각과 서명. 그 사람만 쓸 수 있다"""
sig = hmac.new(settings.jwt_access_secret.encode(), f"game:{user_id}:{ts}".encode(), hashlib.sha256).hexdigest()[:16]
return f"{ts}.{sig}"
def game_round_ok(user_id: uuid.UUID, play: str, round_no: int, now: int) -> bool:
ts, _, _ = play.partition(".")
if not ts.isdigit() or not hmac.compare_digest(game_token(user_id, int(ts)), play):
return False
elapsed = now - int(ts)
return 1 <= round_no <= GAME_MAX_ROUND and round_no * GAME_ROUND_MIN_SEC <= elapsed <= GAME_MAX_SEC
def streak(days: set[date], today: date) -> int:
"""오늘부터 거꾸로 이어 출석한 날 수"""
n = 0
@@ -139,3 +162,11 @@ class LevelService:
async def share(self, user: User) -> tuple[ErrorType, Optional[Status]]:
await award(user.user_id, "share")
return await self.status(user)
def game_start(self, user: User) -> str:
return game_token(user.user_id, int(time.time()))
async def game_round(self, user: User, play: str, round_no: int) -> tuple[ErrorType, Optional[Status]]:
if game_round_ok(user.user_id, play, round_no, int(time.time())):
await award(user.user_id, "game", f"{play}:{round_no}")
return await self.status(user)