...
This commit is contained in:
parent
1d1ed55181
commit
9e9a9f9519
@ -190,6 +190,11 @@ class GuildDao {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 插入公会成员
|
||||
// gId 公会id
|
||||
// uId 用户id
|
||||
// rank 成员等级
|
||||
// state 申请状态 0-未通过 1-被邀请 2-已通过
|
||||
async insertGuildMember(gId, uId, rank, state) {
|
||||
const qfm = "SELECT * FROM t_guild_members where uid=?";
|
||||
const rfm = await query_guild(qfm, [uId]);
|
||||
|
@ -120,6 +120,7 @@ class ChatHandler {
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "route": "onAdd",
|
||||
* "user": "5f9f9f9f9f9f9f9f9f9f9f9f"
|
||||
* }
|
||||
@ -169,6 +170,12 @@ class ChatHandler {
|
||||
* @apiGroup Chat
|
||||
* @apiParam {String} user 用户ID
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "route": "onLeave",
|
||||
* "user": "5f9f9f9f9f9f9f9f9f9f9f9f"
|
||||
* }
|
||||
*/
|
||||
channel.pushMessage({
|
||||
code: Code.OK,
|
||||
@ -212,18 +219,13 @@ class ChatHandler {
|
||||
*
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* {
|
||||
* "code": 200,
|
||||
* "route": "onChat",
|
||||
* "from": "username",
|
||||
* "content": "content",
|
||||
* "type": "world"
|
||||
* }
|
||||
*
|
||||
* @apiErrorExample {json} Error-Response:
|
||||
* {
|
||||
* "code": 500,
|
||||
* "msg": "Failed to push message."
|
||||
* }
|
||||
*
|
||||
*/
|
||||
channel.pushMessage({
|
||||
code: Code.OK,
|
||||
|
@ -2,9 +2,32 @@ module.exports = function(app) {
|
||||
return new ChatRemote(app, app.get('chatService'));
|
||||
}
|
||||
|
||||
var ChatRemote = function(app, chatService) {
|
||||
this.app = app;
|
||||
this.chatService = chatService;
|
||||
}
|
||||
class ChatRemote {
|
||||
constructor(app, chatService) {
|
||||
this.app = app;
|
||||
this.chatService = chatService;
|
||||
this.channelService = app.get('channelService');
|
||||
}
|
||||
|
||||
var handler = ChatRemote.prototype;
|
||||
add = function (uid, name, channelName, cb) {
|
||||
this.chatService.add(uid, name, channelName, cb);
|
||||
cb();
|
||||
};
|
||||
|
||||
leave = function(uid, channelName, cb) {
|
||||
this.chatService.leave(uid, channelName, cb);
|
||||
cb();
|
||||
}
|
||||
|
||||
kick = function(uid, sid, cb) {
|
||||
|
||||
const channelId = "worldChannel";
|
||||
const channel = this.channelService.getChannel(channelId, false);
|
||||
if (channel) {
|
||||
channel.leave(uid, sid);
|
||||
}
|
||||
|
||||
this.chatService.kick(uid, cb);
|
||||
cb();
|
||||
}
|
||||
}
|
||||
|
@ -40,14 +40,17 @@ Handler.prototype.entry = function (msg, session, next) {
|
||||
console.log(`-------entry ${session.id} : ${uid}`);
|
||||
|
||||
// 重复登录检查
|
||||
// if( !! sessionService.getByUid(uid)) {
|
||||
// console.log(`-------kick ${session.id} : ${uid}`)
|
||||
// sessionService.kick(uid, ()=>{
|
||||
// console.log(`-------kicked ${session.id} : ${uid}`)
|
||||
// bindUser();
|
||||
// return;
|
||||
// })
|
||||
// }
|
||||
const oldSession = sessionService.getByUid(uid);
|
||||
if (oldSession) {
|
||||
oldSession.forEach(element => {
|
||||
console.log(element);
|
||||
console.log(`-------kick ${element.uid} : ${element.uid}`)
|
||||
sessionService.kick(element.uid, ()=>{
|
||||
console.log(`-------kicked ${element.id} : ${element.uid}`)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
(bindUser.bind(this))();
|
||||
|
||||
async function bindUser() {
|
||||
@ -74,15 +77,9 @@ var onUserLeave = function (app, session, reason) {
|
||||
if (!session || !session.uid) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(session);
|
||||
const channelId = "worldChannel";
|
||||
const channel = this.channelService.getChannel(channelId, false);
|
||||
if (channel) {
|
||||
channel.leave(session.uid, session.get("sid"));
|
||||
}
|
||||
|
||||
logger.debug(`onUserLeave ${session.id} : ${session.uid}`);
|
||||
|
||||
app.rpc.chat.chatRemote.kick(session, session.uid, session.get('sid'), null);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -90,7 +90,6 @@ class Handler {
|
||||
* @api {post} guild.guildHandler.joinGuild joinGuild 加入工会
|
||||
* @apiGroup Guild
|
||||
* @apiParam {String} guildId 工会ID
|
||||
* @apiParam {String} uid 用户ID
|
||||
*
|
||||
* @apiSuccess {Number} code 状态码
|
||||
* @apiSuccess {String} msg 消息
|
||||
@ -110,7 +109,8 @@ class Handler {
|
||||
*/
|
||||
async joinGuild(msg, session, next) {
|
||||
try {
|
||||
const { uid, guildId } = msg;
|
||||
const { guildId } = msg;
|
||||
const { uid } = session;
|
||||
const result = await this.guildService.joinGuild(uid, guildId);
|
||||
const response = result
|
||||
? { code: Code.OK, msg: "Join guild done" }
|
||||
|
@ -11,12 +11,12 @@ class ChatService {
|
||||
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);
|
||||
// this.app.rpcInvoke(selectedServer.id, {
|
||||
// namespace: "user",
|
||||
// service: "chatRemote",
|
||||
// method: "worldChat",
|
||||
// args: [msg]
|
||||
// }, cb);
|
||||
}
|
||||
|
||||
teamChat(teamId, msg, cb) {
|
||||
@ -27,12 +27,28 @@ class ChatService {
|
||||
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);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ client.on("close", function () {
|
||||
|
||||
stick.onBody((msgId, data) => {
|
||||
const len = data.readUInt16LE(0);
|
||||
const buf1 = data.subarray(2, 2+len);
|
||||
const buf1 = data.subarray(2, 2 + len);
|
||||
const msg = JSON.parse(buf1);
|
||||
console.log(msgId, msg);
|
||||
data = JSON.parse(buf1);
|
||||
@ -45,7 +45,7 @@ stick.onBody((msgId, data) => {
|
||||
const stick = new Stick(1024);
|
||||
stick.setMaxBodyLen(MaxBodyLen["32K"], true);
|
||||
game = new net.Socket();
|
||||
|
||||
let step = 0;
|
||||
game.connect(data.port, data.host, function () {
|
||||
console.log("Connected");
|
||||
let param = {
|
||||
@ -67,15 +67,42 @@ stick.onBody((msgId, data) => {
|
||||
});
|
||||
game.on("data", function (data) {
|
||||
stick.putData(data);
|
||||
game.destroy(); // kill client after server's response
|
||||
});
|
||||
|
||||
stick.onBody((msgId, data) => {
|
||||
const len = data.readUInt16LE(0);
|
||||
const buf1 = data.subarray(2, 2+len);
|
||||
const buf1 = data.subarray(2, 2 + len);
|
||||
const msg = JSON.parse(buf1);
|
||||
|
||||
console.log(msgId, msg);
|
||||
switch (step) {
|
||||
case 0:
|
||||
let param = {
|
||||
serial: 123457,
|
||||
route: "chat.chatHandler.joinWorldChannel",
|
||||
params: {
|
||||
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
|
||||
},
|
||||
};
|
||||
game.write(
|
||||
stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param))
|
||||
);
|
||||
step++;
|
||||
break;
|
||||
case 1:
|
||||
let param1 = {
|
||||
serial: 123457,
|
||||
route: "chat.chatHandler.worldChat",
|
||||
params: {
|
||||
content: "test world message",
|
||||
},
|
||||
};
|
||||
game.write(
|
||||
stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param1))
|
||||
);
|
||||
step++;
|
||||
break;
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user