Implement friends list functionality

This commit is contained in:
tgpethan 2020-09-02 12:19:19 +01:00
parent 888330ea0f
commit 3e15b9ada3
5 changed files with 29 additions and 3 deletions

View file

@ -5,12 +5,12 @@ An implementation of osu!bancho in Javascript
### Features: ### Features:
- Multiplayer + Invites - Multiplayer + Invites
- Spectator - Spectator
- User Panel (Missing Friends) - User Panel
- Friends List
- Chat & Channels - Chat & Channels
- Private Messages - Private Messages
### Currently unimplemented things: ### Currently unimplemented things:
- Friends List
- Bot - Bot
## Bugs: ## Bugs:

View file

@ -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});`);
}

View file

@ -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`);
}

View file

@ -86,8 +86,14 @@ module.exports = function(req, res, loginInfo) {
osuPacketWriter.ProtocolNegotiation(19); osuPacketWriter.ProtocolNegotiation(19);
// Permission level 4 is osu!supporter // Permission level 4 is osu!supporter
osuPacketWriter.LoginPermissions(4); 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 // Send user's friends list
// TODO: friends? Haha, you have no friends! osuPacketWriter.FriendsList(friendsArray);
// Set title screen image // Set title screen image
osuPacketWriter.TitleUpdate("http://puu.sh/jh7t7/20c04029ad.png|https://osu.ppy.sh/news/123912240253"); osuPacketWriter.TitleUpdate("http://puu.sh/jh7t7/20c04029ad.png|https://osu.ppy.sh/news/123912240253");

View file

@ -87,6 +87,8 @@ const ChangeAction = require("./Packets/ChangeAction.js"),
SendPrivateMessage = require("./Packets/SendPrivateMessage.js"), SendPrivateMessage = require("./Packets/SendPrivateMessage.js"),
Multiplayer = require("./Multiplayer.js"), Multiplayer = require("./Multiplayer.js"),
ChannelPart = require("./Packets/ChannelPart.js"), ChannelPart = require("./Packets/ChannelPart.js"),
AddFriend = require("./Packets/AddFriend.js"),
RemoveFriend = require("./Packets/RemoveFriend.js"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"), UserPresence = require("./Packets/UserPresence.js"),
UserStatsRequest = require("./Packets/UserStatsRequest.js"), UserStatsRequest = require("./Packets/UserStatsRequest.js"),
@ -246,6 +248,14 @@ module.exports = function(req, res) {
ChannelPart(userClass, CurrentPacket.data); ChannelPart(userClass, CurrentPacket.data);
break; break;
case packetIDs.client_friendAdd:
AddFriend(userClass, CurrentPacket.data);
break;
case packetIDs.client_friendRemove:
RemoveFriend(userClass, CurrentPacket.data);
break;
case packetIDs.client_userStatsRequest: case packetIDs.client_userStatsRequest:
UserStatsRequest(userClass, CurrentPacket.data); UserStatsRequest(userClass, CurrentPacket.data);
break; break;