Upload files to "routes"

This commit is contained in:
2026-07-24 15:43:04 +00:00
parent e3a7b0b125
commit 646a270645
3 changed files with 771 additions and 0 deletions

408
routes/Account.cs Normal file
View File

@@ -0,0 +1,408 @@
using System.Text.Json;
using Microsoft.Extensions.Primitives;
using MongoDB.Driver;
using Stella.Models;
using Stella.Routes.API;
namespace Stella.Routes
{
public class Account
{
[ServerAPI.GET("/account/me")]
[ServerAPI.UseAuthorization]
public dynamic AccountInfo(MongoDB.User user)
{
return new AccountDTO
{
AccountId = user.AccountId,
CreatedAt = user.CreatedAt,
DisplayName = user.DisplayName,
Username = user.Username,
ProfileImage = user.ProfileImage,
IsJunior = user.IsJunior,
PlatformMask = PlatformMask.None
};
}
[ServerAPI.GET("/account/bulk")]
public List<AccountDTO> BulkAccountInfo(HttpContext ctx)
{
StringValues idStrings = ctx.Request.Query["id"];
if (idStrings.Count == 0) return [];
List<long> ids = [];
for (int i = 0; i < idStrings.Count; i++)
{
if (int.TryParse(idStrings[i], out int val))
{
ids.Add(val);
}
}
if (ids.Count == 0) return [];
List<MongoDB.User> users = MongoDB.usersCollection.Find(u => ids.Contains(u.AccountId)).ToList();
return [.. users.Select(u => new AccountDTO
{
AccountId = u.AccountId,
Username = u.Username,
DisplayName = u.DisplayName,
CreatedAt = u.CreatedAt,
ProfileImage = u.ProfileImage,
IsJunior = u.IsJunior,
PlatformMask = PlatformMask.None
})];
}
[ServerAPI.GET("/account/{accountId}")]
public dynamic ReturnGetAccount(long accountId)
{
MongoDB.User user = MongoDB.usersCollection.Find(u => u.AccountId == accountId).FirstOrDefault();
return new AccountDTO
{
AccountId = accountId,
CreatedAt = user.CreatedAt,
DisplayName = user.DisplayName,
Username = user.Username,
ProfileImage = user.ProfileImage,
IsJunior = user.IsJunior,
PlatformMask = PlatformMask.None
};
}
[ServerAPI.PUT("/account/me/bio")]
[ServerAPI.UseAuthorization]
public async Task<RecNetResult> ReturnBio(HttpContext ctx, MongoDB.User user)
{
string? bio = (ctx.Request.Form["bio"]);
var bannedJson = await File.ReadAllTextAsync("Data/bannednames.json");
var bannedObj = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(bannedJson);
var bannedWords = bannedObj?["banned"] ?? new List<string>();
if (!string.IsNullOrWhiteSpace(bio) && bannedWords.Any(word => bio.Contains(word, StringComparison.OrdinalIgnoreCase)))
{
return new RecNetResult
{
Success = false,
Error = "no"
};
}
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.Bio, bio)
);
return new RecNetResult
{
Success = true,
Error = ""
};
}
[ServerAPI.PUT("/account/me/profileimage")]
[ServerAPI.UseAuthorization]
public async Task<RecNetResult> ReturnProfileImage(HttpContext ctx, MongoDB.User user)
{
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.ProfileImage, (string?)ctx.Request.Form["imageName"])
);
await NotificationHub.SendWebsocket(user.AccountId, new
{
Id = "AccountUpdate",
Msg = new AccountDTO
{
AccountId = user.AccountId,
CreatedAt = user.CreatedAt,
DisplayName = user.DisplayName,
Username = user.Username,
ProfileImage = (string?)ctx.Request.Form["imageName"],
IsJunior = user.IsJunior,
PlatformMask = PlatformMask.None
}
});
return new RecNetResult
{
Success = true,
Error = ""
};
}
[ServerAPI.PUT("/account/me/displayname")]
[ServerAPI.UseAuthorization]
public async Task<RecNetResult> ReturnDisplayName(HttpContext ctx, MongoDB.User user)
{
string? displayName = (string?)ctx.Request.Form["displayName"];
var bannedJson = await File.ReadAllTextAsync("Data/bannednames.json");
var bannedObj = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(bannedJson);
var bannedWords = bannedObj?["banned"] ?? new List<string>();
if (!string.IsNullOrWhiteSpace(displayName) && bannedWords.Any(word => displayName.Contains(word, StringComparison.OrdinalIgnoreCase)))
{
return new RecNetResult
{
Success = false,
Error = "no"
};
}
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update
.Set(u => u.DisplayName, displayName)
.Set(u => u.Username, displayName)
);
await NotificationHub.SendWebsocket(user.AccountId, new
{
Id = "AccountUpdate",
Msg = new AccountDTO
{
AccountId = user.AccountId,
CreatedAt = user.CreatedAt,
DisplayName = displayName,
Username = displayName,
ProfileImage = user.ProfileImage,
IsJunior = user.IsJunior,
PlatformMask = PlatformMask.None
}
});
await NotificationHub.SendWebsocket(user.AccountId, new
{
Id = "SelfAccountUpdate",
Msg = new AccountDTO
{
AccountId = user.AccountId,
CreatedAt = user.CreatedAt,
DisplayName = displayName,
Username = displayName,
ProfileImage = user.ProfileImage,
IsJunior = user.IsJunior,
PlatformMask = PlatformMask.None
}
});
return new RecNetResult
{
Success = true,
Error = ""
};
}
[ServerAPI.GET("/account/{accountId}/bio")]
[ServerAPI.UseAuthorization]
public dynamic ReturnGetBio(long accountId)
{
MongoDB.User user = MongoDB.usersCollection.Find(u => u.AccountId == accountId).FirstOrDefault();
return new BioDTO
{
AccountId = accountId,
Bio = user.Bio
};
}
[ServerAPI.GET("/parentalcontrol/me")]
[ServerAPI.UseAuthorization]
public dynamic ReturnParentalControl(MongoDB.User user)
{
return new ParentalControl
{
AccountId = user.AccountId,
DisallowInAppPurchase = true
};
}
[ServerAPI.POST("/account/create")]
public async Task<dynamic> ReturnCreateAccount(HttpContext ctx)
{
long newAccountId = MongoDB.usersCollection.CountDocuments(_ => true) + 1;
ulong platformId = ulong.Parse(ctx.Request.Form["platformId"]!);
if (!int.TryParse(ctx.Request.Form["platform"], out int platformValue) || !Enum.IsDefined(typeof(PlatformType), platformValue))
{
return Results.Forbid();
}
PlatformType platform = (PlatformType)platformValue;
OculusServer.User? user = await OculusServer.GetUserAsync(platformId);
if (user == null)
{
return Results.Forbid();
}
MongoDB.RoomDetailsMongoDB roomDetails = new()
{
Room = new()
{
RoomId = MongoDB.roomsCollection.CountDocuments(_ => true) + 1,
Name = $"@{user.Alias}'s Dorm",
Description = "A private room.",
CreatorPlayerId = newAccountId,
ImageName = "ca673ff19c054158a15ff00f0b844ba7",
State = 0,
Accessibility = Accessibility.Unlisted,
SupportsLevelVoting = false,
IsAGRoom = false,
IsDormRoom = true,
CloningAllowed = false,
SupportsScreens = true,
SupportsWalkVR = true,
SupportsTeleportVR = true,
AllowsJuniors = true,
WarningMask = 0,
RoomWarningMask = 0,
CustomRoomWarning = null,
DisableMicAutoMute = true
},
Scenes = [
new()
{
RoomSceneId = 1,
RoomId = 1,
RoomSceneLocationId = "76d98498-60a1-430c-ab76-b54a29b7a163",
Name = "Home",
IsSandbox = true,
DataBlobName = "",
MaxPlayers = 4,
CanMatchmakeInto = true,
DataModifiedAt = DateTime.UtcNow
}
],
CoOwners = [],
InvitedCoOwners = [],
Moderators = [],
InvitedModerators = [],
Hosts = [],
InvitedHosts = [],
CheerCount = 0,
FavoriteCount = 0,
VisitCount = 0,
Tags = []
};
MongoDB.roomsCollection.InsertOne(roomDetails);
MongoDB.User newUser = new()
{
AccountId = newAccountId,
Username = user.Alias,
DisplayName = user.Alias,
CreatedAt = DateTime.UtcNow,
ProfileImage = "DefaultProfilePicture",
IsJunior = false,
Email = null,
Password = null,
DateOfBirth = DateTime.UtcNow,
PlatformId = platformId,
Platform = platform,
OtherData = new()
{
RoomInstance = null,
Avatar = new()
{
OutfitSelections = $"{AvatarHelper.FemaleTShirt},,,,1",
FaceFeatures = "{\"ver\":3,\"eyeId\":\"AjGMoJhEcEehacRZjUMuDg\",\"eyePos\":{\"x\":-0.009999999776482582,\"y\":-0.03999999910593033},\"eyeScl\":0.05000000074505806,\"mouthId\":\"FrZBRanXEEK29yKJ4jiMjg\",\"mouthPos\":{\"x\":0.0,\"y\":0.07999999821186066},\"mouthScl\":0.05000000074505806,\"beardColorId\":\"81_c6R0my0qK9hYM_0a7LQ\"}",
SkinColor = "4fb0fdbd-b10a-492e-8df2-b43f981b2ce6",
HairColor = "81_c6R0my0qK9hYM_0a7LQ"
},
AvatarItems = [
new() { AvatarItemDesc = $"{AvatarHelper.Hair_AngledBob},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Angled Bob", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Fonzie},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Fonzie", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_FlatTop},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Flat Top", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Emo},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Emo", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Shagg},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Shagg", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Afro},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Afro", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Ponytail},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Ponytail", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Lori},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Lori", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_HalfUp},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Half Up", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_ManBun},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Man Bun", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Mullet},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Mullet", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_PunkGirl},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Punk Girl", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Pompadour},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Pompadour", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Jazzercise},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Jazzercise", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Spiky},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Spiky", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_PigTails},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Pig Tails", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_WavyShort},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Wavy Short", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Bob},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Bob", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_PulpFiction},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Pulp Fiction", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Part},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Part", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_GordonGekko},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Gordon Gekko", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_MeatballBuns},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Meatball Buns", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Undercut},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Undercut", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_BaldTop},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Bald Top", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_ChunkyAfro},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Chunky Afro", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Bishop},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Bishop", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_FemaleCheerleader},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Female Cheerleader", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_ManPony},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Man Pony", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_DutchBraid},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Dutch Braid", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Malibu},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Malibu", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Punk},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Punk", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_RecedingHairline},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Receding Hairline", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Rhianna},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Rhianna", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_GiantAfro},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Giant Afro", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Buzz},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Buzz", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_FauxHawk},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Faux Hawk", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Bob_Bangs},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Bob Bangs", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Mohawk},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Mohawk", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_WavyLong},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Wavy Long", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_DreadsLong},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Dreads Long", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Scientist},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Scientist", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_UnderCutSheet},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Under Cut Sheet", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_JackFrostNoCrystalsHair},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Jack Frost No Crystals Hair", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_Bun},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Bun", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.Hair_LongBangs},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "Long Bangs", Rarity = GiftRarity.Common, Tooltip = "" },
new() { AvatarItemDesc = $"{AvatarHelper.FemaleTShirt},,,", AvatarItemType = AvatarItemType.Outfit, FriendlyName = "RecRoom Shirt", Rarity = GiftRarity.Common, Tooltip = "" }
],
LoginLockCode = null,
DormRoomId = roomDetails.Room.RoomId
}
};
MongoDB.usersCollection.InsertOne(newUser);
AccountDTO accountDto = new()
{
AccountId = newUser.AccountId,
Username = newUser.Username,
DisplayName = newUser.DisplayName,
CreatedAt = newUser.CreatedAt,
ProfileImage = newUser.ProfileImage,
IsJunior = newUser.IsJunior,
PlatformMask = 0
};
return Results.Ok(new ValueResponse
{
Value = accountDto,
Success = true,
Error = ""
});
}
[ServerAPI.POST("/account/me/email")]
[ServerAPI.UseAuthorization]
public RecNetResult ReturnChangePassword(MongoDB.User user, HttpContext ctx)
{
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.Email, (string?)ctx.Request.Form["email"])
);
return new RecNetResult
{
Error = "",
Success = true
};
}
}
}

