Guest User

Untitled

a guest
Aug 6th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.72 KB | None | 0 0
  1. /*
  2. Works to make any download request required.
  3. From pagination(making pages of the loadouts requested, for fitting into a UI)
  4. to Downloading a singular loadout by it's ID.
  5.  
  6. Author: Phpminor
  7. */
  8. _params = _this select 0;
  9. _playerID = _params select 0;
  10. _playerobj = _params select 1;
  11. _mode = _params select 2;
  12. urlparams = "";
  13. _code = "";
  14. switch(_mode) do {
  15.     case "byID": {
  16.     _ID = _params select 3;
  17.     urlparams = "?pgsz=1&pg=1&id=" + _ID;
  18.     _instructions = format ["%1",'
  19. _request = _request select 0 splitstring "&";
  20. missionNamespace setVariable ["DownloadedLoadout",nil];
  21. [_request select 1, "download", "nop"`] call func_ConvertToLoadout;
  22. waitUntil{_var = missionNamespace GetVariable ["DownloadedLoadout", "empty"]; _exit = false; if(_var isEqualType []) then {_exit = true}; if(_var IsEqualType "") then {if (_var != "empty") then {_exit = true}}; _exit};
  23. loadout = missionNamespace GetVariable["DownloadedLoadout", "error"];
  24. try {if (loadout isEqualType "") then{if (loadout == "error") throw "Error in func_CovertToLoadout, variable may have been deleted early!"}} catch{hint str _exception};
  25. _loadout = loadout;
  26. loadout = nil;
  27.  
  28. /*hint str _loadout;*/
  29. _playerobj setUnitLoadout _loadout;
  30. '];
  31.     missionNamespace setVariable ["DownloadCode",_instructions];
  32.     };
  33.     case "Paginate": {
  34.         _searchparams = _params select 3;
  35.         _page = missionNamespace getVariable["HTTPLoadoutPage",1];
  36.         if(_searchparams isEqualType []) then{
  37.         switch(count _searchparams) do { //quick check to set up a proper response(sets tag/username responses to be tag&username response)
  38.             case 4: {
  39.                 if(HTTPTagsAreForced != 0)
  40.                     then {_searchparams resize 2; _searchparams set[1,HTTPTagsForced]}};
  41.             case 8:{
  42.                 if(HTTPUsernameIsForced != 0)
  43.                     then {_searchparams resize 2; _searchparams set[1,_searchparams select 0]}}; //doesn't exactly matter if both entries in original are tags, in this case user is overwritten anyway.
  44.         };
  45.         switch(count _searchparams) do {  //we are effectively doing bitflags now using the number of array indexes, this is honestly cursed
  46.             case 2: {_searchparams = format["&user=%1&tags=%2",
  47.                 if(HTTPUsernameIsForced != 0)
  48.                     then{HTTPUsernameForced}
  49.                         else {_searchparams select 0},
  50.                 if(HTTPTagsAreForced != 0)
  51.                     then {if(_searchparams select 1 == "*")
  52.                         then {HTTPTagsForced}
  53.                             else{_str = _searchparams select 1; _num = count _str; _lastletter = _str select[_num-1]; if(_lastletter != ",")
  54.                                 then {_str + "," + HTTPTagsForced} // this is complicated, pretty much gets last letter to check if it's "," then decides to add a , between if last letter was not ,
  55.                             else {_str + HTTPTagsForced}}}
  56.                         else {_searchparams select 1}];
  57.                     };
  58.             case 4: {_searchparams = format["&user=%1",
  59.                 if(HTTPUsernameIsForced != 0)
  60.                     then {HTTPUsernameForced}
  61.                         else {_searchparams select 0}]};
  62.             case 8: {_searchparams = format["&tags=%1",
  63.                 if(HTTPTagsAreForced != 0)
  64.                     then{_str = _searchparams select 0; _num = count _str; _lastletter = _str select[_num-1]; if(_lastletter != ",")
  65.                         then {_str + "," + HTTPTagsForced}
  66.                             else {_str + HTTPTagsForced}}
  67.                         else {_searchparams select 0}]
  68.                         };
  69.             default {hint format["HTTPLoadoutSearchParams was not 2, 4, or 8 \n Received: %1 \n Searchparams = %2",_num,str _searchparams]; nil = nil};};
  70.         urlparams = "?pgsz=10&pg=" + str _page + _searchparams;
  71.         _instructions = format["%1",'_results = str _request splitstring "&"; [_results,_playerid] call func_PrepareResults;'];
  72.         missionNamespace setVariable ["DownloadCode",_instructions];
  73.         }
  74.         else{if (_searchparams isEqualType "String") then {
  75.         urlparams = "?pgsz=10&pg=" + str _page +_searchparams;
  76.         _instructions = format["%1",'_results = str _request splitstring "&"; [_results,_playerid] call func_PrepareResults;'];
  77.         missionNamespace setVariable ["DownloadCode",_instructions];}};
  78.     missionNamespace setVariable["HTTPLoadoutPage",nil];
  79. }};
  80. _instructions = missionnamespace getVariable["DownloadCode", "hint format['instructions have failed, no code. Mode was: %1',_mode]"];
  81. missionnamespace setVariable ["DownloadCode",nil];
  82. _code = compile _instructions;
  83. _url = HTTPServerUrl + "/loadout" + urlparams;
  84. "ArmaAsyncExt" callExtension ["GET",[_url]];
  85. //sleep 2; useless, for debugging
  86. testhandling1 = urlparams;
  87. urlparams = nil;
  88. _seconds = 0;
  89.  
  90. waituntil{_seconds = _seconds+diag_DeltaTime;
  91. request = "ArmaAsyncExt" callExtension ["Result",[""]];
  92. //hint str format ["Request has taken %1 seconds!\n\n Request\n%2", _seconds, request];
  93. request select 0 != "WAIT|Is requesting" && request select 0 != "WAIT|ready";
  94. };
  95. //hint format ["%1\n\n%2",request,_url];
  96. _request = request;
  97. request = nil; //transforming back to a non-global variable asap
  98. testhandling2 = _request;
  99.  
  100. call _code;
Advertisement
Add Comment
Please, Sign In to add comment