dayzplayerinventory.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732
  1. //Post event containers
  2. class DeferredEvent
  3. {
  4. InventoryMode m_mode;
  5. bool ReserveInventory(HumanInventory inventory){return true;}
  6. void ClearInventoryReservation(HumanInventory inventory){}
  7. }
  8. class DeferredTakeToDst : DeferredEvent
  9. {
  10. ref InventoryLocation m_src;
  11. ref InventoryLocation m_dst;
  12. void DeferredTakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  13. {
  14. m_mode = mode;
  15. m_src = src;
  16. m_dst = dst;
  17. }
  18. override bool ReserveInventory(HumanInventory inventory)
  19. {
  20. if (!inventory.HasInventoryReservation(m_dst.GetItem(), m_dst))
  21. {
  22. if ( inventory.AddInventoryReservationEx(m_dst.GetItem(), m_dst, GameInventory.c_InventoryReservationTimeoutShortMS) )
  23. {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. override void ClearInventoryReservation(HumanInventory inventory)
  30. {
  31. inventory.ClearInventoryReservationEx(m_dst.GetItem(), m_dst);
  32. }
  33. }
  34. class DeferredSwapEntities : DeferredEvent
  35. {
  36. EntityAI m_item1;
  37. EntityAI m_item2;
  38. ref InventoryLocation m_dst1;
  39. ref InventoryLocation m_dst2;
  40. void DeferredSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
  41. {
  42. m_mode = mode;
  43. m_item1 = item1;
  44. m_item2 = item2;
  45. m_dst1 = dst1;
  46. m_dst2 = dst2;
  47. }
  48. override bool ReserveInventory(HumanInventory inventory)
  49. {
  50. if (!inventory.HasInventoryReservation(m_item1, m_dst1) && !inventory.HasInventoryReservation(m_item2, m_dst2))
  51. {
  52. if (inventory.AddInventoryReservationEx(m_item1, m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS))
  53. {
  54. if (inventory.AddInventoryReservationEx(m_item2, m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS))
  55. {
  56. return true;
  57. }
  58. else
  59. {
  60. inventory.ClearInventoryReservationEx(m_item1, m_dst1);
  61. }
  62. }
  63. }
  64. return false;
  65. }
  66. override void ClearInventoryReservation(HumanInventory inventory)
  67. {
  68. inventory.ClearInventoryReservationEx(m_item1, m_dst1);
  69. inventory.ClearInventoryReservationEx(m_item2, m_dst2);
  70. }
  71. }
  72. class DeferredForceSwapEntities : DeferredEvent
  73. {
  74. EntityAI m_item1;
  75. EntityAI m_item2;
  76. ref InventoryLocation m_dst1;
  77. ref InventoryLocation m_dst2;
  78. void DeferredForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
  79. {
  80. m_mode = mode;
  81. m_item1 = item1;
  82. m_item2 = item2;
  83. m_dst1 = dst1;
  84. m_dst2 = dst2;
  85. }
  86. override bool ReserveInventory(HumanInventory inventory)
  87. {
  88. if (!inventory.HasInventoryReservation(m_item1, m_dst1) && !inventory.HasInventoryReservation(m_item2, m_dst2))
  89. {
  90. if (inventory.AddInventoryReservationEx(m_item1, m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS))
  91. {
  92. if (inventory.AddInventoryReservationEx(m_item2, m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS))
  93. {
  94. return true;
  95. }
  96. else
  97. {
  98. inventory.ClearInventoryReservationEx(m_item1, m_dst1);
  99. }
  100. }
  101. }
  102. return false;
  103. }
  104. override void ClearInventoryReservation(HumanInventory inventory)
  105. {
  106. inventory.ClearInventoryReservationEx(m_item1, m_dst1);
  107. inventory.ClearInventoryReservationEx(m_item2, m_dst2);
  108. }
  109. }
  110. class DeferredHandEvent: DeferredEvent
  111. {
  112. ref HandEventBase m_event;
  113. void DeferredHandEvent(InventoryMode mode, HandEventBase e)
  114. {
  115. m_mode = mode;
  116. m_event = e;
  117. }
  118. override bool ReserveInventory(HumanInventory inventory)
  119. {
  120. return m_event.ReserveInventory();
  121. }
  122. override void ClearInventoryReservation(HumanInventory inventory)
  123. {
  124. m_event.ClearInventoryReservation();
  125. }
  126. }
  127. /**
  128. * @class DayZPlayerInventory
  129. **/
  130. class DayZPlayerInventory : HumanInventoryWithFSM
  131. {
  132. ref DeferredEvent m_DeferredEvent = NULL;
  133. ref Timer m_DeferredWeaponTimer = new Timer;
  134. //protected ref HandEventBase m_PostedHandEvent = NULL; /// deferred hand event
  135. protected ref HandEventBase m_DeferredPostedHandEvent = NULL; /// deferred hand event
  136. ref WeaponEventBase m_DeferredWeaponEvent = NULL; /// deferred weapon event
  137. // states with animations
  138. protected ref HandAnimatedTakingFromAtt m_Taking;
  139. protected ref HandAnimatedMovingToAtt m_MovingTo;
  140. protected ref HandAnimatedSwapping m_Swapping;
  141. protected ref HandAnimatedForceSwapping m_FSwapping;
  142. protected ref HandAnimatedForceSwapping_Inst m_FSwappingInst;
  143. void DayZPlayerInventory ()
  144. {
  145. }
  146. DayZPlayer GetDayZPlayerOwner () { return DayZPlayer.Cast(GetInventoryOwner()); }
  147. bool IsAuthoritative()
  148. {
  149. DayZPlayer player;
  150. if (!Class.CastTo(player, GetInventoryOwner()))
  151. {
  152. return false;
  153. }
  154. return (player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_CLIENT && player.GetInstanceType() != DayZPlayerInstanceType.INSTANCETYPE_REMOTE);
  155. }
  156. bool IsOwner()
  157. {
  158. DayZPlayer player;
  159. if (!Class.CastTo(player, GetInventoryOwner()))
  160. {
  161. return false;
  162. }
  163. return (player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SERVER || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_SINGLEPLAYER);
  164. }
  165. bool IsProxy()
  166. {
  167. DayZPlayer player;
  168. if (!Class.CastTo(player, GetInventoryOwner()))
  169. {
  170. return false;
  171. }
  172. return (player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_REMOTE || player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_AI_REMOTE);
  173. }
  174. override void Init ()
  175. {
  176. if (LogManager.IsInventoryHFSMLogEnable())
  177. {
  178. hndDebugPrint("[hndfsm] Creating DayZPlayer Inventory FSM");
  179. }
  180. CreateStableStates(); // stable states needs to be created first
  181. m_Taking = new HandAnimatedTakingFromAtt(GetManOwner(), null);
  182. m_MovingTo = new HandAnimatedMovingToAtt(GetManOwner(), null);
  183. m_Swapping = new HandAnimatedSwapping(GetManOwner(), null);
  184. m_FSwapping = new HandAnimatedForceSwapping(GetManOwner(), null);
  185. m_FSwappingInst = new HandAnimatedForceSwapping_Inst(GetManOwner(), null);
  186. // events
  187. HandEventBase _fin_ = new HandEventHumanCommandActionFinished;
  188. HandEventBase _abt_ = new HandEventHumanCommandActionAborted;
  189. HandEventBase __T__ = new HandEventTake;
  190. HandEventBase __M__ = new HandEventMoveTo;
  191. HandEventBase __W__ = new HandEventSwap;
  192. //HandEventBase __D__ = new HandEventDropping;
  193. HandEventBase __Xd_ = new HandEventDestroyed;
  194. HandEventBase __F__ = new HandEventForceSwap;
  195. // setup transitions
  196. m_FSM.AddTransition(new HandTransition( m_Empty , __T__, m_Taking, NULL, new HandSelectAnimationOfTakeToHandsEvent(GetManOwner())));
  197. m_FSM.AddTransition(new HandTransition( m_Taking , _fin_, m_Empty, null, new HandGuardNot(new HandGuardHasItemInHands(GetManOwner()))));
  198. m_FSM.AddTransition(new HandTransition( m_Taking , _fin_, m_Equipped, null, null));
  199. m_FSM.AddTransition(new HandTransition( m_Taking , __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
  200. m_Taking.AddTransition(new HandTransition( m_Taking.m_Hide, _abt_, m_Empty));
  201. m_Taking.AddTransition(new HandTransition( m_Taking.m_Show, _abt_, m_Equipped));
  202. m_FSM.AddTransition(new HandTransition( m_Equipped, __M__, m_MovingTo, NULL, new HandSelectAnimationOfMoveFromHandsEvent(GetManOwner())));
  203. m_FSM.AddTransition(new HandTransition( m_MovingTo, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
  204. m_FSM.AddTransition(new HandTransition( m_MovingTo, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
  205. m_FSM.AddTransition(new HandTransition( m_MovingTo, _fin_, m_Empty , null, null));
  206. m_MovingTo.AddTransition(new HandTransition( m_MovingTo.m_Hide, _abt_, m_Equipped));
  207. m_MovingTo.AddTransition(new HandTransition( m_MovingTo.m_Show, _abt_, m_Empty));
  208. m_FSM.AddTransition(new HandTransition( m_Equipped, __W__, m_Swapping, NULL, new HandSelectAnimationOfSwapInHandsEvent(GetManOwner())));
  209. m_FSM.AddTransition(new HandTransition( m_Swapping, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
  210. m_FSM.AddTransition(new HandTransition( m_Swapping, _fin_, m_Empty, null, new HandGuardNot(new HandGuardHasItemInHands(GetManOwner()))));
  211. m_FSM.AddTransition(new HandTransition( m_Swapping, _fin_, m_Equipped, null, null));
  212. m_FSM.AddTransition(new HandTransition( m_Swapping, _abt_, m_Equipped, null, null));
  213. m_FSM.AddTransition(new HandTransition( m_Equipped, __F__, m_FSwappingInst, NULL, new HandGuardAnd( new HandSelectAnimationOfForceSwapInHandsEvent(GetManOwner()), new HandGuardInstantForceSwap(GetManOwner()) ) ));
  214. m_FSM.AddTransition(new HandTransition(m_FSwappingInst, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
  215. m_FSM.AddTransition(new HandTransition(m_FSwappingInst, _fin_, m_Empty, null, null));
  216. m_FSM.AddTransition(new HandTransition(m_FSwappingInst, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
  217. m_FSM.AddTransition(new HandTransition( m_FSwappingInst, _abt_, m_Equipped, null, null));
  218. m_FSM.AddTransition(new HandTransition( m_Equipped, __F__, m_FSwapping, NULL, new HandSelectAnimationOfForceSwapInHandsEvent(GetManOwner())));
  219. m_FSM.AddTransition(new HandTransition(m_FSwapping, _fin_, m_Equipped, null, new HandGuardHasItemInHands(GetManOwner())));
  220. m_FSM.AddTransition(new HandTransition(m_FSwapping, _fin_, m_Empty, null, null));
  221. m_FSM.AddTransition(new HandTransition(m_FSwapping, __Xd_, m_Empty, new HandActionDestroyed, new HandGuardHasDestroyedItemInHands(GetManOwner())));
  222. m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Start, _abt_, m_Equipped));
  223. m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Hide, _abt_, m_Empty));
  224. m_FSwapping.AddTransition(new HandTransition( m_FSwapping.m_Show, _abt_, m_Equipped));
  225. super.Init(); // initialize ordinary human fsm (no anims)
  226. }
  227. /**@fn CancelHandEvent
  228. * @brief cancels any handevents that will be executed this frame
  229. * @NOTE: this is used in situations where the player performs an action that renders the event invalid exactly on the frame it will be executed
  230. **/
  231. void CancelHandEvent ()
  232. {
  233. m_DeferredPostedHandEvent = null;
  234. //m_postedHandEvent = null;
  235. }
  236. void CancelWeaponEvent ()
  237. {
  238. m_DeferredWeaponEvent = null;
  239. m_DeferredWeaponTimer.Stop();
  240. }
  241. void AbortWeaponEvent ()
  242. {
  243. HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
  244. Weapon_Base weapon;
  245. Class.CastTo(weapon, GetEntityInHands());
  246. if (hcw && weapon && weapon.CanProcessWeaponEvents() && !weapon.IsIdle())
  247. {
  248. if (LogManager.IsWeaponLogEnable())
  249. {
  250. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: ABORT! notifying running state=" + weapon.GetCurrentState());
  251. }
  252. weapon.ProcessWeaponAbortEvent(new WeaponEventHumanCommandActionAborted(GetDayZPlayerOwner()));
  253. }
  254. }
  255. /**@fn PostWeaponEvent
  256. * @brief deferred weapon's fsm handling of events
  257. * @NOTE: "post" stores the event for later use when ::CommandHandler is being run
  258. **/
  259. void PostWeaponEvent (WeaponEventBase e)
  260. {
  261. if (m_DeferredWeaponEvent == NULL)
  262. {
  263. m_DeferredWeaponEvent = e;
  264. if (LogManager.IsWeaponLogEnable())
  265. {
  266. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " Posted event m_DeferredWeaponEvent=" + m_DeferredWeaponEvent.DumpToString());
  267. }
  268. }
  269. else
  270. {
  271. Error("[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " warning - pending event already posted, curr_event=" + m_DeferredWeaponEvent.DumpToString() + " new_event=" + e.DumpToString());
  272. }
  273. }
  274. void DeferredWeaponFailed()
  275. {
  276. Weapon_Base weapon;
  277. Class.CastTo(weapon, GetEntityInHands());
  278. string secondPart = " - ENTITY IN HANDS IS NOT A WEAPON: " + Object.GetDebugName(GetEntityInHands());
  279. string firstPart = "[wpnfsm] " + Object.GetDebugName(GetInventoryOwner()) + " failed to perform weaponevent " + m_DeferredWeaponEvent.DumpToString();
  280. if (weapon)
  281. {
  282. secondPart = " on " + Object.GetDebugName(GetEntityInHands()) + " which is in state " + weapon.GetCurrentState();
  283. secondPart += " with physical state: J: " + weapon.IsJammed() + " | ";
  284. for (int i = 0; i < weapon.GetMuzzleCount(); ++i)
  285. {
  286. secondPart += "Chamber_" + i + ": B(" + weapon.IsChamberFull(i) + ") F(" + weapon.IsChamberFiredOut(i) + ") E(" + weapon.IsChamberEmpty(i) + ") | ";
  287. secondPart += "Magazine_" + i + ": " + weapon.GetMagazine(i);
  288. if (i < weapon.GetMuzzleCount() - 1)
  289. secondPart += " | ";
  290. }
  291. }
  292. Error(firstPart + secondPart);
  293. CancelWeaponEvent();
  294. }
  295. void HandleWeaponEvents (float dt, out bool exitIronSights)
  296. {
  297. HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
  298. Weapon_Base weapon;
  299. Class.CastTo(weapon, GetEntityInHands());
  300. if (weapon)
  301. {
  302. weapon.UpdateCoolDown(dt);
  303. if (hcw && weapon.CanProcessWeaponEvents())
  304. {
  305. weapon.GetCurrentState().OnUpdate(dt);
  306. if (LogManager.IsWeaponLogEnable())
  307. {
  308. wpnDebugSpamALot("[wpnfsm] " + Object.GetDebugName(weapon) + " HCW: playing A=" + typename.EnumToString(WeaponActions, hcw.GetRunningAction()) + " AT=" + WeaponActionTypeToString(hcw.GetRunningAction(), hcw.GetRunningActionType()) + " fini=" + hcw.IsActionFinished());
  309. }
  310. if (!weapon.IsIdle())
  311. {
  312. while (true)
  313. {
  314. int weaponEventId = hcw.IsEvent();
  315. if (weaponEventId == -1)
  316. {
  317. break;
  318. }
  319. if (weaponEventId == WeaponEvents.CHANGE_HIDE)
  320. {
  321. break;
  322. }
  323. WeaponEventBase anim_event = WeaponAnimEventFactory(weaponEventId, GetDayZPlayerOwner(), NULL);
  324. if (LogManager.IsWeaponLogEnable())
  325. {
  326. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " HandleWeapons: event arrived " + typename.EnumToString(WeaponEvents, weaponEventId) + "(" + weaponEventId + ") fsm_ev=" + anim_event.ToString());
  327. }
  328. if (anim_event != NULL)
  329. {
  330. weapon.ProcessWeaponEvent(anim_event);
  331. }
  332. }
  333. if (hcw.IsActionFinished())
  334. {
  335. if (weapon.IsWaitingForActionFinish())
  336. {
  337. if (LogManager.IsWeaponLogEnable())
  338. {
  339. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: finished! notifying waiting state=" + weapon.GetCurrentState());
  340. }
  341. weapon.ProcessWeaponEvent(new WeaponEventHumanCommandActionFinished(GetDayZPlayerOwner()));
  342. }
  343. else
  344. {
  345. if (LogManager.IsWeaponLogEnable())
  346. {
  347. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: ABORT! notifying running state=" + weapon.GetCurrentState());
  348. }
  349. weapon.ProcessWeaponAbortEvent(new WeaponEventHumanCommandActionAborted(GetDayZPlayerOwner()));
  350. }
  351. }
  352. }
  353. if (m_DeferredWeaponEvent)
  354. {
  355. if (LogManager.IsWeaponLogEnable())
  356. {
  357. wpnDebugPrint("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: deferred " + m_DeferredWeaponEvent.DumpToString());
  358. }
  359. if (weapon.ProcessWeaponEvent(m_DeferredWeaponEvent))
  360. {
  361. exitIronSights = true;
  362. if (LogManager.IsWeaponLogEnable())
  363. {
  364. fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(weapon) + " Weapon event: resetting deferred event" + m_DeferredWeaponEvent.DumpToString());
  365. }
  366. m_DeferredWeaponEvent = NULL;
  367. m_DeferredWeaponTimer.Stop();
  368. }
  369. else if (!m_DeferredWeaponTimer.IsRunning())
  370. {
  371. m_DeferredWeaponTimer.Run(3, this, "DeferredWeaponFailed");
  372. }
  373. }
  374. }
  375. }
  376. }
  377. void HandleInventory(float dt)
  378. {
  379. HumanCommandWeapons hcw = GetDayZPlayerOwner().GetCommandModifier_Weapons();
  380. EntityAI ih = GetEntityInHands();
  381. Weapon_Base weapon;
  382. Class.CastTo(weapon, ih);
  383. if (hcw)
  384. {
  385. m_FSM.GetCurrentState().OnUpdate(dt);
  386. #ifdef ENABLE_LOGGING
  387. if (LogManager.IsInventoryHFSMLogEnable())
  388. {
  389. hndDebugSpamALot("[hndfsm] HCW: playing A=" + typename.EnumToString(WeaponActions, hcw.GetRunningAction()) + " AT=" + WeaponActionTypeToString(hcw.GetRunningAction(), hcw.GetRunningActionType()) + " fini=" + hcw.IsActionFinished());
  390. }
  391. #endif
  392. if ( !m_FSM.GetCurrentState().IsIdle() || !m_FSM.IsRunning())
  393. {
  394. while (true)
  395. {
  396. int weaponEventId = hcw.IsEvent();
  397. if (weaponEventId == -1)
  398. {
  399. break;
  400. }
  401. HandEventBase anim_event = HandAnimEventFactory(weaponEventId, GetManOwner(), NULL);
  402. #ifdef ENABLE_LOGGING
  403. if (LogManager.IsInventoryHFSMLogEnable())
  404. {
  405. hndDebugPrint("[hndfsm] HandleInventory: event arrived " + typename.EnumToString(WeaponEvents, weaponEventId) + "(" + weaponEventId + ") fsm_ev=" + anim_event.ToString());
  406. }
  407. #endif
  408. if (anim_event != NULL)
  409. {
  410. SyncHandEventToRemote(anim_event);
  411. ProcessHandEvent(anim_event);
  412. }
  413. }
  414. if (hcw.IsActionFinished())
  415. {
  416. if (m_FSM.GetCurrentState().IsWaitingForActionFinish())
  417. {
  418. #ifdef ENABLE_LOGGING
  419. if (LogManager.IsInventoryHFSMLogEnable())
  420. {
  421. hndDebugPrint("[hndfsm] Hand-Weapon event: finished! notifying waiting state=" + m_FSM.GetCurrentState());
  422. }
  423. #endif
  424. HandEventBase fin_event = new HandEventHumanCommandActionFinished(GetManOwner());
  425. SyncHandEventToRemote(fin_event);
  426. ProcessHandEvent(fin_event);
  427. }
  428. else
  429. {
  430. #ifdef ENABLE_LOGGING
  431. if (LogManager.IsInventoryHFSMLogEnable())
  432. {
  433. hndDebugPrint("[hndfsm] Hand-Weapon event: ABORT! notifying running state=" + m_FSM.GetCurrentState());
  434. }
  435. #endif
  436. HandEventBase abt_event = new HandEventHumanCommandActionAborted(GetManOwner());
  437. SyncHandEventToRemote(abt_event);
  438. ProcessHandAbortEvent(abt_event);
  439. //m_FSM.ProcessHandAbortEvent(new WeaponEventHumanCommandActionAborted(GetManOwner()));
  440. }
  441. }
  442. }
  443. }
  444. }
  445. ///@{ juncture
  446. /**@fn OnInventoryJunctureFromServer
  447. * @brief reaction to engine callback
  448. * originates in:
  449. * engine - DayZPlayer::OnSyncJuncture
  450. * script - PlayerBase.OnSyncJuncture
  451. **/
  452. override bool OnInventoryJunctureFromServer (ParamsReadContext ctx)
  453. {
  454. int tmp = -1;
  455. ctx.Read(tmp);
  456. #ifdef ENABLE_LOGGING
  457. if (LogManager.IsSyncLogEnable())
  458. {
  459. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " store Juncture packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
  460. }
  461. #endif
  462. StoreJunctureData(ctx);
  463. return true;
  464. }
  465. ///@{ juncture
  466. /**@fn OnInventoryJunctureFromServer
  467. * @brief reaction to engine callback
  468. * originates in:
  469. * engine - DayZPlayer::OnSyncJuncture
  470. * script - PlayerBase.OnSyncJuncture
  471. **/
  472. override bool OnInventoryJunctureRepairFromServer (ParamsReadContext ctx)
  473. {
  474. /* InventoryLocation il = new InventoryLocation;
  475. if (!il.ReadFromContext(ctx) )
  476. return false;
  477. InventoryLocation il_current = new InventoryLocation;
  478. EntityAI item = il.GetItem();
  479. item.GetInventory().GetCurrentInventoryLocation(il_current);
  480. if( !il_current.CompareLocationOnly(il))
  481. {
  482. LocationMoveEntity(il_current,il);
  483. }*/
  484. return true;
  485. }
  486. ///@{ juncture
  487. /**@fn OnInventoryJunctureFailureFromServer
  488. * @brief reaction to engine callback
  489. * originates in:
  490. * engine - DayZPlayer::OnSyncJuncture
  491. * script - PlayerBase.OnSyncJuncture
  492. **/
  493. override void OnInventoryJunctureFailureFromServer(ParamsReadContext ctx)
  494. {
  495. /**
  496. * Function and setup is still messy due to the switch statement and relation with reading.
  497. *
  498. * It could be cleaner if we used classes to handle each inventory command type, but that comes at a performance cost and will also probably require making a fair amount of changes elsewhere.
  499. *
  500. * The downsides with this system right now:
  501. * 1. It makes it hard to track what is written/read from the serializer
  502. * 2. It makes this file very very large
  503. *
  504. * The new changes at least remove the massive switch block and allow for all inventory commands to respond back to the client if something goes wrong
  505. *
  506. */
  507. if (GetGame().IsDedicatedServer())
  508. {
  509. return;
  510. }
  511. int udtIdentifier = -1;
  512. if (!ctx.Read(udtIdentifier) || udtIdentifier != INPUT_UDT_INVENTORY)
  513. {
  514. return;
  515. }
  516. InventoryLocation src = new InventoryLocation;
  517. InventoryLocation dst = new InventoryLocation;
  518. InventoryLocation temp = new InventoryLocation;
  519. InventoryCommandType type = -1;
  520. if (!ctx.Read(type))
  521. {
  522. return;
  523. }
  524. switch (type)
  525. {
  526. case InventoryCommandType.SYNC_MOVE:
  527. {
  528. src.ReadFromContext(ctx);
  529. dst.ReadFromContext(ctx);
  530. ClearInventoryReservationEx(dst.GetItem(), dst);
  531. break;
  532. }
  533. case InventoryCommandType.HAND_EVENT:
  534. {
  535. HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
  536. src = e.GetSrc();
  537. dst = e.GetDst();
  538. e.ClearInventoryReservation();
  539. break;
  540. }
  541. case InventoryCommandType.SWAP:
  542. {
  543. src.ReadFromContext(ctx);
  544. temp.ReadFromContext(ctx);
  545. dst.ReadFromContext(ctx);
  546. temp.ReadFromContext(ctx);
  547. ClearInventoryReservationEx(dst.GetItem(), dst);
  548. ClearInventoryReservationEx(temp.GetItem(), temp);
  549. break;
  550. }
  551. case InventoryCommandType.FORCESWAP:
  552. {
  553. break;
  554. }
  555. case InventoryCommandType.DESTROY:
  556. {
  557. src.ReadFromContext(ctx);
  558. break;
  559. }
  560. }
  561. InventoryValidationReason reason;
  562. if (!ctx.Read(reason))
  563. {
  564. reason = InventoryValidationReason.UNKNOWN;
  565. }
  566. OnInventoryFailure(type, reason, src, dst);
  567. }
  568. override void OnInventoryFailure(InventoryCommandType type, InventoryValidationReason reason, InventoryLocation src, InventoryLocation dst)
  569. {
  570. if (reason == InventoryValidationReason.DROP_PREVENTED)
  571. {
  572. //! TODO(kumarjac): Notify player here
  573. return;
  574. }
  575. }
  576. /**@fn OnHandleStoredJunctureData
  577. * @brief reaction to engine callback
  578. * originates in engine - DayZPlayerInventory::HandleStoredJunctureData
  579. **/
  580. protected void OnHandleStoredJunctureData(ParamsReadContext ctx)
  581. {
  582. int tmp = -1;
  583. ctx.Read(tmp);
  584. #ifdef ENABLE_LOGGING
  585. if (LogManager.IsSyncLogEnable())
  586. {
  587. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " handle JunctureData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
  588. }
  589. #endif
  590. //! Juncture is only ever Server Req->Client Ack and Perform->Server Perform, never remote
  591. ProcessInputData(ctx, true, false);
  592. }
  593. /**@fn StoreJunctureData
  594. * @brief stores received input user data for later handling
  595. /aaa
  596. **/
  597. proto native void StoreJunctureData(ParamsReadContext ctx);
  598. ///@} juncture
  599. ///@{ input user data
  600. /**@fn OnInputUserDataProcess
  601. * @brief reaction to engine callback
  602. * originates in:
  603. * engine - DayZPlayer::OnInputUserDataReceived
  604. * script - DayZPlayerImplement.OnInputUserDataReceived
  605. **/
  606. override bool OnInputUserDataProcess(ParamsReadContext ctx)
  607. {
  608. #ifdef ENABLE_LOGGING
  609. if (LogManager.IsSyncLogEnable())
  610. {
  611. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " store InputUserData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
  612. }
  613. #endif
  614. StoreInputUserData(ctx);
  615. return true;
  616. }
  617. /**@fn OnHandleStoredInputUserData
  618. * @brief reaction to engine callback
  619. * originates in engine - DayZPlayerInventory::HandleStoredInputUserData
  620. **/
  621. protected void OnHandleStoredInputUserData(ParamsReadContext ctx)
  622. {
  623. int tmp = -1;
  624. ctx.Read(tmp);
  625. #ifdef ENABLE_LOGGING
  626. if (LogManager.IsSyncLogEnable())
  627. {
  628. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " handle InputUserData packet STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp());
  629. }
  630. #endif
  631. ProcessInputData(ctx, false, false);
  632. }
  633. /**@fn StoreInputUserData
  634. * @brief stores received input user data for later handling
  635. **/
  636. proto native void StoreInputUserData(ParamsReadContext ctx);
  637. ///@} input user data
  638. void OnInputUserDataForRemote(ParamsReadContext ctx)
  639. {
  640. #ifdef ENABLE_LOGGING
  641. if (LogManager.IsSyncLogEnable())
  642. {
  643. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " remote handling InputUserData packet from server");
  644. }
  645. #endif
  646. ProcessInputData(ctx, false, true);
  647. }
  648. override void OnServerInventoryCommand(ParamsReadContext ctx)
  649. {
  650. #ifdef ENABLE_LOGGING
  651. if (LogManager.IsSyncLogEnable())
  652. {
  653. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " DZPInventory command from server");
  654. }
  655. #endif
  656. ProcessInputData(ctx, true, true);
  657. }
  658. bool ValidateSyncMove(inout Serializer ctx, InventoryValidation validation)
  659. {
  660. InventoryCommandType type = InventoryCommandType.SYNC_MOVE;
  661. InventoryLocation src = new InventoryLocation;
  662. InventoryLocation dst = new InventoryLocation;
  663. bool success = true;
  664. src.ReadFromContext(ctx);
  665. dst.ReadFromContext(ctx);
  666. #ifdef ENABLE_LOGGING
  667. if (LogManager.IsInventoryMoveLogEnable())
  668. {
  669. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + "src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  670. }
  671. #endif
  672. if (validation.m_IsRemote && (!src.GetItem() || !dst.GetItem()))
  673. {
  674. //! kumarjac: This indicates a failure in replication relationships as player full inventory should be synchronized always if player exists on the remote
  675. #ifdef ENABLE_LOGGING
  676. if (LogManager.IsInventoryMoveLogEnable())
  677. {
  678. Debug.InventoryMoveLog("Failed - item not in bubble", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  679. }
  680. if (LogManager.IsSyncLogEnable())
  681. {
  682. syncDebugPrint("[syncinv] HandleInputData remote input (cmd=SYNC_MOVE) dropped, item not in bubble! src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  683. }
  684. #endif
  685. return true;
  686. }
  687. EnableMovableOverride(src.GetItem());
  688. //! Do not check for action validity on remotes or when performing through juncture.
  689. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  690. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  691. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckRequestSrc(src, GameInventory.c_MaxItemDistanceRadius))
  692. {
  693. //! kumarjac: This indicates a failure in replication relationships as player full inventory should be synchronized always if player exists on the remote
  694. #ifdef ENABLE_LOGGING
  695. if (LogManager.IsInventoryMoveLogEnable())
  696. {
  697. Debug.InventoryMoveLog("Failed - CheckRequestSrc", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  698. }
  699. if (LogManager.IsSyncLogEnable())
  700. {
  701. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src));
  702. }
  703. #endif
  704. RemoveMovableOverride(src.GetItem());
  705. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  706. {
  707. success = false;
  708. }
  709. else
  710. {
  711. return true;
  712. }
  713. }
  714. //! Do not check for action validity on remotes or when performing through juncture.
  715. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  716. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  717. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckRequestDst(src, dst, GameInventory.c_MaxItemDistanceRadius))
  718. {
  719. #ifdef ENABLE_LOGGING
  720. if (LogManager.IsInventoryMoveLogEnable())
  721. {
  722. Debug.InventoryMoveLog("Failed - CheckMoveToDstRequest", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  723. }
  724. if (LogManager.IsSyncLogEnable())
  725. {
  726. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  727. }
  728. #endif
  729. RemoveMovableOverride(src.GetItem());
  730. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  731. {
  732. success = false;
  733. }
  734. else
  735. {
  736. return true;
  737. }
  738. }
  739. RemoveMovableOverride(src.GetItem());
  740. #ifdef ENABLE_LOGGING
  741. if (LogManager.IsSyncLogEnable())
  742. {
  743. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " HandleInputData t=" + GetGame().GetTime() + "ms received cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  744. }
  745. #endif
  746. //! Check if this this is being executed on the server and not by a juncture or AI so we can lock the item and ensure replication relationships are setup
  747. if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  748. {
  749. JunctureRequestResult result_mv = TryAcquireInventoryJunctureFromServer(GetDayZPlayerOwner(), src, dst);
  750. if (result_mv == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
  751. {
  752. #ifdef ENABLE_LOGGING
  753. if (LogManager.IsInventoryMoveLogEnable())
  754. {
  755. Debug.InventoryMoveLog("Juncture not required", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  756. }
  757. #endif
  758. if (success)
  759. {
  760. //! TODO(kumarjac): We should continue with the execution and not have this special block but making a change here now will require testing
  761. LocationSyncMoveEntity(src, dst);
  762. validation.m_Result = InventoryValidationResult.SUCCESS;
  763. }
  764. return true;
  765. }
  766. else if (success && result_mv == JunctureRequestResult.JUNCTURE_ACQUIRED)
  767. {
  768. #ifdef ENABLE_LOGGING
  769. if (LogManager.IsInventoryMoveLogEnable())
  770. {
  771. Debug.InventoryMoveLog("Juncture sended", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  772. }
  773. #endif
  774. if (!GameInventory.LocationCanMoveEntity(src, dst))
  775. {
  776. #ifdef ENABLE_LOGGING
  777. #ifdef DEVELOPER
  778. DumpInventoryDebug();
  779. #endif
  780. if (LogManager.IsInventoryMoveLogEnable())
  781. {
  782. Debug.InventoryMoveLog("Failed - LocationCanMoveEntity - Juncture denied", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  783. }
  784. #endif
  785. validation.m_Result = InventoryValidationResult.FAILED;
  786. return true;
  787. }
  788. validation.m_Result = InventoryValidationResult.JUNCTURE;
  789. EnableMovableOverride(src.GetItem());
  790. return true;
  791. }
  792. else
  793. {
  794. #ifdef ENABLE_LOGGING
  795. if ( LogManager.IsInventoryMoveLogEnable() )
  796. {
  797. Debug.InventoryMoveLog("Juncture denied", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  798. }
  799. #endif
  800. validation.m_Result = InventoryValidationResult.FAILED;
  801. validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
  802. return true;
  803. }
  804. }
  805. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  806. {
  807. ClearInventoryReservationEx(dst.GetItem(), dst);
  808. }
  809. //! Is called twice unfortunately...
  810. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  811. {
  812. CheckForRope(src, dst);
  813. }
  814. //! Do not check for action validity on remotes or when performing through juncture.
  815. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  816. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  817. if (!validation.m_IsRemote && !validation.m_IsJuncture && !GameInventory.LocationCanMoveEntitySyncCheck(src, dst))
  818. {
  819. #ifdef ENABLE_LOGGING
  820. #ifdef DEVELOPER
  821. DumpInventoryDebug();
  822. #endif
  823. if (LogManager.IsInventoryMoveLogEnable())
  824. {
  825. Debug.InventoryMoveLog("Failed - LocationCanMoveEntity", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  826. }
  827. #endif
  828. Error("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT move cmd=" + typename.EnumToString(InventoryCommandType, type) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  829. return true;
  830. }
  831. //TODO: hotfix solution
  832. if (!validation.m_IsRemote && validation.m_IsJuncture && !MoveCheckExclusionMaskLocal(src,dst))
  833. {
  834. #ifdef ENABLE_LOGGING
  835. if (LogManager.IsInventoryMoveLogEnable())
  836. {
  837. Debug.InventoryMoveLog("Failed - MoveCheckExclusionMaskLocal - condition failed locally", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  838. }
  839. #endif
  840. return false;
  841. }
  842. #ifdef ENABLE_LOGGING
  843. if (LogManager.IsInventoryMoveLogEnable())
  844. {
  845. Debug.InventoryMoveLog("Success - LocationSyncMoveEntity", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  846. }
  847. #endif
  848. LocationSyncMoveEntity(src, dst);
  849. validation.m_Result = InventoryValidationResult.SUCCESS;
  850. return true;
  851. }
  852. bool ValidateHandEvent(inout Serializer ctx, InventoryValidation validation)
  853. {
  854. InventoryCommandType type = InventoryCommandType.HAND_EVENT;
  855. bool success = true;
  856. HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
  857. e.ClearInventoryReservation();
  858. //! Pass partial information to guards so guards can do minimal checks if needed
  859. //! The guards can't prevent event so it would be incorrect to pass full InventoryValidation struct.
  860. //! 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)
  861. e.m_IsRemote = validation.m_IsRemote;
  862. e.m_IsJuncture = validation.m_IsJuncture;
  863. EntityAI itemSrc = e.GetSrcEntity();
  864. EntityAI itemDst = e.GetSecondSrcEntity();
  865. #ifdef ENABLE_LOGGING
  866. if (LogManager.IsInventoryMoveLogEnable())
  867. {
  868. Debug.InventoryMoveLog("STS = " + e.m_Player.GetSimulationTimeStamp() + " event= " + e.DumpToString(), "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  869. }
  870. #endif
  871. if (validation.m_IsRemote && !e.GetSrcEntity())
  872. {
  873. //! kumarjac: This indicates a failure in replication relationships as player full inventory should be synchronized always if player exists on the remote
  874. if (itemDst && (e.GetEventID() == HandEventID.SWAP || e.GetEventID() == HandEventID.FORCESWAP)) //presumed swap, replace with take
  875. {
  876. InventoryLocation srcNew = new InventoryLocation();
  877. srcNew.Copy(e.GetSrc());
  878. e = HandEventBase.HandEventFactory(HandEventID.TAKE, e.m_Player, srcNew);
  879. Error("[syncinv] HandleInputData remote swap event REPLACED with TAKE (cmd=HAND_EVENT, event=" + e.DumpToString() + "), src item is null! Continuing.");
  880. }
  881. else
  882. {
  883. #ifdef ENABLE_LOGGING
  884. if (LogManager.IsInventoryMoveLogEnable())
  885. {
  886. Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  887. }
  888. #endif
  889. Error("[syncinv] HandleInputData remote input (cmd=HAND_EVENT, event=" + e.DumpToString() + ") dropped, item not in bubble");
  890. return true;
  891. }
  892. }
  893. //! TODO(kumarjac): Is this one correct to be 'RemoveMovableOverride' or are the other Validate methdos wrong with 'EnableMovableOverride'?
  894. if (itemSrc)
  895. RemoveMovableOverride(itemSrc);
  896. if (itemDst)
  897. RemoveMovableOverride(itemDst);
  898. //! Do not check for action validity on remotes or when performing through juncture.
  899. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  900. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  901. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !e.CheckRequestSrc())
  902. {
  903. #ifdef ENABLE_LOGGING
  904. if (LogManager.IsInventoryMoveLogEnable())
  905. {
  906. Debug.InventoryMoveLog("Failed - CheckRequestSrc", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  907. }
  908. #endif
  909. if (!validation.m_IsRemote)
  910. {
  911. ctx = new ScriptInputUserData;
  912. InventoryInputUserData.SerializeHandEvent(ctx, e);
  913. }
  914. RemoveMovableOverride(itemSrc);
  915. RemoveMovableOverride(itemDst);
  916. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  917. {
  918. success = false;
  919. }
  920. else
  921. {
  922. return true;
  923. }
  924. }
  925. if (success && !e.CheckRequestEx(validation))
  926. {
  927. #ifdef ENABLE_LOGGING
  928. if (LogManager.IsInventoryMoveLogEnable())
  929. {
  930. Debug.InventoryMoveLog("Failed - CheckRequest", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  931. }
  932. #endif
  933. //! 'HandEventBase.CheckRequestEx' updates failure reason
  934. ctx = new ScriptInputUserData;
  935. InventoryInputUserData.SerializeHandEvent(ctx, e);
  936. #ifdef ENABLE_LOGGING
  937. if (LogManager.IsSyncLogEnable())
  938. {
  939. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " event=" + e.DumpToString());
  940. }
  941. #endif
  942. RemoveMovableOverride(itemSrc);
  943. RemoveMovableOverride(itemDst);
  944. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  945. {
  946. success = false;
  947. }
  948. else
  949. {
  950. return true;
  951. }
  952. }
  953. //! if it already happened on server, remote just needs to comply
  954. //! TODO(kumarjac): Move m_IsRemote check to inside of HandEventBase.CanPerformEventEx
  955. if (success && !validation.m_IsRemote && !e.CanPerformEventEx(validation))
  956. {
  957. #ifdef ENABLE_LOGGING
  958. if (LogManager.IsInventoryMoveLogEnable())
  959. {
  960. Debug.InventoryMoveLog("Failed - CanPerformEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  961. }
  962. #endif
  963. //! 'HandEventBase.CanPerformEventEx' updates failure reason
  964. ctx = new ScriptInputUserData;
  965. InventoryInputUserData.SerializeHandEvent(ctx, e);
  966. #ifdef ENABLE_LOGGING
  967. if (LogManager.IsSyncLogEnable())
  968. {
  969. syncDebugPrint("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT do cmd=HAND_EVENT e=" + e.DumpToString());
  970. }
  971. #endif
  972. RemoveMovableOverride(itemSrc);
  973. RemoveMovableOverride(itemDst);
  974. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  975. {
  976. success = false;
  977. }
  978. else
  979. {
  980. return true;
  981. }
  982. }
  983. RemoveMovableOverride(itemSrc);
  984. RemoveMovableOverride(itemDst);
  985. //! Check if this this is being executed on the server and not by a juncture or AI
  986. if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  987. {
  988. JunctureRequestResult result_ev = e.AcquireInventoryJunctureFromServer(GetDayZPlayerOwner());
  989. if (result_ev == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
  990. {
  991. #ifdef ENABLE_LOGGING
  992. if (LogManager.IsInventoryMoveLogEnable())
  993. {
  994. Debug.InventoryMoveLog("Juncture not required", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  995. }
  996. #endif
  997. //! Continuing on with execution of rest of the function
  998. }
  999. else if (success && result_ev == JunctureRequestResult.JUNCTURE_ACQUIRED)
  1000. {
  1001. #ifdef ENABLE_LOGGING
  1002. if (LogManager.IsInventoryMoveLogEnable())
  1003. {
  1004. Debug.InventoryMoveLog("Juncture sended", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  1005. }
  1006. #endif
  1007. ctx = new ScriptInputUserData;
  1008. InventoryInputUserData.SerializeHandEvent(ctx, e);
  1009. validation.m_Result = InventoryValidationResult.JUNCTURE;
  1010. if (itemSrc)
  1011. EnableMovableOverride(itemSrc);
  1012. if (itemDst)
  1013. EnableMovableOverride(itemDst);
  1014. return true;
  1015. }
  1016. else
  1017. {
  1018. #ifdef ENABLE_LOGGING
  1019. if (LogManager.IsInventoryMoveLogEnable())
  1020. {
  1021. Debug.InventoryMoveLog("Juncture denied", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  1022. }
  1023. #endif
  1024. validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
  1025. return true;
  1026. }
  1027. }
  1028. //! Is called twice unfortunately... but it works so won't change
  1029. if (success && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1030. {
  1031. CheckForRope(e.GetSrc(), e.GetDst());
  1032. }
  1033. #ifdef ENABLE_LOGGING
  1034. if (LogManager.IsInventoryMoveLogEnable())
  1035. {
  1036. Debug.InventoryMoveLog("Success - ProcessHandEvent", "HAND_EVENT" , "n/a", "ProcessInputData", e.m_Player.ToString() );
  1037. }
  1038. #endif
  1039. if (success)
  1040. {
  1041. validation.m_Result = InventoryValidationResult.SUCCESS;
  1042. if (!e.m_Player.GetHumanInventory().ProcessHandEvent(e))
  1043. {
  1044. //! TODO(kumarjac): We should probably set the result to failure like so
  1045. //result = InventoryValidationResult.FAILURE;
  1046. }
  1047. }
  1048. return true;
  1049. }
  1050. bool ValidateSwap(inout Serializer ctx, InventoryValidation validation)
  1051. {
  1052. InventoryCommandType type = InventoryCommandType.SWAP;
  1053. InventoryLocation src1 = new InventoryLocation;
  1054. InventoryLocation src2 = new InventoryLocation;
  1055. InventoryLocation dst1 = new InventoryLocation;
  1056. InventoryLocation dst2 = new InventoryLocation;
  1057. bool skippedSwap = false;
  1058. bool success = true;
  1059. src1.ReadFromContext(ctx);
  1060. src2.ReadFromContext(ctx);
  1061. dst1.ReadFromContext(ctx);
  1062. dst2.ReadFromContext(ctx);
  1063. ctx.Read(skippedSwap);
  1064. #ifdef ENABLE_LOGGING
  1065. if (LogManager.IsInventoryMoveLogEnable())
  1066. {
  1067. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2), "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1068. }
  1069. #endif
  1070. if (validation.m_IsRemote && (!src1.GetItem() || !src2.GetItem()))
  1071. {
  1072. if (skippedSwap)
  1073. {
  1074. #ifdef ENABLE_LOGGING
  1075. if (LogManager.IsInventoryMoveLogEnable())
  1076. {
  1077. Debug.InventoryMoveLog("Remote - skipped", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1078. }
  1079. #endif
  1080. /*
  1081. if (LogManager.IsSyncLogEnable())
  1082. {
  1083. syncDebugPrint("[syncinv] HandleInputData remote input (cmd=SWAP) dropped, swap is skipped");
  1084. }
  1085. */
  1086. }
  1087. else
  1088. {
  1089. //! kumarjac: This indicates a failure in replication relationships as player full inventory should be synchronized always if player exists on the remote
  1090. #ifdef ENABLE_LOGGING
  1091. if (LogManager.IsInventoryMoveLogEnable())
  1092. {
  1093. Debug.InventoryMoveLog("Failed - item1 or item2 not exist", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1094. }
  1095. #endif
  1096. Error("[syncinv] HandleInputData remote input (cmd=SWAP) dropped, item not in bubble");
  1097. }
  1098. return true;
  1099. }
  1100. EnableMovableOverride(src1.GetItem());
  1101. EnableMovableOverride(src2.GetItem());
  1102. //! Do not check for action validity on remotes or when performing through juncture.
  1103. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  1104. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  1105. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckRequestSrc(src1, GameInventory.c_MaxItemDistanceRadius))
  1106. {
  1107. #ifdef ENABLE_LOGGING
  1108. if (LogManager.IsInventoryMoveLogEnable())
  1109. {
  1110. Debug.InventoryMoveLog("Failed - CheckRequestSrc1", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1111. }
  1112. if (LogManager.IsSyncLogEnable())
  1113. {
  1114. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src1 check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1));
  1115. }
  1116. #endif
  1117. RemoveMovableOverride(src1.GetItem());
  1118. RemoveMovableOverride(src2.GetItem());
  1119. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1120. {
  1121. success = false;
  1122. }
  1123. else
  1124. {
  1125. return true;
  1126. }
  1127. }
  1128. //! Do not check for action validity on remotes or when performing through juncture.
  1129. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  1130. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  1131. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckRequestSrc(src2, GameInventory.c_MaxItemDistanceRadius))
  1132. {
  1133. #ifdef ENABLE_LOGGING
  1134. if (LogManager.IsInventoryMoveLogEnable())
  1135. {
  1136. Debug.InventoryMoveLog("Failed - CheckRequestSrc2", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1137. }
  1138. if (LogManager.IsSyncLogEnable())
  1139. {
  1140. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " failed src2 check with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2));
  1141. }
  1142. #endif
  1143. RemoveMovableOverride(src1.GetItem());
  1144. RemoveMovableOverride(src2.GetItem());
  1145. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1146. {
  1147. success = false;
  1148. }
  1149. else
  1150. {
  1151. return true;
  1152. }
  1153. }
  1154. //! Do not check for action validity on remotes or when performing through juncture.
  1155. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  1156. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  1157. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckSwapItemsRequest(src1, src2, dst1, dst2, GameInventory.c_MaxItemDistanceRadius))
  1158. {
  1159. #ifdef ENABLE_LOGGING
  1160. if (LogManager.IsInventoryMoveLogEnable())
  1161. {
  1162. Debug.InventoryMoveLog("Failed - CheckSwapItemsRequest", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1163. }
  1164. if (LogManager.IsSyncLogEnable())
  1165. {
  1166. syncDebugPrint("[cheat] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " is cheating with cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  1167. }
  1168. #endif
  1169. RemoveMovableOverride(src1.GetItem());
  1170. RemoveMovableOverride(src2.GetItem());
  1171. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1172. {
  1173. success = false;
  1174. }
  1175. else
  1176. {
  1177. return true;
  1178. }
  1179. }
  1180. RemoveMovableOverride(src1.GetItem());
  1181. RemoveMovableOverride(src2.GetItem());
  1182. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  1183. {
  1184. ClearInventoryReservationEx(dst1.GetItem(), dst1);
  1185. ClearInventoryReservationEx(dst2.GetItem(), dst2);
  1186. }
  1187. //! Do not check for action validity on remotes or when performing through juncture.
  1188. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  1189. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  1190. if (success && !validation.m_IsRemote && !validation.m_IsJuncture && !GameInventory.CanForceSwapEntitiesEx(src1.GetItem(), dst1, src2.GetItem(), dst2))
  1191. {
  1192. #ifdef ENABLE_LOGGING
  1193. #ifdef DEVELOPER
  1194. DumpInventoryDebug();
  1195. #endif
  1196. if (LogManager.IsInventoryMoveLogEnable())
  1197. {
  1198. Debug.InventoryMoveLog("Failed - CanForceSwapEntitiesEx", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1199. }
  1200. #endif
  1201. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1202. {
  1203. success = false;
  1204. }
  1205. else
  1206. {
  1207. Error("[desync] HandleInputData man=" + Object.GetDebugName(GetManOwner()) + " CANNOT swap cmd=" + typename.EnumToString(InventoryCommandType, type) + " src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) +" | src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  1208. return true;
  1209. }
  1210. }
  1211. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  1212. {
  1213. AddInventoryReservationEx(dst1.GetItem(), dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  1214. AddInventoryReservationEx(dst2.GetItem(), dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  1215. }
  1216. if (!(src1.IsValid() && src2.IsValid() && dst1.IsValid() && dst2.IsValid()))
  1217. {
  1218. Error("HandleInputData: cmd=" + typename.EnumToString(InventoryCommandType, type) + " invalid input(s): src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(dst2));
  1219. return true;
  1220. }
  1221. //! Check if this this is being executed on the server and not by a juncture or AI
  1222. if (!validation.m_IsJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1223. {
  1224. JunctureRequestResult result_sw = TryAcquireTwoInventoryJuncturesFromServer(GetDayZPlayerOwner(), src1, src2, dst1, dst2);
  1225. if (result_sw == JunctureRequestResult.JUNCTURE_NOT_REQUIRED)
  1226. {
  1227. #ifdef ENABLE_LOGGING
  1228. if (LogManager.IsInventoryMoveLogEnable())
  1229. {
  1230. Debug.InventoryMoveLog("Juncture not required", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1231. }
  1232. #endif
  1233. //! Continuing on with execution of rest of the function
  1234. }
  1235. else if (success && result_sw == JunctureRequestResult.JUNCTURE_ACQUIRED)
  1236. {
  1237. #ifdef ENABLE_LOGGING
  1238. if (LogManager.IsInventoryMoveLogEnable())
  1239. {
  1240. Debug.InventoryMoveLog("Juncture sended", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1241. }
  1242. #endif
  1243. validation.m_Result = InventoryValidationResult.JUNCTURE;
  1244. EnableMovableOverride(src1.GetItem());
  1245. EnableMovableOverride(src2.GetItem());
  1246. return true;
  1247. }
  1248. else
  1249. {
  1250. #ifdef ENABLE_LOGGING
  1251. if (LogManager.IsInventoryMoveLogEnable())
  1252. {
  1253. Debug.InventoryMoveLog("Juncture denied", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1254. }
  1255. #endif
  1256. validation.m_Result = InventoryValidationResult.FAILED;
  1257. validation.m_Reason = InventoryValidationReason.JUNCTURE_DENIED;
  1258. return true;
  1259. }
  1260. }
  1261. if (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT )
  1262. {
  1263. ClearInventoryReservationEx(dst1.GetItem(), dst1);
  1264. ClearInventoryReservationEx(dst2.GetItem(), dst2);
  1265. }
  1266. else
  1267. {
  1268. GetGame().ClearJunctureEx(GetDayZPlayerOwner(), dst1.GetItem());
  1269. GetGame().ClearJunctureEx(GetDayZPlayerOwner(), dst2.GetItem());
  1270. }
  1271. //TODO: hotfix solution
  1272. if (!validation.m_IsRemote && validation.m_IsJuncture && !SwapCheckExclusionMaskLocal(src1,src2,dst1,dst2))
  1273. {
  1274. #ifdef ENABLE_LOGGING
  1275. if (LogManager.IsInventoryMoveLogEnable())
  1276. {
  1277. Debug.InventoryMoveLog("Failed - !SwapCheckExclusionMaskLocal - condition failed locally", "SYNC_MOVE" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1278. }
  1279. #endif
  1280. return false;
  1281. }
  1282. #ifdef ENABLE_LOGGING
  1283. if (LogManager.IsInventoryMoveLogEnable())
  1284. {
  1285. Debug.InventoryMoveLog("Success - item swap", "SWAP" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  1286. }
  1287. #endif
  1288. if (success)
  1289. {
  1290. bool isNotSkipped = LocationSwap(src1, src2, dst1, dst2);
  1291. ctx = new ScriptInputUserData();
  1292. InventoryInputUserData.SerializeSwap(ctx, src1, src2, dst1, dst2, !isNotSkipped);
  1293. validation.m_Result = InventoryValidationResult.SUCCESS;
  1294. }
  1295. return true;
  1296. }
  1297. /**
  1298. *
  1299. * @return false on malformed data, true on anything else, including cheats
  1300. */
  1301. bool ProcessInputData(ParamsReadContext ctx, bool isJuncture, bool isRemote)
  1302. {
  1303. if (isJuncture && isRemote)
  1304. {
  1305. //! It should be impossible for juncture to be ran on remote
  1306. return false;
  1307. }
  1308. int type = -1;
  1309. if (!ctx.Read(type))
  1310. {
  1311. return false;
  1312. }
  1313. InventoryValidation validation = new InventoryValidation();
  1314. validation.m_IsJuncture = isJuncture;
  1315. validation.m_IsRemote = isRemote;
  1316. //! Serializer can be updated and re-written to when we may want to only correct the client instead of denying the inventory command
  1317. Serializer serializer = ctx;
  1318. switch (type)
  1319. {
  1320. case InventoryCommandType.USER_RESERVATION_CANCEL:
  1321. if (!ValidateUserReservationCancel(serializer, validation))
  1322. {
  1323. return false;
  1324. }
  1325. break;
  1326. case InventoryCommandType.SYNC_MOVE:
  1327. if (!ValidateSyncMove(serializer, validation))
  1328. {
  1329. return false;
  1330. }
  1331. break;
  1332. case InventoryCommandType.HAND_EVENT:
  1333. if (!ValidateHandEvent(serializer, validation))
  1334. {
  1335. return false;
  1336. }
  1337. break;
  1338. case InventoryCommandType.SWAP:
  1339. if (!ValidateSwap(serializer, validation))
  1340. {
  1341. return false;
  1342. }
  1343. break;
  1344. default:
  1345. break;
  1346. }
  1347. bool canSendJuncture = !isJuncture && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER;
  1348. switch (validation.m_Result)
  1349. {
  1350. case InventoryValidationResult.FAILED:
  1351. if (canSendJuncture) //! Only inform client about failure
  1352. {
  1353. //! General purpose serializer change from read to write here if the validation doesn't update it
  1354. if (!serializer.CanWrite())
  1355. {
  1356. ScriptInputUserData writeableSerializer();
  1357. writeableSerializer.CopyFrom(serializer);
  1358. serializer = writeableSerializer;
  1359. }
  1360. serializer.Write(validation.m_Reason);
  1361. GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY_FAILURE, serializer);
  1362. }
  1363. break;
  1364. case InventoryValidationResult.JUNCTURE:
  1365. if (canSendJuncture) //! Only send juncture back to client
  1366. {
  1367. GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY, serializer);
  1368. //StoreInputForRemotes(isJuncture, isRemote, serializer);
  1369. }
  1370. else
  1371. {
  1372. Error("InventoryValidationResult.JUNCTURE returned when not possible to send!");
  1373. }
  1374. break;
  1375. case InventoryValidationResult.SUCCESS:
  1376. StoreInputForRemotes(isJuncture, isRemote, serializer);
  1377. break;
  1378. }
  1379. return true;
  1380. }
  1381. void RemoveMovableOverride(EntityAI item)
  1382. {
  1383. ItemBase itemIB = ItemBase.Cast(item);
  1384. if (itemIB)
  1385. itemIB.SetCanBeMovedOverride(false);
  1386. }
  1387. void EnableMovableOverride(EntityAI item)
  1388. {
  1389. ItemBase itemIB = ItemBase.Cast(item);
  1390. if (itemIB)
  1391. itemIB.SetCanBeMovedOverride(true);
  1392. }
  1393. // Hacky solution for dealing with fencekit rope related issues, could be fixed by introducing some indicator that this item behaves differently or sth..
  1394. void CheckForRope(InventoryLocation src, InventoryLocation dst)
  1395. {
  1396. Rope rope = Rope.Cast(src.GetItem());
  1397. if (rope)
  1398. rope.SetTargetLocation(dst);
  1399. }
  1400. bool IsServerOrLocalPlayer()
  1401. {
  1402. return (GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER) || (GetDayZPlayerOwner() == GetGame().GetPlayer());
  1403. }
  1404. bool StoreInputForRemotes (bool handling_juncture, bool remote, ParamsReadContext ctx)
  1405. {
  1406. if (!remote && GetDayZPlayerOwner().GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1407. {
  1408. #ifdef ENABLE_LOGGING
  1409. if (LogManager.IsInventoryMoveLogEnable())
  1410. {
  1411. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "StoreInputForRemotes", GetDayZPlayerOwner().ToString() );
  1412. }
  1413. #endif
  1414. GetDayZPlayerOwner().StoreInputForRemotes(ctx); // @NOTE: needs to be called _after_ the operation
  1415. return true;
  1416. }
  1417. return false;
  1418. }
  1419. override bool TakeToDst (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  1420. {
  1421. if (GetManOwner().IsAlive() == false)
  1422. return super.TakeToDst(mode, src, dst);
  1423. #ifdef ENABLE_LOGGING
  1424. if (LogManager.IsInventoryMoveLogEnable())
  1425. {
  1426. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
  1427. }
  1428. #endif
  1429. switch (mode)
  1430. {
  1431. case InventoryMode.SERVER:
  1432. if (RedirectToHandEvent(mode, src, dst))
  1433. {
  1434. #ifdef ENABLE_LOGGING
  1435. if (LogManager.IsInventoryMoveLogEnable())
  1436. {
  1437. Debug.InventoryMoveLog("RedirectToHandEvent", "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
  1438. }
  1439. #endif
  1440. return true;
  1441. }
  1442. if (GetDayZPlayerOwner().NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
  1443. {
  1444. if (GetGame().AddInventoryJunctureEx(GetDayZPlayerOwner(), src.GetItem(), dst, true, GameInventory.c_InventoryReservationTimeoutMS))
  1445. {
  1446. #ifdef ENABLE_LOGGING
  1447. if (LogManager.IsSyncLogEnable())
  1448. {
  1449. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") got juncture");
  1450. }
  1451. #endif
  1452. }
  1453. else
  1454. {
  1455. #ifdef ENABLE_LOGGING
  1456. if (LogManager.IsInventoryMoveLogEnable())
  1457. {
  1458. Debug.InventoryMoveLog("Juncture failed", "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
  1459. }
  1460. if (LogManager.IsSyncLogEnable())
  1461. {
  1462. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") got juncture");
  1463. }
  1464. #endif
  1465. return false;
  1466. }
  1467. }
  1468. ScriptInputUserData ctx = new ScriptInputUserData;
  1469. InventoryInputUserData.SerializeMove(ctx, InventoryCommandType.SYNC_MOVE, src, dst);
  1470. GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY, ctx);
  1471. #ifdef ENABLE_LOGGING
  1472. if (LogManager.IsSyncLogEnable())
  1473. {
  1474. syncDebugPrint("[syncinv] " + Object.GetDebugName(GetDayZPlayerOwner()) + " STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " store input for remote - DZPI::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + " server sync move src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  1475. }
  1476. #endif
  1477. //! Remote inputs are processed in sync juncture once performed on the server - this code below was executing the inventory command before the player simulation timeestamp for remotes which is illegal
  1478. //GetDayZPlayerOwner().StoreInputForRemotes(ctx); // @TODO: is this right place? maybe in HandleInputData(server=true, ...)
  1479. #ifdef ENABLE_LOGGING
  1480. if ( LogManager.IsInventoryMoveLogEnable() )
  1481. {
  1482. Debug.InventoryMoveLog("Success - store input for remote mode - " + typename.EnumToString(InventoryMode, mode) + " src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst), "n/a" , "n/a", "TakeToDst", GetDayZPlayerOwner().ToString() );
  1483. }
  1484. #endif
  1485. return true;
  1486. case InventoryMode.LOCAL:
  1487. LocationSyncMoveEntity(src, dst);
  1488. return true;
  1489. }
  1490. if (!super.TakeToDst(mode,src,dst))
  1491. {
  1492. return PostDeferredEventTakeToDst(mode,src,dst);
  1493. }
  1494. return true;
  1495. }
  1496. override bool PostDeferredEventTakeToDst(InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  1497. {
  1498. if (!super.PostDeferredEventTakeToDst(mode,src,dst))
  1499. return false;
  1500. if (!m_DeferredEvent)
  1501. {
  1502. m_DeferredEvent = new DeferredTakeToDst(mode,src,dst);
  1503. if (m_DeferredEvent.ReserveInventory(this))
  1504. return true;
  1505. }
  1506. m_DeferredEvent = null;
  1507. return false;
  1508. }
  1509. void HandleTakeToDst( DeferredEvent deferred_event )
  1510. {
  1511. DeferredTakeToDst deferred_take_to_dst = DeferredTakeToDst.Cast(deferred_event);
  1512. if( deferred_take_to_dst )
  1513. {
  1514. #ifdef ENABLE_LOGGING
  1515. if ( LogManager.IsInventoryHFSMLogEnable() )
  1516. {
  1517. Debug.InventoryHFSMLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
  1518. }
  1519. #endif
  1520. deferred_take_to_dst.ClearInventoryReservation(this);
  1521. if (LogManager.IsInventoryMoveLogEnable())
  1522. {
  1523. inventoryDebugPrint("[inv] I::Take2Dst(" + typename.EnumToString(InventoryMode, deferred_take_to_dst.m_mode) + ") src=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_src) + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst));
  1524. }
  1525. switch (deferred_take_to_dst.m_mode)
  1526. {
  1527. case InventoryMode.PREDICTIVE:
  1528. #ifdef ENABLE_LOGGING
  1529. if (LogManager.IsInventoryHFSMLogEnable())
  1530. {
  1531. Debug.InventoryHFSMLog("PREDICTIVE ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
  1532. }
  1533. #endif
  1534. if (LocationCanMoveEntity(deferred_take_to_dst.m_src,deferred_take_to_dst.m_dst))
  1535. {
  1536. InventoryInputUserData.SendInputUserDataMove(InventoryCommandType.SYNC_MOVE, deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
  1537. LocationSyncMoveEntity(deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
  1538. }
  1539. else
  1540. {
  1541. #ifdef ENABLE_LOGGING
  1542. if (LogManager.IsInventoryMoveLogEnable())
  1543. {
  1544. Debug.InventoryMoveLog("Can not move entity (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item = " + deferred_take_to_dst.m_dst.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString() );
  1545. }
  1546. #endif
  1547. }
  1548. break;
  1549. case InventoryMode.JUNCTURE:
  1550. #ifdef ENABLE_LOGGING
  1551. if (LogManager.IsInventoryHFSMLogEnable())
  1552. {
  1553. Debug.InventoryHFSMLog("JUNCTURE ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString());
  1554. }
  1555. #endif
  1556. if (LocationCanMoveEntity(deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst))
  1557. {
  1558. DayZPlayer player = GetGame().GetPlayer();
  1559. player.GetHumanInventory().AddInventoryReservationEx(deferred_take_to_dst.m_dst.GetItem(), deferred_take_to_dst.m_dst, GameInventory.c_InventoryReservationTimeoutShortMS);
  1560. EnableMovableOverride(deferred_take_to_dst.m_dst.GetItem());
  1561. InventoryInputUserData.SendInputUserDataMove(InventoryCommandType.SYNC_MOVE, deferred_take_to_dst.m_src, deferred_take_to_dst.m_dst);
  1562. }
  1563. else
  1564. {
  1565. #ifdef ENABLE_LOGGING
  1566. if (LogManager.IsInventoryMoveLogEnable())
  1567. {
  1568. Debug.InventoryMoveLog("Can not move entity (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item = " + deferred_take_to_dst.m_dst.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_take_to_dst.m_dst), "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString());
  1569. }
  1570. #endif
  1571. }
  1572. break;
  1573. case InventoryMode.LOCAL:
  1574. #ifdef ENABLE_LOGGING
  1575. if (LogManager.IsInventoryHFSMLogEnable())
  1576. {
  1577. Debug.InventoryHFSMLog("LOCAL ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString());
  1578. }
  1579. #endif
  1580. break;
  1581. case InventoryMode.SERVER:
  1582. #ifdef ENABLE_LOGGING
  1583. if (LogManager.IsInventoryHFSMLogEnable())
  1584. {
  1585. Debug.InventoryHFSMLog("SERVER ", "n/a" , "n/a", "HandleTakeToDst", GetDayZPlayerOwner().ToString());
  1586. }
  1587. #endif
  1588. break;
  1589. default:
  1590. Error("HandEvent - Invalid mode");
  1591. break;
  1592. }
  1593. }
  1594. }
  1595. override bool SwapEntities (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
  1596. {
  1597. #ifdef ENABLE_LOGGING
  1598. if (LogManager.IsInventoryMoveLogEnable())
  1599. {
  1600. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + item1 + " item2 = " + item2, "n/a" , "n/a", "SwapEntities", GetDayZPlayerOwner().ToString() );
  1601. }
  1602. #endif
  1603. InventoryLocation src1, src2, dst1, dst2;
  1604. if( mode == InventoryMode.LOCAL )
  1605. {
  1606. if (GameInventory.MakeSrcAndDstForSwap(item1, item2, src1, src2, dst1, dst2))
  1607. {
  1608. LocationSwap(src1, src2, dst1, dst2);
  1609. return true;
  1610. }
  1611. }
  1612. if(!super.SwapEntities(mode,item1,item2))
  1613. {
  1614. if (GameInventory.MakeSrcAndDstForSwap(item1, item2, src1, src2, dst1, dst2))
  1615. {
  1616. return PostDeferredForceSwapEntities(mode, item1, item2, dst1, dst2);
  1617. }
  1618. }
  1619. return true;
  1620. }
  1621. override bool PostDeferredForceSwapEntities(InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
  1622. {
  1623. if (!super.PostDeferredForceSwapEntities(mode, item1, item2, dst1, dst2))
  1624. return false;
  1625. if (!m_DeferredEvent)
  1626. {
  1627. m_DeferredEvent = new DeferredForceSwapEntities(mode, item1, item2, dst1, dst2);
  1628. if (m_DeferredEvent.ReserveInventory(this))
  1629. return true;
  1630. }
  1631. m_DeferredEvent = null;
  1632. return false;
  1633. }
  1634. void HandleSwapEntities( DeferredEvent deferred_event )
  1635. {
  1636. DeferredSwapEntities deferred_swap_entities = DeferredSwapEntities.Cast(deferred_event);
  1637. if( deferred_swap_entities )
  1638. {
  1639. deferred_swap_entities.ClearInventoryReservation(this);
  1640. InventoryLocation src1, src2, dst1, dst2;
  1641. if (GameInventory.MakeSrcAndDstForSwap(deferred_swap_entities.m_item1, deferred_swap_entities.m_item2, src1, src2, dst1, dst2))
  1642. {
  1643. if (LogManager.IsInventoryMoveLogEnable())
  1644. {
  1645. inventoryDebugPrint("[inv] I::Swap(" + typename.EnumToString(InventoryMode, deferred_swap_entities.m_mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2));
  1646. }
  1647. switch (deferred_swap_entities.m_mode)
  1648. {
  1649. case InventoryMode.PREDICTIVE:
  1650. if (CanSwapEntitiesEx(deferred_swap_entities.m_dst1.GetItem(),deferred_swap_entities.m_dst2.GetItem()) )
  1651. {
  1652. InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
  1653. LocationSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
  1654. }
  1655. else
  1656. {
  1657. #ifdef ENABLE_LOGGING
  1658. if (LogManager.IsInventoryMoveLogEnable())
  1659. {
  1660. Debug.InventoryMoveLog("Can not swap (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
  1661. }
  1662. #endif
  1663. }
  1664. break;
  1665. case InventoryMode.JUNCTURE:
  1666. if (CanSwapEntitiesEx(deferred_swap_entities.m_dst1.GetItem(),deferred_swap_entities.m_dst2.GetItem()) )
  1667. {
  1668. DayZPlayer player = GetGame().GetPlayer();
  1669. player.GetHumanInventory().AddInventoryReservationEx(deferred_swap_entities.m_dst1.GetItem(), deferred_swap_entities.m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  1670. player.GetHumanInventory().AddInventoryReservationEx(deferred_swap_entities.m_dst2.GetItem(), deferred_swap_entities.m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  1671. EnableMovableOverride(deferred_swap_entities.m_dst1.GetItem());
  1672. EnableMovableOverride(deferred_swap_entities.m_dst2.GetItem());
  1673. InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_swap_entities.m_dst1, deferred_swap_entities.m_dst2);
  1674. }
  1675. else
  1676. {
  1677. #ifdef ENABLE_LOGGING
  1678. if (LogManager.IsInventoryMoveLogEnable())
  1679. {
  1680. Debug.InventoryMoveLog("Can not swap (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
  1681. }
  1682. #endif
  1683. }
  1684. break;
  1685. case InventoryMode.LOCAL:
  1686. break;
  1687. default:
  1688. Error("SwapEntities - HandEvent - Invalid mode");
  1689. }
  1690. }
  1691. else
  1692. Error("SwapEntities - MakeSrcAndDstForSwap - no inv loc");
  1693. }
  1694. }
  1695. override bool ForceSwapEntities (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  1696. {
  1697. #ifdef ENABLE_LOGGING
  1698. if (LogManager.IsInventoryMoveLogEnable())
  1699. {
  1700. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + item1 + " item2 = " + item2 + " dst=" + InventoryLocation.DumpToStringNullSafe(item2_dst), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString() );
  1701. }
  1702. #endif
  1703. InventoryLocation src1, src2, dst1;
  1704. if( mode == InventoryMode.LOCAL )
  1705. {
  1706. if (GameInventory.MakeSrcAndDstForForceSwap(item1, item2, src1, src2, dst1, item2_dst))
  1707. {
  1708. LocationSwap(src1, src2, dst1, item2_dst);
  1709. return true;
  1710. }
  1711. }
  1712. if(!super.ForceSwapEntities(mode,item1,item2,item2_dst))
  1713. {
  1714. if (GameInventory.MakeSrcAndDstForForceSwap(item1, item2, src1, src2, dst1, item2_dst))
  1715. {
  1716. return PostDeferredForceSwapEntities(mode, item1, item2, dst1, item2_dst);
  1717. }
  1718. }
  1719. return true;
  1720. }
  1721. void HandleForceSwapEntities( DeferredEvent deferred_event )
  1722. {
  1723. DeferredForceSwapEntities deferred_force_swap_entities = DeferredForceSwapEntities.Cast(deferred_event);
  1724. if (deferred_force_swap_entities)
  1725. {
  1726. deferred_force_swap_entities.ClearInventoryReservation(this);
  1727. InventoryLocation src1 = new InventoryLocation;
  1728. InventoryLocation src2 = new InventoryLocation;
  1729. deferred_force_swap_entities.m_item1.GetInventory().GetCurrentInventoryLocation(src1);
  1730. deferred_force_swap_entities.m_item2.GetInventory().GetCurrentInventoryLocation(src2);
  1731. DayZPlayer player = GetGame().GetPlayer();
  1732. if (LogManager.IsInventoryMoveLogEnable())
  1733. {
  1734. inventoryDebugPrint("[inv] I::FSwap(" + typename.EnumToString(InventoryMode, deferred_force_swap_entities.m_mode) + ") src1=" + InventoryLocation.DumpToStringNullSafe(src1) + " src2=" + InventoryLocation.DumpToStringNullSafe(src2) + " dst1=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst1) + " dst2=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2));
  1735. }
  1736. switch (deferred_force_swap_entities.m_mode)
  1737. {
  1738. case InventoryMode.PREDICTIVE:
  1739. if (CanForceSwapEntitiesEx(deferred_force_swap_entities.m_dst1.GetItem(),deferred_force_swap_entities.m_dst1,deferred_force_swap_entities.m_dst2.GetItem(), deferred_force_swap_entities.m_dst2))
  1740. {
  1741. InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
  1742. LocationSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
  1743. }
  1744. else
  1745. {
  1746. #ifdef ENABLE_LOGGING
  1747. if (LogManager.IsInventoryMoveLogEnable())
  1748. {
  1749. Debug.InventoryMoveLog("Can not force swap (PREDICTIVE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_force_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_force_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString());
  1750. }
  1751. #endif
  1752. }
  1753. break;
  1754. case InventoryMode.JUNCTURE:
  1755. if (CanForceSwapEntitiesEx(deferred_force_swap_entities.m_dst1.GetItem(), deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2.GetItem(), deferred_force_swap_entities.m_dst2))
  1756. {
  1757. player.GetHumanInventory().AddInventoryReservationEx(deferred_force_swap_entities.m_item1, deferred_force_swap_entities.m_dst1, GameInventory.c_InventoryReservationTimeoutShortMS);
  1758. player.GetHumanInventory().AddInventoryReservationEx(deferred_force_swap_entities.m_item2, deferred_force_swap_entities.m_dst2, GameInventory.c_InventoryReservationTimeoutShortMS);
  1759. InventoryInputUserData.SendInputUserDataSwap(src1, src2, deferred_force_swap_entities.m_dst1, deferred_force_swap_entities.m_dst2);
  1760. }
  1761. else
  1762. {
  1763. #ifdef ENABLE_LOGGING
  1764. if (LogManager.IsInventoryMoveLogEnable())
  1765. {
  1766. Debug.InventoryMoveLog("Can not force swap (JUNCTURE) STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " item1 = " + deferred_force_swap_entities.m_dst1.GetItem() + " item2 = " + deferred_force_swap_entities.m_dst2.GetItem() + " dst=" + InventoryLocation.DumpToStringNullSafe(deferred_force_swap_entities.m_dst2), "n/a" , "n/a", "ForceSwapEntities", GetDayZPlayerOwner().ToString());
  1767. }
  1768. #endif
  1769. }
  1770. break;
  1771. case InventoryMode.LOCAL:
  1772. break;
  1773. default:
  1774. Error("ForceSwapEntities - HandEvent - Invalid mode");
  1775. }
  1776. }
  1777. }
  1778. static void SendServerHandEventViaJuncture (notnull DayZPlayer player, HandEventBase e)
  1779. {
  1780. if (GetGame().IsServer())
  1781. {
  1782. if (e.IsServerSideOnly())
  1783. {
  1784. Error("[syncinv] " + Object.GetDebugName(player) + " SendServerHandEventViaJuncture - called on server side event only, e=" + e.DumpToString());
  1785. }
  1786. if (player.IsAlive())
  1787. {
  1788. InventoryLocation dst = e.GetDst();
  1789. InventoryLocation src = e.GetSrc();
  1790. if (src.IsValid() && dst.IsValid())
  1791. {
  1792. if (player.NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
  1793. {
  1794. #ifdef ENABLE_LOGGING
  1795. if (LogManager.IsSyncLogEnable())
  1796. {
  1797. syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") need juncture src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  1798. }
  1799. #endif
  1800. if (GetGame().AddInventoryJunctureEx(player, src.GetItem(), dst, true, GameInventory.c_InventoryReservationTimeoutMS))
  1801. {
  1802. #ifdef ENABLE_LOGGING
  1803. if (LogManager.IsSyncLogEnable())
  1804. {
  1805. syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") got juncture");
  1806. }
  1807. #endif
  1808. }
  1809. else
  1810. {
  1811. #ifdef ENABLE_LOGGING
  1812. if (LogManager.IsSyncLogEnable())
  1813. {
  1814. syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + ") !got juncture");
  1815. }
  1816. #endif
  1817. }
  1818. }
  1819. #ifdef ENABLE_LOGGING
  1820. if (LogManager.IsSyncLogEnable())
  1821. {
  1822. syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + " server hand event src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  1823. }
  1824. #endif
  1825. ScriptInputUserData ctx = new ScriptInputUserData;
  1826. InventoryInputUserData.SerializeHandEvent(ctx, e);
  1827. player.SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY, ctx);
  1828. #ifdef ENABLE_LOGGING
  1829. if (LogManager.IsSyncLogEnable())
  1830. {
  1831. syncDebugPrint("[syncinv] " + Object.GetDebugName(player) + " STS = " + player.GetSimulationTimeStamp() + " store input for remote - SendServerHandEventViaJuncture(" + typename.EnumToString(InventoryMode, InventoryMode.SERVER) + " server hand event src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  1832. }
  1833. #endif
  1834. //! Remote inputs are processed in sync juncture once performed on the server - this code below was executing the inventory command before the player simulation timeestamp for remotes which is illegal
  1835. //player.StoreInputForRemotes(ctx); // @TODO: is this right place? maybe in HandleInputData(server=true, ...)
  1836. }
  1837. }
  1838. else
  1839. {
  1840. Error("[syncinv] SendServerHandEventViaJuncture - called on dead player, juncture is for living only");
  1841. }
  1842. }
  1843. }
  1844. /**@fn NetSyncCurrentStateID
  1845. * @brief Engine callback - network synchronization of FSM's state. not intended to direct use.
  1846. **/
  1847. override void NetSyncCurrentStateID (int id)
  1848. {
  1849. super.NetSyncCurrentStateID(id);
  1850. GetDayZPlayerOwner().GetItemAccessor().OnItemInHandsChanged();
  1851. }
  1852. /**@fn OnAfterStoreLoad
  1853. * @brief engine reaction to load from database
  1854. * originates in:
  1855. * engine - Person::BinLoad
  1856. * script - PlayerBase.OnAfterStoreLoad
  1857. **/
  1858. override void OnAfterStoreLoad ()
  1859. {
  1860. GetDayZPlayerOwner().GetItemAccessor().OnItemInHandsChanged(true);
  1861. }
  1862. /**@fn OnEventForRemoteWeapon
  1863. * @brief reaction of remote weapon to (common user/anim/...) event sent from server
  1864. **/
  1865. bool OnEventForRemoteWeapon (ParamsReadContext ctx)
  1866. {
  1867. if (GetEntityInHands())
  1868. {
  1869. Weapon_Base wpn = Weapon_Base.Cast(GetEntityInHands());
  1870. if (wpn)
  1871. {
  1872. PlayerBase pb = PlayerBase.Cast(GetDayZPlayerOwner());
  1873. WeaponEventBase e = CreateWeaponEventFromContext(ctx);
  1874. if (pb && e)
  1875. {
  1876. pb.GetWeaponManager().SetRunning(true);
  1877. if (LogManager.IsWeaponLogEnable())
  1878. {
  1879. fsmDebugSpam("[wpnfsm] " + Object.GetDebugName(wpn) + " recv event from remote: created event=" + e);
  1880. }
  1881. if (e.GetEventID() == WeaponEventID.HUMANCOMMAND_ACTION_ABORTED)
  1882. {
  1883. wpn.ProcessWeaponAbortEvent(e);
  1884. }
  1885. else
  1886. {
  1887. wpn.ProcessWeaponEvent(e);
  1888. }
  1889. pb.GetWeaponManager().SetRunning(false);
  1890. }
  1891. }
  1892. else
  1893. Error("OnEventForRemoteWeapon - entity in hands, but not weapon. item=" + GetEntityInHands());
  1894. }
  1895. else
  1896. Error("OnEventForRemoteWeapon - no entity in hands");
  1897. return true;
  1898. }
  1899. /**@fn OnHandEventForRemote
  1900. * @brief reaction of remote weapon to (common user/anim/...) event sent from server
  1901. **/
  1902. bool OnHandEventForRemote (ParamsReadContext ctx)
  1903. {
  1904. HandEventBase e = HandEventBase.CreateHandEventFromContext(ctx);
  1905. if (e)
  1906. {
  1907. if (LogManager.IsInventoryHFSMLogEnable())
  1908. {
  1909. hndDebugSpam("[hndfsm] recv event from remote: created event=" + e);
  1910. }
  1911. //m_FSM.ProcessEvent(e);
  1912. if (e.GetEventID() == HandEventID.HUMANCOMMAND_ACTION_ABORTED)
  1913. {
  1914. ProcessEventResult aa;
  1915. m_FSM.ProcessAbortEvent(e, aa);
  1916. }
  1917. else
  1918. {
  1919. m_FSM.ProcessEvent(e);
  1920. }
  1921. return true;
  1922. }
  1923. return false;
  1924. }
  1925. void SyncHandEventToRemote (HandEventBase e)
  1926. {
  1927. DayZPlayer p = GetDayZPlayerOwner();
  1928. if (p && p.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  1929. {
  1930. ScriptRemoteInputUserData ctx = new ScriptRemoteInputUserData;
  1931. ctx.Write(INPUT_UDT_HAND_REMOTE_EVENT);
  1932. e.WriteToContext(ctx);
  1933. if (LogManager.IsInventoryHFSMLogEnable())
  1934. {
  1935. hndDebugPrint("[hndfsm] send 2 remote: sending e=" + e + " id=" + e.GetEventID() + " p=" + p + " e=" + e.DumpToString());
  1936. }
  1937. p.StoreInputForRemotes(ctx);
  1938. }
  1939. }
  1940. override void OnHandsExitedStableState (HandStateBase src, HandStateBase dst)
  1941. {
  1942. super.OnHandsExitedStableState(src, dst);
  1943. if (LogManager.IsInventoryHFSMLogEnable())
  1944. {
  1945. hndDebugPrint("[hndfsm] hand fsm exit stable src=" + src.Type().ToString());
  1946. }
  1947. }
  1948. override void OnHandsEnteredStableState (HandStateBase src, HandStateBase dst)
  1949. {
  1950. super.OnHandsEnteredStableState(src, dst);
  1951. if (LogManager.IsInventoryHFSMLogEnable())
  1952. {
  1953. hndDebugPrint("[hndfsm] hand fsm entered stable dst=" + dst.Type().ToString());
  1954. }
  1955. }
  1956. override void OnHandsStateChanged (HandStateBase src, HandStateBase dst)
  1957. {
  1958. super.OnHandsStateChanged(src, dst);
  1959. if (LogManager.IsInventoryHFSMLogEnable())
  1960. {
  1961. hndDebugPrint("[hndfsm] hand fsm changed state src=" + src.Type().ToString() + " ---> dst=" + dst.Type().ToString());
  1962. }
  1963. if (src.IsIdle())
  1964. OnHandsExitedStableState(src, dst);
  1965. if (dst.IsIdle())
  1966. OnHandsEnteredStableState(src, dst);
  1967. #ifdef DIAG_DEVELOPER
  1968. PlayerBase p = PlayerBase.Cast(GetDayZPlayerOwner());
  1969. if (p && p.m_Bot)
  1970. {
  1971. p.m_Bot.ProcessEvent(new BotEventOnItemInHandsChanged(p));
  1972. }
  1973. #endif
  1974. }
  1975. override bool HandEvent(InventoryMode mode, HandEventBase e)
  1976. {
  1977. if (!IsProcessing())
  1978. {
  1979. EntityAI itemInHands = GetEntityInHands();
  1980. InventoryLocation il = new InventoryLocation();
  1981. il.SetHands(GetInventoryOwner(), itemInHands);
  1982. InventoryValidation validation = new InventoryValidation();
  1983. if (e.CanPerformEventEx(validation))
  1984. {
  1985. m_DeferredEvent = new DeferredHandEvent(mode, e);
  1986. if (m_DeferredEvent.ReserveInventory(this))
  1987. {
  1988. return true;
  1989. }
  1990. }
  1991. m_DeferredEvent = null;
  1992. //! Let the client know a failure happened
  1993. if (!GetGame().IsMultiplayer() || GetGame().IsClient())
  1994. {
  1995. //! If singleplayer or the client is executing this
  1996. OnInventoryFailure(InventoryCommandType.HAND_EVENT, validation.m_Reason, e.GetSrc(), e.GetDst());
  1997. }
  1998. else
  1999. {
  2000. ScriptInputUserData serializer();
  2001. InventoryInputUserData.SerializeHandEvent(serializer, e);
  2002. serializer.Write(validation.m_Reason);
  2003. GetDayZPlayerOwner().SendSyncJuncture(DayZPlayerSyncJunctures.SJ_INVENTORY_FAILURE, serializer);
  2004. }
  2005. }
  2006. return false;
  2007. }
  2008. void HandleHandEvent(DeferredEvent deferred_event)
  2009. {
  2010. //! Default structure suffices
  2011. InventoryValidation validation = new InventoryValidation();
  2012. DeferredHandEvent deferred_hand_event = DeferredHandEvent.Cast(deferred_event);
  2013. if (deferred_hand_event)
  2014. {
  2015. #ifdef ENABLE_LOGGING
  2016. if (LogManager.IsInventoryHFSMLogEnable())
  2017. {
  2018. Debug.InventoryHFSMLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp(), "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString());
  2019. }
  2020. #endif
  2021. if (LogManager.IsInventoryHFSMLogEnable())
  2022. {
  2023. hndDebugPrint("[inv] HumanInventory::HandEvent(" + typename.EnumToString(InventoryMode, deferred_hand_event.m_mode) + ") ev=" + deferred_hand_event.m_event.DumpToString());
  2024. }
  2025. switch (deferred_hand_event.m_mode)
  2026. {
  2027. case InventoryMode.PREDICTIVE:
  2028. #ifdef ENABLE_LOGGING
  2029. if (LogManager.IsInventoryHFSMLogEnable())
  2030. {
  2031. Debug.InventoryHFSMLog("PREDICTIVE", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString());
  2032. }
  2033. #endif
  2034. deferred_hand_event.ClearInventoryReservation(this);
  2035. if (deferred_hand_event.m_event.CanPerformEventEx(validation))
  2036. {
  2037. InventoryInputUserData.SendInputUserDataHandEvent(deferred_hand_event.m_event);
  2038. ProcessHandEvent(deferred_hand_event.m_event);
  2039. }
  2040. break;
  2041. case InventoryMode.JUNCTURE:
  2042. #ifdef ENABLE_LOGGING
  2043. if (LogManager.IsInventoryHFSMLogEnable())
  2044. {
  2045. Debug.InventoryHFSMLog("JUNCTURE", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString());
  2046. }
  2047. #endif
  2048. deferred_hand_event.ClearInventoryReservation(this);
  2049. if (deferred_hand_event.m_event.CanPerformEventEx(validation))
  2050. {
  2051. deferred_hand_event.ReserveInventory(this);
  2052. InventoryInputUserData.SendInputUserDataHandEvent(deferred_hand_event.m_event);
  2053. //Functionality to prevent desync when two players perform interfering action at the same time
  2054. EntityAI itemSrc = deferred_hand_event.m_event.GetSrcEntity();
  2055. EntityAI itemDst = null;
  2056. if (deferred_hand_event.m_event.GetDst())
  2057. itemDst = deferred_hand_event.m_event.GetDst().GetItem();
  2058. if (itemSrc)
  2059. EnableMovableOverride(itemSrc);
  2060. if (itemDst)
  2061. EnableMovableOverride(itemDst);
  2062. }
  2063. break;
  2064. case InventoryMode.LOCAL:
  2065. #ifdef ENABLE_LOGGING
  2066. if (LogManager.IsInventoryHFSMLogEnable())
  2067. {
  2068. Debug.InventoryHFSMLog("LOCAL", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString());
  2069. }
  2070. #endif
  2071. deferred_hand_event.ClearInventoryReservation(this);
  2072. ProcessHandEvent(deferred_hand_event.m_event);
  2073. //PostHandEvent(deferred_hand_event.m_event);
  2074. break;
  2075. case InventoryMode.SERVER:
  2076. #ifdef ENABLE_LOGGING
  2077. if (LogManager.IsInventoryHFSMLogEnable())
  2078. {
  2079. Debug.InventoryHFSMLog("SERVER", "n/a" , "n/a", "HandleHandEvent", GetDayZPlayerOwner().ToString());
  2080. }
  2081. if (LogManager.IsInventoryHFSMLogEnable())
  2082. {
  2083. hndDebugPrint("[inv] DZPI::HandEvent(" + typename.EnumToString(InventoryMode, deferred_hand_event.m_mode) + ")");
  2084. }
  2085. #endif
  2086. if (!deferred_hand_event.m_event.IsServerSideOnly())
  2087. {
  2088. if (GetDayZPlayerOwner().IsAlive())
  2089. {
  2090. SendServerHandEventViaJuncture(GetDayZPlayerOwner(), deferred_hand_event.m_event);
  2091. }
  2092. else
  2093. {
  2094. InventoryInputUserData.SendServerHandEventViaInventoryCommand(GetDayZPlayerOwner(), deferred_hand_event.m_event);
  2095. }
  2096. }
  2097. else
  2098. {
  2099. ProcessHandEvent(deferred_hand_event.m_event);
  2100. }
  2101. break;
  2102. default:
  2103. Error("HumanInventory::HandEvent - Invalid mode");
  2104. }
  2105. }
  2106. }
  2107. override void HandleInventoryManipulation()
  2108. {
  2109. super.HandleInventoryManipulation();
  2110. if(m_DeferredEvent && ScriptInputUserData.CanStoreInputUserData() )
  2111. {
  2112. HandleHandEvent(m_DeferredEvent);
  2113. HandleTakeToDst(m_DeferredEvent);
  2114. HandleSwapEntities(m_DeferredEvent);
  2115. HandleForceSwapEntities(m_DeferredEvent);
  2116. m_DeferredEvent = null;
  2117. }
  2118. }
  2119. bool IsProcessing()
  2120. {
  2121. return !m_FSM.GetCurrentState().IsIdle() || m_DeferredEvent || m_DeferredPostedHandEvent;
  2122. }
  2123. bool PlayerCheckRequestSrc ( notnull InventoryLocation src, float radius )
  2124. {
  2125. bool result = true;
  2126. EntityAI ent = src.GetParent();
  2127. if ( ent )
  2128. {
  2129. PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
  2130. if (player)
  2131. {
  2132. if ( GetDayZPlayerOwner() != player )
  2133. {
  2134. if (player.IsAlive())
  2135. {
  2136. if (!player.IsRestrained() && !player.IsUnconscious())
  2137. {
  2138. return false;
  2139. }
  2140. }
  2141. }
  2142. }
  2143. }
  2144. if ( result )
  2145. {
  2146. result = CheckRequestSrc( GetManOwner(), src, radius);
  2147. }
  2148. return result;
  2149. }
  2150. bool PlayerCheckRequestDst ( notnull InventoryLocation src, notnull InventoryLocation dst, float radius )
  2151. {
  2152. bool result = true;
  2153. EntityAI ent = dst.GetParent();
  2154. if ( ent )
  2155. {
  2156. PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
  2157. if (player)
  2158. {
  2159. if ( GetDayZPlayerOwner() != player )
  2160. {
  2161. if (player.IsAlive())
  2162. {
  2163. if (!player.IsRestrained() && !player.IsUnconscious())
  2164. {
  2165. return false;
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. if ( result )
  2172. {
  2173. result = CheckMoveToDstRequest( GetManOwner(), src, dst, radius);
  2174. }
  2175. return result;
  2176. }
  2177. bool PlayerCheckSwapItemsRequest( notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2, float radius)
  2178. {
  2179. bool result = true;
  2180. EntityAI ent = dst1.GetParent();
  2181. PlayerBase player;
  2182. if ( ent )
  2183. {
  2184. player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
  2185. if (player)
  2186. {
  2187. if ( GetDayZPlayerOwner() != player )
  2188. {
  2189. if (player.IsAlive())
  2190. {
  2191. if (!player.IsRestrained() && !player.IsUnconscious())
  2192. {
  2193. return false;
  2194. }
  2195. }
  2196. }
  2197. }
  2198. }
  2199. ent = dst2.GetParent();
  2200. if ( ent )
  2201. {
  2202. player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
  2203. if (player)
  2204. {
  2205. if ( GetDayZPlayerOwner() != player )
  2206. {
  2207. if (player.IsAlive())
  2208. {
  2209. if (!player.IsRestrained() && !player.IsUnconscious())
  2210. {
  2211. return false;
  2212. }
  2213. }
  2214. }
  2215. }
  2216. }
  2217. if ( result )
  2218. {
  2219. result = CheckSwapItemsRequest( GetManOwner(), src1, src2, dst1, dst2, GameInventory.c_MaxItemDistanceRadius);
  2220. }
  2221. return result;
  2222. }
  2223. bool PlayerCheckDropRequest ( notnull InventoryLocation src, float radius )
  2224. {
  2225. bool result = true;
  2226. EntityAI ent = src.GetParent();
  2227. if ( ent )
  2228. {
  2229. PlayerBase player = PlayerBase.Cast(ent.GetHierarchyRootPlayer());
  2230. if (player)
  2231. {
  2232. if ( GetDayZPlayerOwner() != player )
  2233. {
  2234. if (player.IsAlive())
  2235. {
  2236. if (!player.IsRestrained() && !player.IsUnconscious())
  2237. {
  2238. return false;
  2239. }
  2240. }
  2241. }
  2242. }
  2243. }
  2244. if ( result )
  2245. {
  2246. result = CheckDropRequest( GetManOwner(), src, radius);
  2247. }
  2248. return result;
  2249. }
  2250. //! Local, checks only stuff that is in guaranteed sync
  2251. bool MoveCheckExclusionMaskLocal ( notnull InventoryLocation src, notnull InventoryLocation dst)
  2252. {
  2253. if (dst.GetType() == InventoryLocationType.ATTACHMENT)
  2254. {
  2255. return dst.GetParent().CheckAttachmentReceiveExclusion(src.GetItem(),dst.GetSlot());
  2256. }
  2257. return true;
  2258. }
  2259. //! Local, checks only stuff that is in guaranteed sync
  2260. bool SwapCheckExclusionMaskLocal ( notnull InventoryLocation src1, notnull InventoryLocation src2, notnull InventoryLocation dst1, notnull InventoryLocation dst2)
  2261. {
  2262. bool failed = false;
  2263. if (dst1.GetType() == InventoryLocationType.ATTACHMENT)
  2264. {
  2265. failed |= !dst1.GetParent().CheckAttachmentReceiveExclusion(dst1.GetItem(),dst1.GetSlot());
  2266. }
  2267. if (dst2.GetType() == InventoryLocationType.ATTACHMENT)
  2268. {
  2269. failed |= !dst2.GetParent().CheckAttachmentReceiveExclusion(dst2.GetItem(),dst2.GetSlot());
  2270. }
  2271. return !failed;
  2272. }
  2273. //! DEPRECATED
  2274. bool ValidateDestroy(inout Serializer ctx, InventoryValidation validation)
  2275. {
  2276. InventoryCommandType type = InventoryCommandType.DESTROY;
  2277. if (validation.m_IsJuncture)
  2278. {
  2279. /** TODO(kumarjac):
  2280. * Probably should be called through inventory juncture,
  2281. * we shouldn't allow the client to delete until the
  2282. * server says it is okay as there can be more reasons
  2283. * than "cheater" for it to be rejected such as desync
  2284. */
  2285. return true;
  2286. }
  2287. InventoryLocation src = new InventoryLocation;
  2288. src.ReadFromContext(ctx);
  2289. #ifdef ENABLE_LOGGING
  2290. if (LogManager.IsInventoryMoveLogEnable())
  2291. {
  2292. Debug.InventoryMoveLog("STS = " + GetDayZPlayerOwner().GetSimulationTimeStamp() + " src=" + InventoryLocation.DumpToStringNullSafe(src), "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  2293. }
  2294. #endif
  2295. if (validation.m_IsRemote && !src.GetItem())
  2296. {
  2297. #ifdef ENABLE_LOGGING
  2298. if (LogManager.IsInventoryMoveLogEnable())
  2299. {
  2300. Debug.InventoryMoveLog("Failed item not exist", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  2301. }
  2302. #endif
  2303. Error("[syncinv] HandleInputData remote input (cmd=DESTROY) dropped, item not in bubble");
  2304. return true;
  2305. }
  2306. //! Do not check for action validity on remotes or when performing through juncture.
  2307. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  2308. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  2309. if (!validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckRequestSrc(src, GameInventory.c_MaxItemDistanceRadius))
  2310. {
  2311. #ifdef ENABLE_LOGGING
  2312. if (LogManager.IsInventoryMoveLogEnable())
  2313. {
  2314. Debug.InventoryMoveLog("Failed CheckRequestSrc", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  2315. }
  2316. #endif
  2317. return true;
  2318. }
  2319. //! Do not check for action validity on remotes or when performing through juncture.
  2320. //! Juncture locks guarentee the item is safe to interact with and the server has validated the command at this point.
  2321. //! Checking at this point is both wasteful and can result in a failure which leads to desync
  2322. if (!validation.m_IsRemote && !validation.m_IsJuncture && !PlayerCheckDropRequest(src, GameInventory.c_MaxItemDistanceRadius))
  2323. {
  2324. #ifdef ENABLE_LOGGING
  2325. if (LogManager.IsInventoryMoveLogEnable())
  2326. {
  2327. Debug.InventoryMoveLog("Failed CheckDropRequest", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  2328. }
  2329. #endif
  2330. return true;
  2331. }
  2332. #ifdef ENABLE_LOGGING
  2333. if (LogManager.IsInventoryMoveLogEnable())
  2334. {
  2335. Debug.InventoryMoveLog("Success ObjectDelete", "DESTROY" , "n/a", "ProcessInputData", GetDayZPlayerOwner().ToString() );
  2336. }
  2337. #endif
  2338. GetGame().ObjectDelete(src.GetItem());
  2339. validation.m_Result = InventoryValidationResult.SUCCESS;
  2340. return true;
  2341. }
  2342. }