339
routes/Auth.cs Normal file
View File

@@ -0,0 +1,339 @@
using MongoDB.Driver;
using Stella.Models;
using Stella.Routes.API;
using System.Text;
using System.Text.Json;
namespace Stella.Routes
{
public static class AuthTokenErrors
{
public const string InvalidRequest = "invalid_request";
public const string InvalidClient = "invalid_client";
public const string InvalidGrant = "invalid_grant";
public const string UnauthorizedClient = "unauthorized_client";
public const string UnsupportedGrantType = "unsupported_grant_type";
public const string UnsupportedResponseType = "unsupported_response_type";
public const string InvalidScope = "invalid_scope";
public const string AuthorizationPending = "authorization_pending";
public const string AccessDenied = "access_denied";
public const string SlowDown = "slow_down";
public const string ExpiredToken = "expired_token";
public static class InvalidGrantErrorDescriptions
{
public const string InvalidUsernameOrPassword = "invalid_username_or_password";
public const string InvalidTime = "invalid time";
public const string PlatformVerificationFailed = "platform verification failed";
public const string InvalidPlatform = "invalid platform";
public const string InvalidDeviceClass = "invalid device class";
}
}
public class Auth
{
[ServerAPI.POST("/api/player/photon")]
[ServerAPI.GET("/api/player/photon")]
public async Task<dynamic> ReturnPhoton(HttpContext ctx)
{
if (ctx.Request.Method == "GET")
{
return new
{
ResultCode = 1,
Message = ""
};
}
using var reader = new StreamReader(ctx.Request.Body, Encoding.UTF8);
var body = await reader.ReadToEndAsync();
var jsonDoc = JsonDocument.Parse(body);
var root = jsonDoc.RootElement;
string accountId = root.GetProperty("accountId").GetString()!;
string accessToken = root.GetProperty("accessToken").GetString()!;
MongoDB.User user = MongoDB.usersCollection.Find(u => u.AccountId == long.Parse(accountId)).FirstOrDefault();
IDictionary<string, object>? claims = JsonWebToken.VerifyAndDecode(accessToken);
if (claims == null)
{
return new
{
ResultCode = 0,
Message = ""
};
}
if (!claims.TryGetValue("sub", out var subValue))
{
return new
{
ResultCode = 0,
Message = ""
};
}
if ((string)subValue != accountId)
{
return new
{
ResultCode = 0,
Message = ""
};
}
return new
{
UserId = accountId,
Nickname = user.Username,
ResultCode = 1,
Message = ""
};
}
[ServerAPI.POST("/auth/connect/token")]
public dynamic ReturnLoginAccount(HttpContext ctx)
{
/*
{
"grant_type": "cached_login",
"account_id": "1",
"client_id": "recroom",
"client_secret": "VxZ53kgbbEaRoZAeMe00MagtgD12GLL2",
"platform": "0",
"platform_id": "76561199373121011",
"device_id": "29b97dab367c6d2be33552ca86adf5a21a17021a",
"device_class": "2",
"time": "2025-11-11T13:24:30.5873414Z",
"ver": "20200320",
"asid": "1762867470568",
"device_id2": "BA\u002B8j5stFzJjA4lttE3KPOzpp7sd2jYPnYgu8JE\u002B2Pw=",
"device_id3": "\u002B0Btqnu5U51gRQdjVZ2H2ntHjxRu3bYo7TYWVCkaHdY=",
"platform_auth": "{\u0022Ticket\u0022:\u0022140000006D248F3F3B6E70FEF3753654010010012C361369180000000100000002000000ED5C071BD8F4E79D4CC7AD0431000000B20000003200000004000000F3753654010010019E32070068C91C686F28A8C000000000A8C40B69287427690100DF97010000000000C6E58775B58789FDC0B2A299243F9AD743022B1D22D3921AD997EBACE9708C45DE6A93C68C1C913002C97D905AEC75ACAF25052DCC2534418B5A3BCF5A4EBE9ED48D6B5AAB0831A918ADA3782005B6929F9C1BA21E9B8BC63970B5FADE6CF8387CD42D86B7D0C36E3843B0057A60E03E5C59CCF0438DA058E54D9D1F326ABC08\u0022,\u0022AppId\u0022:\u0022471710\u0022}"
}
*/
string? grantType = ctx.Request.Form["grant_type"];
string? clientId = ctx.Request.Form["client_id"];
long authTime = DateTime.UtcNow.ToUnixTime();
MongoDB.User user = MongoDB.usersCollection.Find(u => u.AccountId == long.Parse(ctx.Request.Form["account_id"])).FirstOrDefault();
if (user.PlatformId != ulong.Parse(ctx.Request.Form["platform_id"].ToString()))
{
return Results.Forbid();
}
if (user.OtherData.DormRoomId == null)
{
long id = MongoDB.roomsCollection.CountDocuments(_ => true) + 1;
MongoDB.RoomDetailsMongoDB roomDetails = new()
{
Room = new()
{
RoomId = id,
Name = $"@{user.Username}'s Dorm",
Description = "A private room.",
CreatorPlayerId = user.AccountId,
ImageName = "ca673ff19c054158a15ff00f0b844ba7",
State = 0,
Accessibility = Accessibility.Unlisted,
SupportsLevelVoting = false,
IsAGRoom = false,
IsDormRoom = true,
CloningAllowed = false,
SupportsScreens = true,
SupportsWalkVR = true,
SupportsTeleportVR = true,
AllowsJuniors = true,
WarningMask = 0,
RoomWarningMask = 0,
CustomRoomWarning = null,
DisableMicAutoMute = true
},
Scenes = [
new()
{
RoomSceneId = 1,
RoomId = id,
RoomSceneLocationId = "76d98498-60a1-430c-ab76-b54a29b7a163",
Name = "Home",
IsSandbox = true,
DataBlobName = "",
MaxPlayers = 4,
CanMatchmakeInto = true,
DataModifiedAt = DateTime.UtcNow
}
],
CoOwners = [],
InvitedCoOwners = [],
Moderators = [],
InvitedModerators = [],
Hosts = [],
InvitedHosts = [],
CheerCount = 0,
FavoriteCount = 0,
VisitCount = 0,
Tags = []
};
MongoDB.roomsCollection.InsertOne(roomDetails);
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.OtherData.DormRoomId, id)
);
}
if (grantType == "cached_login")
{
return new LoginResponseDTO
{
AccessToken = JsonWebToken.Generate(new Dictionary<string, object?>
{
{ "iss", "https://auth.stellaonline.org" }, // Issuer
{ "client_id", clientId }, // Client Application reciving events
{ "role", user.IsDeveloper ? "developer" : "player" }, // Role
{ "sub", ctx.Request.Form["account_id"].ToString() }, // Subject
{ "auth_time", authTime }, // Authentication Time
{ "idp", "local" }, // Identity Provider
{ "jti", Guid.NewGuid().ToString("N").ToUpper() }, // JWT ID
{ "sid", Guid.NewGuid().ToString("N").ToUpper() }, // Session ID
{ "iat", DateTime.UtcNow.ToUnixTime() }, // Issued At
{ "scope", new List<string> { "screenshare" } }, // a grouping of claims
{ "amr", new List<string> { "pwd" } } // Authentication Methods References (pwd=password, mfa=multi-factor authentication)
}, TimeSpan.FromHours(6)),
RefreshToken = JsonWebToken.Generate(new Dictionary<string, object?>
{
{ "iss", "https://auth.stellaonline.org" }, // Issuer
{ "client_id", clientId }, // Client Application reciving events
{ "role", user.IsDeveloper ? "developer" : "player" }, // Role
{ "sub", ctx.Request.Form["account_id"].ToString() }, // Subject
{ "auth_time", authTime }, // Authentication Time
{ "idp", "local" }, // Identity Provider
{ "jti", Guid.NewGuid().ToString("N").ToUpper() }, // JWT ID
{ "sid", Guid.NewGuid().ToString("N").ToUpper() }, // Session ID
{ "iat", DateTime.UtcNow.ToUnixTime() }, // Issued At
{ "scope", new List<string> { "screenshare" } }, // a grouping of claims
{ "amr", new List<string> { "pwd" } } // Authentication Methods References (pwd=password, mfa=multi-factor authentication)
}, TimeSpan.FromHours(6))
};
}
else if (grantType == "refresh_token")
{
var decoded = JsonWebToken.VerifyAndDecode(ctx.Request.Form["refresh_token"]);
return new RefreshLoginResponseDTO
{
Token = JsonWebToken.Generate(new Dictionary<string, object?>
{
{ "iss", "https://auth.stellaonline.org" }, // Issuer
{ "client_id", "recnet" }, // Client Application reciving events
{ "role", user.IsDeveloper ? "developer" : "player" }, // Role
{ "sub", ctx.Request.Form["account_id"].ToString() }, // Subject
{ "auth_time", authTime }, // Authentication Time
{ "idp", "local" }, // Identity Provider
{ "jti", Guid.NewGuid().ToString("N").ToUpper() }, // JWT ID
{ "sid", Guid.NewGuid().ToString("N").ToUpper() }, // Session ID
{ "iat", DateTime.UtcNow.ToUnixTime() }, // Issued At
{ "scope", new List<string> { "screenshare" } }, // a grouping of claims
{ "amr", new List<string> { "pwd" } } // Authentication Methods References (pwd=password, mfa=multi-factor authentication)
}, TimeSpan.FromHours(6))
};
}
return new
{
};
}
[ServerAPI.GET("/auth/cachedlogin/forplatformid/{platformType}/{platformId}")]
public List<CachedLoginDTO> CachedLogins(PlatformType platformType, ulong platformId)
{
List<MongoDB.User> users = MongoDB.usersCollection.Find(u => u.PlatformId == platformId).ToList();
var cachedLogins = users.Select(u => new CachedLoginDTO
{
AccountId = u.AccountId,
Account = new AccountDTO
{
AccountId = u.AccountId,
CreatedAt = u.CreatedAt,
DisplayName = u.DisplayName,
Username = u.Username,
ProfileImage = u.ProfileImage ?? "DefaultProfileImage",
IsJunior = u.IsJunior,
PlatformMask = 0
},
LastLoginTime = DateTime.MinValue,
Platform = platformType,
PlatformId = platformId,
RequirePassword = false
}).ToList();
return cachedLogins;
}
[ServerAPI.GET("/auth/account/me/haspassword")]
[ServerAPI.UseAuthorization]
public IResult ReturnHasPassword(MongoDB.User user)
{
return Results.Json(user.Password != null);
}
[ServerAPI.GET("/auth/role/developer/{accountId}")]
public IResult ReturnHasDeveloper(long accountId)
{
MongoDB.User user = MongoDB.usersCollection.Find(u => u.AccountId == accountId).FirstOrDefault();
return Results.Json(user.IsDeveloper);
}
[ServerAPI.POST("/auth/account/me/changepassword")]
[ServerAPI.UseAuthorization]
public dynamic ReturnChangePassword(MongoDB.User user, HttpContext ctx)
{
if (user.Password == null)
{
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.Password, ((string?)ctx.Request.Form["newPassword"]).ToSHA256())
);
}
else
{
if (user.Password != ((string?)ctx.Request.Form["oldPassword"]).ToSHA256())
{
return Results.Forbid();
}
MongoDB.usersCollection.UpdateOne(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Set(u => u.Password, ((string?)ctx.Request.Form["newPassword"]).ToSHA256())
);
}
return new ValueResponse
{
Value = null,
Error = "",
Success = true
};
}
}
}

24
routes/CDN.cs Normal file
View File

@@ -0,0 +1,24 @@
namespace Stella.Routes
{
public class CDN
{
[ServerAPI.GET("/cdn/config/LoadingScreenTipData")]
public List<object> LoadingScreenTips()
{
return [];
}
[ServerAPI.GET("/cdn/room/{blobname}")]
public IResult GetDatablob(HttpContext ctx, string blobname)
{
string datablobPath = Path.Combine("Data", "Datablobs", blobname);
if (!File.Exists(datablobPath))
return Results.NotFound();
byte[] dbBytes = File.ReadAllBytes(datablobPath);
return Results.File(dbBytes);
}
}
}