r2/game-server/app/services/chatService.js
lightings 9e9a9f9519 ...
2023-04-19 18:49:58 +08:00

57 lines
1.5 KiB
JavaScript

class ChatService {
constructor(app) {
this.app = app;
}
worldChat(msg, cb) {
// 获取所有chat-server服务器
const chatServers = this.app.getServersByType("chat");
// 随机选择一个chat-server
const selectedServer = chatServers[Math.floor(Math.random() * chatServers.length)];
// 向选定的chat-server发送世界聊天请求
// this.app.rpcInvoke(selectedServer.id, {
// namespace: "user",
// service: "chatRemote",
// method: "worldChat",
// args: [msg]
// }, cb);
}
teamChat(teamId, msg, cb) {
// 获取所有chat-server服务器
const chatServers = this.app.getServersByType("chat");
// 随机选择一个chat-server
const selectedServer = chatServers[Math.floor(Math.random() * chatServers.length)];
// 向选定的chat-server发送队伍聊天请求
// this.app.rpcInvoke(selectedServer.id, {
// namespace: "user",
// service: "chatRemote",
// method: "teamChat",
// args: [teamId, msg]
// }, cb);
}
kick(uid, cb) {
// 获取所有chat-server服务器
const chatServers = this.app.getServersByType("chat");
// 随机选择一个chat-server
const selectedServer = chatServers[Math.floor(Math.random() * chatServers.length)];
// // 向选定的chat-server发送踢出请求
// this.app.rpcInvoke(selectedServer.id, {
// namespace: "user",
// service: "chatRemote",
// method: "kick",
// args: [uid]
// }, cb);
}
}
module.exports = function(app) {
return new ChatService(app);
};