diff --git a/game-server/app/dao/userDao.js b/game-server/app/dao/userDao.js index d1e7ec8..ea4b265 100644 --- a/game-server/app/dao/userDao.js +++ b/game-server/app/dao/userDao.js @@ -51,16 +51,16 @@ class UserDao { if (limit>20) { throw new Error(`limit too large: ${limit}`); } - const query = `SELECT idx, account_id, CAST(name as CHAR) as name FROM t_user WHERE idx>? AND (CAST(account_id as CHAR) LIKE ? OR CAST(name as CHAR) LIKE ?) LIMIT ?`; + const query = `SELECT idx, account_id, CAST(name as CHAR) as name FROM t_user WHERE idx>? AND (CAST(account_id as CHAR) = ? OR CAST(name as CHAR) LIKE ?) LIMIT ?`; const results = await query_game(query, [ last_idx, - "%" + name + "%", + name, "%" + name + "%", limit, ]); if (results.length === 0) { - throw new Error(`User not found: ${name}`); + return { users: [], last_idx: last_idx }; } const users = results.map((user) => { diff --git a/game-server/app/servers/friend/handler/friendHandler.js b/game-server/app/servers/friend/handler/friendHandler.js index d5aeb3f..6f6e6ed 100644 --- a/game-server/app/servers/friend/handler/friendHandler.js +++ b/game-server/app/servers/friend/handler/friendHandler.js @@ -181,7 +181,7 @@ class FriendHandler { msg: "User added to blacklist successfully.", }); } catch (err) { - next(null, { code: Code.FAIL, msg: "Failed to add user to blacklist." }); + next(null, { code: Code.FAIL, msg: err.message }); } } @@ -411,7 +411,7 @@ class FriendHandler { * } * */ - async findUser({ name, last_idx, limit }, { uid }, next) { + async findUser({ name, last_idx = 0, limit = 10 }, { uid }, next) { try { const users = await this.friendService.findUser( name, diff --git a/proxy/client.test.js b/proxy/client.test.js index 9412f1c..0171f97 100644 --- a/proxy/client.test.js +++ b/proxy/client.test.js @@ -5,11 +5,11 @@ const { Message } = require("./Message"); const port = 4999; // const host = "192.168.100.173"; // const host = "62.234.46.11"; -const host = "r2.cebggame.com"; -// const host = "192.168.100.83"; -//const test_uuid = "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340"; +// const host = "r2.cebggame.com"; +const host = "192.168.100.83"; +const test_uuid = "6516_2006_0xef59f6cc4d190a0ae576c46d4583e92b61174340"; // const test_uuid = "6516_2006_0xa5069f54f2ed021e0ac47dbb385420a0d5f41be3"; -const test_uuid = "6517_2006_0_104162729566475397176"; +// const test_uuid = "6517_2006_0_104162729566475397176"; const stick = new Stick(1024); stick.setMaxBodyLen(MaxBodyLen["32K"], true); @@ -151,8 +151,8 @@ describe("client", () => { }); test("find User", async () => { - msg = await rpc("friend.friendHandler.findUser", { name: "xiao" }); - console.log(msg); + msg = await rpc("friend.friendHandler.findUser", { name: "6513_2006_md9nVaGIooStTM1D56NLblLosFhWhgxB3", last_idx: 0, limit: 5 }); + console.log(JSON.stringify(msg, null, 2)); expect(msg.code).toBe(200); }); diff --git a/proxy/friend.test.js b/proxy/friend.test.js index c5aeb42..a57b4a2 100644 --- a/proxy/friend.test.js +++ b/proxy/friend.test.js @@ -46,7 +46,7 @@ describe('add friend self', () => { test('add a black', async () => { const msg = await tbc.rpc("friend.friendHandler.addToBlackList", { bid: userA, }); console.log(msg); - expect(msg.code).toBe(200); + expect(msg.code).toBe(500); }); test('end', async()=>{ @@ -158,7 +158,7 @@ describe("accept friend", () => { }); test("delete a friend", async () => { - msg = await rpc("friend.friendHandler.deleteFriend", { fid: userB, }); + msg = await rpc("friend.friendHandler.deleteFriend", { fid: userA, }); console.log(msg); expect(msg.code).toBe(200); });