优化:抽象推送方法

This commit is contained in:
luying
2022-04-08 20:38:54 +08:00
parent a64faac7cd
commit f486a8d8a5
38 changed files with 475 additions and 1257 deletions

View File

@@ -2,7 +2,7 @@ import { Application, BackendSession, ChannelService, HandlerService, } from 'pi
import { resResult, getRandEelm, shouldRefresh, sortArrRandom } from '../../../pubUtils/util';
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE, REDIS_KEY, GUILD_SELECT, USER_GUILD_SELECT, TASK_TYPE, DEBUG_MAGIC_WORD, CHANNEL_PREFIX, MSG_TYPE, MSG_SOURCE, ITEM_CHANGE_REASON, TA_EVENT, GUILD_DISMISS_WAY, GUILD_MASTER_CHANGE_WAY, GUILD_QUIT_WAY } from '../../../consts';
import { UserGuildModel, UserGuildType } from '../../../db/UserGuild';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly, getMyGuildInfo, refreshUserGuild, setUserGuildSession, getInvitationList } from '../../../services/guildService';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly, getMyGuildInfo, refreshUserGuild, setUserGuildSession, getInvitationList, addGuildRecord, pushChangeGuildLeader, pushGuildMemberQuit, pushGuildDismiss, pushGuildInfoUpdate } from '../../../services/guildService';
import { GuildModel, GuildType, GuildUpdateParam } from '../../../db/Guild';
import { RoleModel, RoleType } from '../../../db/Role';
import { ARMY } from '../../../pubUtils/dicParam';
@@ -92,9 +92,7 @@ export class GuildHandler {
addRoleToGuildChannel(roleId, sid, guild.code);
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, guild.code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
let chatSid = await getGuildChannelSid(guild.code);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await addGuildRecord(roleId, guild.code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
// 返回
const result = { ...guild, rank, myInfo: { ...userGuild, isOnline: true } };
@@ -150,8 +148,7 @@ export class GuildHandler {
if(isAuto != undefined) updateInfo.isAuto = isAuto;
if(icon != undefined) updateInfo.icon = icon;
const guild = await GuildModel.updateInfo(code, updateInfo, {}, select.join(' '));
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { name, notice, introduce, ceLimit, isAuto });
await pushGuildInfoUpdate(code, { name, notice, introduce, ceLimit, isAuto });
if(name != undefined) {
await updateUserInfo(REDIS_KEY.GUILD_INFO, code, [{ field: 'name', value: name }]);
@@ -239,19 +236,17 @@ export class GuildHandler {
// 添加动态
if (auth == GUILD_AUTH.MANAGER) {
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { managerCnt: guild.managerCnt });
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await pushGuildInfoUpdate(code, { managerCnt: guild.managerCnt });
await addGuildRecord(roleId, code, GUILD_REC_TYPE.SET_MANAGER, [role.roleName]);
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_MANAGER, memberRoleId, { sendName: roleName, params: [guild.name] });
} else if (auth == GUILD_AUTH.LEADER) {
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.SET_LEADER, [roleName, role.roleName]);
this.app.rpc.chat.guildRemote.changeLeader.toServer(chatSid, code, guild.managerCnt, role, roleId);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await pushChangeGuildLeader(code, guild.managerCnt, role, roleId);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.SET_LEADER, [roleName, role.roleName]);
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_LEADER, memberRoleId, { sendName: roleName, params: [guild.name] });
reportTAEvent(roleId, TA_EVENT.GUILD_MASTER_CHANGE, { way: GUILD_MASTER_CHANGE_WAY, change_id_after: memberRoleId }, ip);
} else {
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { managerCnt: guild.managerCnt });
await pushGuildInfoUpdate(code, { managerCnt: guild.managerCnt });
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_MEMBER, memberRoleId, { sendName: roleName, params: [guild.name] });
}
@@ -317,12 +312,10 @@ export class GuildHandler {
}
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
// 更新人数增加
let chatSid = await getGuildChannelSid(code);
await pushGuildInfoUpdate(code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
hasGuild = true;
} else { // 不自动加入,插入申请表
await UserGuildApplyModel.createUserGuildApply(role, guild, GUILD_APPLY_TYPE.APPLY);
@@ -365,13 +358,10 @@ export class GuildHandler {
for (let { roleId } of applyList) {
const joinResult = await joinGuild(code, guild.name, guild.lv, roleId, serverId, session);
if (joinResult.status == -1) continue;
let chatSid = await getGuildChannelSid(code);
// 更新人数增加
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
await pushGuildInfoUpdate(code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
roleIds.push(roleId);
}
} else { // 拒绝申请,删除申请
@@ -491,12 +481,10 @@ export class GuildHandler {
return joinResult.resResult;
}
let chatSid = await getGuildChannelSid(code);
// 更新人数增加
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
await pushGuildInfoUpdate(code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [joinResult.roleName]);
code = guild.code;
}
@@ -572,11 +560,8 @@ export class GuildHandler {
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.broadcast(members.map(roleId => { return { roleId, userGuild: null } })); // 更新session
// 删除channel
let chatSid = await getGuildChannelSid(code);
await guildDismisActivity(code, serverId);
this.app.rpc.chat.guildRemote.dismiss.toServer(chatSid, code);
await pushGuildDismiss(code);
let r = new Rank(REDIS_KEY.GUILD_ACTIVE_RANK, { serverId });
await r.removeFromRank({ guildCode: code });
let r2 = new Rank(REDIS_KEY.GUILD_LV_RANK, { serverId });
@@ -613,10 +598,8 @@ export class GuildHandler {
await removeBossRank(code, roleId);
await removeTrainRank(code, roleId, guild.trainId);
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
this.app.rpc.chat.guildRemote.memberQuit.toServer(chatSid, code, roleId, guild, sid);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
await pushGuildMemberQuit(roleId, code, guild, sid);
setUserGuildSession(session, null);
reportTAEvent(roleId, TA_EVENT.GUILD_QUIT, { name: guild.name, way: GUILD_QUIT_WAY.QUIT }, ip);
@@ -646,14 +629,11 @@ export class GuildHandler {
//删除排名信息
await removeBossRank(code, roleId);
await removeTrainRank(code, roleId, guild.trainId);
let chatSid = await getGuildChannelSid(code);
const { isOnline, sid } = await getRoleOnlineInfo(memberRoleId);
this.app.rpc.chat.guildRemote.memberQuit.toServer(chatSid, code, roleId, guild, sid);
await pushGuildMemberQuit(roleId, code, guild, sid);
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.QUIT_GUILD, [role.roleName]);
if(isOnline) {
await this.app.rpc.connector.connectorRemote.setOtherUserGuildSession.toServer(sid,[{ roleId: memberRoleId, userGuild }]);
changeGuildActivity('', serverId, memberRoleId, sid);
@@ -717,11 +697,8 @@ export class GuildHandler {
const guild = await GuildModel.updateInfo(code, { leader: topUser._id }, { managerCnt: managerCntInc }, 'managerCnt name'); // 如果有转让团长设置leader
// 添加动态
let chatSid = await getGuildChannelSid(code);
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.IMPEACH, [oldRoleName, topUser.roleName]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
this.app.rpc.chat.guildRemote.changeLeader.toServer(chatSid, code, guild.managerCnt, topUser, leaderRoleId);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.IMPEACH, [oldRoleName, topUser.roleName]);
await pushChangeGuildLeader(code, guild.managerCnt, topUser, leaderRoleId);
await sendMailByContent(MAIL_TYPE.GUILD_BE_IMPEACH, leaderRoleId, { sendName: roleName, params: [guild.name] });
await sendMailByContent(MAIL_TYPE.GUILD_BE_SET_LEADER, topUser.roleId, { sendName: roleName, params: [guild.name] });
@@ -776,14 +753,12 @@ export class GuildHandler {
const resultStructure = result.structure.find(cur => cur.id == id);
// 修改信息
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { ...result });
await pushGuildInfoUpdate(code, { ...result });
await updateUserInfo(REDIS_KEY.GUILD_INFO, code, [{ field: 'lv', value: result.lv }]);
// 添加动态
const structureName = GUILD_STRUCTURE_NAME.get(id);
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.STRUCTURE_UP, [structureName, resultStructure.lv.toString()]);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.STRUCTURE_UP, [structureName, resultStructure.lv.toString()]);
// 军团频道聊天消息
pushGuildUpStructureMsg(roleId, roleName, result, resultStructure);
@@ -909,10 +884,7 @@ export class GuildHandler {
const { guild, userGuild } = result;
let { activeDaily, activeWeekly } = guild;
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { activeDaily, activeWeekly });
await pushGuildInfoUpdate(code, { activeDaily, activeWeekly });
return resResult(STATUS.SUCCESS, { activeDaily, activeWeekly, myInfo: userGuild });
}
@@ -934,8 +906,7 @@ export class GuildHandler {
// return resResult(STATUS.TOKEN_ERR);
// }
const guild = await GuildModel.updateInfo(code, {}, { fund: count }, 'fund');
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { fund: guild.fund });
await pushGuildInfoUpdate(code, { fund: guild.fund });
return resResult(STATUS.SUCCESS, { code, fund: guild.fund });
}
@@ -1001,10 +972,8 @@ export class GuildHandler {
await removeBossRank(oldCode, roleId);
await removeTrainRank(oldCode, roleId, guild.trainId);
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, oldCode, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
let chatSid = await getGuildChannelSid(oldCode);
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
this.app.rpc.chat.guildRemote.memberQuit.toServer(chatSid, oldCode, roleId, guild, sid);
await addGuildRecord(roleId, oldCode, GUILD_REC_TYPE.QUIT_GUILD, [roleName]);
await pushGuildMemberQuit(roleId, oldCode, guild, sid);
setUserGuildSession(session, userGuild);
}
@@ -1015,12 +984,9 @@ export class GuildHandler {
}
// 添加动态
const rec = await GuildRecModel.createGuildRec(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
await addGuildRecord(roleId, code, GUILD_REC_TYPE.JOIN_GUILD, [roleName]);
// 更新人数增加
let chatSid = await getGuildChannelSid(code);
this.app.rpc.chat.guildRemote.updateInfo.toServer(chatSid, code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
this.app.rpc.chat.guildRemote.addRec.toServer(chatSid, rec);
await pushGuildInfoUpdate(code, { memberCnt: joinResult.memberCnt, guildCe: joinResult.guildCe });
return resResult(STATUS.SUCCESS, { code });
}
}