CRITICAL ISSUES: Database management service with major problems
WARNING: This commit contains code with significant issues that need immediate attention: 1. Type Safety Issues: - Unused import ZulipAccountsService causing compilation warnings - Implicit 'any' type in formatZulipAccount method parameter - Type inconsistencies in service injections 2. Service Integration Problems: - Inconsistent service interface usage - Missing proper type definitions for injected services - Potential runtime errors due to type mismatches 3. Code Quality Issues: - Violation of TypeScript strict mode requirements - Inconsistent error handling patterns - Missing proper interface implementations Files affected: - src/business/admin/database_management.service.ts (main issue) - Multiple test files and service implementations - Configuration and documentation updates Next steps required: 1. Fix TypeScript compilation errors 2. Implement proper type safety 3. Resolve service injection inconsistencies 4. Add comprehensive error handling 5. Update tests to match new implementations Impact: High - affects admin functionality and system stability Priority: Urgent - requires immediate review and fixes Author: moyin Date: 2026-01-10
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
/**
|
||||
* 清洁的WebSocket网关
|
||||
* 使用原生WebSocket,不依赖NestJS的WebSocket装饰器
|
||||
* 清洁的WebSocket网关 - 优化版本
|
||||
*
|
||||
* 功能描述:
|
||||
* - 使用原生WebSocket,不依赖NestJS的WebSocket装饰器
|
||||
* - 支持游戏内实时聊天广播
|
||||
* - 与优化后的ZulipService集成
|
||||
*
|
||||
* 核心优化:
|
||||
* - 🚀 实时消息广播:直接广播给同区域玩家
|
||||
* - 🔄 与ZulipService的异步同步集成
|
||||
* - ⚡ 低延迟聊天体验
|
||||
*
|
||||
* 最近修改:
|
||||
* - 2026-01-10: 重构优化 - 适配优化后的ZulipService,支持实时广播 (修改者: moyin)
|
||||
*/
|
||||
|
||||
import { Injectable, Logger, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
@@ -74,6 +86,9 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy {
|
||||
});
|
||||
});
|
||||
|
||||
// 🔄 设置WebSocket网关引用到ZulipService
|
||||
this.zulipService.setWebSocketGateway(this);
|
||||
|
||||
this.logger.log(`WebSocket服务器启动成功,端口: ${port},路径: /game`);
|
||||
}
|
||||
|
||||
@@ -163,7 +178,7 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用ZulipService发送消息
|
||||
// 🚀 调用优化后的ZulipService发送消息(实时广播+异步同步)
|
||||
const result = await this.zulipService.sendChatMessage({
|
||||
socketId: ws.id,
|
||||
content: message.content,
|
||||
@@ -177,28 +192,6 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy {
|
||||
message: '消息发送成功'
|
||||
});
|
||||
|
||||
// 广播消息给其他用户(根据scope决定范围)
|
||||
if (message.scope === 'global') {
|
||||
// 全局消息:广播给所有已认证用户
|
||||
this.broadcastMessage({
|
||||
t: 'chat_render',
|
||||
from: ws.username,
|
||||
txt: message.content,
|
||||
bubble: true,
|
||||
scope: 'global'
|
||||
}, ws.id);
|
||||
} else {
|
||||
// 本地消息:只广播给同一地图的用户
|
||||
this.broadcastToMap(ws.currentMap, {
|
||||
t: 'chat_render',
|
||||
from: ws.username,
|
||||
txt: message.content,
|
||||
bubble: true,
|
||||
scope: 'local',
|
||||
mapId: ws.currentMap
|
||||
}, ws.id);
|
||||
}
|
||||
|
||||
this.logger.log(`消息发送成功: ${ws.username} -> ${message.content}`);
|
||||
} else {
|
||||
this.sendMessage(ws, {
|
||||
@@ -247,6 +240,43 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
// 🚀 实现IWebSocketGateway接口方法,供ZulipService调用
|
||||
|
||||
/**
|
||||
* 向指定玩家发送消息
|
||||
*
|
||||
* @param socketId 目标Socket ID
|
||||
* @param data 消息数据
|
||||
*/
|
||||
public sendToPlayer(socketId: string, data: any): void {
|
||||
const client = this.clients.get(socketId);
|
||||
if (client && client.readyState === WebSocket.OPEN) {
|
||||
this.sendMessage(client, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向指定地图广播消息
|
||||
*
|
||||
* @param mapId 地图ID
|
||||
* @param data 消息数据
|
||||
* @param excludeId 排除的Socket ID
|
||||
*/
|
||||
public broadcastToMap(mapId: string, data: any, excludeId?: string): void {
|
||||
const room = this.mapRooms.get(mapId);
|
||||
if (!room) return;
|
||||
|
||||
room.forEach(clientId => {
|
||||
if (clientId !== excludeId) {
|
||||
const client = this.clients.get(clientId);
|
||||
if (client && client.authenticated && client.readyState === WebSocket.OPEN) {
|
||||
this.sendMessage(client, data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 原有的私有方法保持不变
|
||||
private sendMessage(ws: ExtendedWebSocket, data: any) {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify(data));
|
||||
@@ -268,20 +298,6 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private broadcastToMap(mapId: string, data: any, excludeId?: string) {
|
||||
const room = this.mapRooms.get(mapId);
|
||||
if (!room) return;
|
||||
|
||||
room.forEach(clientId => {
|
||||
if (clientId !== excludeId) {
|
||||
const client = this.clients.get(clientId);
|
||||
if (client && client.authenticated) {
|
||||
this.sendMessage(client, data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private joinMapRoom(clientId: string, mapId: string) {
|
||||
if (!this.mapRooms.has(mapId)) {
|
||||
this.mapRooms.set(mapId, new Set());
|
||||
|
||||
Reference in New Issue
Block a user