mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
196 lines
7.1 KiB
C#
196 lines
7.1 KiB
C#
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
|
|
}
|
|
}
|