Skip to content

Commit

Permalink
Implement friend online status notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
flustix committed Mar 17, 2024
1 parent ec42160 commit 16332b7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
16 changes: 15 additions & 1 deletion fluXis.Game/FluXisGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using fluXis.Game.Configuration;
using fluXis.Game.Database.Maps;
using fluXis.Game.Graphics.Background;
using fluXis.Game.Graphics.Sprites;
using fluXis.Game.Graphics.UserInterface.Panel;
using fluXis.Game.Input;
using fluXis.Game.Localization;
Expand Down Expand Up @@ -34,6 +35,7 @@
using fluXis.Game.Screens.Warning;
using fluXis.Game.Utils;
using fluXis.Shared.API.Packets.Other;
using fluXis.Shared.API.Packets.User;
using fluXis.Shared.Components.Users;
using fluXis.Shared.Scoring;
using fluXis.Shared.Utils;
Expand Down Expand Up @@ -187,9 +189,21 @@ protected override void LoadComplete()
});
});

Fluxel.RegisterListener<FriendOnlinePacket>(EventType.FriendOnline, res =>
{
var user = res.Data!.User!;
Schedule(() => NotificationManager.SendSmallText($"{user.PreferredName} is now online!", FontAwesome6.Solid.UserPlus));
});

Fluxel.RegisterListener<FriendOnlinePacket>(EventType.FriendOffline, res =>
{
var user = res.Data!.User!;
Schedule(() => NotificationManager.SendSmallText($"{user.PreferredName} is now offline.", FontAwesome6.Solid.UserMinus));
});

Fluxel.RegisterListener<ServerMessagePacket>(EventType.ServerMessage, res =>
{
var data = res.Data.Message;
var data = res.Data!.Message;

switch (data.Type)
{
Expand Down
1 change: 1 addition & 0 deletions fluXis.Game/Graphics/Sprites/FontAwesome6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static class Solid
public static IconUsage User => getSolid(0xf007);
public static IconUsage UserAstronaut => getSolid(0xf4fb);
public static IconUsage UserGroup => getSolid(0xf500);
public static IconUsage UserMinus => getSolid(0xf503);
public static IconUsage UserPlus => getSolid(0xf234);
public static IconUsage UserShield => getSolid(0xf505);
public static IconUsage Users => getSolid(0xf0c0);
Expand Down
55 changes: 34 additions & 21 deletions fluXis.Game/Online/Fluxel/FluxelClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using fluXis.Shared.API.Packets.Chat;
using fluXis.Shared.API.Packets.Multiplayer;
using fluXis.Shared.API.Packets.Other;
using fluXis.Shared.API.Packets.User;
using fluXis.Shared.Components.Users;
using fluXis.Shared.Utils;
using osu.Framework.Allocation;
Expand Down Expand Up @@ -273,11 +274,17 @@ void handleListener<T>(string msg)
EventType.Login => handleListener<LoginPacket>,
EventType.Register => handleListener<RegisterPacket>,
EventType.Logout => handleListener<LogoutPacket>,

EventType.Achievement => handleListener<AchievementPacket>,
EventType.ServerMessage => handleListener<ServerMessagePacket>,

EventType.FriendOnline => handleListener<FriendOnlinePacket>,
EventType.FriendOffline => handleListener<FriendOnlinePacket>,

EventType.ChatMessage => handleListener<ChatMessagePacket>,
EventType.ChatHistory => handleListener<ChatHistoryPacket>,
EventType.ChatMessageDelete => handleListener<ChatDeletePacket>,

EventType.MultiplayerJoin => handleListener<MultiJoinPacket>,
EventType.MultiplayerLeave => handleListener<MultiLeavePacket>,
// EventType.MultiplayerRoomUpdate => handleListener<MultiplayerRoomUpdate>,
Expand Down Expand Up @@ -458,31 +465,34 @@ private void onLogout(FluxelReply<LogoutPacket> reply)
notifications.SendText("You have been logged out!", "Another device logged in with your account.", FontAwesome6.Solid.TriangleExclamation);
}

private EventType getType(string id)
private static EventType getType(string id)
{
return id switch
{
PacketIDs.AUTH => EventType.Token,
"account/login" => EventType.Login,
"account/register" => EventType.Register,
"account/logout" => EventType.Logout,

"achievement" => EventType.Achievement,
"server/message" => EventType.ServerMessage,

"chat/message" => EventType.ChatMessage,
"chat/history" => EventType.ChatHistory,
"chat/delete" => EventType.ChatMessageDelete,

"multi/create" => EventType.MultiplayerCreateLobby,
"multi/join" => EventType.MultiplayerJoin,
"multi/leave" => EventType.MultiplayerLeave,
"multi/update" => EventType.MultiplayerRoomUpdate,
"multi/ready" => EventType.MultiplayerReady,
"multi/start" => EventType.MultiplayerStartGame,
"multi/finish" => EventType.MultiplayerFinish,

_ => throw new ArgumentOutOfRangeException(nameof(id), id, null)
PacketIDs.LOGIN => EventType.Login,
PacketIDs.REGISTER => EventType.Register,
PacketIDs.LOGOUT => EventType.Logout,

PacketIDs.ACHIEVEMENT => EventType.Achievement,
PacketIDs.SERVER_MESSAGE => EventType.ServerMessage,

PacketIDs.FRIEND_ONLINE => EventType.FriendOnline,
PacketIDs.FRIEND_OFFLINE => EventType.FriendOffline,

PacketIDs.CHAT_MESSAGE => EventType.ChatMessage,
PacketIDs.CHAT_HISTORY => EventType.ChatHistory,
PacketIDs.CHAT_DELETE => EventType.ChatMessageDelete,

PacketIDs.MULTIPLAYER_CREATE => EventType.MultiplayerCreateLobby,
PacketIDs.MULTIPLAYER_JOIN => EventType.MultiplayerJoin,
PacketIDs.MULTIPLAYER_LEAVE => EventType.MultiplayerLeave,
PacketIDs.MULTIPLAYER_UPDATE => EventType.MultiplayerRoomUpdate,
PacketIDs.MULTIPLAYER_READY => EventType.MultiplayerReady,
PacketIDs.MULTIPLAYER_START => EventType.MultiplayerStartGame,
PacketIDs.MULTIPLAYER_FINISH => EventType.MultiplayerFinish,

_ => throw new ArgumentOutOfRangeException(nameof(id), id, "Unknown packet ID!")
};
}
}
Expand All @@ -508,6 +518,9 @@ public enum EventType
/// </summary>
Logout,

FriendOnline,
FriendOffline,

Achievement,
ServerMessage,

Expand Down
3 changes: 2 additions & 1 deletion fluXis.Shared/API/PacketIDs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace fluXis.Shared.API;

public class PacketIDs
public static class PacketIDs
{
public const string AUTH = "account/auth";
public const string LOGIN = "account/login";
Expand All @@ -16,6 +16,7 @@ public class PacketIDs
public const string CHAT_MESSAGE = "chat/message";
public const string CHAT_HISTORY = "chat/history";
public const string CHAT_DELETE = "chat/delete";

public const string MULTIPLAYER_CREATE = "multi/create";
public const string MULTIPLAYER_JOIN = "multi/join";
public const string MULTIPLAYER_LEAVE = "multi/leave";
Expand Down

0 comments on commit 16332b7

Please sign in to comment.