Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
S
Server_Files
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 25
    • Issues 25
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • DesolationREDUX
  • Server_Files
  • Issues
  • #43

Closed
Open
Created Apr 03, 2020 by Legodev@legodevOwner

Secure way to use multiple objects as combined item source

Need a PluginManager solution for the following code. The idea is to have a list of items as well as a list of objects.

If the objects inventories in combination can fullfill the item lists request, then those items are removed from the inventories (on request) and true is returned. If the request cannot be fullfilled, then false is returned and no items are removed.

This check might take a while, so the object access has to be protected against timing attacks where people remove items from the objects in the right moment.

params["_itemList", "_sourcesList", ["_removeItems", false]];

private _originalSourcesCargo = [];
private _newSourcesCargo = [];
// backup cargo of source objects
{
	private _crate = _x;
	private _cargo = magazinesAmmoCargo _crate;
	if (_removeItems) then {
		clearMagazineCargoGlobal _crate;
	};
	_originalSourcesCargo pushBack _cargo;
} forEach _sourcesList;


{
	// only procede if _itemList is not empty
	if !(_itemList isEqualTo []) then {
		private _cargo = _x;
		private _newCargo = [];
	
		{
			private _mag = toLower(_cargo select 0);
			private _count = _cargo select 1;
				
			private _index = _itemList find _mag;
			if(_index != -1) then {
				_itemList deleteAt _index;
			} else {
				_newCargo pushback (_cargo);
			};
		} forEach _cargo;
		
		_newSourcesCargo pushback (_newCargo);
	} else {
		_newSourcesCargo pushback (_x);
	};
} forEach _originalSourcesCargo;

// readd removed items
if (_removeItems) then {
	// if items are missing readd all items
	if !(_itemList isEqualTo []) then {
		_newSourcesCargo = _originalSourcesCargo;
	};

	{
		private _crate = _x;
		private _cargo = _newSourcesCargo select _forEachIndex;
		{
			_crate addMagazineAmmoCargo _x;
		} forEach _cargo;
	} forEach _sourcesList;
};

_itemList isEqualTo []
Edited Apr 03, 2020 by Razer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
Apr 5, 2020
Due date
Apr 5, 2020