Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. /*
  2. File: fn_queryRequest.sqf
  3. Author: Bryan "Tonic" Boardwine
  4.  
  5. Description:
  6. Handles the incoming request and sends an asynchronous query
  7. request to the database.
  8.  
  9. Return:
  10. ARRAY - If array has 0 elements it should be handled as an error in client-side files.
  11. STRING - The request had invalid handles or an unknown error and is logged to the RPT.
  12. */
  13. private["_uid","_side","_query","_return","_queryResult","_qResult","_handler","_thread","_tickTime","_loops","_returnCount","_retHouses","_queryGang","_Gangqhandle","_threadGang","_queryGangResult"];
  14. _uid = [_this,0,"",[""]] call BIS_fnc_param;
  15. _side = [_this,1,sideUnknown,[civilian]] call BIS_fnc_param;
  16. _ownerID = [_this,2,ObjNull,[ObjNull]] call BIS_fnc_param;
  17.  
  18. if(isNull _ownerID) exitWith {};
  19. _ownerID = owner _ownerID;
  20.  
  21. /*
  22. _returnCount is the count of entries we are expecting back from the async call.
  23. The other part is well the SQL statement.
  24. */
  25. _query = switch(_side) do {
  26. case west: {_returnCount = 11; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, cop_licenses, coplevel, cop_gear, blacklist, swatlevel, cop_alive, cop_position FROM players WHERE playerid='%1'",_uid];};
  27. case civilian: {_returnCount = 9; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, civ_licenses, arrested, civ_gear, civ_alive, civ_position FROM players WHERE playerid='%1'",_uid];};
  28. case independent: {_returnCount = 9; format["SELECT playerid, name, cash, bankacc, adminlevel, donatorlvl, med_licenses, mediclevel, med_gear, med_alive, med_position FROM players WHERE playerid='%1'",_uid];};
  29. };
  30.  
  31. waitUntil{sleep (random 0.3); !DB_Async_Active};
  32. _tickTime = diag_tickTime;
  33. _queryResult = [_query,2] call DB_fnc_asyncCall;
  34.  
  35. diag_log "------------- Client Query Request -------------";
  36. diag_log format["QUERY: %1",_query];
  37. diag_log format["Time to complete: %1 (in seconds)",(diag_tickTime - _tickTime)];
  38. diag_log format["Result: %1",_queryResult];
  39. diag_log "------------------------------------------------";
  40.  
  41. if(typeName _queryResult == "STRING") exitWith {
  42. [[],"SOCK_fnc_insertPlayerInfo",_ownerID,false,true] spawn life_fnc_MP;
  43. };
  44.  
  45. if(count _queryResult == 0) exitWith {
  46. [[],"SOCK_fnc_insertPlayerInfo",_ownerID,false,true] spawn life_fnc_MP;
  47. };
  48.  
  49. //Blah conversion thing from a2net->extdb
  50. private["_tmp"];
  51. _tmp = _queryResult select 2;
  52. _queryResult set[2,[_tmp] call DB_fnc_numberSafe];
  53. _tmp = _queryResult select 3;
  54. _queryResult set[3,[_tmp] call DB_fnc_numberSafe];
  55.  
  56. //Parse licenses (Always index 6)
  57. _new = [(_queryResult select 6)] call DB_fnc_mresToArray;
  58. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  59. _queryResult set[6,_new];
  60.  
  61. //Convert tinyint to boolean
  62. _old = _queryResult select 6;
  63. for "_i" from 0 to (count _old)-1 do
  64. {
  65. _data = _old select _i;
  66. _old set[_i,[_data select 0, ([_data select 1,1] call DB_fnc_bool)]];
  67. };
  68.  
  69. _queryResult set[6,_old];
  70.  
  71. _new = [(_queryResult select 8)] call DB_fnc_mresToArray;
  72. if(typeName _new == "STRING") then {_new = call compile format["%1", _new];};
  73. _queryResult set[8,_new];
  74. //Parse data for specific side.
  75. switch (_side) do {
  76. case west: {
  77. _queryResult set[9,([_queryResult select 9,1] call DB_fnc_bool)];
  78. _queryResult set[11,([_queryResult select 11,1] call DB_fnc_bool)];
  79. };
  80.  
  81. case civilian: {
  82. _queryResult set[7,([_queryResult select 7,1] call DB_fnc_bool)];
  83.  
  84. _queryResult set[9,([_queryResult select 9,1] call DB_fnc_bool)];
  85.  
  86. _houseData = _uid spawn TON_fnc_fetchPlayerHouses;
  87. waitUntil {scriptDone _houseData};
  88. _queryResult set[count _queryResult,(missionNamespace getVariable[format["houses_%1",_uid],[]])];
  89. _gangData = _uid spawn TON_fnc_queryPlayerGang;
  90. waitUntil{scriptDone _gangData};
  91. _queryResult set[count _queryResult,(missionNamespace getVariable[format["gang_%1",_uid],[]])];
  92. };
  93.  
  94. case independent: {
  95. _queryResult set[9,([_queryResult select 9,1] call DB_fnc_bool)];
  96. };
  97. };
  98.  
  99. _keyArr = missionNamespace getVariable [format["%1_KEYS_%2",_uid,_side],[]];
  100. _queryResult set[12,_keyArr];
  101.  
  102. [_queryResult,"SOCK_fnc_requestReceived",_ownerID,false] spawn life_fnc_MP;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement