Files
rr3-server/RR3CommunityServer/Program.cs
Daniel Elliott a6bab92282 Add user authentication and account management system
Features:
- User registration with username, email, password
- Login with JWT token authentication
- Password hashing with BCrypt
- Account settings & management
- Device linking to accounts
- Change password & password reset
- Account-User relationship (1-to-1 with game data)

Database entities:
- Account: User accounts with credentials
- DeviceAccount: Link devices to accounts (many-to-many)

API endpoints:
- POST /api/auth/register
- POST /api/auth/login
- POST /api/auth/change-password
- POST /api/auth/forgot-password
- POST /api/auth/reset-password
- GET /api/auth/me
- POST /api/auth/link-device
- DELETE /api/auth/unlink-device/{deviceId}

Starting resources for new accounts:
- 100,000 Gold
- 500,000 Cash
- Level 1

Ready for VPS deployment with HTTPS.
2026-02-19 15:00:16 -08:00

80 lines
2.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using RR3CommunityServer.Data;
using RR3CommunityServer.Services;
using RR3CommunityServer.Middleware;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container
builder.Services.AddControllers();
builder.Services.AddRazorPages(); // Add Razor Pages support
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Database
builder.Services.AddDbContext<RR3DbContext>(options =>
options.UseSqlite("Data Source=rr3community.db"));
// Custom services
builder.Services.AddScoped<ISessionService, SessionService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<ICatalogService, CatalogService>();
builder.Services.AddScoped<IDrmService, DrmService>();
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddScoped<AssetExtractionService>();
// CORS for cross-origin requests
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
// Initialize database
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<RR3DbContext>();
db.Database.EnsureCreated();
}
app.UseHttpsRedirection();
app.UseCors();
// Custom middleware
app.UseMiddleware<SynergyHeadersMiddleware>();
app.UseMiddleware<SessionValidationMiddleware>();
app.UseAuthorization();
app.MapControllers();
app.MapRazorPages(); // Add Razor Pages routing
// Redirect root to admin panel
app.MapGet("/", () => Results.Redirect("/admin"));
Console.WriteLine("╔══════════════════════════════════════════════════════════╗");
Console.WriteLine("║ Real Racing 3 Community Server - RUNNING ║");
Console.WriteLine("╠══════════════════════════════════════════════════════════╣");
Console.WriteLine("║ Server is ready to accept connections ║");
Console.WriteLine("║ Ensure DNS/hosts file points EA servers to this IP ║");
Console.WriteLine("╚══════════════════════════════════════════════════════════╝");
Console.WriteLine();
Console.WriteLine("Listening on: https://localhost:5001");
Console.WriteLine("Director endpoint: /director/api/android/getDirectionByPackage");
Console.WriteLine();
app.Run();