yuanshen/Yuanshen.Gameserver/Controllers/EventController.cs
wisedev fc2ac1050f First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:10:50 +03:00

56 lines
2.2 KiB
C#

using Yuanshen.Gameserver.Controllers.Attributes;
using Yuanshen.Gameserver.Controllers.Result;
using Yuanshen.Gameserver.Game;
using Yuanshen.Protocol;
using Microsoft.Extensions.Logging;
namespace Yuanshen.Gameserver.Controllers;
[NetController]
internal sealed class EventController : ControllerBase
{
[NetCommand(CmdType.SeeMonsterReq)]
public ValueTask<IResult> OnSeeMonsterReq()
{
SeeMonsterReq req = Packet!.DecodeBody<SeeMonsterReq>();
return ValueTask.FromResult(Response(CmdType.SeeMonsterRsp, new SeeMonsterRsp { Retcode = Retcode.RET_SUCC }));
}
[NetCommand(CmdType.EvtAvatarEnterFocusNotify)]
public ValueTask<IResult> OnEvtAvatarEnterFocusNotify() => Handled<EvtAvatarEnterFocusNotify>();
[NetCommand(CmdType.EvtAvatarUpdateFocusNotify)]
public ValueTask<IResult> OnEvtAvatarUpdateFocusNotify() => Handled<EvtAvatarUpdateFocusNotify>();
[NetCommand(CmdType.EvtAvatarExitFocusNotify)]
public ValueTask<IResult> OnEvtAvatarExitFocusNotify() => Handled<EvtAvatarExitFocusNotify>();
[NetCommand(CmdType.EvtCreateGadgetNotify)]
public ValueTask<IResult> OnEvtCreateGadgetNotify(Player player, ILogger<EventController> logger)
{
EvtCreateGadgetNotify notify = Packet!.DecodeBody<EvtCreateGadgetNotify>();
player.ClientGadgets[notify.EntityId] = notify.ConfigId;
logger.LogDebug("Gadget created entity={entity} config={config} owner={owner}",
notify.EntityId, notify.ConfigId, notify.OwnerEntityId);
return ValueTask.FromResult(Ok());
}
[NetCommand(CmdType.EvtDestroyGadgetNotify)]
public ValueTask<IResult> OnEvtDestroyGadgetNotify(Player player, ILogger<EventController> logger)
{
EvtDestroyGadgetNotify notify = Packet!.DecodeBody<EvtDestroyGadgetNotify>();
player.ClientGadgets.Remove(notify.EntityId);
logger.LogDebug("Gadget destroyed entity={entity}", notify.EntityId);
return ValueTask.FromResult(Ok());
}
private ValueTask<IResult> Handled<TMessage>() where TMessage : Google.Protobuf.IMessage<TMessage>, new()
{
Packet!.DecodeBody<TMessage>();
return ValueTask.FromResult(Ok());
}
}