diff --git a/JavascriptServer/cmd/handlers/friends.js b/JavascriptServer/cmd/handlers/friends.js index e2fd8d7..a64a423 100644 --- a/JavascriptServer/cmd/handlers/friends.js +++ b/JavascriptServer/cmd/handlers/friends.js @@ -1,4 +1,5 @@ import addHandler from "#cmd/handlePacket"; +import FriendRequest from "#schemas/friend_request"; addHandler('friend req inc', async (c, data) => { let from_profiles = await c.getIncomingFriendRequests(); @@ -16,18 +17,20 @@ addHandler('friend list', async (c, data) => { }); addHandler('friend req send', (c, data) => { - c.friendRequestSend(data.friend); + if (!c.profile.friends.includes(data.friend._id) && !FriendRequest.exists({ sender: data.friend._id })) + c.friendRequestSend(data.friend); + c.send({ cmd: 'friend req sent', to: data.friend.name }); }); -addHandler('friend req accept', (c, data) => { - c.friendRequestAccept(data.friend); - c.send({ cmd: 'friend req accepted', from: data.friend.name }); +addHandler('friend req accept', async (c, data) => { + if (await c.friendRequestAccept(data.friend)) + c.send({ cmd: 'friend req accepted', from: data.friend.name }); }); -addHandler('friend req reject', (c, data) => { - c.friendRequestReject(data.friend); - c.send({ cmd: 'friend req rejected', from: data.friend.name }); +addHandler('friend req reject', async (c, data) => { + if (await c.friendRequestReject(data.friend)) + c.send({ cmd: 'friend req rejected', from: data.friend.name }); }); addHandler('friend req cancel', (c, data) => { @@ -36,8 +39,9 @@ addHandler('friend req cancel', (c, data) => { }); addHandler('friend add', async (c, data) => { - c.friendAdd(data.friend); - c.send({ cmd: 'friend added', name: data.friend.name }); + let res = await c.friendAdd(data.friend); + if (res) + c.send({ cmd: 'friend added', name: data.friend.name }); }); addHandler('friend remove', async (c, data) => { diff --git a/JavascriptServer/concepts/client.js b/JavascriptServer/concepts/client.js index ad417d9..55f916b 100644 --- a/JavascriptServer/concepts/client.js +++ b/JavascriptServer/concepts/client.js @@ -274,6 +274,17 @@ export default class Client extends SendStuff { return await FriendRequest.findOutgoing(this.profile._id); } + async friendCanAdd(friend) { + friend = friend instanceof Client ? friend.profile : friend; + if (!this.logged_in) + return false; + + let this_id = this.profile._id; + let friend_id = friend._id; + + return this_id != friend_id && !(await this.getFriendIds()).includes(friend_id); + } + /** * Send a new friend request or accept an existing one from the user * @param friend {IProfile|Client} @@ -282,11 +293,13 @@ export default class Client extends SendStuff { friend = friend instanceof Client ? friend.profile : friend; if (!this.logged_in) return false; + if (!await this.friendCanAdd(friend)) + return false; let sender_id = this.profile._id; let receiver_id = friend._id; - let friend_exists = this.profile.friends.includes(receiver_id); + let friend_exists = this.profile.friends.some(friend_id => friend_id === receiver_id); if (friend_exists) { // already friends trace('already friends'); return false; @@ -344,13 +357,16 @@ export default class Client extends SendStuff { async friendRequestAccept(user_from) { user_from = user_from instanceof Client ? user_from.profile : user_from; if (!this.logged_in) - return; + return false; // find a request FROM the user let inc_request_id = await this.friendRequestFind(user_from, this); if (inc_request_id) { await FriendRequest.accept(inc_request_id); // this method also updates the .friends arrays + return true; } + + return false; } /** @@ -359,13 +375,16 @@ export default class Client extends SendStuff { async friendRequestReject(user_from) { user_from = user_from instanceof Client ? user_from.profile : user_from; if (!this.logged_in) - return; + return false; // find a request FROM the user let inc_request_id = await this.friendRequestFind(user_from, this); if (inc_request_id) { await FriendRequest.reject(inc_request_id); + return true; } + + return false; } /** @@ -374,13 +393,15 @@ export default class Client extends SendStuff { async friendRequestCancel(user_to) { user_to = user_to instanceof Client ? user_to.profile : user_to; if (!this.logged_in) - return null; + return false; // find a request from us TO the user let req_id = await this.friendRequestFind(this, user_to); if (req_id) { await FriendRequest.cancel(req_id); + return true; } + return false; } /** @@ -389,7 +410,7 @@ export default class Client extends SendStuff { async friendRemove(friend) { friend = friend instanceof Client ? friend.profile : friend; if (!this.logged_in) - return; + return false; let my_id = this.profile._id; let friend_id = friend._id; @@ -397,6 +418,8 @@ export default class Client extends SendStuff { // delete from each others' profiles await Profile.findByIdAndUpdate(my_id, { $pull: { friends: friend_id } }); await Profile.findByIdAndUpdate(friend_id, { $pull: { friends: my_id } }); + + return true; } diff --git a/JavascriptServer/concepts/matchmaking/matchmaker.js b/JavascriptServer/concepts/matchmaking/matchmaker.js index 2fe5b27..879a5fd 100644 --- a/JavascriptServer/concepts/matchmaking/matchmaker.js +++ b/JavascriptServer/concepts/matchmaking/matchmaker.js @@ -48,8 +48,8 @@ export default class MatchMaker { // sort once again potential_pool.sort((p1, p2) => p1.mmr - p2.mmr); - if (potential_pool.length > 0) - trace('pp', potential_pool.map(t => t.by.name)); + // if (potential_pool.length > 0) + // trace('pp', potential_pool.map(t => (t.by as Client).name)); // define the pool of players/parties with close enough mmr for the match diff --git a/JavascriptServer/game_modes/1v1.js b/JavascriptServer/game_modes/1v1.js index 919637a..76f4b41 100644 --- a/JavascriptServer/game_modes/1v1.js +++ b/JavascriptServer/game_modes/1v1.js @@ -4,5 +4,5 @@ export default new GameMode({ name: '1v1', teams: 2, team_size: 1, - ranked: true + ranked: false }); diff --git a/Release/GMClient.zip b/Release/GMClient.zip index f8704b8..2e6a853 100644 Binary files a/Release/GMClient.zip and b/Release/GMClient.zip differ diff --git a/Release/JSServer.zip b/Release/JSServer.zip index df3eb2a..932e488 100644 Binary files a/Release/JSServer.zip and b/Release/JSServer.zip differ diff --git a/Release/TSServer.zip b/Release/TSServer.zip index 03e3ad9..00a7d70 100644 Binary files a/Release/TSServer.zip and b/Release/TSServer.zip differ diff --git a/Release/Warp.yymps b/Release/Warp.yymps index f8704b8..936748b 100644 Binary files a/Release/Warp.yymps and b/Release/Warp.yymps differ diff --git a/TypescriptServer/src/concepts/matchmaking/matchmaker.ts b/TypescriptServer/src/concepts/matchmaking/matchmaker.ts index 0451188..d71cd76 100644 --- a/TypescriptServer/src/concepts/matchmaking/matchmaker.ts +++ b/TypescriptServer/src/concepts/matchmaking/matchmaker.ts @@ -53,8 +53,8 @@ export default class MatchMaker { // sort once again potential_pool.sort((p1, p2) => p1.mmr - p2.mmr); - if (potential_pool.length > 0) - trace('pp', potential_pool.map(t => (t.by as Client).name)); + // if (potential_pool.length > 0) + // trace('pp', potential_pool.map(t => (t.by as Client).name)); // define the pool of players/parties with close enough mmr for the match diff --git a/TypescriptServer/src/game_modes/1v1.ts b/TypescriptServer/src/game_modes/1v1.ts index 6e492ac..caf48f5 100644 --- a/TypescriptServer/src/game_modes/1v1.ts +++ b/TypescriptServer/src/game_modes/1v1.ts @@ -4,5 +4,5 @@ export default new GameMode({ name: '1v1', teams: 2, team_size: 1, - ranked: true + ranked: false }); \ No newline at end of file