mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-06 22:50:30 -04:00
Removed NioTSO client and server
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
This commit is contained in:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
73
server/FSO.Server.Api.Core/Controllers/Admin/AdminTasksController.cs
Executable file
73
server/FSO.Server.Api.Core/Controllers/Admin/AdminTasksController.cs
Executable file
|
@ -0,0 +1,73 @@
|
|||
using FSO.Server.Api.Core.Utils;
|
||||
using FSO.Server.Database.DA.Tasks;
|
||||
using FSO.Server.Protocol.Gluon.Packets;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
namespace FSO.Server.Api.Core.Controllers.Admin
|
||||
{
|
||||
[EnableCors("AdminAppPolicy")]
|
||||
[Route("admin/tasks")]
|
||||
[ApiController]
|
||||
public class AdminTasksController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IActionResult Get(int limit, int offset)
|
||||
{
|
||||
var api = Api.INSTANCE;
|
||||
api.DemandAdmin(Request);
|
||||
|
||||
using (var da = api.DAFactory.Get())
|
||||
{
|
||||
|
||||
if (limit > 100)
|
||||
{
|
||||
limit = 100;
|
||||
}
|
||||
|
||||
var result = da.Tasks.All((int)offset, (int)limit);
|
||||
return ApiResponse.PagedList<DbTask>(Request, HttpStatusCode.OK, result);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("request")]
|
||||
public IActionResult request([FromBody] TaskRequest task)
|
||||
{
|
||||
var api = Api.INSTANCE;
|
||||
api.DemandAdmin(Request);
|
||||
|
||||
var taskServer = api.HostPool.GetByRole(Database.DA.Hosts.DbHostRole.task).FirstOrDefault();
|
||||
if (taskServer == null)
|
||||
{
|
||||
return ApiResponse.Json(HttpStatusCode.OK, -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = taskServer.Call(new RequestTask()
|
||||
{
|
||||
TaskType = task.task_type.ToString(),
|
||||
ParameterJson = JsonConvert.SerializeObject(task.parameter),
|
||||
ShardId = (task.shard_id == null || !task.shard_id.HasValue) ? -1 : task.shard_id.Value
|
||||
}).Result;
|
||||
return ApiResponse.Json(HttpStatusCode.OK, id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResponse.Json(HttpStatusCode.OK, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class TaskRequest
|
||||
{
|
||||
public DbTaskType task_type;
|
||||
public int? shard_id;
|
||||
public dynamic parameter;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue