Skip to content

Commit

Permalink
v6.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
evolutionleo committed Jan 7, 2024
1 parent 33c9f66 commit 9786a12
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
22 changes: 13 additions & 9 deletions JavascriptServer/cmd/handlers/friends.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down
33 changes: 28 additions & 5 deletions JavascriptServer/concepts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -389,14 +410,16 @@ 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;

// 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;
}


Expand Down
4 changes: 2 additions & 2 deletions JavascriptServer/concepts/matchmaking/matchmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion JavascriptServer/game_modes/1v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default new GameMode({
name: '1v1',
teams: 2,
team_size: 1,
ranked: true
ranked: false
});
Binary file modified Release/GMClient.zip
Binary file not shown.
Binary file modified Release/JSServer.zip
Binary file not shown.
Binary file modified Release/TSServer.zip
Binary file not shown.
Binary file modified Release/Warp.yymps
Binary file not shown.
4 changes: 2 additions & 2 deletions TypescriptServer/src/concepts/matchmaking/matchmaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion TypescriptServer/src/game_modes/1v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default new GameMode({
name: '1v1',
teams: 2,
team_size: 1,
ranked: true
ranked: false
});

0 comments on commit 9786a12

Please sign in to comment.