diff --git a/README.md b/README.md index 837b5ac..e5a99e5 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,12 @@ An implementation of osu!bancho in Javascript ### Features: - Multiplayer + Invites - Spectator - - User Panel (Missing Friends) + - User Panel + - Friends List - Chat & Channels - Private Messages ### Currently unimplemented things: - - Friends List - Bot ## Bugs: diff --git a/server/Packets/AddFriend.js b/server/Packets/AddFriend.js new file mode 100644 index 0000000..4cf64fa --- /dev/null +++ b/server/Packets/AddFriend.js @@ -0,0 +1,5 @@ +const DatabaseHelper = require("../DatabaseHelper.js"); + +module.exports = function(CurrentUser, FriendToAdd) { + DatabaseHelper.getFromDB(`INSERT INTO friends (user, friendsWith) VALUES (${CurrentUser.id}, ${FriendToAdd});`); +} \ No newline at end of file diff --git a/server/Packets/RemoveFriend.js b/server/Packets/RemoveFriend.js new file mode 100644 index 0000000..d072368 --- /dev/null +++ b/server/Packets/RemoveFriend.js @@ -0,0 +1,5 @@ +const DatabaseHelper = require("../DatabaseHelper.js"); + +module.exports = function(CurrentUser, FriendToRemove) { + DatabaseHelper.getFromDB(`DELETE FROM friends WHERE user = ${CurrentUser.id} AND friendsWith = ${FriendToRemove} LIMIT 1`); +} \ No newline at end of file diff --git a/server/loginHandler.js b/server/loginHandler.js index 30d9bd5..90af5fb 100644 --- a/server/loginHandler.js +++ b/server/loginHandler.js @@ -86,8 +86,14 @@ module.exports = function(req, res, loginInfo) { osuPacketWriter.ProtocolNegotiation(19); // Permission level 4 is osu!supporter osuPacketWriter.LoginPermissions(4); + // Construct user's friends list + const userFriends = DatabaseHelper.getListFromDB(`SELECT friendsWith FROM friends WHERE user = ${userClass.id}`); + let friendsArray = []; + for (let i = 0; i < userFriends.length; i++) { + friendsArray.push(userFriends[i].friendsWith); + } // Send user's friends list - // TODO: friends? Haha, you have no friends! + osuPacketWriter.FriendsList(friendsArray); // Set title screen image osuPacketWriter.TitleUpdate("http://puu.sh/jh7t7/20c04029ad.png|https://osu.ppy.sh/news/123912240253"); diff --git a/server/serverHandler.js b/server/serverHandler.js index 80d2dd2..5ddb611 100644 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -87,6 +87,8 @@ const ChangeAction = require("./Packets/ChangeAction.js"), SendPrivateMessage = require("./Packets/SendPrivateMessage.js"), Multiplayer = require("./Multiplayer.js"), ChannelPart = require("./Packets/ChannelPart.js"), + AddFriend = require("./Packets/AddFriend.js"), + RemoveFriend = require("./Packets/RemoveFriend.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), UserPresence = require("./Packets/UserPresence.js"), UserStatsRequest = require("./Packets/UserStatsRequest.js"), @@ -246,6 +248,14 @@ module.exports = function(req, res) { ChannelPart(userClass, CurrentPacket.data); break; + case packetIDs.client_friendAdd: + AddFriend(userClass, CurrentPacket.data); + break; + + case packetIDs.client_friendRemove: + RemoveFriend(userClass, CurrentPacket.data); + break; + case packetIDs.client_userStatsRequest: UserStatsRequest(userClass, CurrentPacket.data); break;