2022-05-02 15:12:46 +00:00
|
|
|
import mongoose from 'mongoose'
|
2022-05-09 14:09:08 +00:00
|
|
|
import { uuidToNoSymboUUID } from '../generator.js'
|
2022-05-13 02:16:32 +00:00
|
|
|
import { ImageSecurity } from '../secure.js'
|
2022-05-29 18:12:54 +00:00
|
|
|
import { server } from '../index.js'
|
2022-05-02 15:12:46 +00:00
|
|
|
|
2022-05-16 05:19:28 +00:00
|
|
|
export const Player = mongoose.model("Player", new mongoose.Schema({
|
2022-05-03 10:57:20 +00:00
|
|
|
username: String, // 有符号 UUID
|
2022-05-02 15:12:46 +00:00
|
|
|
password: String,
|
|
|
|
email: String,
|
|
|
|
uuid: String,
|
|
|
|
textures: {
|
|
|
|
skin: String,
|
|
|
|
cape: String,
|
|
|
|
},
|
|
|
|
registerDate: Number,
|
2022-05-03 10:57:20 +00:00
|
|
|
permissions: [{ node: String, allowed: Boolean, duration: Number, startDate: Number, highPriority: Boolean }], // ban -> true
|
2022-05-14 16:29:52 +00:00
|
|
|
telegramBind: {
|
|
|
|
username: String,
|
|
|
|
verified: Boolean,
|
|
|
|
}
|
2022-05-16 05:19:28 +00:00
|
|
|
}))
|
2022-05-03 10:57:20 +00:00
|
|
|
|
|
|
|
export const PlayerSeriliazationSchema = {
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"id": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"name": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"signature": {
|
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PlayerAccountSerializationSchema = {
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"id": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"name": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"value": {
|
|
|
|
"type": "string"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-09 14:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getPlayerSerialization(player) {
|
|
|
|
const textures = {
|
|
|
|
timestamp: 0,
|
|
|
|
profileId: uuidToNoSymboUUID(player.uuid),
|
|
|
|
profileName: player.username,
|
|
|
|
textures: { }
|
|
|
|
}
|
|
|
|
|
|
|
|
if(player.textures.skin && player.textures.skin != 0) { // Must be '!=' if this change to '!==' will never works
|
|
|
|
textures.textures.SKIN = {
|
2022-05-29 18:12:54 +00:00
|
|
|
url: player.textures.skin
|
2022-05-09 14:09:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-29 18:12:54 +00:00
|
|
|
if(player.textures.cape && player.textures.cape != 0) { // Must be '!=' if this change to '!==' will never works
|
2022-05-09 14:09:08 +00:00
|
|
|
textures.textures.CAPE = {
|
|
|
|
url: player.textures.cape,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-13 02:16:32 +00:00
|
|
|
const val = Buffer.from(JSON.stringify(textures)).toString('base64')
|
|
|
|
|
2022-05-29 18:12:54 +00:00
|
|
|
server.log.info({
|
|
|
|
id: uuidToNoSymboUUID(player.uuid),
|
|
|
|
name: player.username,
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
name: "texturs",
|
|
|
|
value: val,
|
|
|
|
signature: ImageSecurity.sign(val),
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2022-05-09 14:09:08 +00:00
|
|
|
return {
|
2022-05-29 18:12:54 +00:00
|
|
|
id: uuidToNoSymboUUID(player.uuid),
|
2022-05-09 14:09:08 +00:00
|
|
|
name: player.username,
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
name: "texturs",
|
2022-05-13 02:16:32 +00:00
|
|
|
value: val,
|
|
|
|
signature: ImageSecurity.sign(val),
|
2022-05-09 14:09:08 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-05-03 10:57:20 +00:00
|
|
|
}
|