From 51659d03cc19877e409bd0d8217976c45e07a771 Mon Sep 17 00:00:00 2001 From: NguyenVanDat Date: Wed, 29 Oct 2025 17:05:57 +0700 Subject: [PATCH] fixx --- .../Scripts/Managers/EC_HPWorkTrace.cs | 14 +- .../Scripts/Managers/EC_ManPlayer.cs | 1 + .../Scripts/Network/CSNetwork/GameSession.cs | 234 +++++++++++------- 3 files changed, 156 insertions(+), 93 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_HPWorkTrace.cs b/Assets/PerfectWorld/Scripts/Managers/EC_HPWorkTrace.cs index 94570e1619..d15c4ca942 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_HPWorkTrace.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_HPWorkTrace.cs @@ -527,7 +527,7 @@ public class CECHPWorkTrace : CECHPWork // Change trace target //void ChangeTarget(int idTarget, int iReason, bool bUseAutoPF=false); - // É趨traceobject + // �趨traceobject public void SetTraceTarget(CECTracedObject pTraceObj, bool bUseAutoPF = false) { ResetUseAutoPF(bUseAutoPF); @@ -601,8 +601,8 @@ public class CECHPWorkTrace : CECHPWork { if (IsGoodTimeToTouch()) { - //OnTouchTarget(); - //return true; + OnTouchTarget(); + return true; if (m_pTraceObject.CanTouchFrom(m_pHost.GetPos() + new A3DVECTOR3(0f, m_pHost.m_CDRInfo.vExtent.y, 0f))) { OnTouchTarget(); @@ -612,7 +612,7 @@ public class CECHPWorkTrace : CECHPWork } m_bCheckTouch = true; - //return true; // TO DO: remove later + return true; // TO DO: remove later if (!m_pHost.IsRooting()) { // Continue tracing object @@ -786,13 +786,13 @@ public class CECHPWorkTrace : CECHPWork protected bool m_bMoreClose; // Move close flag protected bool m_bForceAttack; // Force attack flag protected CECSkill m_pPrepSkill; // Skill prepared to be casted - protected bool m_bActionDone; // Ä¿±êÐÐΪ³É¹¦·¢³ö + protected bool m_bActionDone; // Ŀ����Ϊ�ɹ����� protected bool m_bShouldResetUseAutoPF; protected bool m_bUseAutoPFResetValue; protected bool m_bUseAutoPF; // Use CECIntelligentRoute::Search - protected uint m_dwAutoPFNextCheckTime; // Ï´μì²éʱ¼ä + protected uint m_dwAutoPFNextCheckTime; // �´μ��ʱ�� - protected CECTracedObject m_pTraceObject; // ¶¨ÒåtraceÄ¿±ê¶ÔÏó + protected CECTracedObject m_pTraceObject; // ����traceĿ����� // Operations diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs index b2d1402019..4a4609027c 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs @@ -30,6 +30,7 @@ namespace PerfectWorld.Scripts.Managers if (Msg.iSubID == 0) { if (GameController.Instance == null) return true; + if (GameController.Instance.GetHostPlayer() == null) return true; GameController.Instance.GetHostPlayer().ProcessMessage(Msg); } else if (Msg.iSubID < 0) diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index dd5015a0b2..d1be236edd 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -22,7 +22,8 @@ namespace CSNetwork { public class GameSession : IDisposable { - private static IPrefixedLogger _logger = LoggerFactory.GetLogger(nameof(GameSession)); // Get class-specific logger + private static IPrefixedLogger + _logger = LoggerFactory.GetLogger(nameof(GameSession)); // Get class-specific logger private NetworkManager _networkManager; private string _host; @@ -31,8 +32,10 @@ namespace CSNetwork private string _password; private int _currentUserId = -1; // To store the UserID after successful login private int m_iCharID; - private int m_idLastSelTarget = 0; // ID of selected item last time + private int m_idLastSelTarget = 0; // ID of selected item last time + CECStringTab m_ErrorMsgs; + // State management for async operations and callbacks private Action _loginCallback; private Action> _roleListCallback; @@ -65,6 +68,7 @@ namespace CSNetwork _logger = LoggerFactory.GetCustomLogger(path, nameof(GameSession) + GetHashCode(), LoggerType.File); _networkManager.SetLogPath(path); } + /// /// Connects to the game server asynchronously. /// @@ -78,6 +82,7 @@ namespace CSNetwork _logger.Log(LogType.Warning, "ConnectAsync called but already connected."); return; } + _host = host; _port = port; _logger.Log(LogType.Info, $"Attempting to connect to {_host}:{_port}..."); @@ -90,7 +95,8 @@ namespace CSNetwork } else { - _logger.Log(LogType.Warning, "Connection failed after ConnectAsync completed (check NetworkManager logs/events)."); + _logger.Log(LogType.Warning, + "Connection failed after ConnectAsync completed (check NetworkManager logs/events)."); } } catch (Exception ex) @@ -121,6 +127,7 @@ namespace CSNetwork callback?.Invoke(false); return; } + if (_loginCallback != null) { _logger.Log(LogType.Warning, "LoginAsync called while another login is already in progress."); @@ -148,15 +155,18 @@ namespace CSNetwork callback?.Invoke(null); return; } + if (_currentUserId == -1) { _logger.Log(LogType.Warning, "GetRoleListAsync called but not logged in."); callback?.Invoke(null); return; } + if (_roleListCallback != null) { - _logger.Log(LogType.Warning, "GetRoleListAsync called while another role list retrieval is already in progress."); + _logger.Log(LogType.Warning, + "GetRoleListAsync called while another role list retrieval is already in progress."); callback?.Invoke(null); return; } @@ -166,10 +176,12 @@ namespace CSNetwork _logger.Log(LogType.Info, "Requesting role list..."); RequestRoleListInternal(); } + public RoleInfo GetRoleInfo() { return _selectedRole; } + public void SelectRoleAsync(RoleInfo role, Action callback) { _selectedRole = role; @@ -180,8 +192,8 @@ namespace CSNetwork Roleid = role.roleid, Flag = 0 }); - } + public void EnterWorldAsync(RoleInfo role, Action callback) { SendProtocol(new enterworld() @@ -190,12 +202,14 @@ namespace CSNetwork Provider_link_id = 0, }, callback); } + public void RequestDropIvtrItem(byte index, int amount) { gamedatasend gamedatasendRequest = new gamedatasend(); gamedatasendRequest.Data = C2SCommandFactory.CreateDropIvtrItem(index, amount); SendProtocol(gamedatasendRequest); } + public void RequestDropEquipItem(byte index) { gamedatasend gamedatasendRequest = new gamedatasend(); @@ -209,6 +223,7 @@ namespace CSNetwork gamedatasendRequest.Data = C2SCommandFactory.CreatePickupItem(idItem, tid); SendProtocol(gamedatasendRequest); } + public void RequestInventoryAsync(byte byPackage, Action callback) { gamedatasend gamedatasendRequest = new gamedatasend(); @@ -222,6 +237,7 @@ namespace CSNetwork gamedatasendRequest.Data = C2SCommandFactory.CreateQueryPlayerCash(); SendProtocol(gamedatasendRequest); } + public void RequestCheckSecurityPassWd(string password) { gamedatasend gamedatasendRequest = new gamedatasend(); @@ -242,6 +258,7 @@ namespace CSNetwork gamedatasendRequest.Data = CSNetwork.C2SCommand.C2SCommandFactory.CreateGetMallShopping(count, goodsArray); SendProtocol(gamedatasendRequest); } + public void RequestOwnItemInfoAsync( byte byPackage, byte bySlot, @@ -255,7 +272,8 @@ namespace CSNetwork Action callback) { gamedatasend gamedatasendRequest = new gamedatasend(); - gamedatasendRequest.Data = C2SCommandFactory.CreateOwnItemInfo(byPackage, bySlot, type, expire_date, state, count, crc, content_length, content); + gamedatasendRequest.Data = C2SCommandFactory.CreateOwnItemInfo(byPackage, bySlot, type, expire_date, state, + count, crc, content_length, content); SendProtocol(gamedatasendRequest, callback); } @@ -264,7 +282,8 @@ namespace CSNetwork { if (IsConnected) { - _logger.Log(LogType.Debug, $"Sending protocol: {protocol.GetType().Name} (Detail: {protocol.ToString})"); + _logger.Log(LogType.Debug, + $"Sending protocol: {protocol.GetType().Name} (Detail: {protocol.ToString})"); _networkManager.Send(protocol); complete?.Invoke(); } @@ -278,13 +297,11 @@ namespace CSNetwork private void OnProtocolReceived(Protocol protocol) { - _logger.Log(LogType.Debug, $"Received protocol: {protocol.GetType().Name} (Type: {protocol.Type})"); if (protocol is null) return; - // Route protocol to appropriate handler switch (protocol.GetPType()) { @@ -373,7 +390,8 @@ namespace CSNetwork case CommandID.PLAYER_INFO_00: case CommandID.SELF_INFO_1: // OnMsgPlayerInfo(-1, pDataBuf, pCmdHeader); - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERINFO, (int)MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader, iHostID, _selectedRole); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERINFO, (int)MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, + pCmdHeader, iHostID, _selectedRole); break; case CommandID.OBJECT_MOVE: int lenghtDataType = Marshal.SizeOf(); @@ -381,31 +399,38 @@ namespace CSNetwork int idObjMove = BitConverter.ToInt32(arrByteData); if (ISPLAYERID(idObjMove)) { - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERMOVE, (int)MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader, iHostID); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERMOVE, (int)MANAGER_INDEX.MAN_PLAYER, -1, + pDataBuf, pCmdHeader, iHostID); } else if (ISNPCID(idObjMove)) { - EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCMOVE, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCMOVE, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, + pCmdHeader); } + break; case CommandID.OBJECT_STOP_MOVE: + { + int id1 = GPDataTypeHelper.FromBytes(pDataBuf); + if (ISPLAYERID(id1)) { - int id1 = GPDataTypeHelper.FromBytes(pDataBuf); - if (ISPLAYERID(id1)) - { - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERSTOPMOVE, (int)MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader); - } - else if (ISNPCID(id1)) - { - EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCSTOPMOVE, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, pCmdHeader); - } - break; + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERSTOPMOVE, (int)MANAGER_INDEX.MAN_PLAYER, -1, + pDataBuf, pCmdHeader); } + else if (ISNPCID(id1)) + { + EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCSTOPMOVE, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, + pCmdHeader); + } + + break; + } case CommandID.OWN_IVTR_DATA: - case CommandID.OWN_IVTR_DETAIL_DATA: + case CommandID.OWN_IVTR_DETAIL_DATA: case CommandID.GET_OWN_MONEY: case CommandID.CHANGE_IVTR_SIZE: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_IVTRINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader, iHostID); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_IVTRINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader, iHostID); break; case CommandID.EXG_IVTR_ITEM: case CommandID.MOVE_IVTR_ITEM: @@ -415,49 +440,61 @@ namespace CSNetwork case CommandID.MOVE_EQUIP_ITEM: case CommandID.UNFREEZE_IVTR_SLOT: case CommandID.PLAYER_EQUIP_TRASHBOX_ITEM: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ITEMOPERATION, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ITEMOPERATION, (int)MANAGER_INDEX.MAN_PLAYER, 0, + pDataBuf, pCmdHeader); break; case CommandID.PLAYER_CASH: { - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_IVTRINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader, iHostID); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_IVTRINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader, iHostID); break; } case CommandID.MATTER_INFO_LIST: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_MM_MATTERINFO, (int)MANAGER_INDEX.MAN_MATTER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_MM_MATTERINFO, (int)MANAGER_INDEX.MAN_MATTER, 0, pDataBuf, + pCmdHeader); break; case CommandID.MATTER_ENTER_WORLD: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_MM_MATTERENTWORLD, (int)MANAGER_INDEX.MAN_MATTER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_MM_MATTERENTWORLD, (int)MANAGER_INDEX.MAN_MATTER, 0, + pDataBuf, pCmdHeader); break; - case CommandID.PICKUP_ITEM: + case CommandID.PICKUP_ITEM: case CommandID.HOST_OBTAIN_ITEM: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_PICKUPITEM, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_PICKUPITEM, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.MATTER_PICKUP: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PICKUPMATTER, (int)MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader); - break; + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PICKUPMATTER, (int)MANAGER_INDEX.MAN_PLAYER, -1, + pDataBuf, pCmdHeader); + break; case CommandID.PICKUP_MONEY: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_PICKUPMONEY, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_PICKUPMONEY, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.HOST_CORRECT_POS: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_CORRECTPOS, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader, iHostID); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_CORRECTPOS, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader, iHostID); break; case CommandID.OWN_ITEM_INFO: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_OWNITEMINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader, iHostID); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_OWNITEMINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader, iHostID); break; case CommandID.NPC_ENTER_SLICE: case CommandID.NPC_INFO_LIST: case CommandID.NPC_INFO_00: case CommandID.NPC_ENTER_WORLD: case CommandID.NPC_VISIBLE_TID_NOTIFY: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCINFO, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, pCmdHeader, dwDataSize); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCINFO, (int)MANAGER_INDEX.MAN_NPC, 0, pDataBuf, + pCmdHeader, dwDataSize); break; case CommandID.TASK_DATA: case CommandID.TASK_VAR_DATA: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_TASKDATA, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader, dwDataSize); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_TASKDATA, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader, dwDataSize); break; case CommandID.BE_HURT: case CommandID.HURT_RESULT: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_HURTRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_HURTRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.OBJECT_ATTACK_RESULT: //int id = GPDataTypeHelper.FromBytes(pDataBuf); @@ -465,38 +502,39 @@ namespace CSNetwork //BMLogger.LogError($"OBJECT_ATTACK_RESULT: npc ? " + ISNPCID(id)); if (ISPLAYERID(pCmdAtk.attacker_id)) - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERATKRESULT, MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERATKRESULT, MANAGER_INDEX.MAN_PLAYER, -1, + pDataBuf, pCmdHeader); else if (ISNPCID(pCmdAtk.attacker_id)) - EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCATKRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCATKRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.HOST_ATTACKRESULT: _logger.Info($"HOST_ATTACKRESULT: " + pCmdHeader); - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ATKRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ATKRESULT, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.HOST_ATTACKED: _logger.Info($"HOST_ATTACKED: " + pCmdHeader); - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ATTACKED, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_ATTACKED, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.ERROR_MESSAGE: _logger.Info($"### GameDataSend: ERROR_MESSAGE: {BitConverter.ToInt32(pDataBuf, 0)}"); - cmd_error_msg pCmd = GPDataTypeHelper.FromBytes(pDataBuf); + cmd_error_msg pCmd = GPDataTypeHelper.FromBytes(pDataBuf); BMLogger.LogError("hOANGdEV : ERROR_MESSAGE pCmd.iMessage!=0 " + pCmd.iMessage); - if (pCmd.iMessage!=0) + if (pCmd.iMessage != 0) { - string szMsg = m_ErrorMsgs.GetWideString(pCmd.iMessage); - if (string.IsNullOrEmpty( szMsg)) - BMLogger.LogError("SERVER - unknown error !"); + if (string.IsNullOrEmpty(szMsg)) + BMLogger.LogError("SERVER - unknown error !"); //else if (pCmd.iMessage != 2) - //g_pGame->GetGameRun()->AddChatMessage(szMsg, GP_CHAT_MISC); - + //g_pGame->GetGameRun()->AddChatMessage(szMsg, GP_CHAT_MISC); } if (pCmd.iMessage == 2) { - // Attack target is too far //pGameRun->PostMessage(MSG_HST_TARGETISFAR, MAN_PLAYER, 0, (DWORD)pDataBuf, pCmdHeader->cmd); } @@ -517,15 +555,18 @@ namespace CSNetwork } else if (pCmd.iMessage == 108 /*&& pGameRun->GetHostPlayer()->IsInKingService()*/) { - /* CECGameUIMan* pGameUI = pGameRun->GetUIManager()->GetInGameUIMan(); - if (pGameUI) - pGameUI->EndNPCService();*/ + /* CECGameUIMan* pGameUI = pGameRun->GetUIManager()->GetInGameUIMan(); + if (pGameUI) + pGameUI->EndNPCService();*/ } - else if (pCmd.iMessage == 108 /*&& pGameRun->GetHostPlayer()->GetOfflineShopCtrl()->GetNPCSevFlag() != COfflineShopCtrl::NPCSEV_NULL*/) + else if + (pCmd.iMessage == + 108 /*&& pGameRun->GetHostPlayer()->GetOfflineShopCtrl()->GetNPCSevFlag() != COfflineShopCtrl::NPCSEV_NULL*/ + ) { - /* CECGameUIMan* pGameUI = pGameRun->GetUIManager()->GetInGameUIMan(); - if (pGameUI) - pGameUI->EndNPCService();*/ + /* CECGameUIMan* pGameUI = pGameRun->GetUIManager()->GetInGameUIMan(); + if (pGameUI) + pGameUI->EndNPCService();*/ } else if (pCmd.iMessage == 175) { @@ -541,7 +582,8 @@ namespace CSNetwork case CommandID.SELECT_TARGET: case CommandID.UNSELECT: - EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_SELTARGET, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); + EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_SELTARGET, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, + pCmdHeader); break; case CommandID.NPC_DIED: case CommandID.NPC_DIED2: @@ -549,18 +591,19 @@ namespace CSNetwork EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCDIED, MANAGER_INDEX.MAN_NPC, 0, pDataBuf, pCmdHeader); break; case CommandID.OBJECT_DISAPPEAR: - { - int lenghtDataType1 = Marshal.SizeOf(); - byte[] arrByteData1 = GetBytes(pDataBuf, lenghtDataType1, 0); - int idObjMove1 = BitConverter.ToInt32(arrByteData1); - if (ISPLAYERID(idObjMove1)) - EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERDISAPPEAR, MANAGER_INDEX.MAN_PLAYER, -1, pDataBuf, pCmdHeader); - else if (ISNPCID(idObjMove1)) - EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCDISAPPEAR, MANAGER_INDEX.MAN_NPC, 0, pDataBuf, pCmdHeader); - - break; - } + { + int lenghtDataType1 = Marshal.SizeOf(); + byte[] arrByteData1 = GetBytes(pDataBuf, lenghtDataType1, 0); + int idObjMove1 = BitConverter.ToInt32(arrByteData1); + if (ISPLAYERID(idObjMove1)) + EC_ManMessage.PostMessage(EC_MsgDef.MSG_PM_PLAYERDISAPPEAR, MANAGER_INDEX.MAN_PLAYER, -1, + pDataBuf, pCmdHeader); + else if (ISNPCID(idObjMove1)) + EC_ManMessage.PostMessage(EC_MsgDef.MSG_NM_NPCDISAPPEAR, MANAGER_INDEX.MAN_NPC, 0, pDataBuf, + pCmdHeader); + break; + } case CommandID.SELF_INFO_00: EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_INFO00, MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf, pCmdHeader); @@ -572,7 +615,6 @@ namespace CSNetwork { if (iSubID == 0) { - } else if (iSubID < 0) { @@ -583,24 +625,25 @@ namespace CSNetwork { byteArray[i] = data[i]; } + int cid = BitConverter.ToInt32(byteArray); switch (pCmdHeader) { case CommandID.PLAYER_INFO_1: case CommandID.PLAYER_ENTER_WORLD: case CommandID.PLAYER_ENTER_SLICE: + { + if (cid != iHostID) { - if (cid != iHostID) - { - _logger.Info("### OnMsgPlayerInfo: ElsePlayer join"); - } - break; + _logger.Info("### OnMsgPlayerInfo: ElsePlayer join"); } + + break; + } } } else { - } } @@ -708,7 +751,8 @@ namespace CSNetwork return; } - _logger.Log(LogType.Debug, $"Received RoleListResponse. Handle: {response.handle}, Result: {response.result}, Count: {response.rolelist.Count}"); + _logger.Log(LogType.Debug, + $"Received RoleListResponse. Handle: {response.handle}, Result: {response.result}, Count: {response.rolelist.Count}"); if (response.result == 0) { @@ -793,10 +837,12 @@ namespace CSNetwork _networkManager.Dispose(); _networkManager = null; } + _loginCallback = null; _roleListCallback = null; _accumulatedRoles = null; } + disposedValue = true; } } @@ -811,8 +857,10 @@ namespace CSNetwork { return id != 0 && (id & 0x80000000) == 0; } + public bool ISNPCID(int id) => ((id & unchecked((int)0x80000000)) != 0) - && ((id & 0x40000000) == 0); + && ((id & 0x40000000) == 0); + private byte[] GetBytes(byte[] bytes, int length, int index) { byte[] arrByteData = new byte[length]; @@ -820,25 +868,30 @@ namespace CSNetwork { arrByteData[i] = bytes[i + index]; } + return arrByteData; } + public void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest, - int iTime, float fSpeed, int iMoveMode, ushort wStamp) + int iTime, float fSpeed, int iMoveMode, ushort wStamp) { gamedatasend gamedatasend = new gamedatasend(); - gamedatasend.Data = C2SCommandFactory.CreatePlayerMove(vCurPos, vDest, (ushort)iTime, fSpeed, (byte)iMoveMode, wStamp); + gamedatasend.Data = + C2SCommandFactory.CreatePlayerMove(vCurPos, vDest, (ushort)iTime, fSpeed, (byte)iMoveMode, wStamp); SendProtocol(gamedatasend); } + public void c2s_SendCmdStopMove(in Vector3 vDest, float fSpeed, int iMoveMode, - byte byDir, ushort wStamp, int iTime) + byte byDir, ushort wStamp, int iTime) { - gamedatasend gamedatasend = new gamedatasend(); - gamedatasend.Data = C2SCommandFactory.CreatePlayerStop(vDest, fSpeed, (byte)iMoveMode, byDir, wStamp, (ushort)iTime); + gamedatasend.Data = + C2SCommandFactory.CreatePlayerStop(vDest, fSpeed, (byte)iMoveMode, byDir, wStamp, (ushort)iTime); SendProtocol(gamedatasend); } + public void SendChatData(byte cChannel, in string szMsg, int iPack, int iSlot) { publicchat publicChat = new publicchat(); @@ -850,7 +903,12 @@ namespace CSNetwork _logger.Log(LogType.Warning, $"HoangDev : publicChat {publicChat}"); SendProtocol(publicChat); } - private void SetCharacterID(int iCharID) { m_iCharID = iCharID; } + + private void SetCharacterID(int iCharID) + { + m_iCharID = iCharID; + } + private void OnPrtcChatMessage(Protocol pProtocol, bool bCalledagain) { chatmessage p = (chatmessage)pProtocol; @@ -864,7 +922,11 @@ namespace CSNetwork public struct ChatMessageEvent { public string context; - public ChatMessageEvent(string context) { this.context = context; } + + public ChatMessageEvent(string context) + { + this.context = context; + } } public void c2s_SendCmdGetAllData(bool byPack, bool byEquip, bool byTask) @@ -919,4 +981,4 @@ namespace CSNetwork } } } -} +} \ No newline at end of file