This commit is contained in:
lightings 2023-04-20 17:15:42 +08:00
parent ef6718e968
commit 92359be0b9
7 changed files with 3700 additions and 805 deletions

View File

@ -80,6 +80,25 @@ class UserDao {
}
}
async findUser(name, uid) {
const query = `SELECT account_id, name FROM t_user WHERE CAST(name as CHAR) LIKE ?`;
const results = await query_game(query, ["%"+name+"%"]);
if (results.length === 0) {
throw new Error(`User not found: ${name}`);
}
const users = results.map((user) => {
this.getUserInfo(user.account_id);
return {
uid: user.account_id,
name: user.name.toString(),
};
});
return users;
}
}
module.exports = new UserDao();

View File

@ -265,9 +265,7 @@ class FriendHandler {
*/
async getPendingFriendInvitations(msg, { uid }, next) {
try {
const friendInvitations = await friendService.getPendingFriendInvitations(
uid
);
const friendInvitations = await friendService.getPendingFriendInvitations(uid);
next(null, { code: Code.OK, friendInvitations });
} catch (err) {
next(null, {
@ -276,6 +274,15 @@ class FriendHandler {
});
}
}
async findUser({name}, {uid}, next) {
try {
const users = await friendService.findUser(name, uid);
next(null, {code: Code.OK, users});
} catch (err) {
next(null, {code: Code.FAIL, msg: "Failed to find user."});
}
}
}
module.exports = function () {

View File

@ -58,6 +58,11 @@ class FriendService {
const myIdx = await userDao.getUserIdx(uid);
return await friendDao.getInviteFriendRequests(myIdx);
}
async findUser(name, uid) {
const users = await userDao.findUser(name, uid);
return users;
}
}
module.exports = new FriendService();

View File

@ -87,6 +87,10 @@ stick.onBody((msgId, data) => {
console.log(msg);
msg = await rpc("chat.chatHandler.worldChat", { content: "hello" });
console.log(msg);
msg = await rpc("friend.friendHandler.findUser", { name: "Xiao" });
console.log(msg);
game.destroy();
});
game.on("error", function (error) {

View File

@ -30,7 +30,7 @@ game.on("error", function (error) {
console.log("Error: " + error);
});
game.on("close", function () {
console.log("Connection closed");
// console.log("Connection closed");
});
game.on("data", function (data) {
stickGame.putData(data);
@ -88,17 +88,6 @@ stickGame.onBody((msgId, data) => {
beforeAll(() => {
return new Promise((resolve, reject) => {
client.connect(port, host, function () {
let param = {
serial: 123456,
route: "gate.gateHandler.queryEntry",
params: {
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
},
};
client.write(stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param)));
});
stick.onBody((msgId, data) => {
const len = data.readUInt16LE(0);
const buf1 = data.subarray(2, 2 + len);
@ -111,7 +100,18 @@ beforeAll(() => {
game.connect(data.port, data.host, async function () {
resolve();
});
}, 500);
}, 0);
});
client.connect(port, host, function () {
let param = {
serial: 123456,
route: "gate.gateHandler.queryEntry",
params: {
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
},
};
client.write(stick.makeData(Message.TYPE_REQUEST, JSON.stringify(param)));
});
});
});
@ -120,9 +120,7 @@ describe("client", () => {
let msg;
test("entry", async () => {
msg = await rpc("connector.entryHandler.entry", {
uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340",
});
msg = await rpc("connector.entryHandler.entry", { uid: "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340", });
console.log(msg);
expect(msg.code).toBe(200);
});
@ -145,4 +143,14 @@ describe("client", () => {
expect(msg.code).toBe(200);
});
test("find User", async () => {
msg = await rpc("friend.friendHandler.findUser", { name: "xiao" });
console.log(msg);
expect(msg.code).toBe(200);
});
test('end', async()=>{
game.destroy();
})
});

4420
proxy/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"jest": "^29.5.0"
"devDependencies": {
"jest": "^26.6.3"
}
}