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); } } module.exports = function(app) { return new ChatService(app); };