feat: update 2.1.9
This commit is contained in:
@@ -39,6 +39,10 @@ function InitModule(ctx, logger, nk, initializer) {
|
||||
initializer.registerRpc("sync_leaderboard", rpcSyncLeaderboard);
|
||||
initializer.registerRpc("change_credentials", rpcChangeCredentials);
|
||||
initializer.registerRpc("reset_stats", rpcResetStats);
|
||||
initializer.registerRpc("send_lobby_invite", rpcSendLobbyInvite);
|
||||
|
||||
// Steam auth hooks
|
||||
initializer.registerAfterAuthenticateSteam(afterAuthenticateSteam);
|
||||
|
||||
// Create default native leaderboard
|
||||
// id: "global_high_score", authoritative: true, sort: "desc", operator: "best", reset: None
|
||||
@@ -154,6 +158,67 @@ function requireAdminOrHost(ctx, nk, matchId) {
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Lobby Invite RPC
|
||||
// =============================================================================
|
||||
|
||||
function rpcSendLobbyInvite(ctx, logger, nk, payload) {
|
||||
if (!ctx.userId) throw new Error("Not authenticated");
|
||||
var req = JSON.parse(payload || "{}");
|
||||
var toUserId = req.to_user_id;
|
||||
var matchId = req.match_id;
|
||||
if (!toUserId || !matchId) throw new Error("Missing to_user_id or match_id");
|
||||
|
||||
var sender = nk.accountGetId(ctx.userId);
|
||||
var senderName = sender.user.displayName || sender.user.username || "Someone";
|
||||
|
||||
nk.notificationSend(
|
||||
toUserId,
|
||||
senderName + " invited you to their lobby",
|
||||
JSON.stringify({ match_id: matchId, from_name: senderName }),
|
||||
1001,
|
||||
ctx.userId,
|
||||
true
|
||||
);
|
||||
|
||||
logger.info("Lobby invite sent from " + ctx.userId + " to " + toUserId + " for match " + matchId);
|
||||
return JSON.stringify({ success: true });
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Steam Auth Hook
|
||||
// =============================================================================
|
||||
|
||||
function afterAuthenticateSteam(ctx, logger, nk, out, request) {
|
||||
if (!ctx.userId) return;
|
||||
|
||||
try {
|
||||
var account = nk.accountGetId(ctx.userId);
|
||||
|
||||
// On first login (no display name set), use Steam username
|
||||
if (!account.user.displayName) {
|
||||
var steamName = request.username || "SteamPlayer";
|
||||
nk.accountUpdateId(ctx.userId, null, steamName, null, null, null, null, null);
|
||||
logger.info("Steam user " + ctx.userId + " display name set to: " + steamName);
|
||||
}
|
||||
|
||||
// Set default role if not set
|
||||
var metadata = {};
|
||||
try {
|
||||
metadata = typeof account.user.metadata === "string"
|
||||
? JSON.parse(account.user.metadata || "{}")
|
||||
: (account.user.metadata || {});
|
||||
} catch (e) {}
|
||||
|
||||
if (!metadata.role) {
|
||||
metadata.role = "player";
|
||||
nk.accountUpdateId(ctx.userId, null, null, null, null, null, null, JSON.stringify(metadata));
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error("afterAuthenticateSteam error: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Admin RPCs
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user