DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ ValidateHandEvent()

bool ValidateHandEvent ( inout Serializer ctx,
InventoryValidation validation )
protected

Pass partial information to guards so guards can do minimal checks if needed The guards can't prevent event so it would be incorrect to pass full InventoryValidation struct. We have to make sure guards don't inadvertantly produce different results in the FSM as that will create desync (two players attempting to put a rag into the same fireplace slot at the same time)

kumarjac: This indicates a failure in replication relationships as player full inventory should be synchronized always if player exists on the remote

TODO(kumarjac): Is this one correct to be 'RemoveMovableOverride' or are the other Validate methdos wrong with 'EnableMovableOverride'?

Do not check for action validity on remotes or when performing through juncture. Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point. Checking at this point is both wasteful and can result in a failure which leads to desync

'HandEventBase.CheckRequestEx' updates failure reason

if it already happened on server, remote just needs to comply TODO(kumarjac): Move m_IsRemote check to inside of HandEventBase.CanPerformEventEx

'HandEventBase.CanPerformEventEx' updates failure reason

Check if this this is being executed on the server and not by a juncture or AI

Continuing on with execution of rest of the function

Is called twice unfortunately... but it works so won't change

TODO(kumarjac): We should probably set the result to failure like so

См. определение в файле DayZPlayerInventory.c строка 1519

