Advertisement
Guest User

Untitled

a guest
Apr 5th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /*
  2. File: asyncCall.sqf
  3. Author: Bryan "Tonic" Boardwine
  4.  
  5. Description:
  6. Commits an asynchronous call to extDB
  7. Gets result via extDB 4:x + uses 5:x if message is Multi-Part
  8.  
  9. Parameters:
  10. 0: STRING (Query to be ran).
  11. 1: INTEGER (1 = ASYNC + not return for update/insert, 2 = ASYNC + return for query's).
  12. 3: BOOL (False to return a single array, True to return multiple entries mainly for garage).
  13. */
  14.  
  15. private["_queryStmt","_queryResult","_key","_mode","_return","_loop"];
  16.  
  17. _tickTime = diag_tickTime;
  18.  
  19. _queryStmt = [_this,0,"",[""]] call BIS_fnc_param;
  20. _mode = [_this,1,1,[0]] call BIS_fnc_param;
  21. _multiarr = [_this,2,false,[false]] call BIS_fnc_param;
  22.  
  23. _key = "extDB2" callExtension format["%1:%2:%3",_mode, 1, _queryStmt];
  24.  
  25. if(_mode isEqualTo 1) exitWith {true};
  26.  
  27. _key = call compile format["%1",_key];
  28. _key = _key select 1;
  29.  
  30. uisleep (random .03);
  31.  
  32. // Get Result via 4:x (single message return) v19 and later
  33. _queryResult = "";
  34. _loop = true;
  35. while{_loop} do
  36. {
  37. _queryResult = "extDB2" callExtension format["4:%1", _key];
  38. if (_queryResult isEqualTo "[5]") then {
  39. // extDB2 returned that result is Multi-Part Message
  40. _queryResult = "";
  41. while{true} do {
  42. _pipe = "extDB2" callExtension format["5:%1", _key];
  43. if(_pipe isEqualTo "") exitWith {_loop = false};
  44. _queryResult = _queryResult + _pipe;
  45. };
  46. }
  47. else
  48. {
  49. if (_queryResult isEqualTo "[3]") then
  50. {
  51. diag_log format ["extDB2: uisleep [4]: %1", diag_tickTime];
  52. uisleep 0.1;
  53. } else {
  54. _loop = false;
  55. };
  56. };
  57. };
  58.  
  59.  
  60. _queryResult = call compile _queryResult;
  61.  
  62. // Not needed, its SQF Code incase extDB ever returns error message i.e Database Died
  63. if ((_queryResult select 0) isEqualTo 0) exitWith {diag_log format ["extDB2: Protocol Error: %1", _queryResult]; []};
  64. _return = (_queryResult select 1);
  65.  
  66. if(!_multiarr) then {
  67. _return = _return select 0;
  68. };
  69.  
  70. _return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement