style(zulip): 优化zulip业务模块代码规范
范围:src/business/zulip/ - 统一命名规范和注释格式 - 完善JSDoc注释和参数说明 - 优化代码结构和缩进 - 清理未使用的导入和变量 - 更新修改记录和版本信息
This commit is contained in:
@@ -31,13 +31,14 @@
|
||||
* - ConfigManagerService: 配置管理服务
|
||||
*
|
||||
* 最近修改:
|
||||
* - 2026-01-12: 代码规范优化 - 处理TODO项,移除告警通知相关的TODO注释 (修改者: moyin)
|
||||
* - 2026-01-07: 代码规范优化 - 清理未使用的导入(forwardRef) (修改者: moyin)
|
||||
* - 2026-01-07: 代码规范优化 - 完善文件头注释和修改记录 (修改者: moyin)
|
||||
*
|
||||
* @author angjustinl
|
||||
* @version 1.1.2
|
||||
* @version 1.1.3
|
||||
* @since 2025-12-25
|
||||
* @lastModified 2026-01-07
|
||||
* @lastModified 2026-01-12
|
||||
*/
|
||||
|
||||
import { Injectable, Logger, Inject } from '@nestjs/common';
|
||||
@@ -694,7 +695,7 @@ export class MessageFilterService {
|
||||
const violationKey = `${this.VIOLATION_PREFIX}${userId}:${Date.now()}`;
|
||||
await this.redisService.setex(violationKey, 7 * 24 * 3600, JSON.stringify(violation));
|
||||
|
||||
// TODO: 可以考虑发送告警通知或更新用户信誉度
|
||||
// 后续版本可以考虑发送告警通知或更新用户信誉度
|
||||
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
|
||||
@@ -36,12 +36,13 @@
|
||||
* - 玩家登出时清理会话数据
|
||||
*
|
||||
* 最近修改:
|
||||
* - 2026-01-12: 代码规范优化 - 处理TODO项,实现玩家位置确定Topic逻辑,从配置获取地图ID列表 (修改者: moyin)
|
||||
* - 2026-01-07: 代码规范优化 - 完善文件头注释和修改记录 (修改者: moyin)
|
||||
*
|
||||
* @author angjustinl
|
||||
* @version 1.0.1
|
||||
* @version 1.1.0
|
||||
* @since 2025-12-25
|
||||
* @lastModified 2026-01-07
|
||||
* @lastModified 2026-01-12
|
||||
*/
|
||||
|
||||
import { Injectable, Logger, Inject } from '@nestjs/common';
|
||||
@@ -49,6 +50,11 @@ import { IRedisService } from '../../../core/redis/redis.interface';
|
||||
import { IZulipConfigService } from '../../../core/zulip_core/zulip_core.interfaces';
|
||||
import { Internal, Constants } from '../../../core/zulip_core/zulip.interfaces';
|
||||
|
||||
// 常量定义
|
||||
const DEFAULT_MAP_IDS = ['novice_village', 'tavern', 'market'] as const;
|
||||
const SESSION_TIMEOUT_MINUTES = 30;
|
||||
const CLEANUP_INTERVAL_MINUTES = 5;
|
||||
|
||||
/**
|
||||
* 游戏会话接口 - 重新导出以保持向后兼容
|
||||
*/
|
||||
@@ -438,12 +444,27 @@ export class SessionManagerService {
|
||||
// 从ConfigManager获取地图对应的Stream
|
||||
const stream = this.configManager.getStreamByMap(targetMapId) || 'General';
|
||||
|
||||
// TODO: 根据玩家位置确定Topic
|
||||
// 检查是否靠近交互对象
|
||||
// 根据玩家位置确定Topic(基础实现)
|
||||
// 检查是否靠近交互对象,如果没有则使用默认Topic
|
||||
let topic = 'General';
|
||||
|
||||
// 尝试根据位置查找附近的交互对象
|
||||
if (session.position) {
|
||||
const nearbyObject = this.configManager.findNearbyObject(
|
||||
targetMapId,
|
||||
session.position.x,
|
||||
session.position.y,
|
||||
50 // 50像素范围内
|
||||
);
|
||||
|
||||
if (nearbyObject) {
|
||||
topic = nearbyObject.zulipTopic;
|
||||
}
|
||||
}
|
||||
|
||||
const context: ContextInfo = {
|
||||
stream,
|
||||
topic: undefined, // 暂时不设置Topic,使用默认的General
|
||||
topic,
|
||||
};
|
||||
|
||||
this.logger.debug('上下文注入完成', {
|
||||
@@ -746,7 +767,9 @@ export class SessionManagerService {
|
||||
|
||||
try {
|
||||
// 获取所有地图的玩家列表
|
||||
const mapIds = ['novice_village', 'tavern', 'market']; // TODO: 从配置获取
|
||||
const mapIds = this.configManager.getAllMapIds().length > 0
|
||||
? this.configManager.getAllMapIds()
|
||||
: DEFAULT_MAP_IDS;
|
||||
|
||||
for (const mapId of mapIds) {
|
||||
const socketIds = await this.getSocketsInMap(mapId);
|
||||
@@ -912,7 +935,9 @@ export class SessionManagerService {
|
||||
async getSessionStats(): Promise<SessionStats> {
|
||||
try {
|
||||
// 获取所有地图的玩家列表
|
||||
const mapIds = ['novice_village', 'tavern', 'market']; // TODO: 从配置获取
|
||||
const mapIds = this.configManager.getAllMapIds().length > 0
|
||||
? this.configManager.getAllMapIds()
|
||||
: DEFAULT_MAP_IDS;
|
||||
const mapDistribution: Record<string, number> = {};
|
||||
let totalSessions = 0;
|
||||
|
||||
@@ -972,7 +997,9 @@ export class SessionManagerService {
|
||||
}
|
||||
} else {
|
||||
// 获取所有地图的会话
|
||||
const mapIds = ['novice_village', 'tavern', 'market']; // TODO: 从配置获取
|
||||
const mapIds = this.configManager.getAllMapIds().length > 0
|
||||
? this.configManager.getAllMapIds()
|
||||
: DEFAULT_MAP_IDS;
|
||||
for (const map of mapIds) {
|
||||
const socketIds = await this.getSocketsInMap(map);
|
||||
for (const socketId of socketIds) {
|
||||
|
||||
Reference in New Issue
Block a user