-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathUserActivityWebSocketDataSource.cs
More file actions
84 lines (70 loc) · 2.72 KB
/
Copy pathUserActivityWebSocketDataSource.cs
File metadata and controls
84 lines (70 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Configuration;
using osu.Game.IPC.Messages;
using osu.Game.IPC.Models;
using osu.Game.Users;
namespace osu.Game.IPC.DataSources
{
public partial class UserActivityWebSocketDataSource : WebSocketDataSource
{
private readonly Bindable<UserActivity?> userActivity = new Bindable<UserActivity?>();
public UserActivityWebSocketDataSource(IWebSocketProvider provider)
: base(provider) { }
[BackgroundDependencyLoader]
private void load(SessionStatics sessionStatics)
{
sessionStatics.BindWith(Static.UserOnlineActivity, userActivity);
}
protected override void LoadComplete()
{
base.LoadComplete();
userActivity.BindValueChanged(onUserActivityChange);
}
private void onUserActivityChange(ValueChangedEvent<UserActivity?> change)
{
if (change.NewValue == null)
return;
var msg = new UserActivityWebSocketMessage
{
Status = change.NewValue.GetType().Name,
Data = getUserActivityData(change.NewValue),
};
BroadcastMessage(msg);
}
private static object? getUserActivityData(UserActivity userActivity)
{
switch (userActivity)
{
case UserActivity.InGame inGame:
return new WebSocketInGameUserActivityData
{
BeatmapId = inGame.BeatmapID,
RulesetId = inGame.RulesetID,
};
case UserActivity.InLobby inLobby:
return new WebSocketInLobbyUserActivityData
{
RoomId = inLobby.RoomID,
RoomName = inLobby.RoomName,
};
case UserActivity.WatchingReplay watchingReplay:
return new WebSocketWatchingReplayUserActivityData
{
ScoreId = watchingReplay.ScoreID,
PlayerName = watchingReplay.PlayerName,
BeatmapId = watchingReplay.BeatmapID,
};
case UserActivity.EditingBeatmap editingBeatmap:
return new WebSocketEditingBeatmapUserActivityData
{
BeatmapId = editingBeatmap.BeatmapID,
};
default:
return null;
}
}
}
}