forked from MrOkiDoki/BattleBit-Community-Server-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandAPI.cs
More file actions
41 lines (35 loc) · 1.06 KB
/
CommandAPI.cs
File metadata and controls
41 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.AspNetCore.Mvc;
namespace BattleBitAPI.Server;
[Route("api/{steamId}/{action}/{amount}/{executorName}/{data}")]
[ApiController]
public class CommandController : ControllerBase
{
private readonly CommandQueue _commandQueue;
public CommandController(CommandQueue commandQueue)
{
_commandQueue = commandQueue;
}
[HttpGet]
public IActionResult ExecuteCommand(ulong steamId, string action, int amount, string executorName, string data)
{
ActionType validAction;
try
{
validAction = (ActionType)Enum.Parse(typeof(ActionType), action, true);
}
catch
{
return BadRequest("Invalid action.");
}
var command = new Command
{
Action = validAction,
StreamerId = steamId,
Amount = amount,
ExecutorName = executorName,
Data = data.Split('§')
};
_commandQueue.Enqueue(command);
return Ok($"Command for {executorName} has been queued for execution.");
}
}