1520 {
1522 bool success = true;
1523
1524 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
1525
1526 //client only
1528
1532 e.m_IsRemote = validation.m_IsRemote;
1533 e.m_IsJuncture = validation.m_IsJuncture;
1534
1535 EntityAI itemSrc = e.GetSrcEntity();
1536 EntityAI itemDst = e.GetSecondSrcEntity();
1537
1538 #ifdef ENABLE_LOGGING
1540 {
1541 Debug.InventoryMoveLog("STS = " + e.m_Player.GetSimulationTimeStamp() + " event= " + e.DumpToString(), "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1542 }
1543 #endif
1544
1545 if (validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER && e.m_Player != GetManOwner())
1546 {
1547 Error("[syncinv] Inventory owner " + GetManOwner() + " and event sender " + e.m_Player + " do not match.");
1548 return true;
1549 }
1550
1551 if (e.IsServerSideOnly())
1552 {
1553 Error("[syncinv] ValidateHandEvent This event " + e.GetDebugName() + " should not be use for synchronization.");
1554 return true;
1555 }
1556
1557 if (validation.m_IsRemote && !itemSrc)
1558 {
1560 if (itemDst && (e.GetEventID() == HandEventID.SWAP || e.GetEventID() == HandEventID.FORCESWAP)) //presumed swap, replace with take
1561 {
1562 InventoryLocation srcNew = new InventoryLocation();
1563 srcNew.Copy(e.GetSrc());
1564 e = HandEventBase.HandEventFactory(HandEventID.TAKE, e.m_Player, srcNew);
1565
1566 Error("[syncinv] HandleInputData remote swap event REPLACED with TAKE (cmd=HAND_EVENT, event=" + e.DumpToString() + "), src item is null! Continuing.");
1567 }
1568 else
1569 {
1570 #ifdef ENABLE_LOGGING
1572 {
1573 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1574 }
1575 #endif
1576
1577 Error("[syncinv] HandleInputData remote input (cmd=HAND_EVENT, event=" + e.DumpToString() + ") dropped, item not in bubble");
1578
1579 return true;
1580 }
1581 }
1582
1584 if (itemSrc)
1585 RemoveMovableOverride(itemSrc);
1586 if (itemDst)
1587 RemoveMovableOverride(itemDst);
1588
1592 if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !e.CheckRequestSrc())
1593 {
1594 #ifdef ENABLE_LOGGING
1596 {
1597 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1598 }
1599 #endif
1600
1601 if (!validation.m_IsRemote)
1602 {
1603 ctx = new ScriptInputUserData;
1605 }
1606
1607 RemoveMovableOverride(itemSrc);
1608 RemoveMovableOverride(itemDst);
1609
1610 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1611 {
1612 success = false;
1613 #ifdef DIAG_DEVELOPER
1614 if (PluginInventoryDebug.Cast(GetPlugin(PluginInventoryDebug)).IsDesyncRepairEnable())
1615 {
1616 #endif
1617 array<EntityAI> itemsToRepair = new array<EntityAI>;
1618 InventoryLocation repairIl = new InventoryLocation();
1619 if(!itemSrc)
1620 {
1621 return false;
1622 }
1623
1624 itemSrc.GetInventory().GetCurrentInventoryLocation(repairIl);
1625
1626 if(e.GetSrc() != repairIl)
1627 {
1628 itemsToRepair.Insert(itemSrc);
1629 }
1630
1631 if(itemDst && itemSrc != itemDst )
1632 {
1633 itemDst.GetInventory().GetCurrentInventoryLocation(repairIl);
1634 if(e.GetSecondSrc() != repairIl)
1635 {
1636 itemsToRepair.Insert(itemDst);
1637 }
1638 }
1639
1640 if (itemsToRepair.Count())
1641 {
1643 }
1644 #ifdef DIAG_DEVELOPER
1645 }
1646 #endif
1647 }
1648 else
1649 {
1650 return true;
1651 }
1652 }
1653
1654 if (success && !e.CheckRequestEx(validation))
1655 {
1656 #ifdef ENABLE_LOGGING
1658 {
1659 Debug.InventoryMoveLog("Failed - CheckRequest", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1660 }
1661 #endif
1662
1664
1665 ctx = new ScriptInputUserData;
1667
1668#ifdef ENABLE_LOGGING
1670 {
1671 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
1672 }
1673#endif
1674
1675 RemoveMovableOverride(itemSrc);
1676 RemoveMovableOverride(itemDst);
1677
1678 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1679 {
1680 success = false;
1681 }
1682 else
1683 {
1684 return true;
1685 }
1686 }
1687
1690 if (success && !validation.m_IsRemote && !e.CanPerformEventEx(validation))
1691 {
1692 #ifdef ENABLE_LOGGING
1694 {
1695 Debug.InventoryMoveLog("Failed - CanPerformEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1696 }
1697 #endif
1698
1700
1701 ctx = new ScriptInputUserData;
1703
1704#ifdef ENABLE_LOGGING
1706 {
1707 syncDebugPrint("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT do cmd=HAND_EVENT e=" + e.DumpToString());
1708 }
1709#endif
1710
1711 RemoveMovableOverride(itemSrc);
1712 RemoveMovableOverride(itemDst);
1713
1714 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1715 {
1716 InventoryLocation ilDst = e.GetDst();
1717 if (ilDst)
1718 SendRepairToClientDst(ilDst);
1719
1720 ilDst = e.GetSecondDst();
1721 if (ilDst)
1722 SendRepairToClientDst(ilDst);
1723
1724 success = false;
1725 }
1726 else
1727 {
1728 return true;
1729 }
1730 }
1731
1732 RemoveMovableOverride(itemSrc);
1733 RemoveMovableOverride(itemDst);
1734
1736 if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1737 {
1739 if (result_ev == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
1740 {
1741 #ifdef ENABLE_LOGGING
1743 {
1744 Debug.InventoryMoveLog("Juncture not required", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1745 }
1746 #endif
1747
1749 }
1750 else if (success && result_ev == JunctureRequestResult.JUNCTURE_ACQUIRED)
1751 {
1752 #ifdef ENABLE_LOGGING
1754 {
1755 Debug.InventoryMoveLog("Juncture sended", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1756 }
1757 #endif
1758
1759 ctx = new ScriptInputUserData;
1761
1762 validation.m_Result = InventoryValidationResult.JUNCTURE;
1763
1764 if (itemSrc)
1765 EnableMovableOverride(itemSrc);
1766 if (itemDst)
1767 EnableMovableOverride(itemDst);
1768 return true;
1769 }
1770 else
1771 {
1772 #ifdef ENABLE_LOGGING
1774 {
1775 Debug.InventoryMoveLog("Juncture denied", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1776 }
1777 #endif
1778
1779 validation.m_Result = InventoryValidationResult.FAILED;
1780 validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
1781 return true;
1782 }
1783 }
1784 // Check whether the juncture for the related player and items has been acquired.
1785 else if (validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1786 {
1787 bool hasJuncture = false;
1788
1789 if (itemSrc != null && itemDst != null)
1790 {
1791 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemSrc) && g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemDst);
1792 }
1793 else if (itemSrc != null)
1794 {
1795 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemSrc);
1796 }
1797 else if (itemDst != null)
1798 {
1799 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemDst);
1800 }
1801
1802 if (!hasJuncture)
1803 {
1804#ifdef ENABLE_LOGGING
1806 {
1807 Debug.InventoryMoveLog("Failed - missing juncture", "HAND_EVENT", "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
1808 }
1809#endif
1810 success = false;
1811 }
1812 }
1813
1815 if (success && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1816 {
1817 CheckForRope(e.GetSrc(), e.GetDst());
1818 }
1819
1820 #ifdef ENABLE_LOGGING
1822 {
1823 Debug.InventoryMoveLog("Success - ProcessHandEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1824 }
1825 #endif
1826
1827 if (success)
1828 {
1829 validation.m_Result = InventoryValidationResult.SUCCESS;
1830 if (!e.m_Player.GetHumanInventory().ProcessHandEvent(e))
1831 {
1833 //result = InventoryValidationResult.FAILURE;
1834 }
1835 }
1836
1837 return true;
1838 }
void syncDebugPrint(string s)
InventoryCommandType
InventoryValidationResult
InventoryValidationReason
DayZGame g_Game
Определения DayZGame.c:4074
void EnableMovableOverride(EntityAI item)
Определения DayZPlayerInventory.c:3690
void CheckForRope(InventoryLocation src, InventoryLocation dst)
Определения DayZPlayerInventory.c:3698
void RemoveMovableOverride(EntityAI item)
Определения DayZPlayerInventory.c:3683
void SendRepairToClientDst(notnull InventoryLocation dst)
Определения DayZPlayerInventory.c:4726
DayZPlayer GetDayZPlayerOwner()
Определения DayZPlayerInventory.c:170
proto string ToString()
JunctureRequestResult
Определения Hand_Events.c:28
HandEventID
events
Определения Hand_Events.c:7
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:326
static void InventoryMoveLog(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Определения 3_Game/DayZ/tools/Debug.c:198
Определения 3_Game/DayZ/tools/Debug.c:2
override InventoryLocation GetSecondDst()
Определения Hand_Events.c:605
override InventoryLocation GetDst()
Определения Hand_Events.c:215
override bool AcquireInventoryJunctureFromServer(notnull Man player)
Определения Hand_Events.c:255
override EntityAI GetSecondSrcEntity()
Определения Hand_Events.c:610
override bool IsServerSideOnly()
Определения Hand_Events.c:777
override string DumpToString()
Определения Hand_Events.c:333
override void ClearInventoryReservation()
Определения Hand_Events.c:724
override bool CheckRequestSrc()
Определения Hand_Events.c:222
override bool CanPerformEventEx(InventoryValidation validation)
Определения Hand_Events.c:238
override InventoryLocation GetSecondSrc()
Определения Hand_Events.c:600
Abstracted event, not to be used, only inherited.
Определения Hand_Events.c:212
static void SendServerInventoryCheck(array< EntityAI > items, DayZPlayer player)
Определения InventoryInputUserData.c:44
static void SerializeHandEvent(ParamsWriteContext ctx, HandEventBase e)
hand
Определения InventoryInputUserData.c:105
proto native InventoryLocation Copy(notnull InventoryLocation rhs)
copies location data to another location
InventoryLocation.
Определения InventoryLocation.c:30
InventoryValidationResult m_Result
InventoryValidationReason m_Reason
static bool IsSyncLogEnable()
Определения 3_Game/DayZ/tools/Debug.c:789
static bool IsInventoryMoveLogEnable()
Определения 3_Game/DayZ/tools/Debug.c:759
Определения ObjectTyped.c:2
Определения gameplay.c:121
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerInstanceType
defined in C++
Определения dayzplayer.c:1084
proto native DayZPlayerInstanceType GetInstanceType()
void Error(string err)
Messagebox with error message.
Определения EnDebug.c:90

Перекрестные ссылки HandEventBase::AcquireInventoryJunctureFromServer(), HandEventBase::CanPerformEventEx(), CheckForRope(), HandEventBase::CheckRequestSrc(), HandEventBase::ClearInventoryReservation(), InventoryLocation::Copy(), HandEventBase::DumpToString(), EnableMovableOverride(), Error(), g_Game, GetDayZPlayerOwner(), HandEventBase::GetDst(), GetInstanceType(), GetPlugin(), HandEventBase::GetSecondDst(), HandEventBase::GetSecondSrc(), HandEventBase::GetSecondSrcEntity(), Debug::InventoryMoveLog(), LogManager::IsInventoryMoveLogEnable(), HandEventBase::IsServerSideOnly(), LogManager::IsSyncLogEnable(), InventoryValidation::m_IsJuncture, InventoryValidation::m_IsRemote, InventoryValidation::m_Reason, InventoryValidation::m_Result, RemoveMovableOverride(), SendRepairToClientDst(), InventoryInputUserData::SendServerInventoryCheck(), InventoryInputUserData::SerializeHandEvent(), syncDebugPrint() и ToString().

Используется в ProcessInputData().