世界消息
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user