DayZ 1.29
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 строка 1048

1049 {
1051 bool success = true;
1052
1053 HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
1055
1059 e.m_IsRemote = validation.m_IsRemote;
1060 e.m_IsJuncture = validation.m_IsJuncture;
1061
1062 EntityAI itemSrc = e.GetSrcEntity();
1063 EntityAI itemDst = e.GetSecondSrcEntity();
1064
1065 #ifdef ENABLE_LOGGING
1067 {
1068 Debug.InventoryMoveLog("STS = " + e.m_Player.GetSimulationTimeStamp() + " event= " + e.DumpToString(), "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1069 }
1070 #endif
1071
1072 if (validation.m_IsRemote && !e.GetSrcEntity())
1073 {
1075 if (itemDst && (e.GetEventID() == HandEventID.SWAP || e.GetEventID() == HandEventID.FORCESWAP)) //presumed swap, replace with take
1076 {
1077 InventoryLocation srcNew = new InventoryLocation();
1078 srcNew.Copy(e.GetSrc());
1079 e = HandEventBase.HandEventFactory(HandEventID.TAKE, e.m_Player, srcNew);
1080
1081 Error("[syncinv] HandleInputData remote swap event REPLACED with TAKE (cmd=HAND_EVENT, event=" + e.DumpToString() + "), src item is null! Continuing.");
1082 }
1083 else
1084 {
1085 #ifdef ENABLE_LOGGING
1087 {
1088 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1089 }
1090 #endif
1091
1092 Error("[syncinv] HandleInputData remote input (cmd=HAND_EVENT, event=" + e.DumpToString() + ") dropped, item not in bubble");
1093
1094 return true;
1095 }
1096 }
1097
1099 if (itemSrc)
1100 RemoveMovableOverride(itemSrc);
1101 if (itemDst)
1102 RemoveMovableOverride(itemDst);
1103
1107 if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !e.CheckRequestSrc())
1108 {
1109 #ifdef ENABLE_LOGGING
1111 {
1112 Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1113 }
1114 #endif
1115
1116 if (!validation.m_IsRemote)
1117 {
1118 ctx = new ScriptInputUserData;
1120 }
1121
1122 RemoveMovableOverride(itemSrc);
1123 RemoveMovableOverride(itemDst);
1124
1125 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1126 {
1127 success = false;
1128 #ifdef DIAG_DEVELOPER
1129 if (PluginInventoryDebug.Cast(GetPlugin(PluginInventoryDebug)).IsDesyncRepairEnable())
1130 {
1131 #endif
1132 array<EntityAI> itemsToRepair = new array<EntityAI>;
1133 InventoryLocation repairIl = new InventoryLocation();
1134 itemSrc.GetInventory().GetCurrentInventoryLocation(repairIl);
1135
1136 if(e.GetSrc() != repairIl)
1137 {
1138 itemsToRepair.Insert(itemSrc);
1139 }
1140
1141 if(itemDst && itemSrc != itemDst )
1142 {
1143 itemDst.GetInventory().GetCurrentInventoryLocation(repairIl);
1144 if(e.GetSecondSrc() != repairIl)
1145 {
1146 itemsToRepair.Insert(itemDst);
1147 }
1148 }
1149
1150 if (itemsToRepair.Count())
1151 {
1153 }
1154 #ifdef DIAG_DEVELOPER
1155 }
1156 #endif
1157 }
1158 else
1159 {
1160 return true;
1161 }
1162 }
1163
1164 if (success && !e.CheckRequestEx(validation))
1165 {
1166 #ifdef ENABLE_LOGGING
1168 {
1169 Debug.InventoryMoveLog("Failed - CheckRequest", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1170 }
1171 #endif
1172
1174
1175 ctx = new ScriptInputUserData;
1177
1178#ifdef ENABLE_LOGGING
1180 {
1181 syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
1182 }
1183#endif
1184
1185 RemoveMovableOverride(itemSrc);
1186 RemoveMovableOverride(itemDst);
1187
1188 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1189 {
1190 success = false;
1191 }
1192 else
1193 {
1194 return true;
1195 }
1196 }
1197
1200 if (success && !validation.m_IsRemote && !e.CanPerformEventEx(validation))
1201 {
1202 #ifdef ENABLE_LOGGING
1204 {
1205 Debug.InventoryMoveLog("Failed - CanPerformEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1206 }
1207 #endif
1208
1210
1211 ctx = new ScriptInputUserData;
1213
1214#ifdef ENABLE_LOGGING
1216 {
1217 syncDebugPrint("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT do cmd=HAND_EVENT e=" + e.DumpToString());
1218 }
1219#endif
1220
1221 RemoveMovableOverride(itemSrc);
1222 RemoveMovableOverride(itemDst);
1223
1224 if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1225 {
1226 InventoryLocation ilDst = e.GetDst();
1227 if (ilDst)
1228 SendRepairToClientDst(ilDst);
1229
1230 ilDst = e.GetSecondDst();
1231 if (ilDst)
1232 SendRepairToClientDst(ilDst);
1233
1234 success = false;
1235 }
1236 else
1237 {
1238 return true;
1239 }
1240 }
1241
1242 RemoveMovableOverride(itemSrc);
1243 RemoveMovableOverride(itemDst);
1244
1246 if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1247 {
1249 if (result_ev == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
1250 {
1251 #ifdef ENABLE_LOGGING
1253 {
1254 Debug.InventoryMoveLog("Juncture not required", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1255 }
1256 #endif
1257
1259 }
1260 else if (success && result_ev == JunctureRequestResult.JUNCTURE_ACQUIRED)
1261 {
1262 #ifdef ENABLE_LOGGING
1264 {
1265 Debug.InventoryMoveLog("Juncture sended", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1266 }
1267 #endif
1268
1269 ctx = new ScriptInputUserData;
1271
1272 validation.m_Result = InventoryValidationResult.JUNCTURE;
1273
1274 if (itemSrc)
1275 EnableMovableOverride(itemSrc);
1276 if (itemDst)
1277 EnableMovableOverride(itemDst);
1278 return true;
1279 }
1280 else
1281 {
1282 #ifdef ENABLE_LOGGING
1284 {
1285 Debug.InventoryMoveLog("Juncture denied", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1286 }
1287 #endif
1288
1289 validation.m_Result = InventoryValidationResult.FAILED;
1290 validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
1291 return true;
1292 }
1293 }
1294 // Check whether the juncture for the related player and items has been acquired.
1295 else if (validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1296 {
1297 bool hasJuncture = false;
1298
1299 if (itemSrc != null && itemDst != null)
1300 {
1301 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemSrc) && g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemDst);
1302 }
1303 else if (itemSrc != null)
1304 {
1305 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemSrc);
1306 }
1307 else if (itemDst != null)
1308 {
1309 hasJuncture = g_Game.HasInventoryJuncture(GetDayZPlayerOwner(), itemDst);
1310 }
1311
1312 if (!hasJuncture)
1313 {
1314 success = false;
1315 }
1316 }
1317
1319 if (success && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
1320 {
1321 CheckForRope(e.GetSrc(), e.GetDst());
1322 }
1323
1324 #ifdef ENABLE_LOGGING
1326 {
1327 Debug.InventoryMoveLog("Success - ProcessHandEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
1328 }
1329 #endif
1330
1331 if (success)
1332 {
1333 validation.m_Result = InventoryValidationResult.SUCCESS;
1334 if (!e.m_Player.GetHumanInventory().ProcessHandEvent(e))
1335 {
1337 //result = InventoryValidationResult.FAILURE;
1338 }
1339 }
1340
1341 return true;
1342 }
void syncDebugPrint(string s)
InventoryCommandType
InventoryValidationResult
InventoryValidationReason
DayZGame g_Game
Определения DayZGame.c:3942
void EnableMovableOverride(EntityAI item)
Определения DayZPlayerInventory.c:1860
void CheckForRope(InventoryLocation src, InventoryLocation dst)
Определения DayZPlayerInventory.c:1868
void RemoveMovableOverride(EntityAI item)
Определения DayZPlayerInventory.c:1853
void SendRepairToClientDst(notnull InventoryLocation dst)
Определения DayZPlayerInventory.c:2896
DayZPlayer GetDayZPlayerOwner()
Определения DayZPlayerInventory.c:167
JunctureRequestResult
Определения Hand_Events.c:28
HandEventID
events
Определения Hand_Events.c:7
PluginBase GetPlugin(typename plugin_type)
Определения PluginManager.c:325
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:197
Определения 3_Game/DayZ/tools/Debug.c:2
override InventoryLocation GetSecondDst()
Определения Hand_Events.c:610
override InventoryLocation GetDst()
Определения Hand_Events.c:215
override bool AcquireInventoryJunctureFromServer(notnull Man player)
Определения Hand_Events.c:260
override EntityAI GetSecondSrcEntity()
Определения Hand_Events.c:615
override string DumpToString()
Определения Hand_Events.c:338
override void ClearInventoryReservation()
Определения Hand_Events.c:718
override bool CheckRequestSrc()
Определения Hand_Events.c:222
override bool CanPerformEventEx(InventoryValidation validation)
Определения Hand_Events.c:238
override InventoryLocation GetSecondSrc()
Определения Hand_Events.c:605
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:776
static bool IsInventoryMoveLogEnable()
Определения 3_Game/DayZ/tools/Debug.c:746
Определения ObjectTyped.c:2
Определения gameplay.c:121
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerInstanceType
defined in C++
Определения dayzplayer.c:1071
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(), LogManager::IsSyncLogEnable(), InventoryValidation::m_IsJuncture, InventoryValidation::m_IsRemote, InventoryValidation::m_Reason, InventoryValidation::m_Result, RemoveMovableOverride(), SendRepairToClientDst(), InventoryInputUserData::SendServerInventoryCheck(), InventoryInputUserData::SerializeHandEvent() и syncDebugPrint().

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