107 lines
2.7 KiB
JavaScript
107 lines
2.7 KiB
JavaScript
import mongoose from 'mongoose'
|
|
import { uuidToNoSymboUUID } from '../generator.js'
|
|
import { ImageSecurity } from '../secure.js'
|
|
|
|
export const Player = mongoose.model("Player", new mongoose.Schema({
|
|
username: String, // 有符号 UUID
|
|
password: String,
|
|
email: String,
|
|
uuid: String,
|
|
textures: {
|
|
skin: String,
|
|
cape: String,
|
|
},
|
|
registerDate: Number,
|
|
permissions: [{ node: String, allowed: Boolean, duration: Number, startDate: Number, highPriority: Boolean }], // ban -> true
|
|
telegramBind: {
|
|
username: String,
|
|
verified: Boolean,
|
|
}
|
|
}))
|
|
|
|
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"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = {
|
|
url: player.textures.skin,
|
|
}
|
|
}
|
|
|
|
if(player.textures.skin && player.textures.skin != 0) { // Must be '!=' if this change to '!==' will never works
|
|
textures.textures.CAPE = {
|
|
url: player.textures.cape,
|
|
}
|
|
}
|
|
|
|
const val = Buffer.from(JSON.stringify(textures)).toString('base64')
|
|
|
|
return {
|
|
uuid: uuidToNoSymboUUID(player.uuid),
|
|
name: player.username,
|
|
properties: [
|
|
{
|
|
name: "texturs",
|
|
value: val,
|
|
signature: ImageSecurity.sign(val),
|
|
}
|
|
]
|
|
}
|
|
} |