mirror of
https://git.recroomarchive.org/RecRoomArchive/RRAC.git
synced 2026-09-08 14:41:25 -07:00
387ec7ba89
Added basic info to get in game for like...August 2016 ;-; It's not much but it's a start
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RecRoomArchive.Models.API.Players;
|
|
using RecRoomArchive.Services;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace RecRoomArchive.Controllers.API.Players
|
|
{
|
|
/// <summary>
|
|
/// Used in August 2016 RecNet
|
|
/// </summary>
|
|
[Route(template: "api/[controller]")]
|
|
[ApiController]
|
|
public class PlayersController(AccountService accountService) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Returns the profile tied to a SteamID (If it exists)
|
|
/// </summary>
|
|
/// <param name="steamId">The SteamID of the player we are trying to get the profile of</param>
|
|
/// <returns>The profile of the player, if it exists</returns>
|
|
[HttpGet]
|
|
public async Task<ActionResult<AugustProfile>> GetProfile([Required, FromQuery] ulong steamId)
|
|
{
|
|
var baseProfile = accountService.GetSelfAccount();
|
|
if (baseProfile == null)
|
|
return NotFound();
|
|
|
|
var profile = new AugustProfile(baseProfile)
|
|
{
|
|
SteamID = steamId
|
|
};
|
|
|
|
return profile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a profile and links it to a SteamID if the player does not already exist
|
|
/// </summary>
|
|
/// <param name="steamId">The SteamID of the player that we are creating a profile for</param>
|
|
/// <param name="username">The Steam username of the player that we are creating a profile for</param>
|
|
/// <returns>A new AugustProfile</returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult<AugustProfile>> CreateProfile(
|
|
[Required, FromForm(Name = "SteamID")] ulong steamId,
|
|
[Required, FromForm(Name = "Name")] string username)
|
|
{
|
|
if (!accountService.AccountExists())
|
|
{
|
|
accountService.CreateAccount(username);
|
|
}
|
|
|
|
var baseProfile = accountService.GetSelfAccount();
|
|
if (baseProfile == null)
|
|
return NotFound();
|
|
|
|
var profile = new AugustProfile(baseProfile)
|
|
{
|
|
SteamID = steamId
|
|
};
|
|
|
|
return profile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stores data related to the player onto the server
|
|
/// </summary>
|
|
/// <param name="profileId">The Id of the Profile we are storing data for</param>
|
|
/// <param name="model">The data the client posts...it happens to be an entire profile but we can take only the data we need :)</param>
|
|
/// <returns>A successful response, likely will just return the updated profile</returns>
|
|
[HttpPut(template: "{profileId:long}")]
|
|
public async Task<ActionResult<AugustProfile>> UpdateProfile([Required] ulong profileId, [FromBody] AugustProfile model)
|
|
{
|
|
return (AugustProfile)accountService.GetSelfAccount()!;
|
|
}
|
|
}
|
|
} |