世界消息

This commit is contained in:
luying
2021-01-22 09:46:40 +08:00
parent b2785450ac
commit 65320fb9e0
3 changed files with 65 additions and 21 deletions

View File

@@ -14,6 +14,7 @@ import { UserGuildApplyModel } from '../../../db/UserGuildApply';
import { hasStructureConsume, getStructureConsume, gameData } from '../../../pubUtils/data';
import { GuildRecModel } from '../../../db/GuildRec';
import { MailModel } from '../../../db/Mail';
import { getRedis } from '../../../services/redisService';
export default function (app: Application) {
return new GuildHandler(app);
@@ -717,4 +718,26 @@ export class GuildHandler {
return resResult(STATUS.SUCCESS, { isSuccess: true });
}
// 团长发送世界频道
async recruit(msg: { code: string, info: string }, session: BackendSession) {
const roleId = session.get('roleId');
// const roleName = session.get('roleName');
const sid = session.get('sid');
const serverId = session.get('serverId');
const { code, info } = msg;
const checkResult = await checkAuth(GUILD_OPERATE.RECRUIT, roleId, code);
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
const guild = await GuildModel.findByCode(code, serverId);
if(!guild) return resResult(STATUS.GUILD_NOT_FOUND);
// 发送世界频道消息
this.app.rpc.chat.chatRemote.sendWorldMessage.toServer('chat-server-1', serverId, { info });
return resResult(STATUS.SUCCESS, { isSuccess: true });
}
}

View File

@@ -1,4 +1,4 @@
import { Application, ChannelService, FrontendSession, RemoterClass } from 'pinus';
import { Application, ChannelService, FrontendSession, RemoterClass, pinus } from 'pinus';
import { resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
@@ -27,27 +27,28 @@ export class ChatRemote {
private channelService: ChannelService;
/**
* Add user into chat channel.
* 加入世界频道(分服).
*
* @param {String} uid unique id for user
* @param {String} roleId roleId
* @param {String} sid server id
* @param {String} name channel name
* @param {boolean} flag channel parameter
* @param {String} serverId 区id
* @param {boolean} flag 是否创建新channel
*
*/
public async add(uid: string, sid: string, name: string, flag: boolean) {
public async addWorldChannel(roleId: string, serverId: number, flag: boolean = true) {
const name = `world${serverId}`;
const sid = this.app.getServerId();
let channel = this.channelService.getChannel(name, flag);
let username = uid.split('*')[0];
let param = {
user: username
roleId
};
channel.pushMessage('onAdd', resResult(STATUS.SUCCESS, param));
channel.pushMessage('onWorldAdd', resResult(STATUS.SUCCESS, param));
if (!!channel) {
channel.add(uid, sid);
channel.add(roleId, sid);
}
return this.get(name, flag);
return this.getWorldChannel(name);
}
/**
@@ -59,7 +60,7 @@ export class ChatRemote {
* @return {Array} users uids in channel
*
*/
private get(name: string, flag: boolean) {
private getWorldChannel(name: string, flag: boolean = true): Array<any> {
let users: string[] = [];
let channel = this.channelService.getChannel(name, flag);
if (!!channel) {
@@ -72,23 +73,42 @@ export class ChatRemote {
}
/**
* Kick user out chat channel.
* 踢出世界频道.
*
* @param {String} uid unique id for user
* @param {String} roleId roleId
* @param {String} sid server id
* @param {String} name channel name
* @param {String} serverId 区id
*
*/
public async kick(uid: string, sid: string, name: string) {
public async kickWorldChannel(roleId: string, serverId: number) {
const name = `world${serverId}`;
const sid = this.app.getServerId();
let channel = this.channelService.getChannel(name, false);
// leave channel
if (!!channel) {
channel.leave(uid, sid);
channel.leave(roleId, sid);
}
let username = uid.split('*')[0];
let param = {
user: username
roleId
};
channel.pushMessage('onLeave', resResult(STATUS.SUCCESS, param));
}
/**
* 向世界频道全服发送消息
*
* @param serverId 区id
* @param param 信息
*/
public async sendWorldMessage(serverId: number, param: any) {
const name = `world${serverId}`;
let channel = this.channelService.getChannel(name, false);
// leave channel
if (!!channel) {
channel.pushMessage('onWorldMessage', resResult(STATUS.SUCCESS, param));
}
}
}

View File

@@ -78,7 +78,8 @@ export class EntryHandler {
// put user into channel
// console.log(JSON.stringify(self.app.rpc.battle))
// await self.app.rpc.battle.battleRemote.add.route(session)(role.roleId, self.app.get('serverId'), role.serverId, true);
// let users = await self.app.rpc.chat.chatRemote.add.route(session)(role.roleId, self.app.get('serverId'), rid, true);
await self.app.rpc.chat.chatRemote.addWorldChannel.route(session)(role.roleId, serverId);
let heros = await HeroModel.findByRole(role.roleId);
let equips = await EquipModel.findbyRole(role.roleId);
let items = await ItemModel.findbyRole(role.roleId);
@@ -118,7 +119,7 @@ export class EntryHandler {
let channel = channelService.getChannel(roleId, true);
channel.leave(roleId, sid);
// this.app.rpc.battle.battleRemote.kick.route(session)(roleId, this.app.get('serverId'), serverId);
// this.app.rpc.chat.chatRemote.kick.route(session, true)(session.uid, this.app.get('serverId'), session.get('rid'));
this.app.rpc.chat.chatRemote.kickWorldChannel.route(session, true)(roleId, serverId);
}