Show live online-players count on the home screen
- OnlineService.getOnlineCount(); mock random-walks a believable number, SignalrService reads GET /api/stats/online (server tracks hub connections) - Home screen badge with pulsing dot, polls every 8s, localized digits Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -135,9 +135,18 @@ public sealed class GameManager
|
||||
public void ChooseTrump(string userId, string suit) => RoomOf(userId)?.HumanChooseTrump(userId, suit);
|
||||
public void SendReaction(string userId, string reaction) => RoomOf(userId)?.Reaction(userId, reaction);
|
||||
|
||||
public void OnConnected(string userId) => RoomOf(userId)?.SetConnected(userId, true);
|
||||
private int _online;
|
||||
public int OnlineCount => Volatile.Read(ref _online);
|
||||
|
||||
public void OnConnected(string userId)
|
||||
{
|
||||
Interlocked.Increment(ref _online);
|
||||
RoomOf(userId)?.SetConnected(userId, true);
|
||||
}
|
||||
|
||||
public void OnDisconnected(string userId)
|
||||
{
|
||||
if (Interlocked.Decrement(ref _online) < 0) Interlocked.Exchange(ref _online, 0);
|
||||
CancelMatchmaking(userId);
|
||||
RoomOf(userId)?.SetConnected(userId, false);
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapGet("/", () => Results.Json(new { service = "Hokm SignalR server", status = "ok" }));
|
||||
app.MapGet("/api/stats/online", (GameManager m) => Results.Json(new { online = m.OnlineCount }));
|
||||
|
||||
// --- dev auth (mock OTP + email). Replace with the V2 Identity Service later. ---
|
||||
app.MapPost("/api/auth/otp/request", (OtpRequest req) =>
|
||||
|
||||
Reference in New Issue
Block a user