mirror of
				https://github.com/unanmed/HumanBreak.git
				synced 2025-10-31 12:12:58 +08:00 
			
		
		
		
	Deploying to gh-pages from  @ 8ec41d634a 🚀
				
					
				
			This commit is contained in:
		
							parent
							
								
									350603e640
								
							
						
					
					
						commit
						ce9c2d075f
					
				
							
								
								
									
										2
									
								
								project/plugin.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								project/plugin.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										222
									
								
								server.cjs
									
									
									
									
									
								
							
							
						
						
									
										222
									
								
								server.cjs
									
									
									
									
									
								
							| @ -44,6 +44,7 @@ next(); | |||||||
| let repStart; | let repStart; | ||||||
| 
 | 
 | ||||||
| const listenedFloors = []; | const listenedFloors = []; | ||||||
|  | const listenedPlugins = []; | ||||||
| 
 | 
 | ||||||
| // ----- GET file
 | // ----- GET file
 | ||||||
| 
 | 
 | ||||||
| @ -172,6 +173,7 @@ async function writeFile(req, res) { | |||||||
|         const value = /&value=[^]+/.exec(data)[0].slice(7); |         const value = /&value=[^]+/.exec(data)[0].slice(7); | ||||||
|         await fs.writeFile(dir, value, { encoding: type }); |         await fs.writeFile(dir, value, { encoding: type }); | ||||||
|         testWatchFloor(name); |         testWatchFloor(name); | ||||||
|  |         testWatchPlugin(name); | ||||||
|         if (name.endsWith('project/events.js')) doDeclaration('events', value); |         if (name.endsWith('project/events.js')) doDeclaration('events', value); | ||||||
|         if (name.endsWith('project/items.js')) doDeclaration('items', value); |         if (name.endsWith('project/items.js')) doDeclaration('items', value); | ||||||
|         if (name.endsWith('project/maps.js')) doDeclaration('maps', value); |         if (name.endsWith('project/maps.js')) doDeclaration('maps', value); | ||||||
| @ -332,7 +334,7 @@ async function watch() { | |||||||
|         watchOneFloor(v.slice(15)); |         watchOneFloor(v.slice(15)); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     // 脚本编辑 及 插件 热重载
 |     // 脚本编辑 热重载
 | ||||||
|     const scripts = await extract('project/functions.js', 'project/plugins.js'); |     const scripts = await extract('project/functions.js', 'project/plugins.js'); | ||||||
|     scripts.forEach(v => { |     scripts.forEach(v => { | ||||||
|         const dir = path.resolve(__dirname, v); |         const dir = path.resolve(__dirname, v); | ||||||
| @ -343,6 +345,12 @@ async function watch() { | |||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |     // 插件热重载
 | ||||||
|  |     const plugins = await extract('project/plugin/*.js'); | ||||||
|  |     plugins.forEach(v => { | ||||||
|  |         watchOnePlugin(v.slice(15)); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     // 数据热重载
 |     // 数据热重载
 | ||||||
|     const datas = (await extract('project/*.js')).filter( |     const datas = (await extract('project/*.js')).filter( | ||||||
|         v => !v.endsWith('functions.js') && !v.endsWith('plugins.js') |         v => !v.endsWith('functions.js') && !v.endsWith('plugins.js') | ||||||
| @ -370,6 +378,19 @@ function testWatchFloor(url) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * 检测是否是楼层文件并进行监听 | ||||||
|  |  * @param {string} url 要测试的路径 | ||||||
|  |  */ | ||||||
|  | function testWatchPlugin(url) { | ||||||
|  |     if (/project(\/|\\)plugin(\/|\\).*\.js/.test(url)) { | ||||||
|  |         const f = url.slice(15); | ||||||
|  |         if (!listenedFloors.includes(f.slice(0, -3))) { | ||||||
|  |             watchOnePlugin(f); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * 监听一个楼层文件 |  * 监听一个楼层文件 | ||||||
|  * @param {string} file 要监听的文件 |  * @param {string} file 要监听的文件 | ||||||
| @ -386,6 +407,22 @@ function watchOneFloor(file) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** | ||||||
|  |  * 监听一个楼层文件 | ||||||
|  |  * @param {string} file 要监听的文件 | ||||||
|  |  */ | ||||||
|  | function watchOnePlugin(file) { | ||||||
|  |     if (!/.*\.js/.test(file)) return; | ||||||
|  |     const f = file.slice(0, -3); | ||||||
|  |     listenedFloors.push(file.slice(0, -3)); | ||||||
|  |     fss.watchFile(`project/plugin/${file}`, { interval: 500 }, () => { | ||||||
|  |         const plugin = f; | ||||||
|  |         if (hotReloadData.includes(`@@plugin:${plugin}`)) return; | ||||||
|  |         hotReloadData += `@@plugin:${plugin}`; | ||||||
|  |         console.log(`plugin hot reload: ${plugin}`); | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * 修改部分文件后重新加载及热重载 |  * 修改部分文件后重新加载及热重载 | ||||||
|  * @param {http.IncomingMessage} req |  * @param {http.IncomingMessage} req | ||||||
| @ -411,189 +448,6 @@ function reload(req, res, hot = false) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ----- replay debugger
 |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 录像调试 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| function replay(req, res) { |  | ||||||
|     req.on('data', async chunk => { |  | ||||||
|         if (chunk.toString() === 'test' && !replayed) { |  | ||||||
|             replayed = true; |  | ||||||
|             try { |  | ||||||
|                 await fs.mkdir(path.resolve(__dirname, '_replay')); |  | ||||||
|                 await fs.mkdir(path.resolve(__dirname, '_replay/status')); |  | ||||||
|                 await fs.mkdir(path.resolve(__dirname, '_replay/save')); |  | ||||||
|             } catch {} |  | ||||||
| 
 |  | ||||||
|             try { |  | ||||||
|                 await fs.readFile( |  | ||||||
|                     path.resolve(__dirname, '_replay/.info'), |  | ||||||
|                     'utf-8' |  | ||||||
|                 ); |  | ||||||
|             } catch { |  | ||||||
|                 await fs.writeFile( |  | ||||||
|                     path.resolve(__dirname, '_replay/.info'), |  | ||||||
|                     `{
 |  | ||||||
|     "cnt": 0 |  | ||||||
| }`,
 |  | ||||||
|                     'utf-8' |  | ||||||
|                 ); |  | ||||||
|             } |  | ||||||
|             const data = fss.readFileSync( |  | ||||||
|                 path.resolve(__dirname, '_replay/.info'), |  | ||||||
|                 'utf-8' |  | ||||||
|             ); |  | ||||||
|             repStart = Number(JSON.parse(data).cnt); |  | ||||||
|             console.log(`服务器录像调试模块已开始服务`); |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     req.on('end', () => { |  | ||||||
|         res.end(); |  | ||||||
|     }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 获取未占用的状态栏位 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| async function replayCnt() { |  | ||||||
|     const data = `{
 |  | ||||||
|     "cnt": ${++repStart} |  | ||||||
| }`;
 |  | ||||||
|     fss.writeFileSync(path.resolve(__dirname, '_replay/.info'), data, 'utf-8'); |  | ||||||
| 
 |  | ||||||
|     return repStart; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 写入 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| async function replayWrite(req, res) { |  | ||||||
|     const data = await getPostData(req); |  | ||||||
|     const n = await replayCnt(); |  | ||||||
| 
 |  | ||||||
|     if (isNaN(n)) res.end('@error'); |  | ||||||
| 
 |  | ||||||
|     await Promise.all([ |  | ||||||
|         fs.writeFile( |  | ||||||
|             path.resolve(__dirname, '_replay/.info'), |  | ||||||
|             `{
 |  | ||||||
|     "cnt": ${n + 1} |  | ||||||
| }`,
 |  | ||||||
|             'utf-8' |  | ||||||
|         ), |  | ||||||
|         fs.writeFile( |  | ||||||
|             path.resolve(__dirname, `_replay/status/${n}.rep`), |  | ||||||
|             data, |  | ||||||
|             'utf-8' |  | ||||||
|         ) |  | ||||||
|     ]); |  | ||||||
| 
 |  | ||||||
|     res.end(n.toString()); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 比对录像与本地数据 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| async function replayCheck(req, res) { |  | ||||||
|     const ans = await getPostData(req); |  | ||||||
|     const [n, data] = ans.split('@-|-@'); |  | ||||||
| 
 |  | ||||||
|     const local = ( |  | ||||||
|         await fs.readFile( |  | ||||||
|             path.resolve(__dirname, `_replay/status/${n}.rep`), |  | ||||||
|             'utf-8' |  | ||||||
|         ) |  | ||||||
|     ) |  | ||||||
|         .split('@---@') |  | ||||||
|         .map(v => JSON.parse(v)); |  | ||||||
|     const rep = data.split('@---@').map(v => JSON.parse(v)); |  | ||||||
| 
 |  | ||||||
|     if (local.length !== rep.length) return res.end('false'); |  | ||||||
| 
 |  | ||||||
|     const check = (a, b) => { |  | ||||||
|         if (a === b) return true; |  | ||||||
|         if (typeof a !== typeof b) return false; |  | ||||||
|         if (typeof a === 'object' && a !== null) { |  | ||||||
|             for (const j in a) { |  | ||||||
|                 if (j === 'statistics' || j === 'timeout') continue; // 忽略统计信息
 |  | ||||||
|                 const aa = a[j]; |  | ||||||
|                 const bb = b[j]; |  | ||||||
|                 if (!check(aa, bb)) { |  | ||||||
|                     return false; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
|         if ( |  | ||||||
|             typeof a === 'boolean' || |  | ||||||
|             typeof a === 'number' || |  | ||||||
|             typeof a === 'string' || |  | ||||||
|             typeof a === 'symbol' || |  | ||||||
|             typeof a === 'undefined' || |  | ||||||
|             typeof a === 'bigint' || |  | ||||||
|             a === null |  | ||||||
|         ) { |  | ||||||
|             return a === b; |  | ||||||
|         } |  | ||||||
|         return true; |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     for (let i = 0; i < local.length; i++) { |  | ||||||
|         const a = local[i]; |  | ||||||
|         const b = rep[i]; |  | ||||||
|         if (!check(a, b)) return res.end('false'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     res.end('true'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 获取本地属性 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| async function replayGet(req, res, dir) { |  | ||||||
|     const ans = Number(await getPostData(req)); |  | ||||||
| 
 |  | ||||||
|     const data = await fs.readFile( |  | ||||||
|         path.resolve(__dirname, `_replay/${dir}/${ans}.rep`) |  | ||||||
|     ); |  | ||||||
|     res.end(data); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * 录像回放存档 |  | ||||||
|  * @param {http.IncomingMessage} req |  | ||||||
|  * @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res |  | ||||||
|  */ |  | ||||||
| async function replaySave(req, res) { |  | ||||||
|     const data = await getPostData(req); |  | ||||||
|     const [cnt, save] = data.split('@-|-@'); |  | ||||||
| 
 |  | ||||||
|     if (isNaN(Number(cnt))) { |  | ||||||
|         console.log('Invalid input of save cnt'); |  | ||||||
|         res.end('@error: 不合法的录像存档信息'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     await fs.writeFile( |  | ||||||
|         path.resolve(__dirname, `_replay/save/${cnt}.rep`), |  | ||||||
|         save, |  | ||||||
|         'utf-8' |  | ||||||
|     ); |  | ||||||
| 
 |  | ||||||
|     res.end('success'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // ----- declaration
 | // ----- declaration
 | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 unanmed
						unanmed