mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Cryptography;
|
||||
using RadicadeServer.DB;
|
||||
|
||||
using IOFile = System.IO.File;
|
||||
|
||||
namespace RadicadeServer.Custom.API
|
||||
{
|
||||
[Route("custom/")]
|
||||
public class CCAPI(RecDBContext _db) : Controller
|
||||
{
|
||||
private static string GetHashAndCache(string hashName, string fileName)
|
||||
{
|
||||
if (!IOFile.Exists(hashName))
|
||||
{
|
||||
string hash = CalculateMD5(fileName);
|
||||
IOFile.WriteAllText(hashName, hash);
|
||||
return hash;
|
||||
}
|
||||
return IOFile.ReadAllText(hashName);
|
||||
}
|
||||
private static string CalculateMD5(string filename)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
using (var stream = IOFile.OpenRead(filename))
|
||||
{
|
||||
var hash = md5.ComputeHash(stream);
|
||||
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("all")]
|
||||
public async Task<List<CustomAddition>> GetAllContent()
|
||||
{
|
||||
return await _db.CustomContent.ToListAsync();
|
||||
}
|
||||
[HttpGet("download/{modId}/{fileId}")]
|
||||
public async Task<IActionResult> DownloadContent(long? modId, int? fileId)
|
||||
{
|
||||
if (modId == null || fileId == null) return BadRequest();
|
||||
|
||||
var mod = await _db.CustomContent.FirstOrDefaultAsync(x => x.Id == modId);
|
||||
if (mod == null) return NotFound();
|
||||
|
||||
var files = mod.Files.Split(";", StringSplitOptions.TrimEntries);
|
||||
if (fileId >= files.Length || fileId < 0) return BadRequest();
|
||||
|
||||
string path = Path.Join(DBConfig.CDNCustom, mod.Name, files[(int)fileId]);
|
||||
if (!System.IO.File.Exists(path)) return NotFound();
|
||||
|
||||
return PhysicalFile(path, "application/octet-stream", enableRangeProcessing: true);
|
||||
}
|
||||
[HttpGet("hash/{modId}/{file}")]
|
||||
public async Task<IActionResult> GetHashForMod(string modId, string file)
|
||||
{
|
||||
if (modId == null || file == null) return BadRequest();
|
||||
|
||||
file = file.ToLower().Trim();
|
||||
|
||||
var mod = await _db.CustomContent.FirstOrDefaultAsync(x => x.Name == modId);
|
||||
if (mod == null) return NotFound();
|
||||
|
||||
var files = mod.Files.Split(";", StringSplitOptions.TrimEntries);
|
||||
var expectedFile = files.FirstOrDefault(x => x.ToLower().Trim().Contains(file));
|
||||
|
||||
string path = Path.Join(DBConfig.CDNCustom, mod.Name, file);
|
||||
string hashPath = Path.Join(DBConfig.CDNCustom, mod.Name, file + "-hash");
|
||||
if (!IOFile.Exists(path)) return NotFound();
|
||||
|
||||
string hash = GetHashAndCache(hashPath, path);
|
||||
|
||||
return Ok(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RadicadeServer.Custom
|
||||
{
|
||||
public class CustomAddition
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public string Description { get; set; } = null!;
|
||||
public string Files { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.API.Notifications;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.RecNet.Messages;
|
||||
using RadicadeServer.RecNet.Responses;
|
||||
using RadicadeServer.RecNet.Notifications;
|
||||
using RadicadeServer.RecNet.Rooms;
|
||||
using RadicadeServer.RecNet.Maintenance;
|
||||
using RadicadeServer.Extensions;
|
||||
using RadicadeServer.RecNet.Board;
|
||||
using RadicadeServer.Utils;
|
||||
using RadicadeServer.RecNet.Enums.Messages;
|
||||
using RadicadeServer.RecNet.Enums.Moderation;
|
||||
|
||||
namespace RadicadeServer.Debug
|
||||
{
|
||||
[Route("debug/")]
|
||||
public class DebugAPI : Controller
|
||||
{
|
||||
RecDBContext db;
|
||||
public DebugAPI(RecDBContext context)
|
||||
{
|
||||
db = context;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[HttpGet("{key}/data/player/{who}/room/{name}/")]
|
||||
public async Task<IActionResult> DebugRoom(string key, string who, string name)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var room = await RoomUtils.GetRoom(name);
|
||||
var profile = await db.Profiles.FirstOrDefaultAsync(x => x.username == who);
|
||||
var roomData = await db.Rooms.FirstOrDefaultAsync(x => x.Name == name && (profile != null) ? x.CreatorAccountId == profile.accountId : false);
|
||||
var subRooms = await db.SubRooms.Where(x => (roomData != null) ? x.RoomId == roomData.RoomId : false).ToListAsync();
|
||||
var profileAccountId = profile!.accountId;
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
roomFound = room != null,
|
||||
roomDataFound = roomData != null,
|
||||
subRoomsCount = subRooms.Count,
|
||||
presenceExists = await db.Presences.AnyAsync(x => x.playerId == profileAccountId),
|
||||
roomData = roomData,
|
||||
subRooms = subRooms,
|
||||
profile = profile
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("{key}/global/refresh/board/announcement")]
|
||||
public async Task<IActionResult> RefreshBoardAnnouncement(string key)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var board = (await db.ServerConfig.FirstOrDefaultAsync(x => x.Key == "CommunityBoard"))!.Value.FromJson<CommunityBoard>()!;
|
||||
var players = await db.Profiles.ToListAsync();
|
||||
long playerCount = 0;
|
||||
foreach (var player in players)
|
||||
{
|
||||
await Notify.SendNotify(player.accountId, new Notification { Id = Notifs.CommunityBoardAnnouncementUpdate, Msg = board.CurrentAnnouncement });
|
||||
playerCount++;
|
||||
}
|
||||
return Ok("Players affected: " + playerCount.ToString());
|
||||
}
|
||||
[HttpGet("{key}/global/refresh/board")]
|
||||
public async Task<IActionResult> RefreshBoard(string key)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var board = (await db.ServerConfig.FirstOrDefaultAsync(x => x.Key == "CommunityBoard"))!.Value.FromJson<CommunityBoard>()!;
|
||||
var players = await db.Profiles.ToListAsync();
|
||||
long playerCount = 0;
|
||||
foreach (var player in players)
|
||||
{
|
||||
await Notify.SendNotify(player.accountId, new Notification { Id = Notifs.CommunityBoardUpdate, Msg = board });
|
||||
playerCount++;
|
||||
}
|
||||
return Ok("Players affected: " + playerCount.ToString());
|
||||
}
|
||||
[HttpGet("{key}/global/announce")]
|
||||
public async Task<IActionResult> AnnounceToEveryone(string key, [FromQuery] string msg, [FromQuery] long from = 1)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var players = await db.Profiles.ToListAsync();
|
||||
long playerCount = 0;
|
||||
foreach (var player in players)
|
||||
{
|
||||
await Notify.SendMessage(player.accountId, new Message { Type = MessageType.CoachMessage, Data = msg, FromPlayerId = from });
|
||||
playerCount++;
|
||||
}
|
||||
return Ok("Players affected: " + playerCount.ToString());
|
||||
}
|
||||
[HttpGet("{key}/global/maintenance")]
|
||||
public async Task<IActionResult> SetMaintenance(string key, [FromQuery] int min)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var players = await db.Profiles.ToListAsync();
|
||||
long playerCount = 0;
|
||||
foreach (var player in players)
|
||||
{
|
||||
await Notify.SendNotify(player.accountId, new Notification { Id = Notifs.ServerMaintenance, Msg = new ServerMaintenance { StartsInMinutes = min } });
|
||||
playerCount++;
|
||||
}
|
||||
return Ok("Players affected: " + playerCount.ToString());
|
||||
}
|
||||
[HttpGet("{key}/coach/friend/{id}")]
|
||||
public async Task<IActionResult> CoachFriendRequest(string key, long id)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendMessage(id, new Message { Type = MessageType.FriendInvite, FromPlayerId = 1 });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/coach/friended/{id}")]
|
||||
public async Task<IActionResult> CoachFriended(string key, long id)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendMessage(id, new Message { Type = MessageType.FriendRequestAccepted, FromPlayerId = 1 });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/coach/invite/{id}/{roomId}")]
|
||||
public async Task<IActionResult> CoachInvite(string key, long id, long roomId)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendMessage(id, new Message { Type = MessageType.GameInvite, FromPlayerId = 1, RoomId = roomId });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/{playerId}/invite/{id}/{roomId}")]
|
||||
public async Task<IActionResult> PlayerInvite(string key, long playerId, long id, long roomId)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendMessage(id, new Message { Type = MessageType.GameInvite, FromPlayerId = playerId, RoomId = roomId });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/coach/join/{id}/{roomId}")]
|
||||
public async Task<IActionResult> CoachJoin(string key, long id, long roomId)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendMessage(id, new Message { Type = MessageType.RequestGameInvite, FromPlayerId = 1, RoomId = roomId });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/mod/quit/{id}")]
|
||||
public async Task<IActionResult> ModQuit(string key, long id)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendNotify(id, new Notification { Id = NotificationType.ModerationQuitGame, Msg = null });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
[HttpGet("{key}/mod/kick/{id}")]
|
||||
public async Task<IActionResult> ModKick(string key, long id)
|
||||
{
|
||||
if (key != DBConfig.DebugKey) return Forbid();
|
||||
|
||||
var player = await db.Profiles.FirstOrDefaultAsync(x => x.accountId == id);
|
||||
if (player == null) return NotFound();
|
||||
|
||||
await Notify.SendNotify(id, new Notification { Id = NotificationType.ModerationKick, Msg = PlayerUtils.BuildBlockDetails(true, ReportCategory.Misc, "Kicked via debug command", DateTime.UtcNow.AddMinutes(15)) });
|
||||
|
||||
return Ok("Players affected: 1");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace RadicadeServer.API.TestCaseManagement
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[Route("api/testcasemanagement/")]
|
||||
public class TestCaseManagementAPI : Controller
|
||||
{
|
||||
[HttpGet("v1/testpasssummary"), Authorize]
|
||||
public IActionResult TestPassSummary()
|
||||
{
|
||||
return Ok(Array.Empty<object>());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user