From ce12bde5ae46f8bfcc0c37927d8270d51287a825 Mon Sep 17 00:00:00 2001 From: xeon Date: Thu, 25 Jan 2024 16:28:53 +0300 Subject: [PATCH] Add exception handler, also fix scene loading when some list is null --- RPG.GameCore/Level/Group/LevelGroupInfo.cs | 8 ++-- .../Network/Command/ServiceCommandHandler.cs | 9 +++- .../Game/Maze/MazeManager.cs | 41 +++++++++++-------- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/RPG.GameCore/Level/Group/LevelGroupInfo.cs b/RPG.GameCore/Level/Group/LevelGroupInfo.cs index d68de2c..188c3da 100644 --- a/RPG.GameCore/Level/Group/LevelGroupInfo.cs +++ b/RPG.GameCore/Level/Group/LevelGroupInfo.cs @@ -16,14 +16,14 @@ public class LevelGroupInfo public LevelSaveType SaveType { get; set; } // 0x40 public uint CheckClearMainMissionID { get; set; } // 0x44 public uint UnlockMainMissionID { get; set; } // 0x48 - public LevelAnchorInfo[] AnchorList { get; set; } = []; // 0x50 + public LevelAnchorInfo[]? AnchorList { get; set; } = []; // 0x50 // TODO: public LevelModelInfo[] ModelList { get; set; } // 0x58 - public LevelMonsterInfo[] MonsterList { get; set; } = []; // 0x60 - public LevelPropInfo[] PropList { get; set; } = []; // 0x68 + public LevelMonsterInfo[]? MonsterList { get; set; } = []; // 0x60 + public LevelPropInfo[]? PropList { get; set; } = []; // 0x68 // TODO: public LevelWaypointInfo[] WaypointList { get; set; } // 0x70 // TODO: public LevelPathwayInfo[] PathwayList { get; set; } // 0x78 // TODO: public LevelBattleAreaInfo[] BattleAreaList { get; set; } // 0x80 - public LevelNPCInfo[] NPCList { get; set; } = []; // 0x88 + public LevelNPCInfo[]? NPCList { get; set; } = []; // 0x88 public uint GroupRefreshID { get; set; } // 0x90 // TODO: public RandomNPCMonsterInfo[] RandomNPCMonsterList { get; set; } // 0x98 public uint[] InitialRandomNPCMonsterIDList { get; set; } = []; // 0xA0 diff --git a/RPG.Services.Core/Network/Command/ServiceCommandHandler.cs b/RPG.Services.Core/Network/Command/ServiceCommandHandler.cs index a84539f..fe0479c 100644 --- a/RPG.Services.Core/Network/Command/ServiceCommandHandler.cs +++ b/RPG.Services.Core/Network/Command/ServiceCommandHandler.cs @@ -26,7 +26,14 @@ public abstract class ServiceCommandHandler { if (_handlers.TryGetValue(command.CommandType, out HandlerDelegate? handler)) { - await handler(command); + try + { + await handler(command); + } + catch (Exception handlingException) + { + _logger.LogError("Exception occurred while handling ServiceCommand of type {type}, trace:\n{exception}", command.CommandType, handlingException); + } } else { diff --git a/RPG.Services.Gameserver/Game/Maze/MazeManager.cs b/RPG.Services.Gameserver/Game/Maze/MazeManager.cs index 002ec02..be1663f 100644 --- a/RPG.Services.Gameserver/Game/Maze/MazeManager.cs +++ b/RPG.Services.Gameserver/Game/Maze/MazeManager.cs @@ -123,34 +123,43 @@ internal class MazeManager LevelGroupInfo? levelGroup = _levelTables.GetGroupInfo(groupInstanceInfo.GroupGUID); if (levelGroup == null) continue; - foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList) + if (levelGroup.MonsterList != null) { - if (!levelMonster.CreateOnInitial) continue; + foreach (LevelMonsterInfo levelMonster in levelGroup.MonsterList) + { + if (!levelMonster.CreateOnInitial) continue; - NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID); - monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster)); + NpcMonsterEntity monsterEntity = _entityFactory.CreateNpcMonsterEntity(levelMonster, groupInstanceInfo.ID); + monsterEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelMonster)); - EntityManager.AddEntity(monsterEntity); + EntityManager.AddEntity(monsterEntity); + } } - foreach (LevelPropInfo levelProp in levelGroup.PropList) + if (levelGroup.PropList != null) { - if (!levelProp.CreateOnInitial) continue; + foreach (LevelPropInfo levelProp in levelGroup.PropList) + { + if (!levelProp.CreateOnInitial) continue; - PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID); - propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp)); + PropEntity propEntity = _entityFactory.CreatePropEntity(levelProp, groupInstanceInfo.ID); + propEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelProp)); - EntityManager.AddEntity(propEntity); + EntityManager.AddEntity(propEntity); + } } - foreach (LevelNPCInfo levelNPC in levelGroup.NPCList) + if (levelGroup.NPCList != null) { - if (!levelNPC.CreateOnInitial) continue; + foreach (LevelNPCInfo levelNPC in levelGroup.NPCList) + { + if (!levelNPC.CreateOnInitial) continue; - NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID); - npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC)); + NpcEntity npcEntity = _entityFactory.CreateNpcEntity(levelNPC, groupInstanceInfo.ID); + npcEntity.SetMotion(MazeUtil.CreateDefaultMotion(levelNPC)); - EntityManager.AddEntity(npcEntity); + EntityManager.AddEntity(npcEntity); + } } } } @@ -171,7 +180,7 @@ internal class MazeManager private MotionInfo CreateInitialAvatarMotion() { LevelGroupInfo startGroup = _levelTables.GetGroupInfo(_floor!.StartGroup.GroupGUID)!; - LevelAnchorInfo startAnchor = startGroup.AnchorList.First(anchor => anchor.ID == _floor.StartAnchorID); + LevelAnchorInfo startAnchor = startGroup.AnchorList!.First(anchor => anchor.ID == _floor.StartAnchorID); return MazeUtil.CreateDefaultMotion(startAnchor); }