mirror of
https://github.com/project-redbud/FunGame-Server.git
synced 2025-05-11 20:19:34 +08:00

* PayloadModel 添加 event 属性,添加 Room,Main 的 API 控制器 * 实现 SQLHelper 的自增 ID、异步版本功能 * 填充一些请求控制器的方法 * 添加报价的核心操作 * 涉及库存的物品获取应该使用 Guid 而不是 ItemId * 添加 InventoryController * 添加更新房间设置和用户房间的状态管理 * 优化 API Token 秘钥管理;修复服务器统一报错信息 BUG * 优雅的关闭服务器;补全了所有数据请求实现;API Token 加密方式修改;添加了服务器初始化时创建管理员账号的必要步骤 * 完善 Web API 控制器 --------- Co-authored-by: yeziuku <yezi@wrss.org>
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Milimoe.FunGame.Core.Library.Constant;
|
|
using Milimoe.FunGame.WebAPI.Models;
|
|
|
|
namespace Milimoe.FunGame.WebAPI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
[Authorize]
|
|
public class MainController(RESTfulAPIModel model, ILogger<MainController> logger) : ControllerBase
|
|
{
|
|
private readonly ILogger<MainController> _logger = logger;
|
|
|
|
/// <summary>
|
|
/// 获取公告
|
|
/// </summary>
|
|
[HttpGet("notice")]
|
|
public async Task<IActionResult> GetNotice()
|
|
{
|
|
PayloadModel<DataRequestType> response = new()
|
|
{
|
|
Event = "main_getnotice",
|
|
RequestType = DataRequestType.Main_GetNotice
|
|
};
|
|
|
|
try
|
|
{
|
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Main_GetNotice, []);
|
|
response.StatusCode = 200;
|
|
response.Data = result;
|
|
return Ok(response);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError("Error: {e}", e);
|
|
}
|
|
|
|
response.StatusCode = 500;
|
|
response.Message = "服务器暂时无法处理此请求。";
|
|
return StatusCode(500, response);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送聊天消息
|
|
/// </summary>
|
|
[HttpPost("chat")]
|
|
public async Task<IActionResult> Chat([FromBody] Dictionary<string, object> data)
|
|
{
|
|
PayloadModel<DataRequestType> response = new()
|
|
{
|
|
Event = "main_chat",
|
|
RequestType = DataRequestType.Main_Chat
|
|
};
|
|
|
|
try
|
|
{
|
|
Dictionary<string, object> result = await model.DataRequestController.GetResultData(DataRequestType.Main_Chat, data);
|
|
response.StatusCode = 200;
|
|
response.Data = result;
|
|
return Ok(response);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError("Error: {e}", e);
|
|
}
|
|
|
|
response.StatusCode = 500;
|
|
response.Message = "服务器暂时无法处理此请求。";
|
|
return StatusCode(500, response);
|
|
}
|
|
}
|
|
}
|