init
This commit is contained in:
commit
3de6ad9a2a
|
@ -0,0 +1,2 @@
|
|||
yarn-error.log
|
||||
node_modules
|
|
@ -0,0 +1,46 @@
|
|||
Copyright (c) 2022 Qumolama.d
|
||||
|
||||
"Anti 996" License Version 1.0 (Draft)
|
||||
|
||||
Permission is hereby granted to any individual or legal entity
|
||||
obtaining a copy of this licensed work (including the source code,
|
||||
documentation and/or related items, hereinafter collectively referred
|
||||
to as the "licensed work"), free of charge, to deal with the licensed
|
||||
work for any purpose, including without limitation, the rights to use,
|
||||
reproduce, modify, prepare derivative works of, distribute, publish
|
||||
and sublicense the licensed work, subject to the following conditions:
|
||||
|
||||
1. The individual or the legal entity must conspicuously display,
|
||||
without modification, this License and the notice on each redistributed
|
||||
or derivative copy of the Licensed Work.
|
||||
|
||||
2. The individual or the legal entity must strictly comply with all
|
||||
applicable laws, regulations, rules and standards of the jurisdiction
|
||||
relating to labor and employment where the individual is physically
|
||||
located or where the individual was born or naturalized; or where the
|
||||
legal entity is registered or is operating (whichever is stricter). In
|
||||
case that the jurisdiction has no such laws, regulations, rules and
|
||||
standards or its laws, regulations, rules and standards are
|
||||
unenforceable, the individual or the legal entity are required to
|
||||
comply with Core International Labor Standards.
|
||||
|
||||
3. The individual or the legal entity shall not induce, suggest or force
|
||||
its employee(s), whether full-time or part-time, or its independent
|
||||
contractor(s), in any methods, to agree in oral or written form, to
|
||||
directly or indirectly restrict, weaken or relinquish his or her
|
||||
rights or remedies under such laws, regulations, rules and standards
|
||||
relating to labor and employment as mentioned above, no matter whether
|
||||
such written or oral agreements are enforceable under the laws of the
|
||||
said jurisdiction, nor shall such individual or the legal entity
|
||||
limit, in any methods, the rights of its employee(s) or independent
|
||||
contractor(s) from reporting or complaining to the copyright holder or
|
||||
relevant authorities monitoring the compliance of the license about
|
||||
its violation(s) of the said license.
|
||||
|
||||
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE
|
||||
LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.
|
|
@ -0,0 +1,23 @@
|
|||
版权所有(c)2022 Qumolama.d
|
||||
|
||||
反996许可证版本1.0
|
||||
|
||||
在符合下列条件的情况下,特此免费向任何得到本授权作品的副本(包括源代码、文件和/或相关内容,以
|
||||
下统称为“授权作品”)的个人和法人实体授权:被授权个人或法人实体有权以任何目的处置授权作品,包括
|
||||
但不限于使用、复制,修改,衍生利用、散布,发布和再许可:
|
||||
|
||||
1. 个人或法人实体必须在许可作品的每个再散布或衍生副本上包含以上版权声明和本许可证,不得自行修
|
||||
改。
|
||||
2. 个人或法人实体必须严格遵守与个人实际所在地或个人出生地或归化地、或法人实体注册地或经营地(
|
||||
以较严格者为准)的司法管辖区所有适用的与劳动和就业相关法律、法规、规则和标准。如果该司法管辖区
|
||||
没有此类法律、法规、规章和标准或其法律、法规、规章和标准不可执行,则个人或法人实体必须遵守国际
|
||||
劳工标准的核心公约。
|
||||
3. 个人或法人不得以任何方式诱导、暗示或强迫其全职或兼职员工或其独立承包人以口头或书面形式同意
|
||||
直接或间接限制、削弱或放弃其所拥有的,受相关与劳动和就业有关的法律、法规、规则和标准保护的权利
|
||||
或补救措施,无论该等书面或口头协议是否被该司法管辖区的法律所承认,该等个人或法人实体也不得以任
|
||||
何方法限制其雇员或独立承包人向版权持有人或监督许可证合规情况的有关当局报告或投诉上述违反许可证
|
||||
的行为的权利。
|
||||
|
||||
该授权作品是"按原样"提供,不做任何明示或暗示的保证,包括但不限于对适销性、特定用途适用性和非侵
|
||||
权性的保证。在任何情况下,无论是在合同诉讼、侵权诉讼或其他诉讼中,版权持有人均不承担因本软件或
|
||||
本软件的使用或其他交易而产生、引起或与之相关的任何索赔、损害或其他责任。
|
|
@ -0,0 +1,10 @@
|
|||
# 老色批世界树((
|
||||
|
||||
老色批世界树 —— 一个高性能麻将、奥苏力不-印寨克托接口的实现。使用fastify来把处理速度加速到老色批的速度(
|
||||
|
||||
[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)
|
||||
[![LICENSE](https://img.shields.io/badge/license-Anti%20996-blue.svg)](https://github.com/996icu/996.ICU/blob/master/LICENSE)
|
||||
|
||||
---
|
||||
|
||||
## WIP
|
|
@ -0,0 +1,3 @@
|
|||
const esbuild = require('esbuild')
|
||||
|
||||
esbuild.build({})
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "lsp-yggdrasil",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "A high performance mojang yggdrasil & authlib-injector implmentation",
|
||||
"main": "src/index.js",
|
||||
"license": "Anti-996",
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.14.38",
|
||||
"jest": "^28.0.3",
|
||||
"nodemon": "^2.0.16"
|
||||
},
|
||||
"dependencies": {
|
||||
"fastify": "^3.29.0",
|
||||
"mongoose": "^6.3.1",
|
||||
"pino-pretty": "^7.6.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nodemon --watch src/index.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
export const config = {
|
||||
database: {
|
||||
url: 'mongodb://localhost:27017',
|
||||
db: 'yggdrasil'
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
url: '',
|
||||
},
|
||||
signing: {
|
||||
public: '/path/to/public.pem',
|
||||
private: '/path/to/private.key'
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import * as Crypto from 'crypto'
|
||||
import { server } from './index.js'
|
||||
|
||||
export function generateToken(username) {
|
||||
const key = `${Date.now()}-${ Crypto.createHash('sha256').update(Crypto.randomBytes(32)).digest('hex')}-${username}-lsp-${Math.random() * 1.048596}`
|
||||
const token = Crypto.createHash('sha256').update(key).digest('hex')
|
||||
|
||||
server.log.info(`随机生成器 > 为玩家 ${username} 生成令牌: ${token} | 随机 key = ${key}`)
|
||||
|
||||
return token
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { server } from './index.js'
|
||||
|
||||
export async function headerValidation(req, rep) {
|
||||
if(!(/(authserver)|(sessionserver)|(api)/g).test(req.url)) {
|
||||
return
|
||||
}
|
||||
|
||||
if(Object.keys(req.headers).some(key => {
|
||||
return key.toLowerCase() === "content-type" && req.headers[key].toLowerCase() !== "application/json"
|
||||
})) {
|
||||
return rep.code(400).send({
|
||||
error: "IllegalArgumentException",
|
||||
errorMessage: "请求内容不正确",
|
||||
cause: "请求头中 Content-Type 不是 application/json"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function deserilize(req, payload) {
|
||||
return JSON.parse(payload)
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { fastify } from 'fastify'
|
||||
import { mongoose } from 'mongoose'
|
||||
import { generateToken } from './generator.js'
|
||||
import { registerModels } from './models/index.js';
|
||||
import * as Hooks from './hooks.js'
|
||||
|
||||
export const server = fastify({
|
||||
logger: {
|
||||
prettyPrint: true
|
||||
}
|
||||
})
|
||||
|
||||
//export const logger = server.log
|
||||
|
||||
;(async () => {
|
||||
const { config } = await import('./config.js')
|
||||
|
||||
server.decorate('config', config)
|
||||
|
||||
const mongooseClient = await mongoose.connect(config.database.url)
|
||||
const models = registerModels(mongooseClient)
|
||||
|
||||
server.decorate('mongoose', mongooseClient)
|
||||
server.decorate('models', models)
|
||||
|
||||
server.addHook('preHandler', Hooks.headerValidation)
|
||||
|
||||
|
||||
await server.listen(config.server.port, config.server.url)
|
||||
|
||||
server.log.info("老色批世界树 > 基于 fastify 的高性能 HTTP 服务器已启动")
|
||||
})()
|
|
@ -0,0 +1,9 @@
|
|||
import { TokenSchema } from "./token.js";
|
||||
import { PlayerSchema } from "./player.js";
|
||||
|
||||
export function registerModels(mongoose) {
|
||||
return {
|
||||
Token: mongoose.model("Token", TokenSchema),
|
||||
Player: mongoose.model("Player", PlayerSchema),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import mongoose from 'mongoose'
|
||||
const { Schema } = mongoose
|
||||
|
||||
export const PlayerSchema = new Schema({
|
||||
username: String,
|
||||
password: String,
|
||||
email: String,
|
||||
uuid: String,
|
||||
textures: {
|
||||
skin: String,
|
||||
cape: String,
|
||||
},
|
||||
registerDate: Number,
|
||||
permissions: [{ node: String, allowed: Boolean, duration: Number, eternal: Boolean, startDate: Number, highPriority: Boolean }], // ban -> true
|
||||
})
|
|
@ -0,0 +1,10 @@
|
|||
import mongoose from 'mongoose'
|
||||
const { Schema } = mongoose
|
||||
|
||||
export const TokenSchema = new Schema({
|
||||
uuid: String,
|
||||
token: String,
|
||||
expireDate: Number,
|
||||
deadDate: Number,
|
||||
state: String, // alive, linbo, dead
|
||||
})
|
Loading…
Reference in New Issue