Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Works to make any download request required.
- From pagination(making pages of the loadouts requested, for fitting into a UI)
- to Downloading a singular loadout by it's ID.
- Author: Phpminor
- */
- _params = _this select 0;
- _playerID = _params select 0;
- _playerobj = _params select 1;
- _mode = _params select 2;
- urlparams = "";
- _code = "";
- switch(_mode) do {
- case "byID": {
- _ID = _params select 3;
- urlparams = "?pgsz=1&pg=1&id=" + _ID;
- _instructions = format ["%1",'
- _request = _request select 0 splitstring "&";
- missionNamespace setVariable ["DownloadedLoadout",nil];
- [_request select 1, "download", "nop"`] call func_ConvertToLoadout;
- 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};
- loadout = missionNamespace GetVariable["DownloadedLoadout", "error"];
- try {if (loadout isEqualType "") then{if (loadout == "error") throw "Error in func_CovertToLoadout, variable may have been deleted early!"}} catch{hint str _exception};
- _loadout = loadout;
- loadout = nil;
- /*hint str _loadout;*/
- _playerobj setUnitLoadout _loadout;
- '];
- missionNamespace setVariable ["DownloadCode",_instructions];
- };
- case "Paginate": {
- _searchparams = _params select 3;
- _page = missionNamespace getVariable["HTTPLoadoutPage",1];
- if(_searchparams isEqualType []) then{
- switch(count _searchparams) do { //quick check to set up a proper response(sets tag/username responses to be tag&username response)
- case 4: {
- if(HTTPTagsAreForced != 0)
- then {_searchparams resize 2; _searchparams set[1,HTTPTagsForced]}};
- case 8:{
- if(HTTPUsernameIsForced != 0)
- 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.
- };
- switch(count _searchparams) do { //we are effectively doing bitflags now using the number of array indexes, this is honestly cursed
- case 2: {_searchparams = format["&user=%1&tags=%2",
- if(HTTPUsernameIsForced != 0)
- then{HTTPUsernameForced}
- else {_searchparams select 0},
- if(HTTPTagsAreForced != 0)
- then {if(_searchparams select 1 == "*")
- then {HTTPTagsForced}
- else{_str = _searchparams select 1; _num = count _str; _lastletter = _str select[_num-1]; if(_lastletter != ",")
- 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 ,
- else {_str + HTTPTagsForced}}}
- else {_searchparams select 1}];
- };
- case 4: {_searchparams = format["&user=%1",
- if(HTTPUsernameIsForced != 0)
- then {HTTPUsernameForced}
- else {_searchparams select 0}]};
- case 8: {_searchparams = format["&tags=%1",
- if(HTTPTagsAreForced != 0)
- then{_str = _searchparams select 0; _num = count _str; _lastletter = _str select[_num-1]; if(_lastletter != ",")
- then {_str + "," + HTTPTagsForced}
- else {_str + HTTPTagsForced}}
- else {_searchparams select 0}]
- };
- default {hint format["HTTPLoadoutSearchParams was not 2, 4, or 8 \n Received: %1 \n Searchparams = %2",_num,str _searchparams]; nil = nil};};
- urlparams = "?pgsz=10&pg=" + str _page + _searchparams;
- _instructions = format["%1",'_results = str _request splitstring "&"; [_results,_playerid] call func_PrepareResults;'];
- missionNamespace setVariable ["DownloadCode",_instructions];
- }
- else{if (_searchparams isEqualType "String") then {
- urlparams = "?pgsz=10&pg=" + str _page +_searchparams;
- _instructions = format["%1",'_results = str _request splitstring "&"; [_results,_playerid] call func_PrepareResults;'];
- missionNamespace setVariable ["DownloadCode",_instructions];}};
- missionNamespace setVariable["HTTPLoadoutPage",nil];
- }};
- _instructions = missionnamespace getVariable["DownloadCode", "hint format['instructions have failed, no code. Mode was: %1',_mode]"];
- missionnamespace setVariable ["DownloadCode",nil];
- _code = compile _instructions;
- _url = HTTPServerUrl + "/loadout" + urlparams;
- "ArmaAsyncExt" callExtension ["GET",[_url]];
- //sleep 2; useless, for debugging
- testhandling1 = urlparams;
- urlparams = nil;
- _seconds = 0;
- waituntil{_seconds = _seconds+diag_DeltaTime;
- request = "ArmaAsyncExt" callExtension ["Result",[""]];
- //hint str format ["Request has taken %1 seconds!\n\n Request\n%2", _seconds, request];
- request select 0 != "WAIT|Is requesting" && request select 0 != "WAIT|ready";
- };
- //hint format ["%1\n\n%2",request,_url];
- _request = request;
- request = nil; //transforming back to a non-global variable asap
- testhandling2 = _request;
- call _code;
Advertisement
Add Comment
Please, Sign In to add comment