修复bug
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Qumolama.d 2022-05-11 08:58:06 +08:00
parent 4aedaea646
commit 95b30485ea
Signed by: Lama3L9R
GPG Key ID: 1762AFC05157CE18
2 changed files with 24 additions and 19 deletions

View File

@ -9,7 +9,7 @@ import { config } from './config.js'
export const server = fastify({
logger: {
prettyPrint: true,
level: 'error'
// level: 'error'
}
})
@ -37,6 +37,7 @@ export const setup = async () => {
server.route(SessionServerRoutings.join)
server.route(SessionServerRoutings.hasJoined)
server.route(SessionServerRoutings.profile)
config.custom.postRouting(server)
@ -90,4 +91,4 @@ export const shutdown = async () => {
await setup()
await launch()
}
})
})()

View File

@ -1,6 +1,6 @@
import { getOverrideHandler, getOverridePreHandler } from '../config.js'
import { toSymboUUID } from '../generator'
import { getPlayerSerialization, PlayerSeriliazationSchema } from '../models/player'
import { toSymboUUID } from '../generator.js'
import { getPlayerSerialization, PlayerSeriliazationSchema } from '../models/player.js'
/*
Key: string Username
@ -45,7 +45,7 @@ export const join = {
})
}
const session = await this.models.Session.findOne({ token: accessToken })
const session = await this.models.Token.findOne({ token: accessToken })
if (!session) {
return await rep.code(401).send({
error: "IllegalArgumentException",
@ -63,9 +63,9 @@ export const join = {
}
joinServerRequest.set(session.uuid, {
accessToken,
serverId,
ip: req.headers['x-forwarded-for'] || req.info.remoteAddress
accessToken: accessToken,
serverId: serverId,
ip: req.headers['x-forwarded-for'] || req.ip
})
await rep.code(204).send()
@ -98,9 +98,21 @@ export const hasJoined = {
preHandler: getOverridePreHandler('/sessionserver/session/minecraft/hasJoined'),
handler: getOverrideHandler('/sessionserver/session/minecraft/hasJoined') ?? async function (req, rep) {
const { username, serverId, ip } = req.query
const { ssID, sIP } = joinServerRequest.get(username)
const player = await this.models.Player.findOne({ username })
if (!player) {
return await rep.code(400).send({
error: "IllegalArgumentException",
errorMessage: "请求内容不正确",
cause: "用户不存在"
})
}
const request = joinServerRequest.get(player.uuid)
this.log.info(request)
if(ip) {
if(ip !== sIP) {
if(ip !== request.ip) {
return await rep.code(401).send({
error: "IllegalArgumentException",
errorMessage: "无效会话",
@ -109,7 +121,7 @@ export const hasJoined = {
}
}
if(serverId !== ssID) {
if(serverId !== request.serverId) {
return await rep.code(401).send({
error: "IllegalArgumentException",
errorMessage: "无效会话",
@ -117,14 +129,6 @@ export const hasJoined = {
})
}
const player = await this.models.Player.findOne({ uuid: toSymboUUID(username) })
if (!player) {
return await rep.code(400).send({
error: "IllegalArgumentException",
errorMessage: "请求内容不正确",
cause: "用户不存在"
})
}
await rep.code(200).send(getPlayerSerialization(player))
}
}