diff --git a/apps/server/chusan/src/index.ts b/apps/server/chusan/src/index.ts index 1cee1cb..23e7728 100644 --- a/apps/server/chusan/src/index.ts +++ b/apps/server/chusan/src/index.ts @@ -10,7 +10,11 @@ import { pingMatching, endMatching, removeMatchingMember, - getMatchingState, mBeginRaidMatchingApi, mGetRaidMatchingStateApi, mEndRaidMatchingApi, mRemoveRaidMatchingMemberApi, + getMatchingState, + mBeginRaidMatchingApi, + mGetRaidMatchingStateApi, + mEndRaidMatchingApi, + mRemoveRaidMatchingMemberApi, MATCHING_TYPES, } from './service' import { mPing, mBeginMatchingApi, mEndMatchingApi, mGetMatchingStateApi, mRemoveMatchingMemberApi, calculateEncryption, gameKeys } from './service/core/encryption' import { buffer } from 'stream/consumers' @@ -111,12 +115,19 @@ app.post('/MatchingServer/:api', async (req, res) => { }) return res.json(await pingMatching()) } else - if (mBeginMatchingApi.includes(api) || mBeginRaidMatchingApi.includes(api)){ + if (mBeginMatchingApi.includes(api)){ log.info({ service: 'Yukiotoko Matching', message: `BeginMatching`, }) - return res.json(await beginMatching(body, req.ip)) + return res.json(await beginMatching(body, req.ip, MATCHING_TYPES.NORMAL)) + } else + if(mBeginRaidMatchingApi.includes(api)){ + log.info({ + service: 'Yukiotoko Matching', + message: `BeginRaidMatching`, + }) + return res.json(await beginMatching(body, req.ip, MATCHING_TYPES.RAID)) } else if (mEndMatchingApi.includes(api) || mEndRaidMatchingApi.includes(api)){ log.info({ @@ -132,13 +143,20 @@ app.post('/MatchingServer/:api', async (req, res) => { }) return res.json(await removeMatchingMember(body)) } else - if (mGetMatchingStateApi.includes(api) || mGetRaidMatchingStateApi.includes(api)){ + if (mGetMatchingStateApi.includes(api)){ log.info({ service: 'Yukiotoko Matching', message: `GetMatchingState`, }) - return res.json(await getMatchingState(body)) + return res.json(await getMatchingState(body, MATCHING_TYPES.NORMAL)) } else + if (mGetRaidMatchingStateApi.includes(api)){ + log.info({ + service: 'Yukiotoko Matching', + message: `GetRaidMatchingState`, + }) + return res.json(await getMatchingState(body, MATCHING_TYPES.RAID)) + } return res.status(403).send() } catch (e) { log.error({ diff --git a/apps/server/chusan/src/service/core/matching.ts b/apps/server/chusan/src/service/core/matching.ts index d4d5417..d7a2834 100644 --- a/apps/server/chusan/src/service/core/matching.ts +++ b/apps/server/chusan/src/service/core/matching.ts @@ -1,5 +1,10 @@ import { db, Prisma } from '@yukiotoko/db' +export const MATCHING_TYPES = { + NORMAL: 0, + RAID: 1 +} + const convertIso88591ToUtf8 = (input: string, romVersion:string): string => { // From X-Verse the usernames are sent in UTF-8 instead of ISO-8859-1 const isUtf8 = convertRomVersionToNumber(romVersion) >= 24000 @@ -34,7 +39,7 @@ export const pingMatching = () => { return { returnCode: 1 } } -export const beginMatching = async (body, ip) => { +export const beginMatching = async (body, ip, type) => { //Check if user is banned const banList = await db.chusanGameBanlist.findMany() var banResult: any @@ -73,7 +78,8 @@ export const beginMatching = async (body, ip) => { if (banResult != null){ return banResult } - var matchingrooms = await db.chusanUserMatching.findMany() + const roomSelector = type == MATCHING_TYPES.NORMAL ? {type:0} : {type:1, course: Number(body.courseId)} + var matchingrooms = await db.chusanUserMatching.findMany({where: roomSelector}) matchingrooms.forEach(async (room) => { var olddate = new Date(room.updatedAt) var DeleteAfterDay = new Date(room.updatedAt) @@ -117,6 +123,7 @@ export const beginMatching = async (body, ip) => { where: { OR:[ { + ...roomSelector, isFull: false, isFinished: false, romVersion: body.matchingMemberInfo.romVersion, @@ -130,7 +137,8 @@ export const beginMatching = async (body, ip) => { gte: 2 } }, { - isFull: false, + ...roomSelector, + isFull: false, isFinished: false, romVersion: body.matchingMemberInfo.romVersion, dataVersion: body.matchingMemberInfo.dataVersion, @@ -172,7 +180,9 @@ export const beginMatching = async (body, ip) => { allowAnybody: false, isFull: false, isFinished: false, - updatedAt: new Date() + updatedAt: new Date(), + type: type, + course: type == MATCHING_TYPES.RAID ? Number(body.courseId) : null, }, }) } else { @@ -314,7 +324,7 @@ export const removeMatchingMember = async body => { } } -export const getMatchingState = async body => { +export const getMatchingState = async (body, type) => { var polling_interval = 1 var matching_room = await db.chusanUserMatching.findFirst({ where: { @@ -402,6 +412,7 @@ export const getMatchingState = async body => { } }) } + const roomSelector = type == MATCHING_TYPES.NORMAL ? {type:0} : {type:1, course: Number(body.courseId)} // If the current room is allowing anybody and only has 1 player in it, try to merge rooms if((matching_room.restMSec < 45) && (matching_room.matchingMemberInfoList.length == 1)){ var newroom = await db.chusanUserMatching.findFirst({ @@ -409,6 +420,7 @@ export const getMatchingState = async body => { NOT: { id: matching_room.id }, + ...roomSelector, isFull: false, isFinished: false, romVersion: body.matchingMemberInfo.romVersion, diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index b5fc849..5916162 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -24,6 +24,8 @@ model ChusanUserMatching { isFinished Boolean allowAnybody Boolean updatedAt DateTime + type Int @default(0) + course Int? mergedRoom Int? }