diff --git a/GameServer/Controllers/AchievementController.cs b/GameServer/Controllers/AchievementController.cs index c6f00bb..bf2c15e 100644 --- a/GameServer/Controllers/AchievementController.cs +++ b/GameServer/Controllers/AchievementController.cs @@ -12,5 +12,5 @@ internal class AchievementController : Controller } [NetEvent(MessageId.AchievementInfoRequest)] - public ResponseMessage OnAchievementInfoRequest() => Response(MessageId.AchievementInfoResponse, new AchievementInfoResponse()); + public RpcResult OnAchievementInfoRequest() => Response(MessageId.AchievementInfoResponse, new AchievementInfoResponse()); } diff --git a/GameServer/Controllers/ChatController.cs b/GameServer/Controllers/ChatController.cs index 31a52ae..4b16b6a 100644 --- a/GameServer/Controllers/ChatController.cs +++ b/GameServer/Controllers/ChatController.cs @@ -18,7 +18,7 @@ internal class ChatController : Controller } [NetEvent(MessageId.PrivateChatDataRequest)] - public async Task OnPrivateChatDataRequest() + public async Task OnPrivateChatDataRequest() { if (!_modelManager.Chat.AllChatRooms.Any()) { @@ -31,7 +31,7 @@ internal class ChatController : Controller } [NetEvent(MessageId.PrivateChatRequest)] - public async Task OnPrivateChatRequest(PrivateChatRequest request, ChatCommandManager chatCommandManager) + public async Task OnPrivateChatRequest(PrivateChatRequest request, ChatCommandManager chatCommandManager) { ChatRoom chatRoom = _modelManager.Chat.GetChatRoom(1338); @@ -54,7 +54,7 @@ internal class ChatController : Controller } [NetEvent(MessageId.PrivateChatOperateRequest)] - public ResponseMessage OnPrivateChatOperateRequest() => Response(MessageId.PrivateChatOperateResponse, new PrivateChatOperateResponse()); + public RpcResult OnPrivateChatOperateRequest() => Response(MessageId.PrivateChatOperateResponse, new PrivateChatOperateResponse()); private async Task PushPrivateChatHistory() { diff --git a/GameServer/Controllers/CombatMessageController.cs b/GameServer/Controllers/CombatMessageController.cs index cf4837c..f3c6a67 100644 --- a/GameServer/Controllers/CombatMessageController.cs +++ b/GameServer/Controllers/CombatMessageController.cs @@ -13,7 +13,7 @@ internal class CombatMessageController : Controller } [NetEvent(MessageId.CombatSendPackRequest)] // TODO: CombatSendPackRequest is important - public async Task OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager) + public async Task OnCombatSendPackRequest(CombatSendPackRequest request, CombatManager combatManager) { CombatReceivePackNotify combatPackNotify = new(); diff --git a/GameServer/Controllers/Controller.cs b/GameServer/Controllers/Controller.cs index d32ab43..c316f56 100644 --- a/GameServer/Controllers/Controller.cs +++ b/GameServer/Controllers/Controller.cs @@ -1,4 +1,5 @@ -using GameServer.Network; +global using GameServer.Controllers.Result; +using GameServer.Network; using GameServer.Network.Messages; using Google.Protobuf; using Protocol; @@ -13,9 +14,9 @@ internal abstract class Controller Session = session; } - protected static ResponseMessage Response(MessageId messageId, TProtoBuf protoBuf) where TProtoBuf : IMessage => new() + protected static RpcResult Response(MessageId messageId, TProtoBuf protoBuf) where TProtoBuf : IMessage => new(new ResponseMessage { MessageId = messageId, Payload = protoBuf.ToByteArray() - }; + }); } diff --git a/GameServer/Controllers/CreatureController.cs b/GameServer/Controllers/CreatureController.cs index 8011bb7..ee493c7 100644 --- a/GameServer/Controllers/CreatureController.cs +++ b/GameServer/Controllers/CreatureController.cs @@ -42,7 +42,7 @@ internal class CreatureController : Controller } [NetEvent(MessageId.EntityActiveRequest)] - public async Task OnEntityActiveRequest(EntityActiveRequest request) + public async Task OnEntityActiveRequest(EntityActiveRequest request) { EntityActiveResponse response; @@ -68,7 +68,7 @@ internal class CreatureController : Controller } [NetEvent(MessageId.SceneLoadingFinishRequest)] - public async Task OnSceneLoadingFinishRequest() + public async Task OnSceneLoadingFinishRequest() { _modelManager.Creature.OnWorldDone(); await UpdateAiHate(); diff --git a/GameServer/Controllers/DailyActivityController.cs b/GameServer/Controllers/DailyActivityController.cs index 116c3ec..bd71157 100644 --- a/GameServer/Controllers/DailyActivityController.cs +++ b/GameServer/Controllers/DailyActivityController.cs @@ -12,8 +12,8 @@ internal class DailyActivityController : Controller } [NetEvent(MessageId.ActivityRequest)] - public ResponseMessage OnActivityRequest() => Response(MessageId.ActivityResponse, new ActivityResponse()); + public RpcResult OnActivityRequest() => Response(MessageId.ActivityResponse, new ActivityResponse()); [NetEvent(MessageId.LivenessRequest)] - public ResponseMessage OnLivenessRequest() => Response(MessageId.LivenessResponse, new LivenessResponse()); + public RpcResult OnLivenessRequest() => Response(MessageId.LivenessResponse, new LivenessResponse()); } diff --git a/GameServer/Controllers/ExchangeRewardController.cs b/GameServer/Controllers/ExchangeRewardController.cs index eae8864..265f7ae 100644 --- a/GameServer/Controllers/ExchangeRewardController.cs +++ b/GameServer/Controllers/ExchangeRewardController.cs @@ -12,5 +12,5 @@ internal class ExchangeRewardController : Controller } [NetEvent(MessageId.ExchangeRewardInfoRequest)] - public ResponseMessage OnExchangeRewardInfoRequest() => Response(MessageId.ExchangeRewardInfoResponse, new ExchangeRewardInfoResponse()); + public RpcResult OnExchangeRewardInfoRequest() => Response(MessageId.ExchangeRewardInfoResponse, new ExchangeRewardInfoResponse()); } diff --git a/GameServer/Controllers/ExploreProgressController.cs b/GameServer/Controllers/ExploreProgressController.cs index 8470978..8dde490 100644 --- a/GameServer/Controllers/ExploreProgressController.cs +++ b/GameServer/Controllers/ExploreProgressController.cs @@ -15,7 +15,7 @@ internal class ExploreProgressController : Controller } [NetEvent(MessageId.ExploreProgressRequest)] - public ResponseMessage OnExploreProgressRequest() + public RpcResult OnExploreProgressRequest() { return Response(MessageId.ExploreProgressResponse, new ExploreProgressResponse { diff --git a/GameServer/Controllers/Factory/EventHandlerFactory.cs b/GameServer/Controllers/Factory/EventHandlerFactory.cs index cd8984b..9d64faa 100644 --- a/GameServer/Controllers/Factory/EventHandlerFactory.cs +++ b/GameServer/Controllers/Factory/EventHandlerFactory.cs @@ -90,13 +90,13 @@ internal class EventHandlerFactory var builder = ImmutableDictionary.CreateBuilder(); MethodInfo getServiceMethod = typeof(ServiceProviderServiceExtensions).GetMethod(nameof(ServiceProviderServiceExtensions.GetRequiredService), [typeof(IServiceProvider)])!; - MethodInfo taskFromResultMethod = typeof(Task).GetMethod(nameof(Task.FromResult))!.MakeGenericMethod(typeof(ResponseMessage)); + MethodInfo taskFromResultMethod = typeof(Task).GetMethod(nameof(Task.FromResult))!.MakeGenericMethod(typeof(RpcResult)); foreach (Type type in controllerTypes) { IEnumerable methods = type.GetMethods() .Where(method => method.GetCustomAttribute() != null - && (method.ReturnType == typeof(Task) || method.ReturnType == typeof(ResponseMessage))); + && (method.ReturnType == typeof(Task) || method.ReturnType == typeof(RpcResult))); foreach (MethodInfo method in methods) { @@ -108,7 +108,7 @@ internal class EventHandlerFactory MethodCallExpression getServiceCall = Expression.Call(getServiceMethod.MakeGenericMethod(type), serviceProviderParam); Expression handlerCall = Expression.Call(getServiceCall, method, FetchArgumentsForMethod(method, serviceProviderParam, getServiceMethod, dataParam)); - if (method.ReturnType == typeof(ResponseMessage)) // Allow non-async methods as well + if (method.ReturnType == typeof(RpcResult)) // Allow non-async methods as well handlerCall = Expression.Call(taskFromResultMethod, handlerCall); Expression lambda = Expression.Lambda(handlerCall, serviceProviderParam, dataParam); diff --git a/GameServer/Controllers/FormationAttributeController.cs b/GameServer/Controllers/FormationAttributeController.cs index 4ee62bb..4f5159b 100644 --- a/GameServer/Controllers/FormationAttributeController.cs +++ b/GameServer/Controllers/FormationAttributeController.cs @@ -12,8 +12,8 @@ internal class FormationAttributeController : Controller } [NetEvent(MessageId.TimeCheckRequest)] - public ResponseMessage OnTimeCheckRequest() => Response(MessageId.TimeCheckResponse, new TimeCheckResponse()); + public RpcResult OnTimeCheckRequest() => Response(MessageId.TimeCheckResponse, new TimeCheckResponse()); [NetEvent(MessageId.FormationAttrRequest)] - public ResponseMessage OnFormationAttrRequest() => Response(MessageId.FormationAttrResponse, new FormationAttrResponse()); + public RpcResult OnFormationAttrRequest() => Response(MessageId.FormationAttrResponse, new FormationAttrResponse()); } diff --git a/GameServer/Controllers/FormationController.cs b/GameServer/Controllers/FormationController.cs index 86282af..4e2c823 100644 --- a/GameServer/Controllers/FormationController.cs +++ b/GameServer/Controllers/FormationController.cs @@ -17,7 +17,7 @@ internal class FormationController : Controller } [NetEvent(MessageId.GetFormationDataRequest)] - public ResponseMessage OnGetFormationDataRequest() => Response(MessageId.GetFormationDataResponse, new GetFormationDataResponse + public RpcResult OnGetFormationDataRequest() => Response(MessageId.GetFormationDataResponse, new GetFormationDataResponse { Formations = { @@ -32,7 +32,7 @@ internal class FormationController : Controller }); [NetEvent(MessageId.UpdateFormationRequest)] - public async Task OnUpdateFormationRequest(UpdateFormationRequest request, EventSystem eventSystem) + public async Task OnUpdateFormationRequest(UpdateFormationRequest request, EventSystem eventSystem) { _modelManager.Formation.Set([.. request.Formation.RoleIds]); await eventSystem.Emit(GameEventType.FormationUpdated); diff --git a/GameServer/Controllers/FriendSystemController.cs b/GameServer/Controllers/FriendSystemController.cs index 8c96be3..ac60d80 100644 --- a/GameServer/Controllers/FriendSystemController.cs +++ b/GameServer/Controllers/FriendSystemController.cs @@ -12,7 +12,7 @@ internal class FriendSystemController : Controller } [NetEvent(MessageId.FriendAllRequest)] - public ResponseMessage OnFriendAllRequest() => Response(MessageId.FriendAllResponse, new FriendAllResponse + public RpcResult OnFriendAllRequest() => Response(MessageId.FriendAllResponse, new FriendAllResponse { FriendInfoList = { diff --git a/GameServer/Controllers/GachaController.cs b/GameServer/Controllers/GachaController.cs index 4abb695..a2f4102 100644 --- a/GameServer/Controllers/GachaController.cs +++ b/GameServer/Controllers/GachaController.cs @@ -12,5 +12,5 @@ internal class GachaController : Controller } [NetEvent(MessageId.GachaInfoRequest)] - public ResponseMessage OnGachaInfoRequest() => Response(MessageId.GachaInfoResponse, new GachaInfoResponse()); + public RpcResult OnGachaInfoRequest() => Response(MessageId.GachaInfoResponse, new GachaInfoResponse()); } diff --git a/GameServer/Controllers/InfluenceReputationController.cs b/GameServer/Controllers/InfluenceReputationController.cs index 4a50940..5db65bd 100644 --- a/GameServer/Controllers/InfluenceReputationController.cs +++ b/GameServer/Controllers/InfluenceReputationController.cs @@ -12,5 +12,5 @@ internal class InfluenceReputationController : Controller } [NetEvent(MessageId.InfluenceInfoRequest)] - public ResponseMessage OnInfluenceInfoRequest() => Response(MessageId.InfluenceInfoResponse, new InfluenceInfoResponse()); + public RpcResult OnInfluenceInfoRequest() => Response(MessageId.InfluenceInfoResponse, new InfluenceInfoResponse()); } diff --git a/GameServer/Controllers/InventoryController.cs b/GameServer/Controllers/InventoryController.cs index 1219cba..6d8c742 100644 --- a/GameServer/Controllers/InventoryController.cs +++ b/GameServer/Controllers/InventoryController.cs @@ -12,14 +12,14 @@ internal class InventoryController : Controller } [NetEvent(MessageId.NormalItemRequest)] - public ResponseMessage OnNormalItemRequest() => Response(MessageId.NormalItemResponse, new NormalItemResponse()); + public RpcResult OnNormalItemRequest() => Response(MessageId.NormalItemResponse, new NormalItemResponse()); [NetEvent(MessageId.WeaponItemRequest)] - public ResponseMessage OnWeaponItemRequest() => Response(MessageId.WeaponItemResponse, new WeaponItemResponse()); + public RpcResult OnWeaponItemRequest() => Response(MessageId.WeaponItemResponse, new WeaponItemResponse()); [NetEvent(MessageId.PhantomItemRequest)] - public ResponseMessage OnPhantomItemRequest() => Response(MessageId.PhantomItemResponse, new PhantomItemResponse()); + public RpcResult OnPhantomItemRequest() => Response(MessageId.PhantomItemResponse, new PhantomItemResponse()); [NetEvent(MessageId.ItemExchangeInfoRequest)] - public ResponseMessage OnItemExchangeInfoRequest() => Response(MessageId.ItemExchangeInfoResponse, new ItemExchangeInfoResponse()); + public RpcResult OnItemExchangeInfoRequest() => Response(MessageId.ItemExchangeInfoResponse, new ItemExchangeInfoResponse()); } diff --git a/GameServer/Controllers/LoginController.cs b/GameServer/Controllers/LoginController.cs index 0e6f5b8..5def7c0 100644 --- a/GameServer/Controllers/LoginController.cs +++ b/GameServer/Controllers/LoginController.cs @@ -1,8 +1,6 @@ using GameServer.Controllers.Attributes; using GameServer.Network; -using GameServer.Network.Messages; using GameServer.Systems.Event; -using Microsoft.Extensions.Logging; using Protocol; namespace GameServer.Controllers; @@ -14,7 +12,7 @@ internal class LoginController : Controller } [NetEvent(MessageId.LoginRequest)] - public async Task OnLoginRequest(EventSystem eventSystem) + public async Task OnLoginRequest(EventSystem eventSystem) { await eventSystem.Emit(GameEventType.Login); @@ -27,16 +25,19 @@ internal class LoginController : Controller } [NetEvent(MessageId.EnterGameRequest)] - public async Task OnEnterGameRequest(EnterGameRequest request, ILogger logger, EventSystem eventSystem) + public RpcResult OnEnterGameRequest() { - logger.LogInformation("Enter Game Request:\n{req}", request); + return Response(MessageId.EnterGameResponse, new EnterGameResponse()) + .AddPostEvent(GameEventType.EnterGame) + .AddPostEvent(GameEventType.PushDataDone); + } - await eventSystem.Emit(GameEventType.EnterGame); + [GameEvent(GameEventType.PushDataDone)] + public async Task OnPushDataDone() + { await Session.Push(MessageId.PushDataCompleteNotify, new PushDataCompleteNotify()); - - return Response(MessageId.EnterGameResponse, new EnterGameResponse()); } [NetEvent(MessageId.HeartbeatRequest)] - public ResponseMessage OnHeartbeatRequest() => Response(MessageId.HeartbeatResponse, new HeartbeatResponse()); + public RpcResult OnHeartbeatRequest() => Response(MessageId.HeartbeatResponse, new HeartbeatResponse()); } \ No newline at end of file diff --git a/GameServer/Controllers/LordGymController.cs b/GameServer/Controllers/LordGymController.cs index cf40b31..a46a69a 100644 --- a/GameServer/Controllers/LordGymController.cs +++ b/GameServer/Controllers/LordGymController.cs @@ -12,5 +12,5 @@ internal class LordGymController : Controller } [NetEvent(MessageId.LordGymInfoRequest)] - public ResponseMessage OnLordGymInfoRequest() => Response(MessageId.LordGymInfoResponse, new LordGymInfoResponse()); + public RpcResult OnLordGymInfoRequest() => Response(MessageId.LordGymInfoResponse, new LordGymInfoResponse()); } diff --git a/GameServer/Controllers/PlayerInfoController.cs b/GameServer/Controllers/PlayerInfoController.cs index 2181043..f102e4e 100644 --- a/GameServer/Controllers/PlayerInfoController.cs +++ b/GameServer/Controllers/PlayerInfoController.cs @@ -42,6 +42,12 @@ internal class PlayerInfoController : Controller Key = (int)PlayerAttrKey.HeadPhoto, ValueType = (int)PlayerAttrType.Int32, Int32Value = 1402 + }, + new PlayerAttr + { + Key = (int)PlayerAttrKey.Sex, + ValueType = (int)PlayerAttrType.Int32, + Int32Value = 1 } }, RoleShowList = @@ -67,7 +73,7 @@ internal class PlayerInfoController : Controller } [NetEvent(MessageId.PlayerBasicInfoGetRequest)] - public ResponseMessage OnPlayerBasicInfoGetRequest() + public RpcResult OnPlayerBasicInfoGetRequest() { return Response(MessageId.PlayerBasicInfoGetResponse, new PlayerBasicInfoGetResponse { diff --git a/GameServer/Controllers/Result/RpcResult.cs b/GameServer/Controllers/Result/RpcResult.cs new file mode 100644 index 0000000..a6c043a --- /dev/null +++ b/GameServer/Controllers/Result/RpcResult.cs @@ -0,0 +1,21 @@ +using GameServer.Network.Messages; +using GameServer.Systems.Event; + +namespace GameServer.Controllers.Result; +internal class RpcResult +{ + public ResponseMessage Response { get; } + public List PostEvents { get; } + + public RpcResult(ResponseMessage response) + { + Response = response; + PostEvents = []; + } + + public RpcResult AddPostEvent(GameEventType type) + { + PostEvents.Add(type); + return this; + } +} diff --git a/GameServer/Controllers/RoguelikeController.cs b/GameServer/Controllers/RoguelikeController.cs index 23ad8ac..615387b 100644 --- a/GameServer/Controllers/RoguelikeController.cs +++ b/GameServer/Controllers/RoguelikeController.cs @@ -12,5 +12,5 @@ internal class RoguelikeController : Controller } [NetEvent(MessageId.RoguelikeSeasonDataRequest)] - public ResponseMessage OnRoguelikeSeasonDataRequest() => Response(MessageId.RoguelikeSeasonDataResponse, new RoguelikeSeasonDataResponse()); + public RpcResult OnRoguelikeSeasonDataRequest() => Response(MessageId.RoguelikeSeasonDataResponse, new RoguelikeSeasonDataResponse()); } diff --git a/GameServer/Controllers/RoleController.cs b/GameServer/Controllers/RoleController.cs index 98b4c4b..1b9cf95 100644 --- a/GameServer/Controllers/RoleController.cs +++ b/GameServer/Controllers/RoleController.cs @@ -36,7 +36,7 @@ internal class RoleController : Controller } [NetEvent(MessageId.SwitchRoleRequest)] - public async Task OnSwitchRoleRequest(SwitchRoleRequest request, CreatureController creatureController) + public async Task OnSwitchRoleRequest(SwitchRoleRequest request, CreatureController creatureController) { await creatureController.SwitchPlayerEntity(request.RoleId); return Response(MessageId.SwitchRoleResponse, new SwitchRoleResponse @@ -46,7 +46,7 @@ internal class RoleController : Controller } [NetEvent(MessageId.RoleFavorListRequest)] - public ResponseMessage OnRoleFavorListRequest() => Response(MessageId.RoleFavorListResponse, new RoleFavorListResponse()); + public RpcResult OnRoleFavorListRequest() => Response(MessageId.RoleFavorListResponse, new RoleFavorListResponse()); private static List CreateBasePropList(BasePropertyConfig? config) { diff --git a/GameServer/Controllers/RouletteController.cs b/GameServer/Controllers/RouletteController.cs index 8c8d9cd..25968eb 100644 --- a/GameServer/Controllers/RouletteController.cs +++ b/GameServer/Controllers/RouletteController.cs @@ -41,7 +41,7 @@ internal class RouletteController : Controller } [NetEvent(MessageId.VisionExploreSkillSetRequest)] - public async Task OnVisionExploreSkillSetRequest(VisionExploreSkillSetRequest request, CreatureController creatureController, EventSystem eventSystem) + public async Task OnVisionExploreSkillSetRequest(VisionExploreSkillSetRequest request, CreatureController creatureController, EventSystem eventSystem) { PlayerEntity? playerEntity = creatureController.GetPlayerEntity(); if (playerEntity == null) return Response(MessageId.VisionExploreSkillSetResponse, new VisionExploreSkillSetResponse { ErrCode = (int)ErrorCode.PlayerNotInAnyScene }); diff --git a/GameServer/Controllers/ShopController.cs b/GameServer/Controllers/ShopController.cs index 11edc99..57a0fdc 100644 --- a/GameServer/Controllers/ShopController.cs +++ b/GameServer/Controllers/ShopController.cs @@ -12,5 +12,5 @@ internal class ShopController : Controller } [NetEvent(MessageId.PayShopInfoRequest)] - public ResponseMessage OnPayShopInfoRequest() => Response(MessageId.PayShopInfoResponse, new PayShopInfoResponse()); + public RpcResult OnPayShopInfoRequest() => Response(MessageId.PayShopInfoResponse, new PayShopInfoResponse()); } diff --git a/GameServer/Controllers/TeleportController.cs b/GameServer/Controllers/TeleportController.cs index f63b162..1e5198a 100644 --- a/GameServer/Controllers/TeleportController.cs +++ b/GameServer/Controllers/TeleportController.cs @@ -12,8 +12,8 @@ internal class TeleportController : Controller } [NetEvent(MessageId.TeleportFinishRequest)] - public ResponseMessage OnTeleportFinishRequest() => Response(MessageId.TeleportFinishResponse, new TeleportFinishResponse()); + public RpcResult OnTeleportFinishRequest() => Response(MessageId.TeleportFinishResponse, new TeleportFinishResponse()); [NetEvent(MessageId.TeleportDataRequest)] - public ResponseMessage OnTeleportDataRequest() => Response(MessageId.TeleportDataResponse, new TeleportDataResponse()); + public RpcResult OnTeleportDataRequest() => Response(MessageId.TeleportDataResponse, new TeleportDataResponse()); } diff --git a/GameServer/Controllers/TowerController.cs b/GameServer/Controllers/TowerController.cs index 7448b62..fa73002 100644 --- a/GameServer/Controllers/TowerController.cs +++ b/GameServer/Controllers/TowerController.cs @@ -12,8 +12,8 @@ internal class TowerController : Controller } [NetEvent(MessageId.TowerChallengeRequest)] - public ResponseMessage OnTowerChallengeRequest() => Response(MessageId.TowerChallengeResponse, new TowerChallengeResponse()); + public RpcResult OnTowerChallengeRequest() => Response(MessageId.TowerChallengeResponse, new TowerChallengeResponse()); [NetEvent(MessageId.CycleTowerChallengeRequest)] - public ResponseMessage OnCycleTowerChallengeRequest() => Response(MessageId.CycleTowerChallengeResponse, new CycleTowerChallengeResponse()); + public RpcResult OnCycleTowerChallengeRequest() => Response(MessageId.CycleTowerChallengeResponse, new CycleTowerChallengeResponse()); } diff --git a/GameServer/Controllers/TutorialController.cs b/GameServer/Controllers/TutorialController.cs index 37203f7..c8e2e14 100644 --- a/GameServer/Controllers/TutorialController.cs +++ b/GameServer/Controllers/TutorialController.cs @@ -12,7 +12,7 @@ internal class TutorialController : Controller } [NetEvent(MessageId.TutorialInfoRequest)] - public ResponseMessage OnTutorialInfoRequest() + public RpcResult OnTutorialInfoRequest() { int[] tutorials = [30001, 30002, 30003, 30004, 30005, 30006, 30007, 30011, 30012, 30008, 30009, 30010, 30013, 30014, 30015, 30016, 30017, 30018, 30019, 30020, 30021, 30022, 30023, 30024, 40001, 30025, 30026, 30027, 30028, 30029, 30030, 30031, 30032, 30033, 30034, 30035, 30036, 50001, 50002, 50003, 50004, 50005, 50006, 50007, 50008, 50009, 50010, 50011, 33001, 34017, 34018, 32001, 32002, 32003, 32004, 32005, 32006, 32007, 32008, 32009, 32010, 32011, 32012, 32013, 32014, 32015, 32016, 32017, 32018, 32019, 32020, 32021, 33002, 33003, 33004, 33005, 34001, 34002, 34003, 34004, 34005, 34006, 34007, 34008, 34009, 34010, 34011, 34012, 34013, 34014, 34015, 34016, 34019, 34020, 34021, 34022, 34023, 34024, 34025, 34027, 34028, 34029, 34030, 34031, 34032, 34033]; TutorialInfoResponse rsp = new(); @@ -30,7 +30,7 @@ internal class TutorialController : Controller } [NetEvent(MessageId.GetDetectionLabelInfoRequest)] - public ResponseMessage OnGetDetectionLabelInfoRequest() + public RpcResult OnGetDetectionLabelInfoRequest() { int[] guides = [0, 1, 2, 3, 14, 15, 16, 4, 21, 22, 7, 5, 18, 6, 61, 8, 9, 10, 11, 12, 13, 17, 19]; int[] detectionTexts = [1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 61]; @@ -43,7 +43,7 @@ internal class TutorialController : Controller } [NetEvent(MessageId.GuideInfoRequest)] - public ResponseMessage OnGuideInfoRequest() => Response(MessageId.GuideInfoResponse, new GuideInfoResponse() + public RpcResult OnGuideInfoRequest() => Response(MessageId.GuideInfoResponse, new GuideInfoResponse() { GuideGroupFinishList = { 60001, 60002, 60003, 60004, 60005, 60006, 60007, 60008, 60009, 60010, 60011, 60012, 60013, 60014, 60015, 60016, 60017, 60018, 60019, 60020, 60021, 60101, 60102, 60103, 62002, 62004, 62005, 62006, 62007, 62009, 62010, 62011, 62012, 62013, 62014, 62015, 62016, 62017, 62022, 62027, 62028, 62029, 62030, 62031, 62032, 62033, 62034, 62036, 65001, 67001, 67002, 67003, 67004, 67005, 67006, 67007, 67008, 67009, 67010, 67011, 67012, 67013, 67014, 67015, 67016, 67017, 67018, 67019, 67022, 62001, 62008, 62018, 62019, 62020, 62021, 62023, 62024, 62025, 62026, 62035, 65002, 65003, 65004, 65005 } }); diff --git a/GameServer/Controllers/WorldController.cs b/GameServer/Controllers/WorldController.cs index 7953c50..bfe1335 100644 --- a/GameServer/Controllers/WorldController.cs +++ b/GameServer/Controllers/WorldController.cs @@ -19,14 +19,14 @@ internal class WorldController : Controller } [NetEvent(MessageId.EntityOnLandedRequest)] - public ResponseMessage OnEntityOnLandedRequest() => Response(MessageId.EntityOnLandedResponse, new EntityOnLandedResponse()); + public RpcResult OnEntityOnLandedRequest() => Response(MessageId.EntityOnLandedResponse, new EntityOnLandedResponse()); [NetEvent(MessageId.PlayerMotionRequest)] - public ResponseMessage OnPlayerMotionRequest() => Response(MessageId.PlayerMotionResponse, new PlayerMotionResponse()); + public RpcResult OnPlayerMotionRequest() => Response(MessageId.PlayerMotionResponse, new PlayerMotionResponse()); [NetEvent(MessageId.EntityLoadCompleteRequest)] - public ResponseMessage OnEntityLoadCompleteRequest() => Response(MessageId.EntityLoadCompleteResponse, new EntityLoadCompleteResponse()); + public RpcResult OnEntityLoadCompleteRequest() => Response(MessageId.EntityLoadCompleteResponse, new EntityLoadCompleteResponse()); [NetEvent(MessageId.UpdateSceneDateRequest)] - public ResponseMessage OnUpdateSceneDateRequest() => Response(MessageId.UpdateSceneDateResponse, new UpdateSceneDateResponse()); + public RpcResult OnUpdateSceneDateRequest() => Response(MessageId.UpdateSceneDateResponse, new UpdateSceneDateResponse()); } diff --git a/GameServer/Controllers/WorldMapController.cs b/GameServer/Controllers/WorldMapController.cs index 5f846cc..5821ff5 100644 --- a/GameServer/Controllers/WorldMapController.cs +++ b/GameServer/Controllers/WorldMapController.cs @@ -15,20 +15,20 @@ internal class WorldMapController : Controller } [NetEvent(MessageId.MapTraceInfoRequest)] - public ResponseMessage OnMapTraceInfoRequest() => Response(MessageId.MapTraceInfoResponse, new MapTraceInfoResponse() + public RpcResult OnMapTraceInfoRequest() => Response(MessageId.MapTraceInfoResponse, new MapTraceInfoResponse() { // Don't. //MarkIdList = { 1, 2, 3, 1000, 1001, 1002, 1003, 1004, 1005, 1007, 1008, 1009, 3000, 3002, 3003, 3005, 3010, 3011, 3012, 4020, 4021, 4022, 4023, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5021, 5022, 5023, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 380000, 380002, 380003, 380004, 380006, 380007, 380015, 301203, 380013, 380014, 301204, 300201, 300202, 300203, 300301, 300302, 300303, 300304, 300306, 300309, 300310, 300311, 300312, 300313, 300401, 300402, 300403, 300404, 300405, 300406, 300407, 300408, 300410, 300413, 300501, 300502, 300506, 300507, 300508, 300509, 300510, 300511, 300601, 300603, 300604, 300605, 300606, 300607, 300608, 300701, 300703, 300704, 300707, 300708, 300711, 300712, 300713, 300901, 300902, 300911, 300912, 300914, 300915, 300918, 301001, 301003, 301004, 301005, 301006, 301007, 301008, 301009, 301010, 301012, 301013, 301014, 301015, 10000, 10001, 10002, 10003, 10005, 10006, 300801, 301201, 300412, 3015, 3016, 3017, 300411 } }); [NetEvent(MessageId.MapUnlockFieldInfoRequest)] - public ResponseMessage OnMapUnlockFieldInfoRequest() => Response(MessageId.MapUnlockFieldInfoResponse, new MapUnlockFieldInfoResponse + public RpcResult OnMapUnlockFieldInfoRequest() => Response(MessageId.MapUnlockFieldInfoResponse, new MapUnlockFieldInfoResponse { FieldId = { Enumerable.Range(1, 12) } }); [NetEvent(MessageId.MapMarkRequest)] - public async Task OnMapMarkRequest(MapMarkRequest request, IOptions gameplayFeatures, CreatureController creatureController) + public async Task OnMapMarkRequest(MapMarkRequest request, IOptions gameplayFeatures, CreatureController creatureController) { if (gameplayFeatures.Value.TeleportByMapMark) { diff --git a/GameServer/Network/Messages/MessageManager.cs b/GameServer/Network/Messages/MessageManager.cs index 049c708..b547478 100644 --- a/GameServer/Network/Messages/MessageManager.cs +++ b/GameServer/Network/Messages/MessageManager.cs @@ -4,7 +4,7 @@ using Protocol; namespace GameServer.Network.Messages; internal delegate Task PushHandler(IServiceProvider serviceProvider, ReadOnlySpan data); -internal delegate Task RpcHandler(IServiceProvider serviceProvider, ReadOnlySpan data); +internal delegate Task RpcHandler(IServiceProvider serviceProvider, ReadOnlySpan data); internal class MessageManager { private readonly EventHandlerFactory _handlerFactory; @@ -16,7 +16,7 @@ internal class MessageManager _serviceProvider = serviceProvider; } - public async Task ExecuteRpc(MessageId messageId, ReadOnlyMemory data) + public async Task ExecuteRpc(MessageId messageId, ReadOnlyMemory data) { RpcHandler? handler = _handlerFactory.GetRpcHandler(messageId); if (handler != null) diff --git a/GameServer/Network/Rpc/RpcManager.cs b/GameServer/Network/Rpc/RpcManager.cs index 957c80b..1b5520b 100644 --- a/GameServer/Network/Rpc/RpcManager.cs +++ b/GameServer/Network/Rpc/RpcManager.cs @@ -1,4 +1,5 @@ using GameServer.Network.Messages; +using GameServer.Systems.Event; using Microsoft.Extensions.Logging; namespace GameServer.Network.Rpc; @@ -7,26 +8,33 @@ internal class RpcManager private readonly IRpcEndPoint _endPoint; private readonly ILogger _logger; private readonly MessageManager _messageManager; + private readonly EventSystem _eventSystem; - public RpcManager(MessageManager messageManager, IRpcEndPoint endPoint, ILogger logger) + public RpcManager(MessageManager messageManager, IRpcEndPoint endPoint, ILogger logger, EventSystem eventSystem) { _endPoint = endPoint; _logger = logger; _messageManager = messageManager; + _eventSystem = eventSystem; } public async Task Execute(RequestMessage request) { - ResponseMessage? response = await _messageManager.ExecuteRpc(request.MessageId, request.Payload); - if (response == null) + RpcResult? result = await _messageManager.ExecuteRpc(request.MessageId, request.Payload); + if (result == null) { _logger.LogWarning("Rpc was not handled properly (message: {msg_id}, id: {rpc_id})", request.MessageId, request.RpcID); return; } - response.RpcID = request.RpcID; - await _endPoint.SendRpcResult(response); + result.Response.RpcID = request.RpcID; + await _endPoint.SendRpcResult(result.Response); - _logger.LogInformation("Rpc with id {rpc_id} was handled, return message: {msg_id}", request.RpcID, response.MessageId); + foreach (GameEventType postEvent in result.PostEvents) + { + await _eventSystem.Emit(postEvent); + } + + _logger.LogInformation("Rpc with id {rpc_id} was handled, return message: {msg_id}", request.RpcID, result.Response.MessageId); } } diff --git a/GameServer/Program.cs b/GameServer/Program.cs index 1d1f6fc..92093df 100644 --- a/GameServer/Program.cs +++ b/GameServer/Program.cs @@ -25,8 +25,8 @@ internal static class Program private static async Task Main(string[] args) { Console.Title = "Wuthering Waves | Game Server"; - Console.WriteLine(" __ __ __ .__ .__ __ __ \r\n/ \\ / \\__ ___/ |_| |__ ___________|__| ____ ____ / \\ / \\_____ ___ __ ____ ______\r\n\\ \\/\\/ / | \\ __\\ | \\_/ __ \\_ __ \\ |/ \\ / ___\\ \\ \\/\\/ /\\__ \\\\ \\/ // __ \\ / ___/\r\n \\ /| | /| | | Y \\ ___/| | \\/ | | \\/ /_/ > \\ / / __ \\\\ /\\ ___/ \\___ \\ \r\n \\__/\\ / |____/ |__| |___| /\\___ >__| |__|___| /\\___ / \\__/\\ / (____ /\\_/ \\___ >____ >\r\n \\/ \\/ \\/ \\//_____/ \\/ \\/ \\/ \\/ \n"); - + Console.WriteLine(" __ __ __ .__ .__ __ __ \r\n/ \\ / \\__ ___/ |_| |__ ___________|__| ____ ____ / \\ / \\_____ ___ __ ____ ______\r\n\\ \\/\\/ / | \\ __\\ | \\_/ __ \\_ __ \\ |/ \\ / ___\\ \\ \\/\\/ /\\__ \\\\ \\/ // __ \\ / ___/\r\n \\ /| | /| | | Y \\ ___/| | \\/ | | \\/ /_/ > \\ / / __ \\\\ /\\ ___/ \\___ \\ \r\n \\__/\\ / |____/ |__| |___| /\\___ >__| |__|___| /\\___ / \\__/\\ / (____ /\\_/ \\___ >____ >\r\n \\/ \\/ \\/ \\//_____/ \\/ \\/ \\/ \\/ \r\n\r\n\t\t\t\t\t\t\t\t\t\t\t\tGame Server\n"); + HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); builder.Logging.AddConsole(); diff --git a/GameServer/Systems/Event/GameEventType.cs b/GameServer/Systems/Event/GameEventType.cs index 6ac5ce7..b95e144 100644 --- a/GameServer/Systems/Event/GameEventType.cs +++ b/GameServer/Systems/Event/GameEventType.cs @@ -3,6 +3,7 @@ internal enum GameEventType { Login = 1, EnterGame, + PushDataDone, // Actions FormationUpdated, diff --git a/GameServer/icon.ico b/GameServer/icon.ico index 2c6c83a..827a9ea 100644 Binary files a/GameServer/icon.ico and b/GameServer/icon.ico differ diff --git a/SDKServer/Program.cs b/SDKServer/Program.cs index 8ba918a..41d3917 100644 --- a/SDKServer/Program.cs +++ b/SDKServer/Program.cs @@ -1,4 +1,3 @@ -using Microsoft.AspNetCore.Builder; using SDKServer.Handlers; using SDKServer.Middleware; @@ -8,11 +7,14 @@ internal static class Program { private static async Task Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); + Console.Title = "Wuthering Waves | SDK Server"; + Console.WriteLine(" __ __ __ .__ .__ __ __ \r\n/ \\ / \\__ ___/ |_| |__ ___________|__| ____ ____ / \\ / \\_____ ___ __ ____ ______\r\n\\ \\/\\/ / | \\ __\\ | \\_/ __ \\_ __ \\ |/ \\ / ___\\ \\ \\/\\/ /\\__ \\\\ \\/ // __ \\ / ___/\r\n \\ /| | /| | | Y \\ ___/| | \\/ | | \\/ /_/ > \\ / / __ \\\\ /\\ ___/ \\___ \\ \r\n \\__/\\ / |____/ |__| |___| /\\___ >__| |__|___| /\\___ / \\__/\\ / (____ /\\_/ \\___ >____ >\r\n \\/ \\/ \\/ \\//_____/ \\/ \\/ \\/ \\/ \r\n\r\n\t\t\t\t\t\t\t\t\t\t\t\tSDK Server\n"); + + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.WebHost.UseUrls("http://*:5500"); builder.Logging.AddSimpleConsole(); - var app = builder.Build(); + WebApplication app = builder.Build(); app.UseMiddleware(); app.MapGet("/api/login", LoginHandler.Login); diff --git a/SDKServer/icon.ico b/SDKServer/icon.ico index 2c6c83a..827a9ea 100644 Binary files a/SDKServer/icon.ico and b/SDKServer/icon.ico differ