Android build v1.0.55
This commit is contained in:
+59
-19
@@ -2589,10 +2589,30 @@ function pvpSnapshot(match) {
|
||||
statuses: match.statuses,
|
||||
progress: match.progress,
|
||||
upgradeChoices: match.upgradeChoices,
|
||||
rematchRequests: match.rematchRequests,
|
||||
updatedAt: match.updatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
function createPvpMatch(contentType, startStage, players, now = Date.now()) {
|
||||
const matchId = randomBytes(12).toString('base64url')
|
||||
const match = {
|
||||
id: matchId,
|
||||
contentType,
|
||||
startStage,
|
||||
createdAt: now,
|
||||
players,
|
||||
states: {},
|
||||
statuses: {},
|
||||
progress: {},
|
||||
upgradeChoices: {},
|
||||
rematchRequests: {},
|
||||
updatedAt: now,
|
||||
}
|
||||
pvpMatches.set(matchId, match)
|
||||
return match
|
||||
}
|
||||
|
||||
function joinPvpQueue(session, payload) {
|
||||
const now = Date.now()
|
||||
cleanupPvpMemory(now)
|
||||
@@ -2622,24 +2642,11 @@ function joinPvpQueue(session, payload) {
|
||||
.sort((left, right) => left.createdAt - right.createdAt)[0]
|
||||
const player = pvpPlayerInfo(session)
|
||||
if (opponent) {
|
||||
const matchId = randomBytes(12).toString('base64url')
|
||||
const match = {
|
||||
id: matchId,
|
||||
contentType,
|
||||
startStage,
|
||||
createdAt: now,
|
||||
players: {
|
||||
a: { side: 'a', ...opponent.player },
|
||||
b: { side: 'b', ...player },
|
||||
},
|
||||
states: {},
|
||||
statuses: {},
|
||||
progress: {},
|
||||
upgradeChoices: {},
|
||||
updatedAt: now,
|
||||
}
|
||||
pvpMatches.set(matchId, match)
|
||||
opponent.matchId = matchId
|
||||
const match = createPvpMatch(contentType, startStage, {
|
||||
a: { side: 'a', ...opponent.player },
|
||||
b: { side: 'b', ...player },
|
||||
}, now)
|
||||
opponent.matchId = match.id
|
||||
opponent.updatedAt = now
|
||||
const ticketId = randomBytes(12).toString('base64url')
|
||||
pvpQueue.set(ticketId, {
|
||||
@@ -2649,7 +2656,7 @@ function joinPvpQueue(session, payload) {
|
||||
contentType,
|
||||
startStage,
|
||||
player,
|
||||
matchId,
|
||||
matchId: match.id,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})
|
||||
@@ -2751,6 +2758,33 @@ function submitPvpUpgradeChoice(session, matchId, payload) {
|
||||
return pvpSnapshot(match)
|
||||
}
|
||||
|
||||
function requestPvpRematch(session, matchId) {
|
||||
const { match, side } = requirePvpMatchForSession(session, matchId)
|
||||
if (match.nextMatchId) {
|
||||
const nextMatch = pvpMatches.get(match.nextMatchId)
|
||||
if (nextMatch) return { status: 'matched', side, match: pvpSnapshot(nextMatch) }
|
||||
}
|
||||
match.rematchRequests = match.rematchRequests ?? {}
|
||||
match.rematchRequests[side] = true
|
||||
match.updatedAt = Date.now()
|
||||
const opponentSide = side === 'a' ? 'b' : 'a'
|
||||
if (!match.rematchRequests[opponentSide]) {
|
||||
return { status: 'waiting', match: pvpSnapshot(match), side }
|
||||
}
|
||||
const nextMatch = createPvpMatch(
|
||||
match.contentType,
|
||||
match.startStage,
|
||||
{
|
||||
a: match.players.a,
|
||||
b: match.players.b,
|
||||
},
|
||||
Date.now(),
|
||||
)
|
||||
match.nextMatchId = nextMatch.id
|
||||
match.updatedAt = Date.now()
|
||||
return { status: 'matched', side, match: pvpSnapshot(nextMatch) }
|
||||
}
|
||||
|
||||
export function gameApiPlugin() {
|
||||
return {
|
||||
name: 'ashen-halls-game-api',
|
||||
@@ -2971,6 +3005,12 @@ export async function handleApiRequest(request, response, next) {
|
||||
return
|
||||
}
|
||||
|
||||
const pvpRematch = request.url.match(/^\/api\/pvp\/matches\/([A-Za-z0-9_-]+)\/rematch$/)
|
||||
if (pvpRematch && request.method === 'POST') {
|
||||
sendJson(response, 200, requestPvpRematch(session, pvpRematch[1]))
|
||||
return
|
||||
}
|
||||
|
||||
const pvpMatch = request.url.match(/^\/api\/pvp\/matches\/([A-Za-z0-9_-]+)$/)
|
||||
if (pvpMatch && request.method === 'GET') {
|
||||
sendJson(response, 200, pvpSnapshot(requirePvpMatchForSession(session, pvpMatch[1]).match))
|
||||
|
||||
Reference in New Issue
Block a user